aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-05-27 10:43:18 +0000
committerChristian Grothoff <christian@grothoff.org>2010-05-27 10:43:18 +0000
commit315a5cc108293e1ac8f8aaa8fda5c9a7bbd71531 (patch)
treeeea7d171b621f287c13280f6be5f4ee9070ce569 /src/testing
parentbbad719b371981f8eee4e9a22c74767140894a46 (diff)
downloadgnunet-315a5cc108293e1ac8f8aaa8fda5c9a7bbd71531.tar.gz
gnunet-315a5cc108293e1ac8f8aaa8fda5c9a7bbd71531.zip
api for controlled churn
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/testing.c7
-rw-r--r--src/testing/testing_group.c130
2 files changed, 100 insertions, 37 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index adcc06193..0c650d313 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -922,7 +922,8 @@ void
922GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, 922GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
923 struct GNUNET_TIME_Relative timeout, 923 struct GNUNET_TIME_Relative timeout,
924 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls, 924 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
925 int delete_files, int allow_restart) 925 int delete_files,
926 int allow_restart)
926{ 927{
927 char *arg; 928 char *arg;
928 char *del_arg; 929 char *del_arg;
@@ -960,13 +961,10 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
961 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); 962 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
962#endif 963#endif
963
964 d->phase = SP_SHUTDOWN_START; 964 d->phase = SP_SHUTDOWN_START;
965 d->running = GNUNET_NO; 965 d->running = GNUNET_NO;
966
967 if (allow_restart == GNUNET_YES) 966 if (allow_restart == GNUNET_YES)
968 d->churn = GNUNET_YES; 967 d->churn = GNUNET_YES;
969
970 if (d->th != NULL) 968 if (d->th != NULL)
971 { 969 {
972 GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d); 970 GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d);
@@ -993,7 +991,6 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
993#endif 991#endif
994 "-c", d->cfgfile, "-e", "-q", del_arg, NULL); 992 "-c", d->cfgfile, "-e", "-q", del_arg, NULL);
995 /* Use -e to end arm, and -d to remove temp files */ 993 /* Use -e to end arm, and -d to remove temp files */
996
997 GNUNET_free (arg); 994 GNUNET_free (arg);
998 } 995 }
999 else 996 else
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index d878ec104..bf90ea4b0 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -2698,17 +2698,20 @@ churn_stop_callback (void *cls, const char *emsg)
2698 2698
2699 error_message = NULL; 2699 error_message = NULL;
2700 if (emsg != NULL) 2700 if (emsg != NULL)
2701 { 2701 {
2702 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Churn stop callback failed with error `%s'\n", emsg); 2702 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
2703 churn_ctx->num_failed_stop++; 2703 "Churn stop callback failed with error `%s'\n", emsg);
2704 } 2704 churn_ctx->num_failed_stop++;
2705 }
2705 else 2706 else
2706 { 2707 {
2707 churn_ctx->num_to_stop--; 2708 churn_ctx->num_to_stop--;
2708 } 2709 }
2709 2710
2710#if DEBUG_CHURN 2711#if DEBUG_CHURN
2711 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopped peer, %d left.\n", churn_ctx->num_to_stop); 2712 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
2713 "Stopped peer, %d left.\n",
2714 churn_ctx->num_to_stop);
2712#endif 2715#endif
2713 total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + (churn_ctx->num_to_start - churn_ctx->num_failed_start); 2716 total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + (churn_ctx->num_to_start - churn_ctx->num_failed_start);
2714 2717
@@ -2716,7 +2719,10 @@ churn_stop_callback (void *cls, const char *emsg)
2716 { 2719 {
2717 if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) 2720 if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0))
2718 { 2721 {
2719 GNUNET_asprintf(&error_message, "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", churn_ctx->num_failed_start, churn_ctx->num_failed_stop); 2722 GNUNET_asprintf(&error_message,
2723 "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!",
2724 churn_ctx->num_failed_start,
2725 churn_ctx->num_failed_stop);
2720 } 2726 }
2721 churn_ctx->cb(churn_ctx->cb_cls, error_message); 2727 churn_ctx->cb(churn_ctx->cb_cls, error_message);
2722 GNUNET_free_non_null(error_message); 2728 GNUNET_free_non_null(error_message);
@@ -2748,17 +2754,21 @@ churn_start_callback (void *cls,
2748 2754
2749 error_message = NULL; 2755 error_message = NULL;
2750 if (emsg != NULL) 2756 if (emsg != NULL)
2751 { 2757 {
2752 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Churn stop callback failed with error `%s'\n", emsg); 2758 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2753 churn_ctx->num_failed_start++; 2759 "Churn stop callback failed with error `%s'\n",
2754 } 2760 emsg);
2761 churn_ctx->num_failed_start++;
2762 }
2755 else 2763 else
2756 { 2764 {
2757 churn_ctx->num_to_start--; 2765 churn_ctx->num_to_start--;
2758 } 2766 }
2759 2767
2760#if DEBUG_CHURN 2768#if DEBUG_CHURN
2761 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Started peer, %d left.\n", churn_ctx->num_to_start); 2769 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
2770 "Started peer, %d left.\n",
2771 churn_ctx->num_to_start);
2762#endif 2772#endif
2763 2773
2764 total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + (churn_ctx->num_to_start - churn_ctx->num_failed_start); 2774 total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) + (churn_ctx->num_to_start - churn_ctx->num_failed_start);
@@ -2766,14 +2776,17 @@ churn_start_callback (void *cls,
2766 if (total_left == 0) 2776 if (total_left == 0)
2767 { 2777 {
2768 if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0)) 2778 if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0))
2769 GNUNET_asprintf(&error_message, "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!", churn_ctx->num_failed_start, churn_ctx->num_failed_stop); 2779 GNUNET_asprintf(&error_message,
2780 "Churn didn't complete successfully, %u peers failed to start %u peers failed to be stopped!",
2781 churn_ctx->num_failed_start,
2782 churn_ctx->num_failed_stop);
2770 churn_ctx->cb(churn_ctx->cb_cls, error_message); 2783 churn_ctx->cb(churn_ctx->cb_cls, error_message);
2771 GNUNET_free_non_null(error_message); 2784 GNUNET_free_non_null(error_message);
2772 GNUNET_free(churn_ctx); 2785 GNUNET_free(churn_ctx);
2773 } 2786 }
2774
2775} 2787}
2776 2788
2789
2777/** 2790/**
2778 * Simulate churn by stopping some peers (and possibly 2791 * Simulate churn by stopping some peers (and possibly
2779 * re-starting others if churn is called multiple times). This 2792 * re-starting others if churn is called multiple times). This
@@ -2885,15 +2898,19 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
2885#if DEBUG_CHURN 2898#if DEBUG_CHURN
2886 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n", running_permute[i]); 2899 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n", running_permute[i]);
2887#endif 2900#endif
2888 GNUNET_TESTING_daemon_stop(pg->peers[running_arr[running_permute[i]]].daemon, timeout, &churn_stop_callback, churn_ctx, GNUNET_NO, GNUNET_YES); 2901 GNUNET_TESTING_daemon_stop (pg->peers[running_arr[running_permute[i]]].daemon,
2902 timeout,
2903 &churn_stop_callback, churn_ctx,
2904 GNUNET_NO, GNUNET_YES);
2889 } 2905 }
2890 2906
2891 for (i = 0; i < von; i++) 2907 for (i = 0; i < von; i++)
2892 { 2908 {
2893#if DEBUG_CHURN 2909#if DEBUG_CHURN
2894 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n", stopped_permute[i]); 2910 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n", stopped_permute[i]);
2895#endif 2911#endif
2896 GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon, timeout, &churn_start_callback, churn_ctx); 2912 GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon,
2913 timeout, &churn_start_callback, churn_ctx);
2897 } 2914 }
2898 2915
2899 GNUNET_free(running_arr); 2916 GNUNET_free(running_arr);
@@ -2932,36 +2949,85 @@ GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TEST
2932} 2949}
2933 2950
2934/** 2951/**
2935 * Shutdown all peers started in the given group. 2952 * Start or stop an individual peer from the given group.
2936 * 2953 *
2937 * @param pg handle to the peer group 2954 * @param pg handle to the peer group
2955 * @param offset which peer to start or stop
2956 * @param desired_status GNUNET_YES to have it running, GNUNET_NO to stop it
2938 * @param timeout how long to wait for shutdown 2957 * @param timeout how long to wait for shutdown
2958 * @param cb function to call at the end
2959 * @param cb_cls closure for cb
2960 */
2961void
2962GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
2963 unsigned int offset,
2964 int desired_status,
2965 struct GNUNET_TIME_Relative timeout,
2966 GNUNET_TESTING_NotifyCompletion cb,
2967 void *cb_cls)
2968{
2969 struct ChurnContext *churn_ctx;
2970
2971 if (GNUNET_NO == desired_status)
2972 {
2973 if (NULL != pg->peers[offset].daemon)
2974 {
2975 churn_ctx = GNUNET_malloc(sizeof(struct ChurnContext));
2976 churn_ctx->num_to_start = 0;
2977 churn_ctx->num_to_stop = 1;
2978 churn_ctx->cb = cb;
2979 churn_ctx->cb_cls = cb_cls;
2980 GNUNET_TESTING_daemon_stop(pg->peers[offset].daemon,
2981 timeout, &churn_stop_callback, churn_ctx,
2982 GNUNET_NO, GNUNET_YES);
2983 }
2984 }
2985 else if (GNUNET_YES == desired_status)
2986 {
2987 if (NULL == pg->peers[offset].daemon)
2988 {
2989 churn_ctx = GNUNET_malloc(sizeof(struct ChurnContext));
2990 churn_ctx->num_to_start = 1;
2991 churn_ctx->num_to_stop = 0;
2992 churn_ctx->cb = cb;
2993 churn_ctx->cb_cls = cb_cls;
2994 GNUNET_TESTING_daemon_start_stopped(pg->peers[offset].daemon,
2995 timeout, &churn_start_callback, churn_ctx);
2996 }
2997 }
2998 else
2999 GNUNET_break (0);
3000}
3001
3002
3003/**
3004 * Shutdown all peers started in the given group.
2939 * 3005 *
3006 * @param pg handle to the peer group
3007 * @param timeout how long to wait for shutdown
2940 */ 3008 */
2941void 3009void
2942GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, struct GNUNET_TIME_Relative timeout) 3010GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
3011 struct GNUNET_TIME_Relative timeout)
2943{ 3012{
2944 unsigned int off; 3013 unsigned int off;
2945 3014
2946 for (off = 0; off < pg->total; off++) 3015 for (off = 0; off < pg->total; off++)
2947 { 3016 {
2948 /* FIXME: should we wait for our 3017 /* FIXME: should we wait for our continuations to be called
2949 continuations to be called here? This 3018 here? This would require us to take a continuation as
2950 would require us to take a continuation 3019 well... */
2951 as well... */
2952 3020
2953 if (NULL != pg->peers[off].daemon) 3021 if (NULL != pg->peers[off].daemon)
2954 GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, NULL, NULL, GNUNET_YES, GNUNET_NO); 3022 GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, NULL, NULL, GNUNET_YES, GNUNET_NO);
2955 if (NULL != pg->peers[off].cfg) 3023 if (NULL != pg->peers[off].cfg)
2956 GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); 3024 GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg);
2957
2958 if (pg->peers[off].allowed_peers != NULL) 3025 if (pg->peers[off].allowed_peers != NULL)
2959 GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].allowed_peers); 3026 GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].allowed_peers);
2960 if (pg->peers[off].connect_peers != NULL) 3027 if (pg->peers[off].connect_peers != NULL)
2961 GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].connect_peers); 3028 GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].connect_peers);
2962 if (pg->peers[off].blacklisted_peers != NULL) 3029 if (pg->peers[off].blacklisted_peers != NULL)
2963 GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].blacklisted_peers); 3030 GNUNET_CONTAINER_multihashmap_destroy(pg->peers[off].blacklisted_peers);
2964
2965 } 3031 }
2966 GNUNET_free (pg->peers); 3032 GNUNET_free (pg->peers);
2967 if (NULL != pg->hosts) 3033 if (NULL != pg->hosts)