diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-07-27 20:41:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-07-27 20:41:53 +0000 |
commit | 216bd97054c16917135c626c1f4b1590f9452ba1 (patch) | |
tree | a72535b567f89611c5c83b791548b7f15af80c40 /src/testing | |
parent | fe9ed98ff54df7d65dd0a0f787c86a734ef4d1a4 (diff) | |
download | gnunet-216bd97054c16917135c626c1f4b1590f9452ba1.tar.gz gnunet-216bd97054c16917135c626c1f4b1590f9452ba1.zip |
working on testing code
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/testing.c | 234 |
1 files changed, 128 insertions, 106 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c index e425171bb..1f6d60229 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -30,6 +30,7 @@ | |||
30 | */ | 30 | */ |
31 | #include "platform.h" | 31 | #include "platform.h" |
32 | #include "gnunet_arm_service.h" | 32 | #include "gnunet_arm_service.h" |
33 | #include "gnunet_core_service.h" | ||
33 | #include "gnunet_constants.h" | 34 | #include "gnunet_constants.h" |
34 | #include "gnunet_testing_lib.h" | 35 | #include "gnunet_testing_lib.h" |
35 | 36 | ||
@@ -39,7 +40,7 @@ | |||
39 | * How long do we wait after starting gnunet-service-arm | 40 | * How long do we wait after starting gnunet-service-arm |
40 | * for the core service to be alive? | 41 | * for the core service to be alive? |
41 | */ | 42 | */ |
42 | #define GNUNET_ARM_START_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 43 | #define ARM_START_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
43 | 44 | ||
44 | /** | 45 | /** |
45 | * How many times are we willing to try to | 46 | * How many times are we willing to try to |
@@ -57,7 +58,8 @@ enum StartPhase | |||
57 | SP_COPIED, | 58 | SP_COPIED, |
58 | SP_START_ARMING, | 59 | SP_START_ARMING, |
59 | SP_START_CORE, | 60 | SP_START_CORE, |
60 | SP_START_DONE | 61 | SP_START_DONE, |
62 | SP_CLEANUP | ||
61 | }; | 63 | }; |
62 | 64 | ||
63 | 65 | ||
@@ -114,6 +116,11 @@ struct GNUNET_TESTING_Daemon | |||
114 | void *dead_cb_cls; | 116 | void *dead_cb_cls; |
115 | 117 | ||
116 | /** | 118 | /** |
119 | * Identity of this peer (once started). | ||
120 | */ | ||
121 | struct GNUNET_PeerIdentity id; | ||
122 | |||
123 | /** | ||
117 | * Flag to indicate that we've already been asked | 124 | * Flag to indicate that we've already been asked |
118 | * to terminate (but could not because some action | 125 | * to terminate (but could not because some action |
119 | * was still pending). | 126 | * was still pending). |
@@ -140,7 +147,7 @@ struct GNUNET_TESTING_Daemon | |||
140 | /** | 147 | /** |
141 | * ID of the current task. | 148 | * ID of the current task. |
142 | */ | 149 | */ |
143 | GNUNET_SCHEDULER_Task task; | 150 | GNUNET_SCHEDULER_TaskIdentifier task; |
144 | 151 | ||
145 | }; | 152 | }; |
146 | 153 | ||
@@ -169,7 +176,7 @@ testing_init (void *cls, | |||
169 | struct GNUNET_TESTING_Daemon *d = cls; | 176 | struct GNUNET_TESTING_Daemon *d = cls; |
170 | GNUNET_TESTING_NotifyDaemonRunning cb; | 177 | GNUNET_TESTING_NotifyDaemonRunning cb; |
171 | 178 | ||
172 | d->phsae = SP_START_DONE; | 179 | d->phase = SP_START_DONE; |
173 | cb = d->cb; | 180 | cb = d->cb; |
174 | d->cb = NULL; | 181 | d->cb = NULL; |
175 | if (server == NULL) | 182 | if (server == NULL) |
@@ -185,6 +192,7 @@ testing_init (void *cls, | |||
185 | "Successfully started peer `%4s'.\n", | 192 | "Successfully started peer `%4s'.\n", |
186 | GNUNET_i2s(my_identity)); | 193 | GNUNET_i2s(my_identity)); |
187 | #endif | 194 | #endif |
195 | d->id = *my_identity; | ||
188 | if (GNUNET_YES == d->dead) | 196 | if (GNUNET_YES == d->dead) |
189 | GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls); | 197 | GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls); |
190 | else | 198 | else |
@@ -202,6 +210,8 @@ static void | |||
202 | start_fsm (void *cls, | 210 | start_fsm (void *cls, |
203 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 211 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
204 | { | 212 | { |
213 | static struct GNUNET_CORE_MessageHandler no_handlers[] = | ||
214 | { { NULL, 0, 0 } }; | ||
205 | struct GNUNET_TESTING_Daemon * d = cls; | 215 | struct GNUNET_TESTING_Daemon * d = cls; |
206 | GNUNET_TESTING_NotifyDaemonRunning cb; | 216 | GNUNET_TESTING_NotifyDaemonRunning cb; |
207 | enum GNUNET_OS_ProcessStatusType type; | 217 | enum GNUNET_OS_ProcessStatusType type; |
@@ -232,7 +242,7 @@ start_fsm (void *cls, | |||
232 | } | 242 | } |
233 | /* wait some more */ | 243 | /* wait some more */ |
234 | d->task | 244 | d->task |
235 | = GNUNET_SCHEDULER_add_delayed (sched, | 245 | = GNUNET_SCHEDULER_add_delayed (d->sched, |
236 | GNUNET_NO, | 246 | GNUNET_NO, |
237 | GNUNET_SCHEDULER_PRIORITY_KEEP, | 247 | GNUNET_SCHEDULER_PRIORITY_KEEP, |
238 | GNUNET_SCHEDULER_NO_TASK, | 248 | GNUNET_SCHEDULER_NO_TASK, |
@@ -261,7 +271,7 @@ start_fsm (void *cls, | |||
261 | /* fall-through */ | 271 | /* fall-through */ |
262 | case SP_COPIED: | 272 | case SP_COPIED: |
263 | /* start GNUnet on remote host */ | 273 | /* start GNUnet on remote host */ |
264 | if (NULL == hostname) | 274 | if (NULL == d->hostname) |
265 | { | 275 | { |
266 | d->pid = GNUNET_OS_start_process ("gnunet-service-arm", | 276 | d->pid = GNUNET_OS_start_process ("gnunet-service-arm", |
267 | "gnunet-service-arm", | 277 | "gnunet-service-arm", |
@@ -272,13 +282,13 @@ start_fsm (void *cls, | |||
272 | } | 282 | } |
273 | else | 283 | else |
274 | { | 284 | { |
275 | if (username != NULL) | 285 | if (d->username != NULL) |
276 | GNUNET_asprintf (&dst, | 286 | GNUNET_asprintf (&dst, |
277 | "%s@%s", | 287 | "%s@%s", |
278 | username, | 288 | d->username, |
279 | hostname); | 289 | d->hostname); |
280 | else | 290 | else |
281 | dst = GNUNET_strdup (hostname); | 291 | dst = GNUNET_strdup (d->hostname); |
282 | d->pid = GNUNET_OS_start_process ("ssh", | 292 | d->pid = GNUNET_OS_start_process ("ssh", |
283 | "ssh", | 293 | "ssh", |
284 | dst, | 294 | dst, |
@@ -293,7 +303,7 @@ start_fsm (void *cls, | |||
293 | { | 303 | { |
294 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 304 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
295 | _("Could not start `%s' process to start GNUnet.\n"), | 305 | _("Could not start `%s' process to start GNUnet.\n"), |
296 | (NULL == hostname) ? "gnunet-service-arm" : "ssh"); | 306 | (NULL == d->hostname) ? "gnunet-service-arm" : "ssh"); |
297 | cb = d->cb; | 307 | cb = d->cb; |
298 | d->cb = NULL; | 308 | d->cb = NULL; |
299 | cb (d->cb_cls, | 309 | cb (d->cb_cls, |
@@ -329,7 +339,7 @@ start_fsm (void *cls, | |||
329 | } | 339 | } |
330 | /* wait some more */ | 340 | /* wait some more */ |
331 | d->task | 341 | d->task |
332 | = GNUNET_SCHEDULER_add_delayed (sched, | 342 | = GNUNET_SCHEDULER_add_delayed (d->sched, |
333 | GNUNET_NO, | 343 | GNUNET_NO, |
334 | GNUNET_SCHEDULER_PRIORITY_KEEP, | 344 | GNUNET_SCHEDULER_PRIORITY_KEEP, |
335 | GNUNET_SCHEDULER_NO_TASK, | 345 | GNUNET_SCHEDULER_NO_TASK, |
@@ -346,7 +356,7 @@ start_fsm (void *cls, | |||
346 | d->phase = SP_START_CORE; | 356 | d->phase = SP_START_CORE; |
347 | GNUNET_CORE_connect (d->sched, | 357 | GNUNET_CORE_connect (d->sched, |
348 | d->cfg, | 358 | d->cfg, |
349 | timeout, | 359 | ARM_START_WAIT, |
350 | d, | 360 | d, |
351 | &testing_init, | 361 | &testing_init, |
352 | NULL, NULL, NULL, | 362 | NULL, NULL, NULL, |
@@ -360,8 +370,53 @@ start_fsm (void *cls, | |||
360 | case SP_START_DONE: | 370 | case SP_START_DONE: |
361 | GNUNET_break (0); | 371 | GNUNET_break (0); |
362 | break; | 372 | break; |
373 | case SP_CLEANUP: | ||
374 | /* confirm copying complete */ | ||
375 | if (GNUNET_OK != | ||
376 | GNUNET_OS_process_status (d->pid, | ||
377 | &type, | ||
378 | &code)) | ||
379 | { | ||
380 | d->wait_runs++; | ||
381 | if (d->wait_runs > MAX_EXEC_WAIT_RUNS) | ||
382 | { | ||
383 | d->dead_cb (d->dead_cb_cls, | ||
384 | _("`ssh' does not seem to terminate.\n")); | ||
385 | GNUNET_free (d->cfgfile); | ||
386 | GNUNET_free_non_null (d->hostname); | ||
387 | GNUNET_free_non_null (d->username); | ||
388 | GNUNET_free (d); | ||
389 | return; | ||
390 | } | ||
391 | /* wait some more */ | ||
392 | d->task | ||
393 | = GNUNET_SCHEDULER_add_delayed (d->sched, | ||
394 | GNUNET_NO, | ||
395 | GNUNET_SCHEDULER_PRIORITY_KEEP, | ||
396 | GNUNET_SCHEDULER_NO_TASK, | ||
397 | GNUNET_CONSTANTS_EXEC_WAIT, | ||
398 | &start_fsm, | ||
399 | d); | ||
400 | return; | ||
401 | } | ||
402 | if ( (type != GNUNET_OS_PROCESS_EXITED) || | ||
403 | (code != 0) ) | ||
404 | { | ||
405 | d->dead_cb (d->dead_cb_cls, | ||
406 | _("`sshp' did not complete cleanly.\n")); | ||
407 | GNUNET_free (d->cfgfile); | ||
408 | GNUNET_free_non_null (d->hostname); | ||
409 | GNUNET_free_non_null (d->username); | ||
410 | GNUNET_free (d); | ||
411 | return; | ||
412 | } | ||
413 | GNUNET_free (d->cfgfile); | ||
414 | GNUNET_free_non_null (d->hostname); | ||
415 | GNUNET_free_non_null (d->username); | ||
416 | d->dead_cb (d->dead_cb_cls, NULL); | ||
417 | GNUNET_free (d); | ||
418 | break; | ||
363 | } | 419 | } |
364 | return ret; | ||
365 | } | 420 | } |
366 | 421 | ||
367 | 422 | ||
@@ -381,17 +436,14 @@ start_fsm (void *cls, | |||
381 | */ | 436 | */ |
382 | struct GNUNET_TESTING_Daemon * | 437 | struct GNUNET_TESTING_Daemon * |
383 | GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, | 438 | GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, |
384 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 439 | struct GNUNET_CONFIGURATION_Handle *cfg, |
385 | const char *hostname, | 440 | const char *hostname, |
386 | GNUNET_TESTING_NotifyDaemonRunning cb, | 441 | GNUNET_TESTING_NotifyDaemonRunning cb, |
387 | void *cb_cls) | 442 | void *cb_cls) |
388 | { | 443 | { |
389 | static struct GNUNET_CORE_MessageHandler no_handlers[] = | ||
390 | { NULL, 0, 0 }; | ||
391 | struct GNUNET_TESTING_Daemon * ret; | 444 | struct GNUNET_TESTING_Daemon * ret; |
392 | char *arg; | 445 | char *arg; |
393 | char *username; | 446 | char *username; |
394 | int unused; | ||
395 | 447 | ||
396 | ret = GNUNET_malloc (sizeof(struct GNUNET_TESTING_Daemon)); | 448 | ret = GNUNET_malloc (sizeof(struct GNUNET_TESTING_Daemon)); |
397 | ret->sched = sched; | 449 | ret->sched = sched; |
@@ -477,15 +529,15 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, | |||
477 | &start_fsm, | 529 | &start_fsm, |
478 | ret); | 530 | ret); |
479 | GNUNET_free (arg); | 531 | GNUNET_free (arg); |
480 | return; | 532 | return ret; |
481 | } | 533 | } |
482 | ret->phase = SP_COPIED; | 534 | ret->phase = SP_COPIED; |
483 | ret->task | 535 | GNUNET_SCHEDULER_add_continuation (sched, |
484 | = GNUNET_SCHEDULER_add_continuation (sched, | 536 | GNUNET_NO, |
485 | GNUNET_NO, | 537 | &start_fsm, |
486 | &start_fsm, | 538 | ret, |
487 | ret, | 539 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
488 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 540 | return ret; |
489 | } | 541 | } |
490 | 542 | ||
491 | 543 | ||
@@ -500,6 +552,9 @@ void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
500 | GNUNET_TESTING_NotifyCompletion cb, | 552 | GNUNET_TESTING_NotifyCompletion cb, |
501 | void * cb_cls) | 553 | void * cb_cls) |
502 | { | 554 | { |
555 | struct GNUNET_CLIENT_Connection *cc; | ||
556 | char *dst; | ||
557 | |||
503 | if (NULL != d->cb) | 558 | if (NULL != d->cb) |
504 | { | 559 | { |
505 | d->dead = GNUNET_YES; | 560 | d->dead = GNUNET_YES; |
@@ -507,75 +562,15 @@ void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
507 | d->dead_cb_cls = cb_cls; | 562 | d->dead_cb_cls = cb_cls; |
508 | return; | 563 | return; |
509 | } | 564 | } |
510 | 565 | /* shutdown ARM process (will also terminate others) */ | |
511 | /* FIXME: shutdown processes! */ | 566 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
512 | char *cmd; | 567 | _("Terminating peer `%4s'\n"), |
513 | int length; | 568 | GNUNET_i2s(&d->id)); |
514 | unsigned int is_local = 0; | 569 | cc = GNUNET_CLIENT_connect (d->sched, |
515 | int unused; | 570 | "arm", |
516 | FILE *output; | 571 | d->cfg); |
517 | pid_t pid; | 572 | GNUNET_CLIENT_service_shutdown (cc); |
518 | 573 | GNUNET_CLIENT_disconnect (cc); | |
519 | if (strcmp (tokill->hostname, "localhost") == 0) | ||
520 | { | ||
521 | is_local = 1; | ||
522 | } | ||
523 | |||
524 | if (is_local) | ||
525 | { | ||
526 | length = snprintf (NULL, 0, "cat %s", tokill->pid); | ||
527 | cmd = GNUNET_malloc (length + 1); | ||
528 | snprintf (cmd, length + 1, "cat %s", tokill->pid); | ||
529 | } | ||
530 | else | ||
531 | { | ||
532 | length = | ||
533 | snprintf (NULL, 0, "ssh %s@%s cat %s", tokill->username, | ||
534 | tokill->hostname, tokill->pid); | ||
535 | cmd = GNUNET_malloc (length + 1); | ||
536 | snprintf (cmd, length + 1, "ssh %s@%s cat %s", tokill->username, | ||
537 | tokill->hostname, tokill->pid); | ||
538 | } | ||
539 | #if VERBOSE | ||
540 | fprintf (stderr, _("exec command is : %s \n"), cmd); | ||
541 | #endif | ||
542 | |||
543 | output = popen (cmd, "r"); | ||
544 | GNUNET_free (cmd); | ||
545 | if (fscanf (output, "%d", &pid) == 1) | ||
546 | { | ||
547 | #if VERBOSE | ||
548 | fprintf (stderr, _("Got pid %d\n"), pid); | ||
549 | #endif | ||
550 | } | ||
551 | else | ||
552 | { | ||
553 | return -1; | ||
554 | } | ||
555 | |||
556 | if (is_local) | ||
557 | { | ||
558 | length = snprintf (NULL, 0, "kill %d", pid); | ||
559 | cmd = GNUNET_malloc (length + 1); | ||
560 | snprintf (cmd, length + 1, "kill %d", pid); | ||
561 | } | ||
562 | else | ||
563 | { | ||
564 | length = | ||
565 | snprintf (NULL, 0, "ssh %s@%s kill %d", tokill->username, | ||
566 | tokill->hostname, pid); | ||
567 | cmd = GNUNET_malloc (length + 1); | ||
568 | snprintf (cmd, length + 1, "ssh %s@%s kill %d", | ||
569 | tokill->username, tokill->hostname, pid); | ||
570 | |||
571 | } | ||
572 | #if VERBOSE | ||
573 | fprintf (stderr, _("exec command is : %s \n"), cmd); | ||
574 | #endif | ||
575 | |||
576 | unused = system (cmd); | ||
577 | |||
578 | GNUNET_free (cmd); | ||
579 | 574 | ||
580 | /* state clean up and notifications */ | 575 | /* state clean up and notifications */ |
581 | if (0 != UNLINK (d->cfgfile)) | 576 | if (0 != UNLINK (d->cfgfile)) |
@@ -584,18 +579,44 @@ void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
584 | d->cfgfile); | 579 | d->cfgfile); |
585 | if (d->hostname != NULL) | 580 | if (d->hostname != NULL) |
586 | { | 581 | { |
587 | GNUNET_asprintf (&cmd, | 582 | if (NULL != d->username) |
588 | "ssh %s@%s rm %s &", | 583 | GNUNET_asprintf (&dst, |
589 | d->username, | 584 | "%s@%s", |
590 | d->hostname, | 585 | d->username, |
591 | d->cfgfile); | 586 | d->hostname); |
592 | #if DEBUG_TESTING | 587 | else |
593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 588 | dst = GNUNET_strdup (d->hostname); |
594 | _("exec command is: `%s'\n"), | 589 | d->pid = GNUNET_OS_start_process ("ssh", |
595 | cmd); | 590 | "ssh", |
596 | #endif | 591 | dst, |
597 | unused = system (cmd); | 592 | "rm", |
598 | GNUNET_free (cmd); | 593 | d->cfgfile, |
594 | NULL); | ||
595 | GNUNET_free (dst); | ||
596 | if (-1 == d->pid) | ||
597 | { | ||
598 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
599 | _("Could not start `%s' process to delete configuration file.\n"), | ||
600 | "ssh"); | ||
601 | GNUNET_free (d->cfgfile); | ||
602 | GNUNET_free_non_null (d->hostname); | ||
603 | GNUNET_free_non_null (d->username); | ||
604 | GNUNET_free (d); | ||
605 | cb (cb_cls, _("Error cleaning up configuration file.\n")); | ||
606 | return; | ||
607 | } | ||
608 | d->phase = SP_CLEANUP; | ||
609 | d->dead_cb = cb; | ||
610 | d->dead_cb_cls = cb_cls; | ||
611 | d->task | ||
612 | = GNUNET_SCHEDULER_add_delayed (d->sched, | ||
613 | GNUNET_NO, | ||
614 | GNUNET_SCHEDULER_PRIORITY_KEEP, | ||
615 | GNUNET_SCHEDULER_NO_TASK, | ||
616 | GNUNET_CONSTANTS_EXEC_WAIT, | ||
617 | &start_fsm, | ||
618 | d); | ||
619 | return; | ||
599 | } | 620 | } |
600 | GNUNET_free (d->cfgfile); | 621 | GNUNET_free (d->cfgfile); |
601 | GNUNET_free_non_null (d->hostname); | 622 | GNUNET_free_non_null (d->hostname); |
@@ -638,6 +659,7 @@ void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
638 | GNUNET_TESTING_NotifyCompletion cb, | 659 | GNUNET_TESTING_NotifyCompletion cb, |
639 | void *cb_cls) | 660 | void *cb_cls) |
640 | { | 661 | { |
662 | cb (cb_cls, "not implemented"); | ||
641 | } | 663 | } |
642 | 664 | ||
643 | 665 | ||