aboutsummaryrefslogtreecommitdiff
path: root/src/testing/test_testing_topology_churn.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-11-16 13:02:52 +0000
committerNathan S. Evans <evans@in.tum.de>2010-11-16 13:02:52 +0000
commitb0685d4301b6ddf5d95e5467add39a23b51aa5a1 (patch)
treea9808ba0b435e871f1b85ac4e7006895979e9d8b /src/testing/test_testing_topology_churn.c
parent7f082ef1cd69b48984b05ae72f3c124493fdd86e (diff)
downloadgnunet-b0685d4301b6ddf5d95e5467add39a23b51aa5a1.tar.gz
gnunet-b0685d4301b6ddf5d95e5467add39a23b51aa5a1.zip
Fix for testing where peer_start callback immediately calls peer_stop (also white space changes)
Diffstat (limited to 'src/testing/test_testing_topology_churn.c')
-rw-r--r--src/testing/test_testing_topology_churn.c93
1 files changed, 50 insertions, 43 deletions
diff --git a/src/testing/test_testing_topology_churn.c b/src/testing/test_testing_topology_churn.c
index 0e3647015..8b2a12069 100644
--- a/src/testing/test_testing_topology_churn.c
+++ b/src/testing/test_testing_topology_churn.c
@@ -75,14 +75,13 @@ struct GNUNET_TestMessage
75/** 75/**
76 * Check whether peers successfully shut down. 76 * Check whether peers successfully shut down.
77 */ 77 */
78void shutdown_callback (void *cls, 78void
79 const char *emsg) 79shutdown_callback (void *cls, const char *emsg)
80{ 80{
81 if (emsg != NULL) 81 if (emsg != NULL)
82 { 82 {
83#if VERBOSE 83#if VERBOSE
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
85 "Shutdown of peers failed!\n");
86#endif 85#endif
87 if (ok == 0) 86 if (ok == 0)
88 ok = 666; 87 ok = 666;
@@ -102,7 +101,7 @@ finish_testing ()
102 GNUNET_assert (pg != NULL); 101 GNUNET_assert (pg != NULL);
103 102
104 if (die_task != GNUNET_SCHEDULER_NO_TASK) 103 if (die_task != GNUNET_SCHEDULER_NO_TASK)
105 GNUNET_SCHEDULER_cancel(die_task); 104 GNUNET_SCHEDULER_cancel (die_task);
106 105
107#if VERBOSE 106#if VERBOSE
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -110,20 +109,18 @@ finish_testing ()
110#endif 109#endif
111 110
112#if VERBOSE 111#if VERBOSE
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
114 "Calling daemons_stop\n");
115#endif 113#endif
116 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 114 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
117#if VERBOSE 115#if VERBOSE
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n");
119 "daemons_stop finished\n");
120#endif 117#endif
121 118
122 ok = 0; 119 ok = 0;
123} 120}
124 121
125static void 122static void
126end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 123end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
127{ 124{
128 char *msg = cls; 125 char *msg = cls;
129 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 126 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -153,61 +150,63 @@ static struct ChurnTestContext churn_ctx;
153 * @param cls closure 150 * @param cls closure
154 * @param emsg NULL on success 151 * @param emsg NULL on success
155 */ 152 */
156void churn_callback(void *cls, 153void
157 const char *emsg) 154churn_callback (void *cls, const char *emsg)
158{ 155{
159 if (emsg == NULL) 156 if (emsg == NULL)
160 { 157 {
161 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Successfully churned peers!\n", emsg); 158 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Successfully churned peers!\n",
162 GNUNET_SCHEDULER_add_now(churn_ctx.next_task, NULL); 159 emsg);
160 GNUNET_SCHEDULER_add_now (churn_ctx.next_task, NULL);
163 } 161 }
164 else 162 else
165 { 163 {
166 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to churn peers with error `%s'\n", emsg); 164 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
167 GNUNET_SCHEDULER_cancel(die_task); 165 "Failed to churn peers with error `%s'\n", emsg);
168 die_task = GNUNET_SCHEDULER_add_now(&end_badly, NULL); 166 GNUNET_SCHEDULER_cancel (die_task);
167 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
169 } 168 }
170} 169}
171 170
172 171
173static void 172static void
174churn_peers_both() 173churn_peers_both ()
175{ 174{
176 churn_ctx.next_task = &finish_testing; 175 churn_ctx.next_task = &finish_testing;
177 GNUNET_TESTING_daemons_churn(pg, 1, 1, TIMEOUT, &churn_callback, NULL); 176 GNUNET_TESTING_daemons_churn (pg, 1, 1, TIMEOUT, &churn_callback, NULL);
178} 177}
179 178
180static void 179static void
181churn_peers_off_again() 180churn_peers_off_again ()
182{ 181{
183 churn_ctx.next_task = &churn_peers_both; 182 churn_ctx.next_task = &churn_peers_both;
184 GNUNET_TESTING_daemons_churn(pg, 2, 0, TIMEOUT, &churn_callback, NULL); 183 GNUNET_TESTING_daemons_churn (pg, 2, 0, TIMEOUT, &churn_callback, NULL);
185} 184}
186 185
187static void 186static void
188churn_peers_on() 187churn_peers_on ()
189{ 188{
190 churn_ctx.next_task = &churn_peers_off_again; 189 churn_ctx.next_task = &churn_peers_off_again;
191 GNUNET_TESTING_daemons_churn(pg, 0, 2, TIMEOUT, &churn_callback, NULL); 190 GNUNET_TESTING_daemons_churn (pg, 0, 2, TIMEOUT, &churn_callback, NULL);
192} 191}
193 192
194static void 193static void
195churn_peers_off() 194churn_peers_off ()
196{ 195{
197 churn_ctx.next_task = &churn_peers_on; 196 churn_ctx.next_task = &churn_peers_on;
198 GNUNET_TESTING_daemons_churn(pg, 2, 0, TIMEOUT, &churn_callback, NULL); 197 GNUNET_TESTING_daemons_churn (pg, 2, 0, TIMEOUT, &churn_callback, NULL);
199} 198}
200 199
201static void 200static void
202peers_started_callback (void *cls, 201peers_started_callback (void *cls,
203 const struct GNUNET_PeerIdentity *id, 202 const struct GNUNET_PeerIdentity *id,
204 const struct GNUNET_CONFIGURATION_Handle *cfg, 203 const struct GNUNET_CONFIGURATION_Handle *cfg,
205 struct GNUNET_TESTING_Daemon *d, const char *emsg) 204 struct GNUNET_TESTING_Daemon *d, const char *emsg)
206{ 205{
207 if (emsg != NULL) 206 if (emsg != NULL)
208 { 207 {
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n", 208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 emsg); 209 "Failed to start daemon with error: `%s'\n", emsg);
211 return; 210 return;
212 } 211 }
213 GNUNET_assert (id != NULL); 212 GNUNET_assert (id != NULL);
@@ -220,15 +219,15 @@ peers_started_callback (void *cls,
220 { 219 {
221#if VERBOSE 220#if VERBOSE
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
223 "All %d daemons started, now testing churn!\n", 222 "All %d daemons started, now testing churn!\n", num_peers);
224 num_peers);
225#endif 223#endif
226 GNUNET_SCHEDULER_cancel (die_task); 224 GNUNET_SCHEDULER_cancel (die_task);
227 /* Set up task in case topology creation doesn't finish 225 /* Set up task in case topology creation doesn't finish
228 * within a reasonable amount of time */ 226 * within a reasonable amount of time */
229 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 227 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
230 (GNUNET_TIME_UNIT_MINUTES, 5), 228 (GNUNET_TIME_UNIT_MINUTES, 5),
231 &end_badly, "from peers_started_callback"); 229 &end_badly,
230 "from peers_started_callback");
232 churn_peers_off (); 231 churn_peers_off ();
233 ok = 0; 232 ok = 0;
234 } 233 }
@@ -247,7 +246,9 @@ run (void *cls,
247 "Starting daemons based on config file %s\n", cfgfile); 246 "Starting daemons based on config file %s\n", cfgfile);
248#endif 247#endif
249 248
250 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) 249 if (GNUNET_YES !=
250 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
251 &test_directory))
251 { 252 {
252 ok = 404; 253 ok = 404;
253 return; 254 return;
@@ -261,7 +262,7 @@ run (void *cls,
261 main_cfg = cfg; 262 main_cfg = cfg;
262 263
263 peers_left = num_peers; 264 peers_left = num_peers;
264 GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1); 265 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
265 266
266 /* For this specific test we only really want a CLIQUE topology as the 267 /* For this specific test we only really want a CLIQUE topology as the
267 * overlay allowed topology, and a RING topology as the underlying connection 268 * overlay allowed topology, and a RING topology as the underlying connection
@@ -275,11 +276,13 @@ run (void *cls,
275 /* Set up a task to end testing if peer start fails */ 276 /* Set up a task to end testing if peer start fails */
276 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 277 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
277 (GNUNET_TIME_UNIT_MINUTES, 5), 278 (GNUNET_TIME_UNIT_MINUTES, 5),
278 &end_badly, "didn't start all daemons in reasonable amount of time!!!"); 279 &end_badly,
280 "didn't start all daemons in reasonable amount of time!!!");
279 281
280 pg = GNUNET_TESTING_daemons_start (cfg, 282 pg = GNUNET_TESTING_daemons_start (cfg,
281 peers_left, TIMEOUT, NULL, NULL, &peers_started_callback, NULL, 283 peers_left, TIMEOUT, NULL, NULL,
282 NULL, NULL, NULL); 284 &peers_started_callback, NULL, NULL,
285 NULL, NULL);
283 286
284} 287}
285 288
@@ -287,7 +290,7 @@ static int
287check () 290check ()
288{ 291{
289 int ret; 292 int ret;
290 char *const argv[] = {"test-testing-topology-churn", 293 char *const argv[] = { "test-testing-topology-churn",
291 "-c", 294 "-c",
292 "test_testing_data_topology_churn.conf", 295 "test_testing_data_topology_churn.conf",
293#if VERBOSE 296#if VERBOSE
@@ -299,11 +302,13 @@ check ()
299 GNUNET_GETOPT_OPTION_END 302 GNUNET_GETOPT_OPTION_END
300 }; 303 };
301 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 304 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
302 argv, "test-testing-topology-churn", "nohelp", 305 argv, "test-testing-topology-churn", "nohelp",
303 options, &run, &ok); 306 options, &run, &ok);
304 if (ret != GNUNET_OK) 307 if (ret != GNUNET_OK)
305 { 308 {
306 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-testing-topology-churn': Failed with error code %d\n", ret); 309 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
310 "`test-testing-topology-churn': Failed with error code %d\n",
311 ret);
307 } 312 }
308 313
309 return ok; 314 return ok;
@@ -331,7 +336,9 @@ main (int argc, char *argv[])
331 { 336 {
332 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) 337 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
333 { 338 {
334 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory); 339 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
340 "Failed to remove testing directory %s\n",
341 test_directory);
335 } 342 }
336 } 343 }
337 344