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 | |
parent | 59ca0059f61b1e2538f2890625601a88b2119f66 (diff) | |
download | gnunet-134afc9acfb4b12c84cdf8b56b2eabb856fde3e7.tar.gz gnunet-134afc9acfb4b12c84cdf8b56b2eabb856fde3e7.zip |
callback for peergroup shutdown in testing, requisite testcase changes
-rw-r--r-- | src/testing/test_testing_connect.c | 1 | ||||
-rw-r--r-- | src/testing/test_testing_data_topology_clique.conf | 2 | ||||
-rw-r--r-- | src/testing/test_testing_data_topology_clique_minimum.conf | 4 | ||||
-rw-r--r-- | src/testing/test_testing_data_topology_clique_random.conf | 4 | ||||
-rw-r--r-- | src/testing/test_testing_group.c | 32 | ||||
-rw-r--r-- | src/testing/test_testing_group_remote.c | 28 | ||||
-rw-r--r-- | src/testing/test_testing_topology.c | 37 | ||||
-rw-r--r-- | src/testing/test_testing_topology_blacklist.c | 29 | ||||
-rw-r--r-- | src/testing/test_testing_topology_churn.c | 28 | ||||
-rw-r--r-- | src/testing/testing_group.c | 101 |
10 files changed, 226 insertions, 40 deletions
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 @@ | |||
26 | 26 | ||
27 | #define VERBOSE GNUNET_NO | 27 | #define VERBOSE GNUNET_NO |
28 | 28 | ||
29 | |||
30 | /** | 29 | /** |
31 | * How long until we give up on connecting the peers? | 30 | * How long until we give up on connecting the peers? |
32 | */ | 31 | */ |
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 | |||
32 | #DEBUG = YES | 32 | #DEBUG = YES |
33 | #PREFIX = xterm -e xterm -T peerinfo -e gdb --args | 33 | #PREFIX = xterm -e xterm -T peerinfo -e gdb --args |
34 | #BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/peerinfo/.libs/gnunet-service-peerinfo | 34 | #BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/peerinfo/.libs/gnunet-service-peerinfo |
35 | #PREFIX = valgrind --tool=memcheck --log-file=peerinfo%p | 35 | PREFIX = valgrind --tool=memcheck --log-file=peerinfo%p |
36 | 36 | ||
37 | [core] | 37 | [core] |
38 | PORT = 2570 | 38 | 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 | |||
40 | #DEBUG = YES | 40 | #DEBUG = YES |
41 | 41 | ||
42 | [testing] | 42 | [testing] |
43 | NUM_PEERS = 5 | 43 | NUM_PEERS = 20 |
44 | WEAKRANDOM = YES | 44 | WEAKRANDOM = YES |
45 | TOPOLOGY = CLIQUE | 45 | TOPOLOGY = CLIQUE |
46 | CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM | 46 | CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM |
47 | CONNECT_TOPOLOGY_OPTION_MODIFIER = 1.0 | 47 | CONNECT_TOPOLOGY_OPTION_MODIFIER = 2.0 |
48 | F2F = YES | 48 | 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 | |||
40 | #DEBUG = YES | 40 | #DEBUG = YES |
41 | 41 | ||
42 | [testing] | 42 | [testing] |
43 | NUM_PEERS = 5 | 43 | NUM_PEERS = 20 |
44 | WEAKRANDOM = YES | 44 | WEAKRANDOM = YES |
45 | TOPOLOGY = CLIQUE | 45 | TOPOLOGY = CLIQUE |
46 | CONNECT_TOPOLOGY_OPTION = CONNECT_RANDOM_SUBSET | 46 | CONNECT_TOPOLOGY_OPTION = CONNECT_RANDOM_SUBSET |
47 | CONNECT_TOPOLOGY_OPTION_MODIFIER = .5 | 47 | CONNECT_TOPOLOGY_OPTION_MODIFIER = .15 |
48 | F2F = YES | 48 | 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 @@ | |||
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_testing_lib.h" | 25 | #include "gnunet_testing_lib.h" |
26 | 26 | ||
27 | #define VERBOSE GNUNET_YES | 27 | #define VERBOSE GNUNET_NO |
28 | 28 | ||
29 | #define NUM_PEERS 4 | 29 | #define NUM_PEERS 4 |
30 | 30 | ||
@@ -43,6 +43,30 @@ static struct GNUNET_TESTING_PeerGroup *pg; | |||
43 | 43 | ||
44 | static struct GNUNET_SCHEDULER_Handle *sched; | 44 | static struct GNUNET_SCHEDULER_Handle *sched; |
45 | 45 | ||
46 | /** | ||
47 | * Check whether peers successfully shut down. | ||
48 | */ | ||
49 | void shutdown_callback (void *cls, | ||
50 | const char *emsg) | ||
51 | { | ||
52 | if (emsg != NULL) | ||
53 | { | ||
54 | #if VERBOSE | ||
55 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
56 | "Shutdown of peers failed!\n"); | ||
57 | #endif | ||
58 | if (ok == 0) | ||
59 | ok = 666; | ||
60 | } | ||
61 | else | ||
62 | { | ||
63 | #if VERBOSE | ||
64 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
65 | "All peers successfully shut down!\n"); | ||
66 | #endif | ||
67 | } | ||
68 | } | ||
69 | |||
46 | 70 | ||
47 | static void | 71 | static void |
48 | my_cb (void *cls, | 72 | my_cb (void *cls, |
@@ -59,7 +83,7 @@ my_cb (void *cls, | |||
59 | { | 83 | { |
60 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); | 84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); |
61 | ok = 1; | 85 | ok = 1; |
62 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT); | 86 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
63 | } | 87 | } |
64 | return; | 88 | return; |
65 | } | 89 | } |
@@ -68,14 +92,14 @@ my_cb (void *cls, | |||
68 | if (peers_left == 0) | 92 | if (peers_left == 0) |
69 | { | 93 | { |
70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started successfully, ending test!\n"); | 94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started successfully, ending test!\n"); |
71 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT); | 95 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
72 | ok = 0; | 96 | ok = 0; |
73 | } | 97 | } |
74 | else if (failed_peers == peers_left) | 98 | else if (failed_peers == peers_left) |
75 | { | 99 | { |
76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); | 100 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); |
77 | ok = 1; | 101 | ok = 1; |
78 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT); | 102 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
79 | } | 103 | } |
80 | } | 104 | } |
81 | 105 | ||
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; | |||
50 | 50 | ||
51 | static char *hostnames; | 51 | static char *hostnames; |
52 | 52 | ||
53 | /** | ||
54 | * Check whether peers successfully shut down. | ||
55 | */ | ||
56 | void shutdown_callback (void *cls, | ||
57 | const char *emsg) | ||
58 | { | ||
59 | if (emsg != NULL) | ||
60 | { | ||
61 | #if VERBOSE | ||
62 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
63 | "Shutdown of peers failed!\n"); | ||
64 | #endif | ||
65 | if (ok == 0) | ||
66 | ok = 666; | ||
67 | } | ||
68 | else | ||
69 | { | ||
70 | #if VERBOSE | ||
71 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
72 | "All peers successfully shut down!\n"); | ||
73 | #endif | ||
74 | } | ||
75 | } | ||
76 | |||
53 | 77 | ||
54 | static void | 78 | static void |
55 | my_cb (void *cls, | 79 | my_cb (void *cls, |
@@ -65,13 +89,13 @@ my_cb (void *cls, | |||
65 | peers_left--; | 89 | peers_left--; |
66 | if (peers_left == 0) | 90 | if (peers_left == 0) |
67 | { | 91 | { |
68 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT); | 92 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
69 | ok = 0; | 93 | ok = 0; |
70 | } | 94 | } |
71 | else if (peers_failed == peers_left) | 95 | else if (peers_failed == peers_left) |
72 | { | 96 | { |
73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); | 97 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n"); |
74 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT); | 98 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
75 | } | 99 | } |
76 | } | 100 | } |
77 | 101 | ||
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 @@ | |||
25 | #include "gnunet_testing_lib.h" | 25 | #include "gnunet_testing_lib.h" |
26 | #include "gnunet_core_service.h" | 26 | #include "gnunet_core_service.h" |
27 | 27 | ||
28 | #define VERBOSE GNUNET_YES | 28 | #define VERBOSE GNUNET_NO |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * How long until we fail the whole testcase? | 31 | * How long until we fail the whole testcase? |
@@ -137,6 +137,30 @@ struct TestMessageContext | |||
137 | 137 | ||
138 | static struct TestMessageContext *test_messages; | 138 | static struct TestMessageContext *test_messages; |
139 | 139 | ||
140 | /** | ||
141 | * Check whether peers successfully shut down. | ||
142 | */ | ||
143 | void shutdown_callback (void *cls, | ||
144 | const char *emsg) | ||
145 | { | ||
146 | if (emsg != NULL) | ||
147 | { | ||
148 | #if VERBOSE | ||
149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
150 | "Shutdown of peers failed!\n"); | ||
151 | #endif | ||
152 | if (ok == 0) | ||
153 | ok = 666; | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | #if VERBOSE | ||
158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
159 | "All peers successfully shut down!\n"); | ||
160 | #endif | ||
161 | } | ||
162 | } | ||
163 | |||
140 | static void | 164 | static void |
141 | finish_testing () | 165 | finish_testing () |
142 | { | 166 | { |
@@ -179,11 +203,8 @@ finish_testing () | |||
179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
180 | "Calling daemons_stop\n"); | 204 | "Calling daemons_stop\n"); |
181 | #endif | 205 | #endif |
182 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT); | 206 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
183 | #if VERBOSE | 207 | |
184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
185 | "daemons_stop finished\n"); | ||
186 | #endif | ||
187 | if (dotOutFile != NULL) | 208 | if (dotOutFile != NULL) |
188 | { | 209 | { |
189 | fprintf(dotOutFile, "}"); | 210 | fprintf(dotOutFile, "}"); |
@@ -282,7 +303,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
282 | 303 | ||
283 | if (pg != NULL) | 304 | if (pg != NULL) |
284 | { | 305 | { |
285 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT); | 306 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
286 | ok = 7331; /* Opposite of leet */ | 307 | ok = 7331; /* Opposite of leet */ |
287 | } | 308 | } |
288 | else | 309 | else |
@@ -295,8 +316,6 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
295 | } | 316 | } |
296 | } | 317 | } |
297 | 318 | ||
298 | |||
299 | |||
300 | static size_t | 319 | static size_t |
301 | transmit_ready (void *cls, size_t size, void *buf) | 320 | transmit_ready (void *cls, size_t size, void *buf) |
302 | { | 321 | { |
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 | |||
96 | uint32_t uid; | 96 | uint32_t uid; |
97 | }; | 97 | }; |
98 | 98 | ||
99 | |||
100 | /** | ||
101 | * Check whether peers successfully shut down. | ||
102 | */ | ||
103 | void shutdown_callback (void *cls, | ||
104 | const char *emsg) | ||
105 | { | ||
106 | if (emsg != NULL) | ||
107 | { | ||
108 | #if VERBOSE | ||
109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
110 | "Shutdown of peers failed!\n"); | ||
111 | #endif | ||
112 | if (ok == 0) | ||
113 | ok = 666; | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | #if VERBOSE | ||
118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
119 | "All peers successfully shut down!\n"); | ||
120 | #endif | ||
121 | } | ||
122 | } | ||
123 | |||
99 | static void | 124 | static void |
100 | finish_testing () | 125 | finish_testing () |
101 | { | 126 | { |
@@ -110,7 +135,7 @@ finish_testing () | |||
110 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
111 | "Calling daemons_stop\n"); | 136 | "Calling daemons_stop\n"); |
112 | #endif | 137 | #endif |
113 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT); | 138 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
114 | #if VERBOSE | 139 | #if VERBOSE |
115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
116 | "daemons_stop finished\n"); | 141 | "daemons_stop finished\n"); |
@@ -133,7 +158,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
133 | 158 | ||
134 | if (pg != NULL) | 159 | if (pg != NULL) |
135 | { | 160 | { |
136 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT); | 161 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
137 | ok = 7331; /* Opposite of leet */ | 162 | ok = 7331; /* Opposite of leet */ |
138 | } | 163 | } |
139 | else | 164 | 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 | |||
74 | uint32_t uid; | 74 | uint32_t uid; |
75 | }; | 75 | }; |
76 | 76 | ||
77 | /** | ||
78 | * Check whether peers successfully shut down. | ||
79 | */ | ||
80 | void shutdown_callback (void *cls, | ||
81 | const char *emsg) | ||
82 | { | ||
83 | if (emsg != NULL) | ||
84 | { | ||
85 | #if VERBOSE | ||
86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
87 | "Shutdown of peers failed!\n"); | ||
88 | #endif | ||
89 | if (ok == 0) | ||
90 | ok = 666; | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | #if VERBOSE | ||
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
96 | "All peers successfully shut down!\n"); | ||
97 | #endif | ||
98 | } | ||
99 | } | ||
100 | |||
77 | static void | 101 | static void |
78 | finish_testing () | 102 | finish_testing () |
79 | { | 103 | { |
@@ -91,7 +115,7 @@ finish_testing () | |||
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
92 | "Calling daemons_stop\n"); | 116 | "Calling daemons_stop\n"); |
93 | #endif | 117 | #endif |
94 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT); | 118 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
95 | #if VERBOSE | 119 | #if VERBOSE |
96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
97 | "daemons_stop finished\n"); | 121 | "daemons_stop finished\n"); |
@@ -109,7 +133,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
109 | 133 | ||
110 | if (pg != NULL) | 134 | if (pg != NULL) |
111 | { | 135 | { |
112 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT); | 136 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
113 | ok = 7331; /* Opposite of leet */ | 137 | ok = 7331; /* Opposite of leet */ |
114 | } | 138 | } |
115 | else | 139 | 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 @@ | |||
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) |