diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-06-28 12:21:40 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-06-28 12:21:40 +0000 |
commit | 134afc9acfb4b12c84cdf8b56b2eabb856fde3e7 (patch) | |
tree | f62956e6c9ac0b39f37afc101270ce8660004831 /src/testing/testing_group.c | |
parent | 59ca0059f61b1e2538f2890625601a88b2119f66 (diff) | |
download | gnunet-134afc9acfb4b12c84cdf8b56b2eabb856fde3e7.tar.gz gnunet-134afc9acfb4b12c84cdf8b56b2eabb856fde3e7.zip |
callback for peergroup shutdown in testing, requisite testcase changes
Diffstat (limited to 'src/testing/testing_group.c')
-rw-r--r-- | src/testing/testing_group.c | 101 |
1 files changed, 86 insertions, 15 deletions
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 @@ | |||
21 | /** | 21 | /** |
22 | * @file testing/testing_group.c | 22 | * @file testing/testing_group.c |
23 | * @brief convenience API for writing testcases for GNUnet | 23 | * @brief convenience API for writing testcases for GNUnet |
24 | * @author Nathan Evans | ||
24 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
25 | * | 26 | * |
26 | * FIXME: have connection processor functions take a cls argument | ||
27 | * which specifies where to write the connection information | ||
28 | * instead of assuming it's certain peergroup places. (maybe?) | ||
29 | * FIXME: create static struct which contains the TOPOLOGY enum, the | ||
30 | * associated string, and the function used to create it. | ||
31 | * Then replace the create_X calls with topology_struct[i][2] | ||
32 | * or something. (Store function pointers instead of using | ||
33 | * switch statements) | ||
34 | */ | 27 | */ |
35 | #include "platform.h" | 28 | #include "platform.h" |
36 | #include "gnunet_arm_service.h" | 29 | #include "gnunet_arm_service.h" |
@@ -55,7 +48,7 @@ | |||
55 | * conflict with the port range for "local" ports (client apps; see | 48 | * conflict with the port range for "local" ports (client apps; see |
56 | * /proc/sys/net/ipv4/ip_local_port_range on Linux for example). | 49 | * /proc/sys/net/ipv4/ip_local_port_range on Linux for example). |
57 | */ | 50 | */ |
58 | #define HIGH_PORT 32000 | 51 | #define HIGH_PORT 56000 |
59 | 52 | ||
60 | #define MAX_OUTSTANDING_CONNECTIONS 50 | 53 | #define MAX_OUTSTANDING_CONNECTIONS 50 |
61 | 54 | ||
@@ -137,6 +130,36 @@ struct RestartContext | |||
137 | 130 | ||
138 | }; | 131 | }; |
139 | 132 | ||
133 | |||
134 | struct ShutdownContext | ||
135 | { | ||
136 | /** | ||
137 | * Total peers to wait for | ||
138 | */ | ||
139 | int total_peers; | ||
140 | |||
141 | /** | ||
142 | * Number of peers successfully shut down | ||
143 | */ | ||
144 | int peers_down; | ||
145 | |||
146 | /** | ||
147 | * Number of peers failed to shut down | ||
148 | */ | ||
149 | int peers_failed; | ||
150 | |||
151 | /** | ||
152 | * Callback to call when all peers either | ||
153 | * shutdown or failed to shutdown | ||
154 | */ | ||
155 | GNUNET_TESTING_NotifyCompletion cb; | ||
156 | |||
157 | /** | ||
158 | * Closure for cb | ||
159 | */ | ||
160 | void *cb_cls; | ||
161 | }; | ||
162 | |||
140 | struct CreateTopologyContext | 163 | struct CreateTopologyContext |
141 | { | 164 | { |
142 | 165 | ||
@@ -3347,25 +3370,73 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, | |||
3347 | 3370 | ||
3348 | 3371 | ||
3349 | /** | 3372 | /** |
3373 | * Callback for shutting down peers in a peer group. | ||
3374 | * | ||
3375 | * @param cls closure (struct ShutdownContext) | ||
3376 | * @param emsg NULL on success | ||
3377 | */ | ||
3378 | void internal_shutdown_callback (void *cls, | ||
3379 | const char *emsg) | ||
3380 | { | ||
3381 | struct ShutdownContext *shutdown_ctx = cls; | ||
3382 | |||
3383 | if (emsg == NULL) | ||
3384 | { | ||
3385 | shutdown_ctx->peers_down++; | ||
3386 | } | ||
3387 | else | ||
3388 | { | ||
3389 | shutdown_ctx->peers_failed++; | ||
3390 | } | ||
3391 | |||
3392 | if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down + shutdown_ctx->peers_failed == shutdown_ctx->total_peers)) | ||
3393 | { | ||
3394 | if (shutdown_ctx->peers_failed > 0) | ||
3395 | shutdown_ctx->cb(shutdown_ctx->cb_cls, "Not all peers successfully shut down!"); | ||
3396 | else | ||
3397 | shutdown_ctx->cb(shutdown_ctx->cb_cls, NULL); | ||
3398 | GNUNET_free(shutdown_ctx); | ||
3399 | } | ||
3400 | } | ||
3401 | |||
3402 | /** | ||
3350 | * Shutdown all peers started in the given group. | 3403 | * Shutdown all peers started in the given group. |
3351 | * | 3404 | * |
3352 | * @param pg handle to the peer group | 3405 | * @param pg handle to the peer group |
3353 | * @param timeout how long to wait for shutdown | 3406 | * @param timeout how long to wait for shutdown |
3407 | * @param cb callback to notify upon success or failure | ||
3408 | * @param cb_cls closure for cb | ||
3354 | */ | 3409 | */ |
3355 | void | 3410 | void |
3356 | GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, | 3411 | GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, |
3357 | struct GNUNET_TIME_Relative timeout) | 3412 | struct GNUNET_TIME_Relative timeout, |
3413 | GNUNET_TESTING_NotifyCompletion cb, | ||
3414 | void *cb_cls) | ||
3358 | { | 3415 | { |
3359 | unsigned int off; | 3416 | unsigned int off; |
3417 | struct ShutdownContext *shutdown_ctx; | ||
3418 | GNUNET_TESTING_NotifyCompletion shutdown_cb; | ||
3419 | void *shutdown_cb_cls; | ||
3360 | 3420 | ||
3361 | for (off = 0; off < pg->total; off++) | 3421 | GNUNET_assert(pg->total > 0); |
3422 | |||
3423 | shutdown_cb = NULL; | ||
3424 | shutdown_ctx = NULL; | ||
3425 | |||
3426 | if (cb != NULL) | ||
3362 | { | 3427 | { |
3363 | /* FIXME: should we wait for our continuations to be called | 3428 | shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext)); |
3364 | here? This would require us to take a continuation as | 3429 | shutdown_ctx->cb = cb; |
3365 | well... */ | 3430 | shutdown_ctx->cb_cls = cb_cls; |
3431 | shutdown_ctx->total_peers = pg->total; | ||
3432 | shutdown_cb = &internal_shutdown_callback; | ||
3433 | shutdown_cb_cls = cb_cls; | ||
3434 | } | ||
3366 | 3435 | ||
3436 | for (off = 0; off < pg->total; off++) | ||
3437 | { | ||
3367 | if (NULL != pg->peers[off].daemon) | 3438 | if (NULL != pg->peers[off].daemon) |
3368 | GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, NULL, NULL, GNUNET_YES, GNUNET_NO); | 3439 | GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, shutdown_cb, shutdown_ctx, GNUNET_YES, GNUNET_NO); |
3369 | if (NULL != pg->peers[off].cfg) | 3440 | if (NULL != pg->peers[off].cfg) |
3370 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); | 3441 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); |
3371 | if (pg->peers[off].allowed_peers != NULL) | 3442 | if (pg->peers[off].allowed_peers != NULL) |