aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2019-08-19 14:20:55 +0200
committerAndreas Schneider <asn@cryptomilk.org>2020-03-29 10:00:57 +0200
commitb06b9368192f493bef86105de9522badc6222ad2 (patch)
tree2d3a0c2d55d17a06896ec12c79a68ae62e380e09 /tests
parent3feb6ebe281b58b06ca8170813e0883fe9fcdaea (diff)
downloadlibssh-b06b9368192f493bef86105de9522badc6222ad2.tar.gz
libssh-b06b9368192f493bef86105de9522badc6222ad2.tar.xz
libssh-b06b9368192f493bef86105de9522badc6222ad2.zip
torture_server_config: Run the server under timeout
Timeout will kill the server if it hangs. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/server/torture_server_config.c89
1 files changed, 10 insertions, 79 deletions
diff --git a/tests/server/torture_server_config.c b/tests/server/torture_server_config.c
index d8ee697e..88385752 100644
--- a/tests/server/torture_server_config.c
+++ b/tests/server/torture_server_config.c
@@ -44,7 +44,6 @@ const char template[] = "temp_dir_XXXXXX";
struct test_server_st {
struct torture_state *state;
- struct server_state_st *ss;
char *cwd;
char *temp_dir;
char ed25519_hostkey[1024];
@@ -195,78 +194,19 @@ static int teardown_temp_dir(void **state)
return 0;
}
-static struct server_state_st *setup_server_state(char *config_file,
- bool parse_global)
-{
- struct server_state_st *ss = NULL;
-
- assert_non_null(config_file);
-
- /* Create default server state */
- ss = (struct server_state_st *)calloc(1, sizeof(struct server_state_st));
- assert_non_null(ss);
-
- ss->address = strdup("127.0.0.10");
- assert_non_null(ss->address);
-
- ss->port = 22;
- ss->host_key = NULL;
-
- /* Use default username and password (set in default_handle_session_cb) */
- ss->expected_username = NULL;
- ss->expected_password = NULL;
-
- ss->verbosity = torture_libssh_verbosity();
- ss->auth_methods = SSH_AUTH_METHOD_PASSWORD | SSH_AUTH_METHOD_PUBLICKEY;
-
- /* TODO make configurable */
- ss->max_tries = 3;
- ss->error = 0;
-
- /* Use the default session handling function */
- ss->handle_session = default_handle_session_cb;
- assert_non_null(ss->handle_session);
-
- /* Set if should parse global configuration before */
- ss->parse_global_config = parse_global;
-
- /* Set the config file to be used */
- ss->config_file = strdup(config_file);
- assert_non_null(ss->config_file);
-
- return ss;
-}
-
static int start_server(void **state)
{
struct test_server_st *tss = *state;
struct torture_state *s;
- struct server_state_st *ss;
-
- char pid_str[1024];
- pid_t pid;
assert_non_null(tss);
s = tss->state;
assert_non_null(s);
- ss = tss->ss;
- assert_non_null(ss);
-
/* Start the server using the default values */
- pid = fork_run_server(ss);
- if (pid < 0) {
- fail();
- }
-
- snprintf(pid_str, sizeof(pid_str), "%d", pid);
-
- torture_write_file(s->srv_pidfile, (const char *)pid_str);
-
- /* TODO properly wait for the server (use ping approach) */
- /* Wait 200ms */
- usleep(200 * 1000);
+ torture_setup_libssh_server((void **)&s, "./test_server/test_server");
+ assert_non_null(s);
return 0;
}
@@ -349,9 +289,7 @@ static int try_config_content(void **state, const char *config_content,
bool parse_global)
{
struct test_server_st *tss = *state;
- struct server_state_st *ss;
struct torture_state *s;
- char config_file[1024];
int rc;
ssh_session session;
@@ -361,23 +299,19 @@ static int try_config_content(void **state, const char *config_content,
s = tss->state;
assert_non_null(s);
- /* Prepare the config file to test */
- snprintf(config_file,
- sizeof(config_file),
- "%s/config_file",
- tss->temp_dir);
+ assert_non_null(s->srv_config);
if (parse_global) {
fprintf(stderr, "Using system-wide configuration\n");
+ } else {
+ /* The string is duplicated to not break the cleanup on error */
+ s->srv_additional_config = strdup("-g");
}
- fprintf(stderr, "Trying content: \n\n%s\n", config_content);
-
- torture_write_file(config_file, config_content);
- ss = setup_server_state(config_file, parse_global);
- assert_non_null(ss);
+ torture_write_file(s->srv_config, config_content);
- tss->ss = ss;
+ fprintf(stderr, "Config file %s content: \n\n%s\n", s->srv_config,
+ config_content);
rc = start_server(state);
assert_int_equal(rc, 0);
@@ -412,10 +346,7 @@ static int try_config_content(void **state, const char *config_content,
rc = stop_server(state);
assert_int_equal(rc, 0);
- free_server_state(tss->ss);
- SAFE_FREE(tss->ss);
-
- unlink(config_file);
+ SAFE_FREE(s->srv_additional_config);
return 0;
}