diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-10 01:06:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-10 01:06:56 +0000 |
commit | 53f0f13a919c33f6bfcb7823ee4908084b259f20 (patch) | |
tree | bb018f7df1bd3d677d9fa41656ff44957a83a43c /src/transport/transport-testing.h | |
parent | c0b81510ffe194dc662c3a6267d5e66a69873c4b (diff) | |
download | gnunet-53f0f13a919c33f6bfcb7823ee4908084b259f20.tar.gz gnunet-53f0f13a919c33f6bfcb7823ee4908084b259f20.zip |
-towards nicer transport-testing lib
Diffstat (limited to 'src/transport/transport-testing.h')
-rw-r--r-- | src/transport/transport-testing.h | 329 |
1 files changed, 321 insertions, 8 deletions
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index fc017e377..842c88374 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h | |||
@@ -33,6 +33,8 @@ | |||
33 | #include "gnunet_testing_lib.h" | 33 | #include "gnunet_testing_lib.h" |
34 | 34 | ||
35 | 35 | ||
36 | /* ************* Basic functions for starting/stopping/connecting *********** */ | ||
37 | |||
36 | /** | 38 | /** |
37 | * Context for a single peer | 39 | * Context for a single peer |
38 | */ | 40 | */ |
@@ -47,12 +49,16 @@ struct GNUNET_TRANSPORT_TESTING_Handle; | |||
47 | /** | 49 | /** |
48 | * Callback when two peers are connected and both have called the connect callback | 50 | * Callback when two peers are connected and both have called the connect callback |
49 | * to notify clients about a new peer | 51 | * to notify clients about a new peer |
52 | * | ||
53 | * @param p FIXME: remove ASAP. | ||
54 | * @param cls closure | ||
50 | */ | 55 | */ |
51 | typedef void | 56 | typedef void |
52 | (*GNUNET_TRANSPORT_TESTING_StartCallback) (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 57 | (*GNUNET_TRANSPORT_TESTING_StartCallback) (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
53 | void *cls); | 58 | void *cls); |
54 | 59 | ||
55 | 60 | ||
61 | |||
56 | /** | 62 | /** |
57 | * Context for a single peer | 63 | * Context for a single peer |
58 | */ | 64 | */ |
@@ -150,17 +156,54 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext | |||
150 | */ | 156 | */ |
151 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest | 157 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest |
152 | { | 158 | { |
159 | /** | ||
160 | * Kept in a DLL. | ||
161 | */ | ||
153 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *next; | 162 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *next; |
163 | |||
164 | /** | ||
165 | * Kept in a DLL. | ||
166 | */ | ||
154 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *prev; | 167 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *prev; |
168 | |||
169 | /** | ||
170 | * Peer we want to connect. | ||
171 | */ | ||
155 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | 172 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; |
173 | |||
174 | /** | ||
175 | * Peer we want to connect. | ||
176 | */ | ||
156 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | 177 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; |
178 | |||
179 | /** | ||
180 | * Task by which we accomplish the connection. | ||
181 | */ | ||
157 | struct GNUNET_SCHEDULER_Task *tct; | 182 | struct GNUNET_SCHEDULER_Task *tct; |
183 | |||
184 | /** | ||
185 | * Handle by which we ask ATS to faciliate the connection. | ||
186 | */ | ||
158 | struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; | 187 | struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; |
188 | |||
189 | /** | ||
190 | * Handle by which we inform the peer about the HELLO of | ||
191 | * the other peer. | ||
192 | */ | ||
159 | struct GNUNET_TRANSPORT_OfferHelloHandle *oh; | 193 | struct GNUNET_TRANSPORT_OfferHelloHandle *oh; |
194 | |||
195 | /** | ||
196 | * Function to call upon completion. | ||
197 | */ | ||
160 | GNUNET_SCHEDULER_TaskCallback cb; | 198 | GNUNET_SCHEDULER_TaskCallback cb; |
199 | |||
200 | /** | ||
201 | * Closure for @e cb. | ||
202 | */ | ||
161 | void *cb_cls; | 203 | void *cb_cls; |
162 | int p1_c; | 204 | |
163 | int p2_c; | 205 | int p1_c; // dead? |
206 | int p2_c; // dead? | ||
164 | }; | 207 | }; |
165 | 208 | ||
166 | 209 | ||
@@ -290,25 +333,264 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerCont | |||
290 | void | 333 | void |
291 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); | 334 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); |
292 | 335 | ||
336 | |||
293 | /* ********************** high-level process functions *************** */ | 337 | /* ********************** high-level process functions *************** */ |
294 | 338 | ||
295 | 339 | ||
296 | /** | 340 | /** |
341 | * Function called once the peers have been launched and | ||
342 | * connected by #GNUNET_TRANSPORT_TESTING_connect_check(). | ||
343 | * | ||
344 | * @param cls closure | ||
345 | * @param num_peers size of the @a p array | ||
346 | * @param p the peers that were launched | ||
347 | */ | ||
348 | typedef void | ||
349 | (*GNUNET_TRANSPORT_TESTING_ConnectContinuation)(void *cls, | ||
350 | unsigned int num_peers, | ||
351 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p[]); | ||
352 | |||
353 | |||
354 | /** | ||
355 | * Internal data structure. | ||
356 | */ | ||
357 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList; | ||
358 | |||
359 | /** | ||
360 | * Internal data structure. | ||
361 | */ | ||
362 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext; | ||
363 | |||
364 | |||
365 | /** | ||
366 | * Function called by the transport for each received message. | ||
367 | * | ||
368 | * @param cls closure | ||
369 | * @param receiver receiver of the message | ||
370 | * @param sender sender of the message | ||
371 | * @param message the message | ||
372 | */ | ||
373 | typedef void | ||
374 | (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (void *cls, | ||
375 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | ||
376 | const struct GNUNET_PeerIdentity *sender, | ||
377 | const struct GNUNET_MessageHeader *message); | ||
378 | |||
379 | |||
380 | /** | ||
381 | * Function called to notify transport users that another | ||
382 | * peer connected to us. | ||
383 | * | ||
384 | * @param cls closure | ||
385 | * @param me peer experiencing the event | ||
386 | * @param other peer that connected to @a me | ||
387 | */ | ||
388 | typedef void | ||
389 | (*GNUNET_TRANSPORT_TESTING_NotifyConnect) (void *cls, | ||
390 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
391 | const struct GNUNET_PeerIdentity *other); | ||
392 | |||
393 | |||
394 | /** | ||
395 | * Function called to notify transport users that another | ||
396 | * peer disconnected from us. | ||
397 | * | ||
398 | * @param cls closure | ||
399 | * @param me peer experiencing the event | ||
400 | * @param other peer that disconnected from @a me | ||
401 | */ | ||
402 | typedef void | ||
403 | (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) (void *cls, | ||
404 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
405 | const struct GNUNET_PeerIdentity *other); | ||
406 | |||
407 | |||
408 | /** | ||
409 | * Closure that must be passed to | ||
410 | * #GNUNET_TRANSPORT_TESTING_connect_check. | ||
411 | */ | ||
412 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext | ||
413 | { | ||
414 | |||
415 | /** | ||
416 | * How should we continue after the connect? | ||
417 | */ | ||
418 | GNUNET_SCHEDULER_TaskCallback connect_continuation; | ||
419 | |||
420 | /** | ||
421 | * Closure for @e connect_continuation. | ||
422 | */ | ||
423 | void *connect_continuation_cls; | ||
424 | |||
425 | /** | ||
426 | * Which configuration file should we pass to the | ||
427 | * #GNUNET_PROGRAM_run() of the testcase? | ||
428 | */ | ||
429 | const char *config_file; | ||
430 | |||
431 | /** | ||
432 | * Receiver argument to give for peers we start. | ||
433 | */ | ||
434 | GNUNET_TRANSPORT_TESTING_ReceiveCallback rec; | ||
435 | |||
436 | /** | ||
437 | * Notify connect argument to give for peers we start. | ||
438 | */ | ||
439 | GNUNET_TRANSPORT_TESTING_NotifyConnect nc; | ||
440 | |||
441 | /** | ||
442 | * Notify disconnect argument to give for peers we start. | ||
443 | */ | ||
444 | GNUNET_TRANSPORT_TESTING_NotifyDisconnect nd; | ||
445 | |||
446 | /** | ||
447 | * Closure for @e rec, @e nc and @e nd. | ||
448 | */ | ||
449 | void *cls; | ||
450 | |||
451 | /** | ||
452 | * Custom task to run on shutdown. | ||
453 | */ | ||
454 | GNUNET_SCHEDULER_TaskCallback shutdown_task; | ||
455 | |||
456 | /** | ||
457 | * Closure for @e shutdown_task. | ||
458 | */ | ||
459 | void *shutdown_task_cls; | ||
460 | |||
461 | /** | ||
462 | * When should the testcase time out? | ||
463 | */ | ||
464 | struct GNUNET_TIME_Relative timeout; | ||
465 | |||
466 | /* ******* fields set by #GNUNET_TRANSPORT_TESTING_connect_check **** */ | ||
467 | |||
468 | /** | ||
469 | * Number of peers involved in the test. | ||
470 | */ | ||
471 | unsigned int num_peers; | ||
472 | |||
473 | /** | ||
474 | * Configuration files we have, array with @e num_peers entries. | ||
475 | */ | ||
476 | char **cfg_files; | ||
477 | |||
478 | /** | ||
479 | * Array with @e num_peers entries. | ||
480 | */ | ||
481 | struct GNUNET_TRANSPORT_TESTING_PeerContext **p; | ||
482 | |||
483 | /** | ||
484 | * Name of the plugin. | ||
485 | */ | ||
486 | const char *test_plugin; | ||
487 | |||
488 | /** | ||
489 | * Name of the testcase. | ||
490 | */ | ||
491 | const char *test_name; | ||
492 | |||
493 | /** | ||
494 | * Configuration object for the testcase. | ||
495 | */ | ||
496 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
497 | |||
498 | /** | ||
499 | * Main testing handle. | ||
500 | */ | ||
501 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; | ||
502 | |||
503 | /** | ||
504 | * Result from the main function, set to #GNUNET_OK on success. | ||
505 | * Clients should set to #GNUNET_SYSERR to indicate test failure. | ||
506 | */ | ||
507 | int global_ret; | ||
508 | |||
509 | /* ******* internal state, clients should not mess with this **** */ | ||
510 | |||
511 | /** | ||
512 | * Task run on timeout. | ||
513 | */ | ||
514 | struct GNUNET_SCHEDULER_Task *timeout_task; | ||
515 | |||
516 | /** | ||
517 | * Number of peers that have been started. | ||
518 | */ | ||
519 | unsigned int started; | ||
520 | |||
521 | /** | ||
522 | * DLL of active connect requests. | ||
523 | */ | ||
524 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_head; | ||
525 | |||
526 | /** | ||
527 | * DLL of active connect requests. | ||
528 | */ | ||
529 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_tail; | ||
530 | |||
531 | /** | ||
532 | * Array with @e num_peers entries. | ||
533 | */ | ||
534 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ip; | ||
535 | |||
536 | }; | ||
537 | |||
538 | |||
539 | /** | ||
540 | * Find peer by peer ID. | ||
541 | * | ||
542 | * @param ccc context to search | ||
543 | * @param peer peer to look for | ||
544 | * @return NULL if @a peer was not found | ||
545 | */ | ||
546 | struct GNUNET_TRANSPORT_TESTING_PeerContext * | ||
547 | GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, | ||
548 | const struct GNUNET_PeerIdentity *peer); | ||
549 | |||
550 | |||
551 | /** | ||
552 | * Common implementation of the #GNUNET_TRANSPORT_TESTING_CheckCallback. | ||
553 | * Starts and connects the two peers, then invokes the | ||
554 | * `connect_continuation` from @a cls. Sets up a timeout to | ||
555 | * abort the test, and a shutdown handler to clean up properly | ||
556 | * on exit. | ||
557 | * | ||
558 | * @param cls closure of type `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` | ||
559 | * @param tth_ initialized testing handle | ||
560 | * @param test_plugin_ name of the plugin | ||
561 | * @param test_name_ name of the test | ||
562 | * @param num_peers number of entries in the @a cfg_file array | ||
563 | * @param cfg_files array of names of configuration files for the peers | ||
564 | * @return #GNUNET_SYSERR on error | ||
565 | */ | ||
566 | int | ||
567 | GNUNET_TRANSPORT_TESTING_connect_check (void *cls, | ||
568 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, | ||
569 | const char *test_plugin_, | ||
570 | const char *test_name_, | ||
571 | unsigned int num_peers, | ||
572 | char *cfg_files[]); | ||
573 | |||
574 | |||
575 | /** | ||
297 | * Main function of a testcase. Called with the initial setup data | 576 | * Main function of a testcase. Called with the initial setup data |
298 | * for the test as derived from the source name and the binary name. | 577 | * for the test as derived from the source name and the binary name. |
299 | * | 578 | * |
300 | * @param cls closure | 579 | * @param cls closure |
301 | * @param tth initialized testing handle | 580 | * @param tth_ initialized testing handle |
302 | * @param test_plugin name of the plugin (if available) | 581 | * @param test_plugin_ name of the plugin |
582 | * @param test_name_ name of the test | ||
303 | * @param num_peers number of entries in the @a cfg_file array | 583 | * @param num_peers number of entries in the @a cfg_file array |
304 | * @param cfg_files array of names of configuration files for the peers | 584 | * @param cfg_files array of names of configuration files for the peers |
585 | * @return #GNUNET_SYSERR on error | ||
305 | */ | 586 | */ |
306 | typedef void | 587 | typedef int |
307 | (*GNUNET_TRANSPORT_TESTING_CheckCallback)(void *cls, | 588 | (*GNUNET_TRANSPORT_TESTING_CheckCallback)(void *cls, |
308 | struct GNUNET_TRANSPORT_TESTING_Handle *tth, | 589 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, |
309 | const char *test_plugin, | 590 | const char *test_plugin_, |
591 | const char *test_name_, | ||
310 | unsigned int num_peers, | 592 | unsigned int num_peers, |
311 | const char *cfg_files[]); | 593 | char *cfg_files[]); |
312 | 594 | ||
313 | 595 | ||
314 | /** | 596 | /** |
@@ -341,6 +623,37 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, | |||
341 | GNUNET_TRANSPORT_TESTING_main_ (argv[0], __FILE__, num_peers, check, check_cls) | 623 | GNUNET_TRANSPORT_TESTING_main_ (argv[0], __FILE__, num_peers, check, check_cls) |
342 | 624 | ||
343 | 625 | ||
626 | |||
627 | /* ********************** log-only convenience functions ************* */ | ||
628 | |||
629 | |||
630 | /** | ||
631 | * Log a connect event. | ||
632 | * | ||
633 | * @param cls NULL | ||
634 | * @param me peer that had the event | ||
635 | * @param other peer that connected. | ||
636 | */ | ||
637 | void | ||
638 | GNUNET_TRANSPORT_TESTING_log_connect (void *cls, | ||
639 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
640 | const struct GNUNET_PeerIdentity *other); | ||
641 | |||
642 | |||
643 | /** | ||
644 | * Log a disconnect event. | ||
645 | * | ||
646 | * @param cls NULL | ||
647 | * @param me peer that had the event | ||
648 | * @param other peer that disconnected. | ||
649 | */ | ||
650 | void | ||
651 | GNUNET_TRANSPORT_TESTING_log_disconnect (void *cls, | ||
652 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
653 | const struct GNUNET_PeerIdentity *other); | ||
654 | |||
655 | |||
656 | |||
344 | /* ********************** low-level filename functions *************** */ | 657 | /* ********************** low-level filename functions *************** */ |
345 | 658 | ||
346 | 659 | ||