@@ -44,7 +44,6 @@ const char template[] = "temp_dir_XXXXXX";
4444
4545struct test_server_st {
4646 struct torture_state * state ;
47- struct server_state_st * ss ;
4847 char * cwd ;
4948 char * temp_dir ;
5049 char ed25519_hostkey [1024 ];
@@ -195,78 +194,19 @@ static int teardown_temp_dir(void **state)
195194 return 0 ;
196195}
197196
198- static struct server_state_st * setup_server_state (char * config_file ,
199- bool parse_global )
200- {
201- struct server_state_st * ss = NULL ;
202-
203- assert_non_null (config_file );
204-
205- /* Create default server state */
206- ss = (struct server_state_st * )calloc (1 , sizeof (struct server_state_st ));
207- assert_non_null (ss );
208-
209- ss -> address = strdup ("127.0.0.10" );
210- assert_non_null (ss -> address );
211-
212- ss -> port = 22 ;
213- ss -> host_key = NULL ;
214-
215- /* Use default username and password (set in default_handle_session_cb) */
216- ss -> expected_username = NULL ;
217- ss -> expected_password = NULL ;
218-
219- ss -> verbosity = torture_libssh_verbosity ();
220- ss -> auth_methods = SSH_AUTH_METHOD_PASSWORD | SSH_AUTH_METHOD_PUBLICKEY ;
221-
222- /* TODO make configurable */
223- ss -> max_tries = 3 ;
224- ss -> error = 0 ;
225-
226- /* Use the default session handling function */
227- ss -> handle_session = default_handle_session_cb ;
228- assert_non_null (ss -> handle_session );
229-
230- /* Set if should parse global configuration before */
231- ss -> parse_global_config = parse_global ;
232-
233- /* Set the config file to be used */
234- ss -> config_file = strdup (config_file );
235- assert_non_null (ss -> config_file );
236-
237- return ss ;
238- }
239-
240197static int start_server (void * * state )
241198{
242199 struct test_server_st * tss = * state ;
243200 struct torture_state * s ;
244- struct server_state_st * ss ;
245-
246- char pid_str [1024 ];
247- pid_t pid ;
248201
249202 assert_non_null (tss );
250203
251204 s = tss -> state ;
252205 assert_non_null (s );
253206
254- ss = tss -> ss ;
255- assert_non_null (ss );
256-
257207 /* Start the server using the default values */
258- pid = fork_run_server (ss );
259- if (pid < 0 ) {
260- fail ();
261- }
262-
263- snprintf (pid_str , sizeof (pid_str ), "%d" , pid );
264-
265- torture_write_file (s -> srv_pidfile , (const char * )pid_str );
266-
267- /* TODO properly wait for the server (use ping approach) */
268- /* Wait 200ms */
269- usleep (200 * 1000 );
208+ torture_setup_libssh_server ((void * * )& s , "./test_server/test_server" );
209+ assert_non_null (s );
270210
271211 return 0 ;
272212}
@@ -349,9 +289,7 @@ static int try_config_content(void **state, const char *config_content,
349289 bool parse_global )
350290{
351291 struct test_server_st * tss = * state ;
352- struct server_state_st * ss ;
353292 struct torture_state * s ;
354- char config_file [1024 ];
355293 int rc ;
356294
357295 ssh_session session ;
@@ -361,23 +299,19 @@ static int try_config_content(void **state, const char *config_content,
361299 s = tss -> state ;
362300 assert_non_null (s );
363301
364- /* Prepare the config file to test */
365- snprintf (config_file ,
366- sizeof (config_file ),
367- "%s/config_file" ,
368- tss -> temp_dir );
302+ assert_non_null (s -> srv_config );
369303
370304 if (parse_global ) {
371305 fprintf (stderr , "Using system-wide configuration\n" );
306+ } else {
307+ /* The string is duplicated to not break the cleanup on error */
308+ s -> srv_additional_config = strdup ("-g" );
372309 }
373- fprintf (stderr , "Trying content: \n\n%s\n" , config_content );
374-
375- torture_write_file (config_file , config_content );
376310
377- ss = setup_server_state (config_file , parse_global );
378- assert_non_null (ss );
311+ torture_write_file (s -> srv_config , config_content );
379312
380- tss -> ss = ss ;
313+ fprintf (stderr , "Config file %s content: \n\n%s\n" , s -> srv_config ,
314+ config_content );
381315
382316 rc = start_server (state );
383317 assert_int_equal (rc , 0 );
@@ -412,10 +346,7 @@ static int try_config_content(void **state, const char *config_content,
412346 rc = stop_server (state );
413347 assert_int_equal (rc , 0 );
414348
415- free_server_state (tss -> ss );
416- SAFE_FREE (tss -> ss );
417-
418- unlink (config_file );
349+ SAFE_FREE (s -> srv_additional_config );
419350
420351 return 0 ;
421352}
0 commit comments