diff options
Diffstat (limited to 'src/cadet/cadet_test_lib.c')
-rw-r--r-- | src/cadet/cadet_test_lib.c | 252 |
1 files changed, 125 insertions, 127 deletions
diff --git a/src/cadet/cadet_test_lib.c b/src/cadet/cadet_test_lib.c index db16e4015..ae1eb6f00 100644 --- a/src/cadet/cadet_test_lib.c +++ b/src/cadet/cadet_test_lib.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file cadet/cadet_test_lib.c | 21 | * @file cadet/cadet_test_lib.c |
22 | * @author Bartlomiej Polot | 22 | * @author Bartlomiej Polot |
@@ -31,8 +31,7 @@ | |||
31 | /** | 31 | /** |
32 | * Test context for a CADET Test. | 32 | * Test context for a CADET Test. |
33 | */ | 33 | */ |
34 | struct GNUNET_CADET_TEST_Context | 34 | struct GNUNET_CADET_TEST_Context { |
35 | { | ||
36 | /** | 35 | /** |
37 | * Array of running peers. | 36 | * Array of running peers. |
38 | */ | 37 | */ |
@@ -92,15 +91,13 @@ struct GNUNET_CADET_TEST_Context | |||
92 | * Number of ports in #ports. | 91 | * Number of ports in #ports. |
93 | */ | 92 | */ |
94 | unsigned int port_count; | 93 | unsigned int port_count; |
95 | |||
96 | }; | 94 | }; |
97 | 95 | ||
98 | 96 | ||
99 | /** | 97 | /** |
100 | * Context for a cadet adapter callback. | 98 | * Context for a cadet adapter callback. |
101 | */ | 99 | */ |
102 | struct GNUNET_CADET_TEST_AdapterContext | 100 | struct GNUNET_CADET_TEST_AdapterContext { |
103 | { | ||
104 | /** | 101 | /** |
105 | * Peer number for the particular peer. | 102 | * Peer number for the particular peer. |
106 | */ | 103 | */ |
@@ -129,33 +126,33 @@ struct GNUNET_CADET_TEST_AdapterContext | |||
129 | * @return service handle to return in 'op_result', NULL on error | 126 | * @return service handle to return in 'op_result', NULL on error |
130 | */ | 127 | */ |
131 | static void * | 128 | static void * |
132 | cadet_connect_adapter (void *cls, | 129 | cadet_connect_adapter(void *cls, |
133 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 130 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
134 | { | 131 | { |
135 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; | 132 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; |
136 | struct GNUNET_CADET_TEST_Context *ctx = actx->ctx; | 133 | struct GNUNET_CADET_TEST_Context *ctx = actx->ctx; |
137 | struct GNUNET_CADET_Handle *h; | 134 | struct GNUNET_CADET_Handle *h; |
138 | 135 | ||
139 | h = GNUNET_CADET_connect (cfg); | 136 | h = GNUNET_CADET_connect(cfg); |
140 | if (NULL == h) | 137 | if (NULL == h) |
141 | { | 138 | { |
142 | GNUNET_break(0); | 139 | GNUNET_break(0); |
143 | return NULL; | 140 | return NULL; |
144 | } | 141 | } |
145 | if (NULL == ctx->ports) | 142 | if (NULL == ctx->ports) |
146 | return h; | 143 | return h; |
147 | actx->ports = GNUNET_new_array (ctx->port_count, | 144 | actx->ports = GNUNET_new_array(ctx->port_count, |
148 | struct GNUNET_CADET_Port *); | 145 | struct GNUNET_CADET_Port *); |
149 | for (unsigned int i = 0; i < ctx->port_count; i++) | 146 | for (unsigned int i = 0; i < ctx->port_count; i++) |
150 | { | 147 | { |
151 | actx->ports[i] = GNUNET_CADET_open_port (h, | 148 | actx->ports[i] = GNUNET_CADET_open_port(h, |
152 | ctx->ports[i], | 149 | ctx->ports[i], |
153 | ctx->connects, | 150 | ctx->connects, |
154 | (void *) (long) actx->peer, | 151 | (void *)(long)actx->peer, |
155 | ctx->window_changes, | 152 | ctx->window_changes, |
156 | ctx->disconnects, | 153 | ctx->disconnects, |
157 | ctx->handlers); | 154 | ctx->handlers); |
158 | } | 155 | } |
159 | return h; | 156 | return h; |
160 | } | 157 | } |
161 | 158 | ||
@@ -168,23 +165,23 @@ cadet_connect_adapter (void *cls, | |||
168 | * @param op_result service handle returned from the connect adapter | 165 | * @param op_result service handle returned from the connect adapter |
169 | */ | 166 | */ |
170 | static void | 167 | static void |
171 | cadet_disconnect_adapter (void *cls, | 168 | cadet_disconnect_adapter(void *cls, |
172 | void *op_result) | 169 | void *op_result) |
173 | { | 170 | { |
174 | struct GNUNET_CADET_Handle *cadet = op_result; | 171 | struct GNUNET_CADET_Handle *cadet = op_result; |
175 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; | 172 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; |
176 | 173 | ||
177 | if (NULL != actx->ports) | 174 | if (NULL != actx->ports) |
178 | { | ||
179 | for (unsigned int i = 0; i < actx->ctx->port_count; i++) | ||
180 | { | 175 | { |
181 | GNUNET_CADET_close_port (actx->ports[i]); | 176 | for (unsigned int i = 0; i < actx->ctx->port_count; i++) |
182 | actx->ports[i] = NULL; | 177 | { |
178 | GNUNET_CADET_close_port(actx->ports[i]); | ||
179 | actx->ports[i] = NULL; | ||
180 | } | ||
181 | GNUNET_free(actx->ports); | ||
183 | } | 182 | } |
184 | GNUNET_free (actx->ports); | 183 | GNUNET_free(actx); |
185 | } | 184 | GNUNET_CADET_disconnect(cadet); |
186 | GNUNET_free (actx); | ||
187 | GNUNET_CADET_disconnect (cadet); | ||
188 | } | 185 | } |
189 | 186 | ||
190 | 187 | ||
@@ -199,7 +196,7 @@ cadet_disconnect_adapter (void *cls, | |||
199 | * NULL if operation has executed successfully. | 196 | * NULL if operation has executed successfully. |
200 | */ | 197 | */ |
201 | static void | 198 | static void |
202 | cadet_connect_cb (void *cls, | 199 | cadet_connect_cb(void *cls, |
203 | struct GNUNET_TESTBED_Operation *op, | 200 | struct GNUNET_TESTBED_Operation *op, |
204 | void *ca_result, | 201 | void *ca_result, |
205 | const char *emsg) | 202 | const char *emsg) |
@@ -207,47 +204,48 @@ cadet_connect_cb (void *cls, | |||
207 | struct GNUNET_CADET_TEST_Context *ctx = cls; | 204 | struct GNUNET_CADET_TEST_Context *ctx = cls; |
208 | 205 | ||
209 | if (NULL != emsg) | 206 | if (NULL != emsg) |
210 | { | ||
211 | fprintf (stderr, | ||
212 | "Failed to connect to CADET service: %s\n", | ||
213 | emsg); | ||
214 | GNUNET_SCHEDULER_shutdown (); | ||
215 | return; | ||
216 | } | ||
217 | for (unsigned int i = 0; i < ctx->num_peers; i++) | ||
218 | if (op == ctx->ops[i]) | ||
219 | { | 207 | { |
220 | ctx->cadets[i] = ca_result; | 208 | fprintf(stderr, |
221 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 209 | "Failed to connect to CADET service: %s\n", |
222 | "...cadet %u connected\n", | 210 | emsg); |
223 | i); | 211 | GNUNET_SCHEDULER_shutdown(); |
212 | return; | ||
224 | } | 213 | } |
225 | for (unsigned int i = 0; i < ctx->num_peers; i++) | 214 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
215 | if (op == ctx->ops[i]) | ||
216 | { | ||
217 | ctx->cadets[i] = ca_result; | ||
218 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
219 | "...cadet %u connected\n", | ||
220 | i); | ||
221 | } | ||
222 | for (unsigned int i = 0; i < ctx->num_peers; i++) | ||
226 | if (NULL == ctx->cadets[i]) | 223 | if (NULL == ctx->cadets[i]) |
227 | return; /* still some CADET connections missing */ | 224 | return; |
225 | /* still some CADET connections missing */ | ||
228 | /* all CADET connections ready! */ | 226 | /* all CADET connections ready! */ |
229 | ctx->app_main (ctx->app_main_cls, | 227 | ctx->app_main(ctx->app_main_cls, |
230 | ctx, | 228 | ctx, |
231 | ctx->num_peers, | 229 | ctx->num_peers, |
232 | ctx->peers, | 230 | ctx->peers, |
233 | ctx->cadets); | 231 | ctx->cadets); |
234 | } | 232 | } |
235 | 233 | ||
236 | 234 | ||
237 | void | 235 | void |
238 | GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx) | 236 | GNUNET_CADET_TEST_cleanup(struct GNUNET_CADET_TEST_Context *ctx) |
239 | { | 237 | { |
240 | for (unsigned int i = 0; i < ctx->num_peers; i++) | 238 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
241 | { | 239 | { |
242 | GNUNET_assert (NULL != ctx->ops[i]); | 240 | GNUNET_assert(NULL != ctx->ops[i]); |
243 | GNUNET_TESTBED_operation_done (ctx->ops[i]); | 241 | GNUNET_TESTBED_operation_done(ctx->ops[i]); |
244 | ctx->ops[i] = NULL; | 242 | ctx->ops[i] = NULL; |
245 | } | 243 | } |
246 | GNUNET_free (ctx->ops); | 244 | GNUNET_free(ctx->ops); |
247 | GNUNET_free (ctx->cadets); | 245 | GNUNET_free(ctx->cadets); |
248 | GNUNET_free (ctx->handlers); | 246 | GNUNET_free(ctx->handlers); |
249 | GNUNET_free (ctx); | 247 | GNUNET_free(ctx); |
250 | GNUNET_SCHEDULER_shutdown (); | 248 | GNUNET_SCHEDULER_shutdown(); |
251 | } | 249 | } |
252 | 250 | ||
253 | 251 | ||
@@ -265,7 +263,7 @@ GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx) | |||
265 | * failed | 263 | * failed |
266 | */ | 264 | */ |
267 | static void | 265 | static void |
268 | cadet_test_run (void *cls, | 266 | cadet_test_run(void *cls, |
269 | struct GNUNET_TESTBED_RunHandle *h, | 267 | struct GNUNET_TESTBED_RunHandle *h, |
270 | unsigned int num_peers, | 268 | unsigned int num_peers, |
271 | struct GNUNET_TESTBED_Peer **peers, | 269 | struct GNUNET_TESTBED_Peer **peers, |
@@ -275,47 +273,47 @@ cadet_test_run (void *cls, | |||
275 | struct GNUNET_CADET_TEST_Context *ctx = cls; | 273 | struct GNUNET_CADET_TEST_Context *ctx = cls; |
276 | 274 | ||
277 | if (0 != links_failed) | 275 | if (0 != links_failed) |
278 | { | 276 | { |
279 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 277 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
280 | "Some links failed (%u), ending\n", | 278 | "Some links failed (%u), ending\n", |
281 | links_failed); | 279 | links_failed); |
282 | exit (77); | 280 | exit(77); |
283 | } | 281 | } |
284 | if (num_peers != ctx->num_peers) | 282 | if (num_peers != ctx->num_peers) |
285 | { | 283 | { |
286 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 284 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
287 | "Peers started %u/%u, ending\n", | 285 | "Peers started %u/%u, ending\n", |
288 | num_peers, | 286 | num_peers, |
289 | ctx->num_peers); | 287 | ctx->num_peers); |
290 | exit (1); | 288 | exit(1); |
291 | } | 289 | } |
292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 290 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
293 | "Testbed up, %u peers and %u links\n", | 291 | "Testbed up, %u peers and %u links\n", |
294 | num_peers, | 292 | num_peers, |
295 | links_succeeded); | 293 | links_succeeded); |
296 | ctx->peers = peers; | 294 | ctx->peers = peers; |
297 | for (unsigned int i = 0; i < num_peers; i++) | 295 | for (unsigned int i = 0; i < num_peers; i++) |
298 | { | 296 | { |
299 | struct GNUNET_CADET_TEST_AdapterContext *newctx; | 297 | struct GNUNET_CADET_TEST_AdapterContext *newctx; |
300 | 298 | ||
301 | newctx = GNUNET_new (struct GNUNET_CADET_TEST_AdapterContext); | 299 | newctx = GNUNET_new(struct GNUNET_CADET_TEST_AdapterContext); |
302 | newctx->peer = i; | 300 | newctx->peer = i; |
303 | newctx->ctx = ctx; | 301 | newctx->ctx = ctx; |
304 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 302 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
305 | "Connecting to cadet %u\n", | 303 | "Connecting to cadet %u\n", |
306 | i); | 304 | i); |
307 | ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx, | 305 | ctx->ops[i] = GNUNET_TESTBED_service_connect(ctx, |
308 | peers[i], | 306 | peers[i], |
309 | "cadet", | 307 | "cadet", |
310 | &cadet_connect_cb, | 308 | &cadet_connect_cb, |
311 | ctx, | 309 | ctx, |
312 | &cadet_connect_adapter, | 310 | &cadet_connect_adapter, |
313 | &cadet_disconnect_adapter, | 311 | &cadet_disconnect_adapter, |
314 | newctx); | 312 | newctx); |
315 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 313 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
316 | "op handle %p\n", | 314 | "op handle %p\n", |
317 | ctx->ops[i]); | 315 | ctx->ops[i]); |
318 | } | 316 | } |
319 | } | 317 | } |
320 | 318 | ||
321 | 319 | ||
@@ -335,41 +333,41 @@ cadet_test_run (void *cls, | |||
335 | * @param ports Ports the peers offer, NULL-terminated. | 333 | * @param ports Ports the peers offer, NULL-terminated. |
336 | */ | 334 | */ |
337 | void | 335 | void |
338 | GNUNET_CADET_TEST_ruN (const char *testname, | 336 | GNUNET_CADET_TEST_ruN(const char *testname, |
339 | const char *cfgfile, | 337 | const char *cfgfile, |
340 | unsigned int num_peers, | 338 | unsigned int num_peers, |
341 | GNUNET_CADET_TEST_AppMain tmain, | 339 | GNUNET_CADET_TEST_AppMain tmain, |
342 | void *tmain_cls, | 340 | void *tmain_cls, |
343 | GNUNET_CADET_ConnectEventHandler connects, | 341 | GNUNET_CADET_ConnectEventHandler connects, |
344 | GNUNET_CADET_WindowSizeEventHandler window_changes, | 342 | GNUNET_CADET_WindowSizeEventHandler window_changes, |
345 | GNUNET_CADET_DisconnectEventHandler disconnects, | 343 | GNUNET_CADET_DisconnectEventHandler disconnects, |
346 | struct GNUNET_MQ_MessageHandler *handlers, | 344 | struct GNUNET_MQ_MessageHandler *handlers, |
347 | const struct GNUNET_HashCode **ports) | 345 | const struct GNUNET_HashCode **ports) |
348 | { | 346 | { |
349 | struct GNUNET_CADET_TEST_Context *ctx; | 347 | struct GNUNET_CADET_TEST_Context *ctx; |
350 | 348 | ||
351 | ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context); | 349 | ctx = GNUNET_new(struct GNUNET_CADET_TEST_Context); |
352 | ctx->num_peers = num_peers; | 350 | ctx->num_peers = num_peers; |
353 | ctx->ops = GNUNET_new_array (num_peers, | 351 | ctx->ops = GNUNET_new_array(num_peers, |
354 | struct GNUNET_TESTBED_Operation *); | 352 | struct GNUNET_TESTBED_Operation *); |
355 | ctx->cadets = GNUNET_new_array (num_peers, | 353 | ctx->cadets = GNUNET_new_array(num_peers, |
356 | struct GNUNET_CADET_Handle *); | 354 | struct GNUNET_CADET_Handle *); |
357 | ctx->app_main = tmain; | 355 | ctx->app_main = tmain; |
358 | ctx->app_main_cls = tmain_cls; | 356 | ctx->app_main_cls = tmain_cls; |
359 | ctx->connects = connects; | 357 | ctx->connects = connects; |
360 | ctx->window_changes = window_changes; | 358 | ctx->window_changes = window_changes; |
361 | ctx->disconnects = disconnects; | 359 | ctx->disconnects = disconnects; |
362 | ctx->handlers = GNUNET_MQ_copy_handlers (handlers); | 360 | ctx->handlers = GNUNET_MQ_copy_handlers(handlers); |
363 | ctx->ports = ports; | 361 | ctx->ports = ports; |
364 | ctx->port_count = 0; | 362 | ctx->port_count = 0; |
365 | while (NULL != ctx->ports[ctx->port_count]) | 363 | while (NULL != ctx->ports[ctx->port_count]) |
366 | ctx->port_count++; | 364 | ctx->port_count++; |
367 | GNUNET_TESTBED_test_run (testname, | 365 | GNUNET_TESTBED_test_run(testname, |
368 | cfgfile, | 366 | cfgfile, |
369 | num_peers, | 367 | num_peers, |
370 | 0LL, NULL, NULL, | 368 | 0LL, NULL, NULL, |
371 | &cadet_test_run, | 369 | &cadet_test_run, |
372 | ctx); | 370 | ctx); |
373 | } | 371 | } |
374 | 372 | ||
375 | /* end of cadet_test_lib.c */ | 373 | /* end of cadet_test_lib.c */ |