aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/testing/test_testing.c2
-rw-r--r--src/testing/test_testing_group_remote.c28
-rw-r--r--src/testing/testing.c96
-rw-r--r--src/testing/testing_group.c62
4 files changed, 163 insertions, 25 deletions
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,
74#if VERBOSE 74#if VERBOSE
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n"); 75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n");
76#endif 76#endif
77 d = GNUNET_TESTING_daemon_start (sched, cfg, TIMEOUT, NULL, NULL, NULL, &my_cb, NULL); 77 d = GNUNET_TESTING_daemon_start (sched, cfg, TIMEOUT, NULL, NULL, 0, NULL, NULL, &my_cb, NULL);
78 GNUNET_assert (d != NULL); 78 GNUNET_assert (d != NULL);
79} 79}
80 80
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,
88 peers_left--; 88 peers_left--;
89 if (peers_left == 0) 89 if (peers_left == 0)
90 { 90 {
91 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 91 //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
92 ok = 0; 92 ok = 0;
93 } 93 }
94 else if (peers_failed == peers_left) 94 else if (peers_failed == peers_left)
95 { 95 {
96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); 96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n");
97 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 97 //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
98 } 98 }
99} 99}
100 100
@@ -113,6 +113,7 @@ run (void *cls,
113 char *buf; 113 char *buf;
114 char *data; 114 char *data;
115 int count; 115 int count;
116 int ret;
116 sched = s; 117 sched = s;
117 ok = 1; 118 ok = 1;
118#if VERBOSE 119#if VERBOSE
@@ -165,11 +166,27 @@ run (void *cls,
165 while (count < frstat.st_size) 166 while (count < frstat.st_size)
166 { 167 {
167 count++; 168 count++;
168 if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count])) 169 if (count >= frstat.st_size)
170 break;
171
172 /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count]))*/
173 if (((data[count] == '\n')) && (buf != &data[count]))
169 { 174 {
170 data[count] = '\0'; 175 data[count] = '\0';
171 temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host)); 176 temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host));
172 temphost->hostname = buf; 177 ret = sscanf(buf, "%a[a-zA-Z0-9]@%a[a-zA-Z0-9.]:%hd", &temphost->username, &temphost->hostname, &temphost->port);
178 if (3 == ret)
179 {
180 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Successfully read host %s, port %d and user %s from file\n", temphost->hostname, temphost->port, temphost->username);
181 }
182 else
183 {
184 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Error reading line `%s' in hostfile\n", buf);
185 GNUNET_free(temphost);
186 buf = &data[count + 1];
187 continue;
188 }
189 /* temphost->hostname = buf; */
173 temphost->next = hosts; 190 temphost->next = hosts;
174 hosts = temphost; 191 hosts = temphost;
175 buf = &data[count + 1]; 192 buf = &data[count + 1];
@@ -195,11 +212,14 @@ run (void *cls,
195 while (hostpos != NULL) 212 while (hostpos != NULL)
196 { 213 {
197 temphost = hostpos->next; 214 temphost = hostpos->next;
215 GNUNET_free(hostpos->hostname);
216 GNUNET_free(hostpos->username);
198 GNUNET_free(hostpos); 217 GNUNET_free(hostpos);
199 hostpos = temphost; 218 hostpos = temphost;
200 } 219 }
201 GNUNET_free_non_null(data); 220 GNUNET_free_non_null(data);
202 GNUNET_assert (pg != NULL); 221 GNUNET_assert (pg != NULL);
222
203} 223}
204 224
205static int 225static 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,
283 "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", d->cfgfile, 283 "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", d->cfgfile,
284 "-sq"); 284 "-sq");
285#endif 285#endif
286 d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", 286 if (d->ssh_port_str == NULL)
287 "ssh", 287 {
288 d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
289 "ssh",
288#if !DEBUG_TESTING 290#if !DEBUG_TESTING
289 "-q", 291 "-q",
290#endif 292#endif
291 dst, 293 dst,
292 "gnunet-peerinfo", 294 "gnunet-peerinfo",
293 "-c", d->cfgfile, "-sq", NULL); 295 "-c", d->cfgfile, "-sq", NULL);
296 }
297 else
298 {
299 d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
300 "ssh", "-p", d->ssh_port_str,
301#if !DEBUG_TESTING
302 "-q",
303#endif
304 dst,
305 "gnunet-peerinfo",
306 "-c", d->cfgfile, "-sq", NULL);
307 }
294 GNUNET_DISK_pipe_close_end(d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); 308 GNUNET_DISK_pipe_close_end(d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
295 GNUNET_free (dst); 309 GNUNET_free (dst);
296 } 310 }
@@ -446,17 +460,35 @@ start_fsm (void *cls,
446 "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", d->cfgfile, 460 "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", d->cfgfile,
447 "-L", "DEBUG", "-s", "-q"); 461 "-L", "DEBUG", "-s", "-q");
448#endif 462#endif
449 d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh", 463 if (d->ssh_port_str == NULL)
450 "ssh", 464 {
465 d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
466 "ssh",
451#if !DEBUG_TESTING 467#if !DEBUG_TESTING
452 "-q", 468 "-q",
453#endif 469#endif
454 dst, 470 dst,
455 "gnunet-arm", 471 "gnunet-arm",
456#if DEBUG_TESTING 472#if DEBUG_TESTING
457 "-L", "DEBUG", 473 "-L", "DEBUG",
458#endif 474#endif
459 "-c", d->cfgfile, "-s", "-q", NULL); 475 "-c", d->cfgfile, "-s", "-q", NULL);
476 }
477 else
478 {
479
480 d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
481 "ssh", "-p", d->ssh_port_str,
482#if !DEBUG_TESTING
483 "-q",
484#endif
485 dst,
486 "gnunet-arm",
487#if DEBUG_TESTING
488 "-L", "DEBUG",
489#endif
490 "-c", d->cfgfile, "-s", "-q", NULL);
491 }
460 GNUNET_free (dst); 492 GNUNET_free (dst);
461 } 493 }
462 if (-1 == d->pid) 494 if (-1 == d->pid)
@@ -708,6 +740,8 @@ GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon,
708 * @param timeout how long to wait starting up peers 740 * @param timeout how long to wait starting up peers
709 * @param hostname name of the machine where to run GNUnet 741 * @param hostname name of the machine where to run GNUnet
710 * (use NULL for localhost). 742 * (use NULL for localhost).
743 * @param ssh_username ssh username to use when connecting to hostname
744 * @param sshport port to pass to ssh process when connecting to hostname
711 * @param hostkey_callback function to call once the hostkey has been 745 * @param hostkey_callback function to call once the hostkey has been
712 * generated for this peer, but it hasn't yet been started 746 * generated for this peer, but it hasn't yet been started
713 * (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start) 747 * (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,
721 const struct GNUNET_CONFIGURATION_Handle *cfg, 755 const struct GNUNET_CONFIGURATION_Handle *cfg,
722 struct GNUNET_TIME_Relative timeout, 756 struct GNUNET_TIME_Relative timeout,
723 const char *hostname, 757 const char *hostname,
758 const char *ssh_username,
759 uint16_t sshport,
724 GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback, 760 GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
725 void *hostkey_cls, 761 void *hostkey_cls,
726 GNUNET_TESTING_NotifyDaemonRunning cb, 762 GNUNET_TESTING_NotifyDaemonRunning cb,
@@ -733,6 +769,12 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
733 ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon)); 769 ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
734 ret->sched = sched; 770 ret->sched = sched;
735 ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname); 771 ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
772 if (sshport != 0)
773 {
774 GNUNET_asprintf(&ret->ssh_port_str, "%d", sshport);
775 }
776 else
777 ret->ssh_port_str = NULL;
736 ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config"); 778 ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config");
737#if DEBUG_TESTING 779#if DEBUG_TESTING
738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -766,10 +808,12 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
766 GNUNET_free (ret); 808 GNUNET_free (ret);
767 return NULL; 809 return NULL;
768 } 810 }
769 if (GNUNET_OK != 811 if (ssh_username != NULL)
812 username = GNUNET_strdup(ssh_username);
813 if ((ssh_username == NULL) && (GNUNET_OK !=
770 GNUNET_CONFIGURATION_get_value_string (cfg, 814 GNUNET_CONFIGURATION_get_value_string (cfg,
771 "TESTING", 815 "TESTING",
772 "USERNAME", &username)) 816 "USERNAME", &username)))
773 { 817 {
774 if (NULL != getenv ("USER")) 818 if (NULL != getenv ("USER"))
775 username = GNUNET_strdup (getenv ("USER")); 819 username = GNUNET_strdup (getenv ("USER"));
@@ -790,12 +834,25 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
790 GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile); 834 GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile);
791 else 835 else
792 GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile); 836 GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile);
793 ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp", 837
794 "scp", 838 if (ret->ssh_port_str == NULL)
839 {
840 ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
841 "scp",
795#if !DEBUG_TESTING 842#if !DEBUG_TESTING
796 "-q", 843 "-q",
797#endif 844#endif
798 ret->cfgfile, arg, NULL); 845 ret->cfgfile, arg, NULL);
846 }
847 else
848 {
849 ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
850 "scp", "-P", ret->ssh_port_str,
851#if !DEBUG_TESTING
852 "-q",
853#endif
854 ret->cfgfile, arg, NULL);
855 }
799 GNUNET_free (arg); 856 GNUNET_free (arg);
800 if (-1 == ret->pid) 857 if (-1 == ret->pid)
801 { 858 {
@@ -983,6 +1040,7 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
983 GNUNET_free_non_null (d->username); 1040 GNUNET_free_non_null (d->username);
984 if (NULL != d->dead_cb) 1041 if (NULL != d->dead_cb)
985 d->dead_cb (d->dead_cb_cls, NULL); 1042 d->dead_cb (d->dead_cb_cls, NULL);
1043 GNUNET_free(d);
986 return; 1044 return;
987 } 1045 }
988 1046
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
242 * Hostname, where to start the peer 242 * Hostname, where to start the peer
243 */ 243 */
244 const char *hostname; 244 const char *hostname;
245
246 /**
247 * Username to use when connecting to the
248 * host via ssh.
249 */
250 const char *username;
251
252 /**
253 * Port to use for ssh.
254 */
255 uint16_t sshport;
256
245}; 257};
246 258
247/** 259/**
@@ -312,6 +324,16 @@ struct HostData
312 char *hostname; 324 char *hostname;
313 325
314 /** 326 /**
327 * SSH username to use when connecting to this host.
328 */
329 char *username;
330
331 /**
332 * SSH port to use when connecting to this host.
333 */
334 uint16_t sshport;
335
336 /**
315 * Lowest port that we have not yet used 337 * Lowest port that we have not yet used
316 * for GNUnet. 338 * for GNUnet.
317 */ 339 */
@@ -729,6 +751,7 @@ update_config (void *cls,
729 value = uval; 751 value = uval;
730 } 752 }
731 GNUNET_free(single_variable); 753 GNUNET_free(single_variable);
754 GNUNET_free(per_host_variable);
732 755
733 } 756 }
734 757
@@ -816,6 +839,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
816 GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-udp", "BINDTO", "127.0.0.1"); 839 GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-udp", "BINDTO", "127.0.0.1");
817 } 840 }
818 841
842
819 *port = (uint16_t) uc.nport; 843 *port = (uint16_t) uc.nport;
820 *upnum = uc.upnum; 844 *upnum = uc.upnum;
821 uc.fdnum++; 845 uc.fdnum++;
@@ -3312,6 +3336,8 @@ internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
3312 internal_context->peer->cfg, 3336 internal_context->peer->cfg,
3313 internal_context->timeout, 3337 internal_context->timeout,
3314 internal_context->hostname, 3338 internal_context->hostname,
3339 internal_context->username,
3340 internal_context->sshport,
3315 &internal_hostkey_callback, 3341 &internal_hostkey_callback,
3316 internal_context, 3342 internal_context,
3317 &internal_startup_callback, 3343 &internal_startup_callback,
@@ -3387,6 +3413,7 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
3387 char *start; 3413 char *start;
3388#endif 3414#endif
3389 const char *hostname; 3415 const char *hostname;
3416 const char *username;
3390 char *baseservicehome; 3417 char *baseservicehome;
3391 char *newservicehome; 3418 char *newservicehome;
3392 char *tmpdir; 3419 char *tmpdir;
@@ -3394,6 +3421,7 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
3394 unsigned int off; 3421 unsigned int off;
3395 unsigned int hostcnt; 3422 unsigned int hostcnt;
3396 uint16_t minport; 3423 uint16_t minport;
3424 uint16_t sshport;
3397 uint32_t upnum; 3425 uint32_t upnum;
3398 uint32_t fdnum; 3426 uint32_t fdnum;
3399 3427
@@ -3428,7 +3456,11 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
3428 while (hostpos != NULL) 3456 while (hostpos != NULL)
3429 { 3457 {
3430 pg->hosts[off].minport = LOW_PORT; 3458 pg->hosts[off].minport = LOW_PORT;
3431 pg->hosts[off++].hostname = GNUNET_strdup(hostpos->hostname); 3459 off++;
3460 pg->hosts[off].hostname = GNUNET_strdup(hostpos->hostname);
3461 if (hostpos->username != NULL)
3462 pg->hosts[off].username = GNUNET_strdup(hostpos->username);
3463 pg->hosts[off].sshport = hostpos->port;
3432 hostpos = hostpos->next; 3464 hostpos = hostpos->next;
3433 } 3465 }
3434 3466
@@ -3495,6 +3527,8 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
3495 if (hostcnt > 0) 3527 if (hostcnt > 0)
3496 { 3528 {
3497 hostname = pg->hosts[off % hostcnt].hostname; 3529 hostname = pg->hosts[off % hostcnt].hostname;
3530 username = pg->hosts[off % hostcnt].username;
3531 sshport = pg->hosts[off % hostcnt].sshport;
3498 pcfg = make_config (cfg, 3532 pcfg = make_config (cfg,
3499 &pg->hosts[off % hostcnt].minport, 3533 &pg->hosts[off % hostcnt].minport,
3500 &upnum, 3534 &upnum,
@@ -3503,6 +3537,8 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
3503 else 3537 else
3504 { 3538 {
3505 hostname = NULL; 3539 hostname = NULL;
3540 username = NULL;
3541 sshport = 0;
3506 pcfg = make_config (cfg, 3542 pcfg = make_config (cfg,
3507 &minport, 3543 &minport,
3508 &upnum, 3544 &upnum,
@@ -3548,6 +3584,8 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
3548 pg->peers[off].internal_context.peer = &pg->peers[off]; 3584 pg->peers[off].internal_context.peer = &pg->peers[off];
3549 pg->peers[off].internal_context.timeout = timeout; 3585 pg->peers[off].internal_context.timeout = timeout;
3550 pg->peers[off].internal_context.hostname = hostname; 3586 pg->peers[off].internal_context.hostname = hostname;
3587 pg->peers[off].internal_context.username = username;
3588 pg->peers[off].internal_context.sshport = sshport;
3551 pg->peers[off].internal_context.hostkey_callback = hostkey_callback; 3589 pg->peers[off].internal_context.hostkey_callback = hostkey_callback;
3552 pg->peers[off].internal_context.hostkey_cls = hostkey_cls; 3590 pg->peers[off].internal_context.hostkey_cls = hostkey_cls;
3553 pg->peers[off].internal_context.start_cb = cb; 3591 pg->peers[off].internal_context.start_cb = cb;
@@ -3740,6 +3778,28 @@ churn_start_callback (void *cls,
3740 } 3778 }
3741} 3779}
3742 3780
3781/**
3782 * Count the number of running peers.
3783 *
3784 * @param pg handle for the peer group
3785 *
3786 * @return the number of currently running peers in the peer group
3787 */
3788unsigned int
3789GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg)
3790{
3791 unsigned int i;
3792 unsigned int running = 0;
3793 for (i = 0; i < pg->total; i++)
3794 {
3795 if (pg->peers[i].daemon->running == GNUNET_YES)
3796 {
3797 GNUNET_assert(running != -1);
3798 running++;
3799 }
3800 }
3801 return running;
3802}
3743 3803
3744/** 3804/**
3745 * Simulate churn by stopping some peers (and possibly 3805 * Simulate churn by stopping some peers (and possibly