From 3d77e0dfbdca29c261506493011b637ef2cd791f Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Tue, 14 Sep 2010 08:45:05 +0000 Subject: some testing changes, features added --- src/testing/test_testing.c | 2 +- src/testing/test_testing_group_remote.c | 28 ++++++++-- src/testing/testing.c | 96 ++++++++++++++++++++++++++------- src/testing/testing_group.c | 62 ++++++++++++++++++++- 4 files changed, 163 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/testing/test_testing.c b/src/testing/test_testing.c index dcfb7be43..519ccc31f 100644 --- a/src/testing/test_testing.c +++ b/src/testing/test_testing.c @@ -74,7 +74,7 @@ run (void *cls, #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n"); #endif - d = GNUNET_TESTING_daemon_start (sched, cfg, TIMEOUT, NULL, NULL, NULL, &my_cb, NULL); + d = GNUNET_TESTING_daemon_start (sched, cfg, TIMEOUT, NULL, NULL, 0, NULL, NULL, &my_cb, NULL); GNUNET_assert (d != NULL); } diff --git a/src/testing/test_testing_group_remote.c b/src/testing/test_testing_group_remote.c index a58a1234e..a0ef63847 100644 --- a/src/testing/test_testing_group_remote.c +++ b/src/testing/test_testing_group_remote.c @@ -88,13 +88,13 @@ my_cb (void *cls, peers_left--; if (peers_left == 0) { - GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); + //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); ok = 0; } else if (peers_failed == peers_left) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); - GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); + //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); } } @@ -113,6 +113,7 @@ run (void *cls, char *buf; char *data; int count; + int ret; sched = s; ok = 1; #if VERBOSE @@ -165,11 +166,27 @@ run (void *cls, while (count < frstat.st_size) { count++; - if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count])) + if (count >= frstat.st_size) + break; + + /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count]))*/ + if (((data[count] == '\n')) && (buf != &data[count])) { data[count] = '\0'; temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host)); - temphost->hostname = buf; + ret = sscanf(buf, "%a[a-zA-Z0-9]@%a[a-zA-Z0-9.]:%hd", &temphost->username, &temphost->hostname, &temphost->port); + if (3 == ret) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Successfully read host %s, port %d and user %s from file\n", temphost->hostname, temphost->port, temphost->username); + } + else + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Error reading line `%s' in hostfile\n", buf); + GNUNET_free(temphost); + buf = &data[count + 1]; + continue; + } + /* temphost->hostname = buf; */ temphost->next = hosts; hosts = temphost; buf = &data[count + 1]; @@ -195,11 +212,14 @@ run (void *cls, while (hostpos != NULL) { temphost = hostpos->next; + GNUNET_free(hostpos->hostname); + GNUNET_free(hostpos->username); GNUNET_free(hostpos); hostpos = temphost; } GNUNET_free_non_null(data); GNUNET_assert (pg != NULL); + } static int diff --git a/src/testing/testing.c b/src/testing/testing.c index 4ece9359d..8156e6a0a 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -283,14 +283,28 @@ start_fsm (void *cls, "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", d->cfgfile, "-sq"); #endif - d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", - "ssh", + if (d->ssh_port_str == NULL) + { + d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", + "ssh", #if !DEBUG_TESTING - "-q", + "-q", #endif - dst, - "gnunet-peerinfo", - "-c", d->cfgfile, "-sq", NULL); + dst, + "gnunet-peerinfo", + "-c", d->cfgfile, "-sq", NULL); + } + else + { + d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", + "ssh", "-p", d->ssh_port_str, +#if !DEBUG_TESTING + "-q", +#endif + dst, + "gnunet-peerinfo", + "-c", d->cfgfile, "-sq", NULL); + } GNUNET_DISK_pipe_close_end(d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); GNUNET_free (dst); } @@ -446,17 +460,35 @@ start_fsm (void *cls, "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", d->cfgfile, "-L", "DEBUG", "-s", "-q"); #endif - d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh", - "ssh", + if (d->ssh_port_str == NULL) + { + d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh", + "ssh", #if !DEBUG_TESTING - "-q", + "-q", #endif - dst, - "gnunet-arm", + dst, + "gnunet-arm", #if DEBUG_TESTING - "-L", "DEBUG", + "-L", "DEBUG", #endif - "-c", d->cfgfile, "-s", "-q", NULL); + "-c", d->cfgfile, "-s", "-q", NULL); + } + else + { + + d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh", + "ssh", "-p", d->ssh_port_str, +#if !DEBUG_TESTING + "-q", +#endif + dst, + "gnunet-arm", +#if DEBUG_TESTING + "-L", "DEBUG", +#endif + "-c", d->cfgfile, "-s", "-q", NULL); + } GNUNET_free (dst); } if (-1 == d->pid) @@ -708,6 +740,8 @@ GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon, * @param timeout how long to wait starting up peers * @param hostname name of the machine where to run GNUnet * (use NULL for localhost). + * @param ssh_username ssh username to use when connecting to hostname + * @param sshport port to pass to ssh process when connecting to hostname * @param hostkey_callback function to call once the hostkey has been * generated for this peer, but it hasn't yet been started * (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start) @@ -721,6 +755,8 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TIME_Relative timeout, const char *hostname, + const char *ssh_username, + uint16_t sshport, GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback, void *hostkey_cls, GNUNET_TESTING_NotifyDaemonRunning cb, @@ -733,6 +769,12 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon)); ret->sched = sched; ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname); + if (sshport != 0) + { + GNUNET_asprintf(&ret->ssh_port_str, "%d", sshport); + } + else + ret->ssh_port_str = NULL; ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config"); #if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -766,10 +808,12 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, GNUNET_free (ret); return NULL; } - if (GNUNET_OK != + if (ssh_username != NULL) + username = GNUNET_strdup(ssh_username); + if ((ssh_username == NULL) && (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", - "USERNAME", &username)) + "USERNAME", &username))) { if (NULL != getenv ("USER")) username = GNUNET_strdup (getenv ("USER")); @@ -790,12 +834,25 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile); else GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile); - ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp", - "scp", + + if (ret->ssh_port_str == NULL) + { + ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp", + "scp", #if !DEBUG_TESTING - "-q", + "-q", #endif - ret->cfgfile, arg, NULL); + ret->cfgfile, arg, NULL); + } + else + { + ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp", + "scp", "-P", ret->ssh_port_str, +#if !DEBUG_TESTING + "-q", +#endif + ret->cfgfile, arg, NULL); + } GNUNET_free (arg); if (-1 == ret->pid) { @@ -983,6 +1040,7 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, GNUNET_free_non_null (d->username); if (NULL != d->dead_cb) d->dead_cb (d->dead_cb_cls, NULL); + GNUNET_free(d); return; } diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 622afcd63..1c9f1c4bb 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -242,6 +242,18 @@ struct InternalStartContext * Hostname, where to start the peer */ const char *hostname; + + /** + * Username to use when connecting to the + * host via ssh. + */ + const char *username; + + /** + * Port to use for ssh. + */ + uint16_t sshport; + }; /** @@ -311,6 +323,16 @@ struct HostData */ char *hostname; + /** + * SSH username to use when connecting to this host. + */ + char *username; + + /** + * SSH port to use when connecting to this host. + */ + uint16_t sshport; + /** * Lowest port that we have not yet used * for GNUnet. @@ -729,6 +751,7 @@ update_config (void *cls, value = uval; } GNUNET_free(single_variable); + GNUNET_free(per_host_variable); } @@ -816,6 +839,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-udp", "BINDTO", "127.0.0.1"); } + *port = (uint16_t) uc.nport; *upnum = uc.upnum; uc.fdnum++; @@ -3312,6 +3336,8 @@ internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) internal_context->peer->cfg, internal_context->timeout, internal_context->hostname, + internal_context->username, + internal_context->sshport, &internal_hostkey_callback, internal_context, &internal_startup_callback, @@ -3387,6 +3413,7 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, char *start; #endif const char *hostname; + const char *username; char *baseservicehome; char *newservicehome; char *tmpdir; @@ -3394,6 +3421,7 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, unsigned int off; unsigned int hostcnt; uint16_t minport; + uint16_t sshport; uint32_t upnum; uint32_t fdnum; @@ -3428,7 +3456,11 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, while (hostpos != NULL) { pg->hosts[off].minport = LOW_PORT; - pg->hosts[off++].hostname = GNUNET_strdup(hostpos->hostname); + off++; + pg->hosts[off].hostname = GNUNET_strdup(hostpos->hostname); + if (hostpos->username != NULL) + pg->hosts[off].username = GNUNET_strdup(hostpos->username); + pg->hosts[off].sshport = hostpos->port; hostpos = hostpos->next; } @@ -3495,6 +3527,8 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, if (hostcnt > 0) { hostname = pg->hosts[off % hostcnt].hostname; + username = pg->hosts[off % hostcnt].username; + sshport = pg->hosts[off % hostcnt].sshport; pcfg = make_config (cfg, &pg->hosts[off % hostcnt].minport, &upnum, @@ -3503,6 +3537,8 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, else { hostname = NULL; + username = NULL; + sshport = 0; pcfg = make_config (cfg, &minport, &upnum, @@ -3548,6 +3584,8 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, pg->peers[off].internal_context.peer = &pg->peers[off]; pg->peers[off].internal_context.timeout = timeout; pg->peers[off].internal_context.hostname = hostname; + pg->peers[off].internal_context.username = username; + pg->peers[off].internal_context.sshport = sshport; pg->peers[off].internal_context.hostkey_callback = hostkey_callback; pg->peers[off].internal_context.hostkey_cls = hostkey_cls; pg->peers[off].internal_context.start_cb = cb; @@ -3740,6 +3778,28 @@ churn_start_callback (void *cls, } } +/** + * Count the number of running peers. + * + * @param pg handle for the peer group + * + * @return the number of currently running peers in the peer group + */ +unsigned int +GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg) +{ + unsigned int i; + unsigned int running = 0; + for (i = 0; i < pg->total; i++) + { + if (pg->peers[i].daemon->running == GNUNET_YES) + { + GNUNET_assert(running != -1); + running++; + } + } + return running; +} /** * Simulate churn by stopping some peers (and possibly -- cgit v1.2.3