From 134afc9acfb4b12c84cdf8b56b2eabb856fde3e7 Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Mon, 28 Jun 2010 12:21:40 +0000 Subject: callback for peergroup shutdown in testing, requisite testcase changes --- src/testing/test_testing_connect.c | 1 - src/testing/test_testing_data_topology_clique.conf | 2 +- .../test_testing_data_topology_clique_minimum.conf | 4 +- .../test_testing_data_topology_clique_random.conf | 4 +- src/testing/test_testing_group.c | 32 ++++++- src/testing/test_testing_group_remote.c | 28 +++++- src/testing/test_testing_topology.c | 37 ++++++-- src/testing/test_testing_topology_blacklist.c | 29 +++++- src/testing/test_testing_topology_churn.c | 28 +++++- src/testing/testing_group.c | 101 ++++++++++++++++++--- 10 files changed, 226 insertions(+), 40 deletions(-) (limited to 'src/testing') diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c index 8563014f2..28c6cddb0 100644 --- a/src/testing/test_testing_connect.c +++ b/src/testing/test_testing_connect.c @@ -26,7 +26,6 @@ #define VERBOSE GNUNET_NO - /** * How long until we give up on connecting the peers? */ diff --git a/src/testing/test_testing_data_topology_clique.conf b/src/testing/test_testing_data_topology_clique.conf index 114364da2..a6cf1eb2e 100644 --- a/src/testing/test_testing_data_topology_clique.conf +++ b/src/testing/test_testing_data_topology_clique.conf @@ -32,7 +32,7 @@ PORT = 2569 #DEBUG = YES #PREFIX = xterm -e xterm -T peerinfo -e gdb --args #BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/peerinfo/.libs/gnunet-service-peerinfo -#PREFIX = valgrind --tool=memcheck --log-file=peerinfo%p +PREFIX = valgrind --tool=memcheck --log-file=peerinfo%p [core] PORT = 2570 diff --git a/src/testing/test_testing_data_topology_clique_minimum.conf b/src/testing/test_testing_data_topology_clique_minimum.conf index c8b056e98..e4a72862c 100644 --- a/src/testing/test_testing_data_topology_clique_minimum.conf +++ b/src/testing/test_testing_data_topology_clique_minimum.conf @@ -40,9 +40,9 @@ PORT = 2570 #DEBUG = YES [testing] -NUM_PEERS = 5 +NUM_PEERS = 20 WEAKRANDOM = YES TOPOLOGY = CLIQUE CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM -CONNECT_TOPOLOGY_OPTION_MODIFIER = 1.0 +CONNECT_TOPOLOGY_OPTION_MODIFIER = 2.0 F2F = YES diff --git a/src/testing/test_testing_data_topology_clique_random.conf b/src/testing/test_testing_data_topology_clique_random.conf index c79698ac1..f66baf439 100644 --- a/src/testing/test_testing_data_topology_clique_random.conf +++ b/src/testing/test_testing_data_topology_clique_random.conf @@ -40,9 +40,9 @@ PORT = 2570 #DEBUG = YES [testing] -NUM_PEERS = 5 +NUM_PEERS = 20 WEAKRANDOM = YES TOPOLOGY = CLIQUE CONNECT_TOPOLOGY_OPTION = CONNECT_RANDOM_SUBSET -CONNECT_TOPOLOGY_OPTION_MODIFIER = .5 +CONNECT_TOPOLOGY_OPTION_MODIFIER = .15 F2F = YES diff --git a/src/testing/test_testing_group.c b/src/testing/test_testing_group.c index 81d949e2a..c0ceaa799 100644 --- a/src/testing/test_testing_group.c +++ b/src/testing/test_testing_group.c @@ -24,7 +24,7 @@ #include "platform.h" #include "gnunet_testing_lib.h" -#define VERBOSE GNUNET_YES +#define VERBOSE GNUNET_NO #define NUM_PEERS 4 @@ -43,6 +43,30 @@ static struct GNUNET_TESTING_PeerGroup *pg; static struct GNUNET_SCHEDULER_Handle *sched; +/** + * Check whether peers successfully shut down. + */ +void shutdown_callback (void *cls, + const char *emsg) +{ + if (emsg != NULL) + { +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shutdown of peers failed!\n"); +#endif + if (ok == 0) + ok = 666; + } + else + { +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All peers successfully shut down!\n"); +#endif + } +} + static void my_cb (void *cls, @@ -59,7 +83,7 @@ my_cb (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); ok = 1; - GNUNET_TESTING_daemons_stop (pg, TIMEOUT); + GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); } return; } @@ -68,14 +92,14 @@ my_cb (void *cls, if (peers_left == 0) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started successfully, ending test!\n"); - GNUNET_TESTING_daemons_stop (pg, TIMEOUT); + GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); ok = 0; } else if (failed_peers == peers_left) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); ok = 1; - GNUNET_TESTING_daemons_stop (pg, TIMEOUT); + GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); } } diff --git a/src/testing/test_testing_group_remote.c b/src/testing/test_testing_group_remote.c index 6b7fabb31..562e858e5 100644 --- a/src/testing/test_testing_group_remote.c +++ b/src/testing/test_testing_group_remote.c @@ -50,6 +50,30 @@ static unsigned long long num_peers; static char *hostnames; +/** + * Check whether peers successfully shut down. + */ +void shutdown_callback (void *cls, + const char *emsg) +{ + if (emsg != NULL) + { +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shutdown of peers failed!\n"); +#endif + if (ok == 0) + ok = 666; + } + else + { +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All peers successfully shut down!\n"); +#endif + } +} + static void my_cb (void *cls, @@ -65,13 +89,13 @@ my_cb (void *cls, peers_left--; if (peers_left == 0) { - GNUNET_TESTING_daemons_stop (pg, TIMEOUT); + 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); + GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); } } diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index d7bb836e9..ba9084e31 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c @@ -25,7 +25,7 @@ #include "gnunet_testing_lib.h" #include "gnunet_core_service.h" -#define VERBOSE GNUNET_YES +#define VERBOSE GNUNET_NO /** * How long until we fail the whole testcase? @@ -137,6 +137,30 @@ struct TestMessageContext static struct TestMessageContext *test_messages; +/** + * Check whether peers successfully shut down. + */ +void shutdown_callback (void *cls, + const char *emsg) +{ + if (emsg != NULL) + { +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shutdown of peers failed!\n"); +#endif + if (ok == 0) + ok = 666; + } + else + { +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All peers successfully shut down!\n"); +#endif + } +} + static void finish_testing () { @@ -179,11 +203,8 @@ finish_testing () GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n"); #endif - GNUNET_TESTING_daemons_stop (pg, TIMEOUT); -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "daemons_stop finished\n"); -#endif + GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); + if (dotOutFile != NULL) { fprintf(dotOutFile, "}"); @@ -282,7 +303,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) if (pg != NULL) { - GNUNET_TESTING_daemons_stop (pg, TIMEOUT); + GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); ok = 7331; /* Opposite of leet */ } else @@ -295,8 +316,6 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) } } - - static size_t transmit_ready (void *cls, size_t size, void *buf) { diff --git a/src/testing/test_testing_topology_blacklist.c b/src/testing/test_testing_topology_blacklist.c index 9788fa87c..b68386cd7 100644 --- a/src/testing/test_testing_topology_blacklist.c +++ b/src/testing/test_testing_topology_blacklist.c @@ -96,6 +96,31 @@ struct GNUNET_TestMessage uint32_t uid; }; + +/** + * Check whether peers successfully shut down. + */ +void shutdown_callback (void *cls, + const char *emsg) +{ + if (emsg != NULL) + { +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shutdown of peers failed!\n"); +#endif + if (ok == 0) + ok = 666; + } + else + { +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All peers successfully shut down!\n"); +#endif + } +} + static void finish_testing () { @@ -110,7 +135,7 @@ finish_testing () GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n"); #endif - GNUNET_TESTING_daemons_stop (pg, TIMEOUT); + GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n"); @@ -133,7 +158,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) if (pg != NULL) { - GNUNET_TESTING_daemons_stop (pg, TIMEOUT); + GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); ok = 7331; /* Opposite of leet */ } else diff --git a/src/testing/test_testing_topology_churn.c b/src/testing/test_testing_topology_churn.c index 0d894378f..ba493e295 100644 --- a/src/testing/test_testing_topology_churn.c +++ b/src/testing/test_testing_topology_churn.c @@ -74,6 +74,30 @@ struct GNUNET_TestMessage uint32_t uid; }; +/** + * Check whether peers successfully shut down. + */ +void shutdown_callback (void *cls, + const char *emsg) +{ + if (emsg != NULL) + { +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shutdown of peers failed!\n"); +#endif + if (ok == 0) + ok = 666; + } + else + { +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All peers successfully shut down!\n"); +#endif + } +} + static void finish_testing () { @@ -91,7 +115,7 @@ finish_testing () GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n"); #endif - GNUNET_TESTING_daemons_stop (pg, TIMEOUT); + GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n"); @@ -109,7 +133,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) if (pg != NULL) { - GNUNET_TESTING_daemons_stop (pg, TIMEOUT); + GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); ok = 7331; /* Opposite of leet */ } else diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index de624f25f..831657305 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -21,16 +21,9 @@ /** * @file testing/testing_group.c * @brief convenience API for writing testcases for GNUnet + * @author Nathan Evans * @author Christian Grothoff * - * FIXME: have connection processor functions take a cls argument - * which specifies where to write the connection information - * instead of assuming it's certain peergroup places. (maybe?) - * FIXME: create static struct which contains the TOPOLOGY enum, the - * associated string, and the function used to create it. - * Then replace the create_X calls with topology_struct[i][2] - * or something. (Store function pointers instead of using - * switch statements) */ #include "platform.h" #include "gnunet_arm_service.h" @@ -55,7 +48,7 @@ * conflict with the port range for "local" ports (client apps; see * /proc/sys/net/ipv4/ip_local_port_range on Linux for example). */ -#define HIGH_PORT 32000 +#define HIGH_PORT 56000 #define MAX_OUTSTANDING_CONNECTIONS 50 @@ -137,6 +130,36 @@ struct RestartContext }; + +struct ShutdownContext +{ + /** + * Total peers to wait for + */ + int total_peers; + + /** + * Number of peers successfully shut down + */ + int peers_down; + + /** + * Number of peers failed to shut down + */ + int peers_failed; + + /** + * Callback to call when all peers either + * shutdown or failed to shutdown + */ + GNUNET_TESTING_NotifyCompletion cb; + + /** + * Closure for cb + */ + void *cb_cls; +}; + struct CreateTopologyContext { @@ -3346,26 +3369,74 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, } +/** + * Callback for shutting down peers in a peer group. + * + * @param cls closure (struct ShutdownContext) + * @param emsg NULL on success + */ +void internal_shutdown_callback (void *cls, + const char *emsg) +{ + struct ShutdownContext *shutdown_ctx = cls; + + if (emsg == NULL) + { + shutdown_ctx->peers_down++; + } + else + { + shutdown_ctx->peers_failed++; + } + + if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down + shutdown_ctx->peers_failed == shutdown_ctx->total_peers)) + { + if (shutdown_ctx->peers_failed > 0) + shutdown_ctx->cb(shutdown_ctx->cb_cls, "Not all peers successfully shut down!"); + else + shutdown_ctx->cb(shutdown_ctx->cb_cls, NULL); + GNUNET_free(shutdown_ctx); + } +} + /** * Shutdown all peers started in the given group. * * @param pg handle to the peer group * @param timeout how long to wait for shutdown + * @param cb callback to notify upon success or failure + * @param cb_cls closure for cb */ void GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, - struct GNUNET_TIME_Relative timeout) + struct GNUNET_TIME_Relative timeout, + GNUNET_TESTING_NotifyCompletion cb, + void *cb_cls) { unsigned int off; + struct ShutdownContext *shutdown_ctx; + GNUNET_TESTING_NotifyCompletion shutdown_cb; + void *shutdown_cb_cls; - for (off = 0; off < pg->total; off++) + GNUNET_assert(pg->total > 0); + + shutdown_cb = NULL; + shutdown_ctx = NULL; + + if (cb != NULL) { - /* FIXME: should we wait for our continuations to be called - here? This would require us to take a continuation as - well... */ + shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext)); + shutdown_ctx->cb = cb; + shutdown_ctx->cb_cls = cb_cls; + shutdown_ctx->total_peers = pg->total; + shutdown_cb = &internal_shutdown_callback; + shutdown_cb_cls = cb_cls; + } + for (off = 0; off < pg->total; off++) + { if (NULL != pg->peers[off].daemon) - GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, NULL, NULL, GNUNET_YES, GNUNET_NO); + GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, shutdown_cb, shutdown_ctx, GNUNET_YES, GNUNET_NO); if (NULL != pg->peers[off].cfg) GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); if (pg->peers[off].allowed_peers != NULL) -- cgit v1.2.3