diff options
Diffstat (limited to 'src/cadet/cadet_test_lib.c')
-rw-r--r-- | src/cadet/cadet_test_lib.c | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/src/cadet/cadet_test_lib.c b/src/cadet/cadet_test_lib.c index 20ef028b2..0efb81ab4 100644 --- a/src/cadet/cadet_test_lib.c +++ b/src/cadet/cadet_test_lib.c | |||
@@ -110,7 +110,7 @@ struct GNUNET_CADET_TEST_AdapterContext | |||
110 | * Port handlers for open ports. | 110 | * Port handlers for open ports. |
111 | */ | 111 | */ |
112 | struct GNUNET_CADET_Port **ports; | 112 | struct GNUNET_CADET_Port **ports; |
113 | 113 | ||
114 | /** | 114 | /** |
115 | * General context. | 115 | * General context. |
116 | */ | 116 | */ |
@@ -135,14 +135,13 @@ cadet_connect_adapter (void *cls, | |||
135 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; | 135 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; |
136 | struct GNUNET_CADET_TEST_Context *ctx = actx->ctx; | 136 | struct GNUNET_CADET_TEST_Context *ctx = actx->ctx; |
137 | struct GNUNET_CADET_Handle *h; | 137 | struct GNUNET_CADET_Handle *h; |
138 | unsigned int i; | ||
139 | 138 | ||
140 | h = GNUNET_CADET_connect (cfg); | 139 | h = GNUNET_CADET_connect (cfg); |
141 | if (NULL == ctx->ports) | 140 | if (NULL == ctx->ports) |
142 | return h; | 141 | return h; |
143 | 142 | actx->ports = GNUNET_new_array (ctx->port_count, | |
144 | actx->ports = GNUNET_new_array (ctx->port_count, struct GNUNET_CADET_Port *); | 143 | struct GNUNET_CADET_Port *); |
145 | for (i = 0; i < ctx->port_count; i++) | 144 | for (unsigned int i = 0; i < ctx->port_count; i++) |
146 | { | 145 | { |
147 | actx->ports[i] = GNUNET_CADET_open_port (h, | 146 | actx->ports[i] = GNUNET_CADET_open_port (h, |
148 | ctx->ports[i], | 147 | ctx->ports[i], |
@@ -165,14 +164,14 @@ cadet_connect_adapter (void *cls, | |||
165 | */ | 164 | */ |
166 | static void | 165 | static void |
167 | cadet_disconnect_adapter (void *cls, | 166 | cadet_disconnect_adapter (void *cls, |
168 | void *op_result) | 167 | void *op_result) |
169 | { | 168 | { |
170 | struct GNUNET_CADET_Handle *cadet = op_result; | 169 | struct GNUNET_CADET_Handle *cadet = op_result; |
171 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; | 170 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; |
172 | 171 | ||
173 | if (NULL != actx->ports) | 172 | if (NULL != actx->ports) |
174 | { | 173 | { |
175 | for (int i = 0; i < actx->ctx->port_count; i++) | 174 | for (unsigned int i = 0; i < actx->ctx->port_count; i++) |
176 | { | 175 | { |
177 | GNUNET_CADET_close_port (actx->ports[i]); | 176 | GNUNET_CADET_close_port (actx->ports[i]); |
178 | actx->ports[i] = NULL; | 177 | actx->ports[i] = NULL; |
@@ -201,22 +200,24 @@ cadet_connect_cb (void *cls, | |||
201 | const char *emsg) | 200 | const char *emsg) |
202 | { | 201 | { |
203 | struct GNUNET_CADET_TEST_Context *ctx = cls; | 202 | struct GNUNET_CADET_TEST_Context *ctx = cls; |
204 | unsigned int i; | ||
205 | 203 | ||
206 | if (NULL != emsg) | 204 | if (NULL != emsg) |
207 | { | 205 | { |
208 | fprintf (stderr, "Failed to connect to CADET service: %s\n", | 206 | fprintf (stderr, |
207 | "Failed to connect to CADET service: %s\n", | ||
209 | emsg); | 208 | emsg); |
210 | GNUNET_SCHEDULER_shutdown (); | 209 | GNUNET_SCHEDULER_shutdown (); |
211 | return; | 210 | return; |
212 | } | 211 | } |
213 | for (i = 0; i < ctx->num_peers; i++) | 212 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
214 | if (op == ctx->ops[i]) | 213 | if (op == ctx->ops[i]) |
215 | { | 214 | { |
216 | ctx->cadets[i] = ca_result; | 215 | ctx->cadets[i] = ca_result; |
217 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "...cadet %u connected\n", i); | 216 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
217 | "...cadet %u connected\n", | ||
218 | i); | ||
218 | } | 219 | } |
219 | for (i = 0; i < ctx->num_peers; i++) | 220 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
220 | if (NULL == ctx->cadets[i]) | 221 | if (NULL == ctx->cadets[i]) |
221 | return; /* still some CADET connections missing */ | 222 | return; /* still some CADET connections missing */ |
222 | /* all CADET connections ready! */ | 223 | /* all CADET connections ready! */ |
@@ -231,9 +232,7 @@ cadet_connect_cb (void *cls, | |||
231 | void | 232 | void |
232 | GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx) | 233 | GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx) |
233 | { | 234 | { |
234 | unsigned int i; | 235 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
235 | |||
236 | for (i = 0; i < ctx->num_peers; i++) | ||
237 | { | 236 | { |
238 | GNUNET_assert (NULL != ctx->ops[i]); | 237 | GNUNET_assert (NULL != ctx->ops[i]); |
239 | GNUNET_TESTBED_operation_done (ctx->ops[i]); | 238 | GNUNET_TESTBED_operation_done (ctx->ops[i]); |
@@ -269,33 +268,37 @@ cadet_test_run (void *cls, | |||
269 | unsigned int links_failed) | 268 | unsigned int links_failed) |
270 | { | 269 | { |
271 | struct GNUNET_CADET_TEST_Context *ctx = cls; | 270 | struct GNUNET_CADET_TEST_Context *ctx = cls; |
272 | unsigned int i; | ||
273 | 271 | ||
274 | if (0 != links_failed) | 272 | if (0 != links_failed) |
275 | { | 273 | { |
276 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Some links failed (%u), ending\n", | 274 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
275 | "Some links failed (%u), ending\n", | ||
277 | links_failed); | 276 | links_failed); |
278 | exit (2); | 277 | exit (2); |
279 | } | 278 | } |
280 | |||
281 | if (num_peers != ctx->num_peers) | 279 | if (num_peers != ctx->num_peers) |
282 | { | 280 | { |
283 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers started %u/%u, ending\n", | 281 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
284 | num_peers, ctx->num_peers); | 282 | "Peers started %u/%u, ending\n", |
283 | num_peers, | ||
284 | ctx->num_peers); | ||
285 | exit (1); | 285 | exit (1); |
286 | } | 286 | } |
287 | |||
288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
289 | "Testbed up, %u peers and %u links\n", | 288 | "Testbed up, %u peers and %u links\n", |
290 | num_peers, links_succeeded); | 289 | num_peers, |
290 | links_succeeded); | ||
291 | ctx->peers = peers; | 291 | ctx->peers = peers; |
292 | for (i = 0; i < num_peers; i++) | 292 | for (unsigned int i = 0; i < num_peers; i++) |
293 | { | 293 | { |
294 | struct GNUNET_CADET_TEST_AdapterContext *newctx; | 294 | struct GNUNET_CADET_TEST_AdapterContext *newctx; |
295 | |||
295 | newctx = GNUNET_new (struct GNUNET_CADET_TEST_AdapterContext); | 296 | newctx = GNUNET_new (struct GNUNET_CADET_TEST_AdapterContext); |
296 | newctx->peer = i; | 297 | newctx->peer = i; |
297 | newctx->ctx = ctx; | 298 | newctx->ctx = ctx; |
298 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to cadet %u\n", i); | 299 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
300 | "Connecting to cadet %u\n", | ||
301 | i); | ||
299 | ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx, | 302 | ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx, |
300 | peers[i], | 303 | peers[i], |
301 | "cadet", | 304 | "cadet", |
@@ -304,7 +307,9 @@ cadet_test_run (void *cls, | |||
304 | &cadet_connect_adapter, | 307 | &cadet_connect_adapter, |
305 | &cadet_disconnect_adapter, | 308 | &cadet_disconnect_adapter, |
306 | newctx); | 309 | newctx); |
307 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "op handle %p\n", ctx->ops[i]); | 310 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
311 | "op handle %p\n", | ||
312 | ctx->ops[i]); | ||
308 | } | 313 | } |
309 | } | 314 | } |
310 | 315 | ||
@@ -340,8 +345,10 @@ GNUNET_CADET_TEST_ruN (const char *testname, | |||
340 | 345 | ||
341 | ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context); | 346 | ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context); |
342 | ctx->num_peers = num_peers; | 347 | ctx->num_peers = num_peers; |
343 | ctx->ops = GNUNET_new_array (num_peers, struct GNUNET_TESTBED_Operation *); | 348 | ctx->ops = GNUNET_new_array (num_peers, |
344 | ctx->cadets = GNUNET_new_array (num_peers, struct GNUNET_CADET_Handle *); | 349 | struct GNUNET_TESTBED_Operation *); |
350 | ctx->cadets = GNUNET_new_array (num_peers, | ||
351 | struct GNUNET_CADET_Handle *); | ||
345 | ctx->app_main = tmain; | 352 | ctx->app_main = tmain; |
346 | ctx->app_main_cls = tmain_cls; | 353 | ctx->app_main_cls = tmain_cls; |
347 | ctx->connects = connects; | 354 | ctx->connects = connects; |
@@ -352,12 +359,12 @@ GNUNET_CADET_TEST_ruN (const char *testname, | |||
352 | ctx->port_count = 0; | 359 | ctx->port_count = 0; |
353 | while (NULL != ctx->ports[ctx->port_count]) | 360 | while (NULL != ctx->ports[ctx->port_count]) |
354 | ctx->port_count++; | 361 | ctx->port_count++; |
355 | |||
356 | GNUNET_TESTBED_test_run (testname, | 362 | GNUNET_TESTBED_test_run (testname, |
357 | cfgfile, | 363 | cfgfile, |
358 | num_peers, | 364 | num_peers, |
359 | 0LL, NULL, NULL, | 365 | 0LL, NULL, NULL, |
360 | &cadet_test_run, ctx); | 366 | &cadet_test_run, |
367 | ctx); | ||
361 | } | 368 | } |
362 | 369 | ||
363 | /* end of cadet_test_lib.c */ | 370 | /* end of cadet_test_lib.c */ |