diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-05-11 07:35:38 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-05-11 07:35:38 +0000 |
commit | 673b8dadbe8cbc17d2c1391d16f15a0d7626b4fd (patch) | |
tree | 2833b35dd50d36e981c0f3bcb5767301a587d93a /src | |
parent | bcfdbb1b6adf43534b70c4e92e4f1a10e15f9687 (diff) | |
download | gnunet-673b8dadbe8cbc17d2c1391d16f15a0d7626b4fd.tar.gz gnunet-673b8dadbe8cbc17d2c1391d16f15a0d7626b4fd.zip |
more testing changes
Diffstat (limited to 'src')
-rw-r--r-- | src/testing/testing.c | 69 | ||||
-rw-r--r-- | src/testing/testing_group.c | 130 |
2 files changed, 188 insertions, 11 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c index b05c02278..1bf3e40cd 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -126,7 +126,7 @@ testing_init (void *cls, | |||
126 | { | 126 | { |
127 | d->server = NULL; | 127 | d->server = NULL; |
128 | if (GNUNET_YES == d->dead) | 128 | if (GNUNET_YES == d->dead) |
129 | GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES); | 129 | GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES, GNUNET_NO); |
130 | else if (NULL != cb) | 130 | else if (NULL != cb) |
131 | cb (d->cb_cls, NULL, d->cfg, d, | 131 | cb (d->cb_cls, NULL, d->cfg, d, |
132 | _("Failed to connect to core service\n")); | 132 | _("Failed to connect to core service\n")); |
@@ -141,7 +141,7 @@ testing_init (void *cls, | |||
141 | d->server = server; | 141 | d->server = server; |
142 | d->running = GNUNET_YES; | 142 | d->running = GNUNET_YES; |
143 | if (GNUNET_YES == d->dead) | 143 | if (GNUNET_YES == d->dead) |
144 | GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES); | 144 | GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES, GNUNET_NO); |
145 | else if (NULL != cb) | 145 | else if (NULL != cb) |
146 | cb (d->cb_cls, my_identity, d->cfg, d, NULL); | 146 | cb (d->cb_cls, my_identity, d->cfg, d, NULL); |
147 | #if DEBUG_TESTING | 147 | #if DEBUG_TESTING |
@@ -155,7 +155,7 @@ testing_init (void *cls, | |||
155 | if (d->th == NULL) | 155 | if (d->th == NULL) |
156 | { | 156 | { |
157 | if (GNUNET_YES == d->dead) | 157 | if (GNUNET_YES == d->dead) |
158 | GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES); | 158 | GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES, GNUNET_NO); |
159 | else if (NULL != d->cb) | 159 | else if (NULL != d->cb) |
160 | d->cb (d->cb_cls, &d->id, d->cfg, d, | 160 | d->cb (d->cb_cls, &d->id, d->cfg, d, |
161 | _("Failed to connect to transport service!\n")); | 161 | _("Failed to connect to transport service!\n")); |
@@ -580,14 +580,19 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
580 | d->th = NULL; | 580 | d->th = NULL; |
581 | } | 581 | } |
582 | /* state clean up and notifications */ | 582 | /* state clean up and notifications */ |
583 | GNUNET_CONFIGURATION_destroy (d->cfg); | 583 | if (d->churn == GNUNET_NO) |
584 | GNUNET_free (d->cfgfile); | 584 | { |
585 | GNUNET_CONFIGURATION_destroy (d->cfg); | ||
586 | GNUNET_free (d->cfgfile); | ||
587 | GNUNET_free_non_null (d->hostname); | ||
588 | GNUNET_free_non_null (d->username); | ||
589 | } | ||
590 | |||
585 | GNUNET_free_non_null(d->hello); | 591 | GNUNET_free_non_null(d->hello); |
586 | GNUNET_free_non_null (d->hostname); | ||
587 | GNUNET_free_non_null (d->username); | ||
588 | GNUNET_free_non_null (d->shortname); | 592 | GNUNET_free_non_null (d->shortname); |
589 | if (NULL != d->dead_cb) | 593 | if (NULL != d->dead_cb) |
590 | d->dead_cb (d->dead_cb_cls, NULL); | 594 | d->dead_cb (d->dead_cb_cls, NULL); |
595 | |||
591 | GNUNET_free (d); | 596 | GNUNET_free (d); |
592 | break; | 597 | break; |
593 | case SP_CONFIG_UPDATE: | 598 | case SP_CONFIG_UPDATE: |
@@ -643,6 +648,39 @@ GNUNET_TESTING_daemon_continue_startup(struct GNUNET_TESTING_Daemon *daemon) | |||
643 | daemon->phase = SP_TOPOLOGY_SETUP; | 648 | daemon->phase = SP_TOPOLOGY_SETUP; |
644 | } | 649 | } |
645 | 650 | ||
651 | |||
652 | /** | ||
653 | * Start a peer that has previously been stopped using the daemon_stop | ||
654 | * call (and files weren't deleted and the allow restart flag) | ||
655 | * | ||
656 | * @param daemon the daemon to start (has been previously stopped) | ||
657 | * @param timeout how long to wait for restart | ||
658 | * @param cb the callback for notification when the peer is running | ||
659 | * @param cb_cls closure for the callback | ||
660 | */ | ||
661 | void | ||
662 | GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon, | ||
663 | struct GNUNET_TIME_Relative timeout, | ||
664 | GNUNET_TESTING_NotifyDaemonRunning cb, | ||
665 | void *cb_cls) | ||
666 | { | ||
667 | if (daemon->running == GNUNET_YES) | ||
668 | { | ||
669 | cb(cb_cls, &daemon->id, daemon->cfg, daemon, "Daemon already running, can't restart!"); | ||
670 | return; | ||
671 | } | ||
672 | |||
673 | daemon->cb = cb; | ||
674 | daemon->cb_cls = cb_cls; | ||
675 | daemon->phase = SP_TOPOLOGY_SETUP; | ||
676 | daemon->max_timeout = GNUNET_TIME_relative_to_absolute(timeout); | ||
677 | |||
678 | GNUNET_SCHEDULER_add_continuation (daemon->sched, | ||
679 | &start_fsm, | ||
680 | daemon, | ||
681 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
682 | } | ||
683 | |||
646 | /** | 684 | /** |
647 | * Starts a GNUnet daemon. GNUnet must be installed on the target | 685 | * Starts a GNUnet daemon. GNUnet must be installed on the target |
648 | * system and available in the PATH. The machine must furthermore be | 686 | * system and available in the PATH. The machine must furthermore be |
@@ -879,14 +917,15 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, | |||
879 | * @param cb function called once the daemon was stopped | 917 | * @param cb function called once the daemon was stopped |
880 | * @param cb_cls closure for cb | 918 | * @param cb_cls closure for cb |
881 | * @param delete_files GNUNET_YES to remove files, GNUNET_NO | 919 | * @param delete_files GNUNET_YES to remove files, GNUNET_NO |
882 | * to leave them (i.e. for restarting at a later time, | 920 | * to leave them |
883 | * or logfile inspection once finished) | 921 | * @param allow_restart GNUNET_YES to restart peer later (using this API) |
922 | * GNUNET_NO to kill off and clean up for good | ||
884 | */ | 923 | */ |
885 | void | 924 | void |
886 | GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | 925 | GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, |
887 | struct GNUNET_TIME_Relative timeout, | 926 | struct GNUNET_TIME_Relative timeout, |
888 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls, | 927 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls, |
889 | int delete_files) | 928 | int delete_files, int allow_restart) |
890 | { | 929 | { |
891 | char *arg; | 930 | char *arg; |
892 | char *del_arg; | 931 | char *del_arg; |
@@ -926,6 +965,16 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
926 | #endif | 965 | #endif |
927 | 966 | ||
928 | d->phase = SP_SHUTDOWN_START; | 967 | d->phase = SP_SHUTDOWN_START; |
968 | d->running = GNUNET_NO; | ||
969 | |||
970 | if (allow_restart == GNUNET_YES) | ||
971 | d->churn = GNUNET_YES; | ||
972 | if (d->th != NULL) | ||
973 | { | ||
974 | GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d); | ||
975 | GNUNET_TRANSPORT_disconnect(d->th); | ||
976 | d->th = NULL; | ||
977 | } | ||
929 | /* Check if this is a local or remote process */ | 978 | /* Check if this is a local or remote process */ |
930 | if (NULL != d->hostname) | 979 | if (NULL != d->hostname) |
931 | { | 980 | { |
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 269df5c21..835b1d979 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -2606,6 +2606,134 @@ void restart_callback (void *cls, | |||
2606 | 2606 | ||
2607 | } | 2607 | } |
2608 | 2608 | ||
2609 | void | ||
2610 | churn_stop_callback (void *cls, const char *emsg) | ||
2611 | { | ||
2612 | |||
2613 | } | ||
2614 | |||
2615 | void | ||
2616 | churn_start_callback (void *cls, | ||
2617 | const struct GNUNET_PeerIdentity *id, | ||
2618 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
2619 | struct GNUNET_TESTING_Daemon *d, | ||
2620 | const char *emsg) | ||
2621 | { | ||
2622 | |||
2623 | } | ||
2624 | |||
2625 | /** | ||
2626 | * Context for handling churning a peer group | ||
2627 | */ | ||
2628 | struct ChurnContext | ||
2629 | { | ||
2630 | |||
2631 | }; | ||
2632 | |||
2633 | /** | ||
2634 | * Simulate churn by stopping some peers (and possibly | ||
2635 | * re-starting others if churn is called multiple times). This | ||
2636 | * function can only be used to create leave-join churn (peers "never" | ||
2637 | * leave for good). First "voff" random peers that are currently | ||
2638 | * online will be taken offline; then "von" random peers that are then | ||
2639 | * offline will be put back online. No notifications will be | ||
2640 | * generated for any of these operations except for the callback upon | ||
2641 | * completion. Note that the implementation is at liberty to keep | ||
2642 | * the ARM service itself (but none of the other services or daemons) | ||
2643 | * running even though the "peer" is being varied offline. | ||
2644 | * | ||
2645 | * @param pg handle for the peer group | ||
2646 | * @param voff number of peers that should go offline | ||
2647 | * @param von number of peers that should come back online; | ||
2648 | * must be zero on first call (since "testbed_start" | ||
2649 | * always starts all of the peers) | ||
2650 | * @param timeout how long to wait for operations to finish before | ||
2651 | * giving up | ||
2652 | * @param cb function to call at the end | ||
2653 | * @param cb_cls closure for cb | ||
2654 | */ | ||
2655 | void | ||
2656 | GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, | ||
2657 | unsigned int voff, | ||
2658 | unsigned int von, | ||
2659 | struct GNUNET_TIME_Relative timeout, | ||
2660 | GNUNET_TESTING_NotifyCompletion cb, | ||
2661 | void *cb_cls) | ||
2662 | { | ||
2663 | struct ChurnContext *churn_ctx; | ||
2664 | unsigned int running; | ||
2665 | unsigned int stopped; | ||
2666 | unsigned int i; | ||
2667 | unsigned int *running_arr; | ||
2668 | unsigned int *stopped_arr; | ||
2669 | unsigned int *running_permute; | ||
2670 | unsigned int *stopped_permute; | ||
2671 | |||
2672 | running = 0; | ||
2673 | stopped = 0; | ||
2674 | |||
2675 | for (i = 0; i < pg->total; i++) | ||
2676 | { | ||
2677 | if (pg->peers[i].daemon->running == GNUNET_YES) | ||
2678 | { | ||
2679 | running++; | ||
2680 | } | ||
2681 | else | ||
2682 | { | ||
2683 | stopped++; | ||
2684 | } | ||
2685 | } | ||
2686 | |||
2687 | if (voff > running) | ||
2688 | { | ||
2689 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Trying to stop more peers than are currently running!\n"); | ||
2690 | cb(cb_cls, "Trying to stop more peers than are currently running!"); | ||
2691 | return; | ||
2692 | } | ||
2693 | |||
2694 | if (von > stopped) | ||
2695 | { | ||
2696 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Trying to start more peers than are currently stopped!\n"); | ||
2697 | cb(cb_cls, "Trying to start more peers than are currently stopped!"); | ||
2698 | return; | ||
2699 | } | ||
2700 | |||
2701 | churn_ctx = GNUNET_malloc(sizeof(struct ChurnContext)); | ||
2702 | running_arr = GNUNET_malloc(running * sizeof(unsigned int)); | ||
2703 | stopped_arr = GNUNET_malloc(stopped * sizeof(unsigned int)); | ||
2704 | running_permute = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, running); | ||
2705 | stopped_permute = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, stopped); | ||
2706 | |||
2707 | running = 0; | ||
2708 | stopped = 0; | ||
2709 | |||
2710 | for (i = 0; i < pg->total; i++) | ||
2711 | { | ||
2712 | if (pg->peers[i].daemon->running == GNUNET_YES) | ||
2713 | { | ||
2714 | running_arr[running] = i; | ||
2715 | running++; | ||
2716 | } | ||
2717 | else | ||
2718 | { | ||
2719 | stopped_arr[stopped] = i; | ||
2720 | stopped++; | ||
2721 | } | ||
2722 | } | ||
2723 | |||
2724 | for (i = 0; i < voff; i++) | ||
2725 | { | ||
2726 | GNUNET_TESTING_daemon_stop(pg->peers[running_arr[running_permute[i]]].daemon, timeout, &churn_stop_callback, churn_ctx, GNUNET_NO, GNUNET_YES); | ||
2727 | } | ||
2728 | |||
2729 | for (i = 0; i < von; i++) | ||
2730 | { | ||
2731 | GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon, timeout, &churn_start_callback, churn_ctx); | ||
2732 | } | ||
2733 | |||
2734 | } | ||
2735 | |||
2736 | |||
2609 | /** | 2737 | /** |
2610 | * Restart all peers in the given group. | 2738 | * Restart all peers in the given group. |
2611 | * | 2739 | * |
@@ -2655,7 +2783,7 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, struct GNUNET_ | |||
2655 | as well... */ | 2783 | as well... */ |
2656 | 2784 | ||
2657 | if (NULL != pg->peers[off].daemon) | 2785 | if (NULL != pg->peers[off].daemon) |
2658 | GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, NULL, NULL, GNUNET_YES); | 2786 | GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, NULL, NULL, GNUNET_YES, GNUNET_NO); |
2659 | if (NULL != pg->peers[off].cfg) | 2787 | if (NULL != pg->peers[off].cfg) |
2660 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); | 2788 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); |
2661 | 2789 | ||