aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_testing_ng_lib.h
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-11-29 17:37:50 +0900
committerChristian Grothoff <grothoff@gnunet.org>2023-11-29 17:38:12 +0900
commit0df5ce8d4215b83c908de5631b12a3939ce1ca9e (patch)
tree84a4ead15336f5fabb86052e19c245f29ba632cb /src/include/gnunet_testing_ng_lib.h
parentc117e2f4e8a5ebd3fb9b7369d0b49161b835ab34 (diff)
downloadgnunet-0df5ce8d4215b83c908de5631b12a3939ce1ca9e.tar.gz
gnunet-0df5ce8d4215b83c908de5631b12a3939ce1ca9e.zip
NEWS: libgnunettesting first major testing NG refactor towards getting dependency structure streamlined
Diffstat (limited to 'src/include/gnunet_testing_ng_lib.h')
-rw-r--r--src/include/gnunet_testing_ng_lib.h951
1 files changed, 15 insertions, 936 deletions
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 991eddbe4..7b19a0ab4 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @brief API for writing an interpreter to test GNUnet components 22 * @brief Meta-header for next-generation testing logic
23 * @author Christian Grothoff <christian@grothoff.org> 23 * @author Christian Grothoff <christian@grothoff.org>
24 * @author Marcello Stanisci 24 * @author Marcello Stanisci
25 * @author t3sserakt 25 * @author t3sserakt
@@ -29,440 +29,13 @@
29 29
30 30
31#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
32#include "gnunet_testing_lib.h"
33
34/**
35 * Maximum length of label in command
36 */
37#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127
38
39/* ********************* Helper functions ********************* */
40
41/**
42 * Print failing line number and trigger shutdown. Useful
43 * quite any time after the command "run" method has been called.
44 */
45#define GNUNET_TESTING_FAIL(is) \
46 do \
47 { \
48 GNUNET_break (0); \
49 GNUNET_TESTING_interpreter_fail (is); \
50 return; \
51 } while (0)
52
53
54/* ******************* Generic interpreter logic ************ */
55
56/**
57 * Global state of the interpreter, used by a command
58 * to access information about other commands.
59 */
60struct GNUNET_TESTING_Interpreter;
61
62/**
63 * State each asynchronous command must have in its closure.
64 */
65struct GNUNET_TESTING_AsyncContext
66{
67
68 /**
69 * Interpreter we are part of.
70 */
71 struct GNUNET_TESTING_Interpreter *is; // Why needed? When available?
72
73 /**
74 * Function to call when done.
75 */
76 GNUNET_SCHEDULER_TaskCallback cont;
77
78 /**
79 * Closure for @e cont.
80 */
81 void *cont_cls;
82
83 /**
84 * Indication if the command finished (#GNUNET_OK).
85 * #GNUNET_NO if it did not finish,
86 * #GNUNET_SYSERR if it failed.
87 */
88 enum GNUNET_GenericReturnValue finished;
89};
90
91
92/**
93 * Signature of a function used to start executing a command
94 * of a test.
95 *
96 * @param cls closure
97 * @param is interpreter running the command
98 */
99typedef void
100(*GNUNET_TESTING_CommandRunRoutine)(void *cls,
101 struct GNUNET_TESTING_Interpreter *is);
102
103
104/**
105 * Signature of a function used to clean up resources allocated
106 * by a command.
107 *
108 * @param cls closure
109 */
110typedef void
111(*GNUNET_TESTING_CommandCleanupRoutine)(void *cls);
112
113
114/**
115 * Signature of a function used to extract traits exposed by a
116 * command.
117 *
118 * @param cls closure
119 * @param[out] ret where to return the trait data
120 * @param trait name of the trait to return
121 * @param index index of the trait (for traits that are indexed)
122 * @return #GNUNET_OK on success
123 */
124typedef enum GNUNET_GenericReturnValue
125(*GNUNET_TESTING_CommandGetTraits) (void *cls,
126 const void **ret,
127 const char *trait,
128 unsigned int index);
129
130/**
131 * Create a new command
132 *
133 * @param cls the closure
134 * @param label the Label. Maximum length is GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
135 * @param run the run routing
136 * @param cleanup the cleanup function
137 * @param traits the traits function (optional)
138 * @param the async context
139 * @return the command the function cannot fail
140 */
141struct GNUNET_TESTING_Command
142GNUNET_TESTING_command_new (void *cls,
143 const char *label,
144 GNUNET_TESTING_CommandRunRoutine run,
145 GNUNET_TESTING_CommandCleanupRoutine cleanup,
146 GNUNET_TESTING_CommandGetTraits traits,
147 struct GNUNET_TESTING_AsyncContext *ac);
148
149/**
150 * A command to be run by the interpreter.
151 */
152struct GNUNET_TESTING_Command
153{
154 /**
155 * Closure for all commands with command-specific context information.
156 */
157 void *cls;
158
159 /**
160 * Label for the command.
161 */
162 char label[GNUNET_TESTING_CMD_MAX_LABEL_LENGTH + 1];
163
164 /**
165 * Runs the command. Note that upon return, the interpreter
166 * will not automatically run the next command, as the command
167 * may continue asynchronously in other scheduler tasks. Thus,
168 * the command must ensure to eventually call
169 * #GNUNET_TESTING_interpreter_next() or
170 * #GNUNET_TESTING_interpreter_fail().
171 *
172 * If this function creates some asynchronous activity, it should
173 * initialize @e finish to a function that can be used to wait for
174 * the asynchronous activity to terminate.
175 *
176 * @param cls closure
177 * @param is interpreter state
178 */
179 GNUNET_TESTING_CommandRunRoutine run;
180
181 /**
182 * Pointer to the asynchronous context in the command's
183 * closure. Used by the
184 * #GNUNET_TESTING_async_finish() and
185 * #GNUNET_TESTING_async_fail() functions.
186 *
187 * Must be NULL if a command is synchronous.
188 */
189 struct GNUNET_TESTING_AsyncContext *ac;
190
191 /**
192 * Clean up after the command. Run during forced termination
193 * (CTRL-C) or test failure or test success.
194 *
195 * @param cls closure
196 */
197 GNUNET_TESTING_CommandCleanupRoutine cleanup;
198
199 /**
200 * Extract information from a command that is useful for other
201 * commands. Can be NULL if a command has no traits.
202 *
203 * @param cls closure
204 * @param[out] ret result (could be anything)
205 * @param trait name of the trait
206 * @param index index number of the object to extract.
207 * @return #GNUNET_OK on success,
208 * #GNUNET_NO if no trait was found
209 */
210 GNUNET_TESTING_CommandGetTraits traits;
211
212 /**
213 * When did the execution of this command start?
214 */
215 struct GNUNET_TIME_Absolute start_time;
216
217 /**
218 * When did the execution of this command finish?
219 */
220 struct GNUNET_TIME_Absolute finish_time;
221
222 /**
223 * When did we start the last run of this command? Delta to @e finish_time
224 * gives the latency for the last successful run. Useful in case @e
225 * num_tries was positive and the command was run multiple times. In that
226 * case, the @e start_time gives the time when we first tried to run the
227 * command, so the difference between @e start_time and @e finish_time would
228 * be the time all of the @e num_tries took, while the delta to @e
229 * last_req_time is the time the last (successful) execution took.
230 */
231 struct GNUNET_TIME_Absolute last_req_time;
232
233 /**
234 * In case @e asynchronous_finish is true, how long should we wait for this
235 * command to complete? If @e finish did not complete after this amount of
236 * time, the interpreter will fail. Should be set generously to ensure
237 * tests do not fail on slow systems.
238 */
239 struct GNUNET_TIME_Relative default_timeout;
240
241 /**
242 * How often did we try to execute this command? (In case it is a request
243 * that is repated.) Note that a command must have some built-in retry
244 * mechanism for this value to be useful.
245 */
246 unsigned int num_tries;
247
248 /**
249 * If "true", the interpreter should not immediately call
250 * @e finish, even if @e finish is non-NULL. Otherwise,
251 * #GNUNET_TESTING_cmd_finish() must be used
252 * to ensure that a command actually completed.
253 */
254 bool asynchronous_finish;
255
256};
257
258
259/**
260 * Lookup command by label.
261 * Only future commands are looked up.
262 *
263 * @param is interpreter to lookup command in
264 * @param label label of the command to lookup.
265 * @return the command, if it is found, or NULL.
266 */
267// FIXME: think harder about whether this is actually needed, likely not.
268const struct GNUNET_TESTING_Command *
269GNUNET_TESTING_interpreter_lookup_future_command (
270 struct GNUNET_TESTING_Interpreter *is,
271 const char *label);
272
273
274/**
275 * Lookup command by label.
276 *
277 * @param is interpreter to lookup command in
278 * @param label label of the command to lookup.
279 * @return the command, if it is found, or NULL.
280 */
281const struct GNUNET_TESTING_Command *
282GNUNET_TESTING_interpreter_lookup_command (
283 struct GNUNET_TESTING_Interpreter *is,
284 const char *label);
285
286
287/**
288 * Lookup command by label.
289 * All commands, first into the past, then into the future are looked up.
290 *
291 * @param is interpreter to lookup command in
292 * @param label label of the command to lookup.
293 * @return the command, if it is found, or NULL.
294 */
295const struct GNUNET_TESTING_Command *
296GNUNET_TESTING_interpreter_lookup_command_all (
297 struct GNUNET_TESTING_Interpreter *is,
298 const char *label);
299
300
301/**
302 * Obtain label of the command being now run.
303 *
304 * @param is interpreter state.
305 * @return the label.
306 */
307const char *
308GNUNET_TESTING_interpreter_get_current_label (
309 struct GNUNET_TESTING_Interpreter *is);
310
311
312/**
313 * Current command failed, clean up and fail the test case.
314 *
315 * @param is interpreter state.
316 */
317void
318GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is);
319
320
321/**
322 * The asynchronous command of @a ac has failed.
323 *
324 * @param ac command-specific context
325 */
326void
327GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac);
328
329
330/**
331 * The asynchronous command of @a ac has finished.
332 *
333 * @param ac command-specific context
334 */
335void
336GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac);
337
338
339/**
340 * Create command array terminator.
341 *
342 * @return a end-command.
343 */
344struct GNUNET_TESTING_Command
345GNUNET_TESTING_cmd_end (void);
346
347
348/**
349 * Turn asynchronous command into non blocking command by setting
350 * asynchronous_finish to true. Modifies (and then returns) @a cmd simply
351 * setting the bit. By default, most commands are blocking, and by wrapping
352 * the command construction in this function a blocking command can be turned
353 * into an asynchronous command where the interpreter continues after
354 * initiating the asynchronous action. Does nothing if the command is
355 * fundamentally synchronous.
356 *
357 * @param cmd command to make synchronous.
358 * @return a finish-command.
359 */
360struct GNUNET_TESTING_Command
361GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd);
362
363
364/**
365 * Create (synchronous) command that waits for another command to finish.
366 * If @a cmd_ref did not finish after @a timeout, this command will fail
367 * the test case.
368 *
369 * @param finish_label label for this command
370 * @param cmd_ref reference to a previous command which we should
371 * wait for (call `finish()` on)
372 * @param timeout how long to wait at most for @a cmd_ref to finish
373 * @return a finish-command.
374 */
375const struct GNUNET_TESTING_Command
376GNUNET_TESTING_cmd_finish (const char *finish_label,
377 const char *cmd_ref,
378 struct GNUNET_TIME_Relative timeout);
379
380
381/**
382 * Make the instruction pointer point to @a target_label
383 * only if @a counter is greater than zero.
384 *
385 * @param label command label
386 * @param target_label label of the new instruction pointer's destination after the jump;
387 * must be before the current instruction
388 * @param counter counts how many times the rewinding is to happen.
389 */
390struct GNUNET_TESTING_Command
391GNUNET_TESTING_cmd_rewind_ip (const char *label,
392 const char *target_label,
393 unsigned int counter);
394
395
396/**
397 * Function called with the final result of the test.
398 * FIXME: This may want to use a GNUNET_ErrorCode (namespaced, e.g.
399 * GNUNET_EC_TESTING_*)
400 *
401 * @param cls closure
402 * @param rv #GNUNET_OK if the test passed
403 */
404typedef void
405(*GNUNET_TESTING_ResultCallback)(void *cls,
406 enum GNUNET_GenericReturnValue rv);
407
408
409/**
410 * Run the testsuite. Note, CMDs are copied into
411 * the interpreter state because they are _usually_
412 * defined into the "run" method that returns after
413 * having scheduled the test interpreter.
414 *
415 * @param commands the array of command to execute
416 * @param timeout how long to wait for each command to execute
417 * @param rc function to call with the final result
418 * @param rc_cls closure for @a rc
419 * @return The interpreter.
420 */
421struct GNUNET_TESTING_Interpreter *
422GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands,
423 struct GNUNET_TIME_Relative timeout,
424 GNUNET_TESTING_ResultCallback rc,
425 void *rc_cls);
426
427
428/**
429 * Start a GNUnet scheduler event loop and
430 * run the testsuite. Return 0 upon success.
431 * Expected to be called directly from main().
432 * FIXME: Why is this commands array here not const?
433 *
434 * @param commands the list of command to execute
435 * @param timeout how long to wait for each command to execute
436 * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure
437 */
438int
439GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands,
440 struct GNUNET_TIME_Relative timeout);
441
442
443/* ************** Specific interpreter commands ************ */
444
445 32
446/** 33/* FIXME: legacy test header, to be removed!! */
447 * Check if the command is running. 34#include "gnunet_testing_lib.h"
448 * FIXME: Unused function.
449 *
450 * @param command The command to check.
451 * @return #GNUNET_NO if the command is not running, #GNUNET_YES if it is running.
452 */
453enum GNUNET_GenericReturnValue
454GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command);
455 35
456 36#include "gnunet_testing_plugin.h"
457/** 37#include "gnunet_testing_loop_lib.h"
458 * Check if a command is finished. 38#include "gnunet_testing_netjail_lib.h"
459 * FIXME: Unused function
460 *
461 * @param command The command to check.
462 * @return #GNUNET_NO if the command is not finished, #GNUNET_YES if it is finished.
463 */
464enum GNUNET_GenericReturnValue
465GNUNET_TESTING_finished (const struct GNUNET_TESTING_Command *command);
466 39
467 40
468/** 41/**
@@ -470,14 +43,12 @@ GNUNET_TESTING_finished (const struct GNUNET_TESTING_Command *command);
470 * 43 *
471 * @param label command label. 44 * @param label command label.
472 * @param process_label label of a command that has a process trait 45 * @param process_label label of a command that has a process trait
473 * @param process_index index of the process trait at @a process_label // FIXME: enum? needed?
474 * @param signal signal to send to @a process. 46 * @param signal signal to send to @a process.
475 * @return the command. 47 * @return the command.
476 */ 48 */
477struct GNUNET_TESTING_Command 49struct GNUNET_TESTING_Command
478GNUNET_TESTING_cmd_signal (const char *label, 50GNUNET_TESTING_cmd_signal (const char *label,
479 const char *process_label, 51 const char *process_label,
480 unsigned int process_index,
481 int signal); 52 int signal);
482 53
483 54
@@ -494,55 +65,10 @@ GNUNET_TESTING_cmd_sleep (const char *label,
494 65
495 66
496/** 67/**
497 * Create a "batch" command. Such command takes a end_CMD-terminated array of
498 * CMDs and executed them. Once it hits the end CMD, it passes the control to
499 * the next top-level CMD, regardless of it being another batch or ordinary
500 * CMD.
501 *
502 * @param label the command label.
503 * @param batch array of CMDs to execute.
504 * @return the command.
505 */
506struct GNUNET_TESTING_Command
507GNUNET_TESTING_cmd_batch (const char *label,
508 struct GNUNET_TESTING_Command *batch);
509
510
511/**
512 * Performance counter.
513 */
514struct GNUNET_TESTING_Timer
515{
516 /**
517 * For which type of commands.
518 */
519 const char *prefix;
520
521 /**
522 * Total time spend in all commands of this type.
523 */
524 struct GNUNET_TIME_Relative total_duration;
525
526 /**
527 * Total time spend waiting for the *successful* exeuction
528 * in all commands of this type.
529 */
530 struct GNUNET_TIME_Relative success_latency;
531
532 /**
533 * Number of commands summed up.
534 */
535 unsigned int num_commands;
536
537 /**
538 * Number of retries summed up.
539 */
540 unsigned int num_retries;
541};
542
543/**
544 * Command to execute a script synchronously. 68 * Command to execute a script synchronously.
545 * 69 *
70 * FIXME: is this accurate? How is this limited to BASH scripts or even scripts?
71 *
546 * @param label Label of the command. 72 * @param label Label of the command.
547 * @param script The name of the script. 73 * @param script The name of the script.
548 * @param script_argv The arguments of the script. 74 * @param script_argv The arguments of the script.
@@ -551,486 +77,39 @@ const struct GNUNET_TESTING_Command
551GNUNET_TESTING_cmd_exec_bash_script (const char *label, 77GNUNET_TESTING_cmd_exec_bash_script (const char *label,
552 const char *script, 78 const char *script,
553 char *const script_argv[], 79 char *const script_argv[],
80 // FIXME: wtf are these two args here for!?
554 int argc, 81 int argc,
555 GNUNET_ChildCompletedCallback cb); 82 GNUNET_ChildCompletedCallback cb);
556 83
557 84
558/**
559 * Retrieve peer identity from the test system with the unique node id.
560 *
561 * @param num The unique node id.
562 * @param tl_system The test system.
563 * @return The peer identity wrapping the public key.
564 */
565struct GNUNET_PeerIdentity *
566GNUNET_TESTING_get_peer (unsigned int num,
567 const struct GNUNET_TESTING_System *tl_system);
568 85
569 86/* ****** Specific traits needed by this component ******* */
570/**
571 * Obtain performance data from the interpreter.
572 *
573 * @param[in,out] timers what commands (by label) to obtain runtimes for
574 * @return the command
575 */
576struct GNUNET_TESTING_Command
577GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers);
578
579
580/* *** Generic trait logic for implementing traits ********* */
581
582/**
583 * A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
584 *
585 * Therefor the cmd which like to provide data to other cmds has to implement
586 * the trait function, where an array of traits is defined with the help of the
587 * GNUNET_TESTING_make_trait_ macro. The data can be retrieved with the help of the
588 * GNUNET_TESTING_get_trait_ macro. Traits name and type must be defined to make
589 * use of the macros.
590 */
591struct GNUNET_TESTING_Trait
592{
593 /**
594 * Index number associated with the trait. This gives the
595 * possibility to have _multiple_ traits on offer under the
596 * same name.
597 */
598 unsigned int index;
599
600 /**
601 * Trait type, for example "reserve-pub" or "coin-priv".
602 */
603 const char *trait_name;
604
605 /**
606 * Pointer to the piece of data to offer.
607 */
608 const void *ptr;
609};
610
611
612/**
613 * "end" trait. Because traits are offered into arrays,
614 * this type of trait is used to mark the end of such arrays;
615 * useful when iterating over those.
616 */
617struct GNUNET_TESTING_Trait
618GNUNET_TESTING_trait_end (void);
619
620
621/**
622 * Extract a trait.
623 * FIXME: Naming. This is something like "contains trait".
624 *
625 * @param traits the array of all the traits.
626 * @param[out] ret where to store the result.
627 * @param trait type of the trait to extract.
628 * @param index index number of the trait to extract.
629 * @return #GNUNET_OK when the trait is found.
630 */
631enum GNUNET_GenericReturnValue
632GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
633 const void **ret,
634 const char *trait,
635 unsigned int index);
636
637
638/* ****** Specific traits supported by this component ******* */
639
640
641typedef void *
642(*GNUNET_TESTING_notify_connect_cb) (struct GNUNET_TESTING_Interpreter *is,
643 const struct GNUNET_PeerIdentity *peer);
644
645/**
646 * Struct to store information needed in callbacks.
647 *
648 */
649struct GNUNET_TESTING_ConnectPeersState
650{
651 /**
652 * Receive callback
653 */
654 struct GNUNET_MQ_MessageHandler *handlers;
655
656 /**
657 * A map with struct GNUNET_MQ_Handle values for each peer this peer
658 * is connected to.
659 */
660 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
661
662 /**
663 * Handle for transport.
664 */
665 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
666
667 /**
668 * Core handle.
669 */
670 struct GNUNET_TRANSPORT_CoreHandle *th;
671
672 /**
673 * Context for our asynchronous completion.
674 */
675 struct GNUNET_TESTING_AsyncContext ac;
676
677 /**
678 * The testing system of this node.
679 */
680 const struct GNUNET_TESTING_System *tl_system;
681
682 // Label of the cmd which started the test system.
683 const char *create_label;
684
685 /**
686 * Number globally identifying the node.
687 *
688 */
689 uint32_t num;
690
691 /**
692 * Label of the cmd to start a peer.
693 *
694 */
695 const char *start_peer_label;
696
697 /**
698 * The topology of the test setup.
699 */
700 struct GNUNET_TESTING_NetjailTopology *topology;
701
702 /**
703 * Connections to other peers.
704 */
705 struct GNUNET_TESTING_NodeConnection *node_connections_head;
706
707 struct GNUNET_TESTING_Interpreter *is;
708
709 /**
710 * Number of connections.
711 */
712 unsigned int con_num;
713
714 /**
715 * Number of additional connects this cmd will wait for not triggered by this cmd.
716 */
717 unsigned int additional_connects;
718
719 /**
720 * Number of connections we already have a notification for.
721 */
722 unsigned int con_num_notified;
723
724 /**
725 * Number of additional connects this cmd will wait for not triggered by this cmd we already have a notification for.
726 */
727 unsigned int additional_connects_notified;
728
729 /**
730 * Flag indicating, whether the command is waiting for peers to connect that are configured to connect.
731 */
732 unsigned int wait_for_connect;
733};
734
735/**
736 * Struct to store information needed in callbacks.
737 *
738 */
739struct ConnectPeersState
740{
741 /**
742 * Context for our asynchronous completion.
743 */
744 struct GNUNET_TESTING_AsyncContext ac;
745
746 GNUNET_TESTING_notify_connect_cb notify_connect;
747
748 /**
749 * The testing system of this node.
750 */
751 const struct GNUNET_TESTING_System *tl_system;
752
753 // Label of the cmd which started the test system.
754 const char *create_label;
755
756 /**
757 * Number globally identifying the node.
758 *
759 */
760 uint32_t num;
761
762 /**
763 * Label of the cmd to start a peer.
764 *
765 */
766 const char *start_peer_label;
767
768 /**
769 * The topology of the test setup.
770 */
771 struct GNUNET_TESTING_NetjailTopology *topology;
772
773 /**
774 * Connections to other peers.
775 */
776 struct GNUNET_TESTING_NodeConnection *node_connections_head;
777
778 struct GNUNET_TESTING_Interpreter *is;
779
780 /**
781 * Number of connections.
782 */
783 unsigned int con_num;
784
785 /**
786 * Number of additional connects this cmd will wait for not triggered by this cmd.
787 */
788 unsigned int additional_connects;
789
790 /**
791 * Number of connections we already have a notification for.
792 */
793 unsigned int con_num_notified;
794
795 /**
796 * Number of additional connects this cmd will wait for not triggered by this cmd we already have a notification for.
797 */
798 unsigned int additional_connects_notified;
799
800 /**
801 * Flag indicating, whether the command is waiting for peers to connect that are configured to connect.
802 */
803 unsigned int wait_for_connect;
804};
805
806
807struct GNUNET_TESTING_StartPeerState
808{
809 /**
810 * Context for our asynchronous completion.
811 */
812 struct GNUNET_TESTING_AsyncContext ac;
813
814 /**
815 * The ip of a node.
816 */
817 char *node_ip;
818
819 /**
820 * Receive callback
821 */
822 struct GNUNET_MQ_MessageHandler *handlers;
823
824 /**
825 * GNUnet configuration file used to start a peer.
826 */
827 char *cfgname;
828
829 /**
830 * Peer's configuration
831 */
832 struct GNUNET_CONFIGURATION_Handle *cfg;
833
834 /**
835 * struct GNUNET_TESTING_Peer returned by GNUNET_TESTING_peer_configure.
836 */
837 struct GNUNET_TESTING_Peer *peer;
838
839 /**
840 * Peer identity
841 */
842 struct GNUNET_PeerIdentity id;
843
844 /**
845 * Peer's transport service handle
846 */
847 struct GNUNET_TRANSPORT_CoreHandle *th;
848
849 /**
850 * Application handle
851 */
852 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
853
854 /**
855 * Peer's PEERSTORE Handle
856 */
857 struct GNUNET_PEERSTORE_Handle *ph;
858
859 /**
860 * Hello get task
861 */
862 struct GNUNET_SCHEDULER_Task *rh_task;
863
864 /**
865 * Peer's transport get hello handle to retrieve peer's HELLO message
866 */
867 struct GNUNET_PEERSTORE_IterateContext *pic;
868
869 /**
870 * Hello
871 */
872 char *hello;
873
874 /**
875 * Hello size
876 */
877 size_t hello_size;
878
879 /**
880 * The label of the command which was started by calling GNUNET_TESTING_cmd_system_create.
881 */
882 char *system_label;
883
884 /**
885 * An unique number to identify the peer
886 */
887 unsigned int no;
888
889 /**
890 * A map with struct GNUNET_MQ_Handle values for each peer this peer
891 * is connected to.
892 */
893 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
894
895 /**
896 * Test setup for this peer.
897 */
898 const struct GNUNET_TESTING_System *tl_system;
899
900 /**
901 * Callback which is called on neighbour connect events.
902 */
903 GNUNET_TESTING_notify_connect_cb notify_connect;
904
905 /**
906 * Flag indicating, if udp broadcast should be switched on.
907 */
908 enum GNUNET_GenericReturnValue broadcast;
909};
910
911
912/**
913 * Create headers for a trait with name @a name for
914 * statically allocated data of type @a type.
915 */
916#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \
917 enum GNUNET_GenericReturnValue \
918 GNUNET_TESTING_get_trait_ ## name ( \
919 const struct GNUNET_TESTING_Command *cmd, \
920 type **ret); \
921 struct GNUNET_TESTING_Trait \
922 GNUNET_TESTING_make_trait_ ## name ( \
923 type * value);
924
925
926/**
927 * Create C implementation for a trait with name @a name for statically
928 * allocated data of type @a type.
929 */
930#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \
931 enum GNUNET_GenericReturnValue \
932 GNUNET_TESTING_get_trait_ ## name ( \
933 const struct GNUNET_TESTING_Command *cmd, \
934 type * *ret) \
935 { \
936 if (NULL == cmd->traits) return GNUNET_SYSERR; \
937 return cmd->traits (cmd->cls, \
938 (const void **) ret, \
939 GNUNET_S (name), \
940 0); \
941 } \
942 struct GNUNET_TESTING_Trait \
943 GNUNET_TESTING_make_trait_ ## name ( \
944 type * value) \
945 { \
946 struct GNUNET_TESTING_Trait ret = { \
947 .trait_name = GNUNET_S (name), \
948 .ptr = (const void *) value \
949 }; \
950 return ret; \
951 }
952
953
954/**
955 * Create headers for a trait with name @a name for
956 * statically allocated data of type @a type.
957 */
958#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \
959 enum GNUNET_GenericReturnValue \
960 GNUNET_TESTING_get_trait_ ## name ( \
961 const struct GNUNET_TESTING_Command *cmd, \
962 unsigned int index, \
963 type **ret); \
964 struct GNUNET_TESTING_Trait \
965 GNUNET_TESTING_make_trait_ ## name ( \
966 unsigned int index, \
967 type *value);
968
969
970/**
971 * Create C implementation for a trait with name @a name for statically
972 * allocated data of type @a type.
973 */
974#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \
975 enum GNUNET_GenericReturnValue \
976 GNUNET_TESTING_get_trait_ ## name ( \
977 const struct GNUNET_TESTING_Command *cmd, \
978 unsigned int index, \
979 type * *ret) \
980 { \
981 if (NULL == cmd->traits) return GNUNET_SYSERR; \
982 return cmd->traits (cmd->cls, \
983 (const void **) ret, \
984 GNUNET_S (name), \
985 index); \
986 } \
987 struct GNUNET_TESTING_Trait \
988 GNUNET_TESTING_make_trait_ ## name ( \
989 unsigned int index, \
990 type * value) \
991 { \
992 struct GNUNET_TESTING_Trait ret = { \
993 .index = index, \
994 .trait_name = GNUNET_S (name), \
995 .ptr = (const void *) value \
996 }; \
997 return ret; \
998 }
999 87
1000 88
1001/** 89/**
1002 * Call #op on all simple traits. 90 * Call #op on all simple traits.
1003 */ 91 */
1004#define GNUNET_TESTING_SIMPLE_TRAITS(op) \ 92#define GNUNET_TESTING_SIMPLE_TRAITS(op) \
1005 op (batch_cmds, struct GNUNET_TESTING_Command *) \ 93 op (process, struct GNUNET_OS_Process *)
1006 op (process, struct GNUNET_OS_Process *) \ 94
1007 op (peer_id, const struct GNUNET_PeerIdentity) \
1008 op (connected_peers_map, const struct GNUNET_CONTAINER_MultiShortmap) \
1009 op (hello_size, const size_t) \
1010 op (hello, const char) \
1011 op (application_handle, const struct GNUNET_TRANSPORT_ApplicationHandle) \
1012 op (connect_peer_state, const struct GNUNET_TESTING_ConnectPeersState) \
1013 op (state, const struct GNUNET_TESTING_StartPeerState) \
1014 op (broadcast, const enum GNUNET_GenericReturnValue)
1015 95
96GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT)
1016 97
1017/** 98/**
1018 * Call #op on all indexed traits. 99 * Call #op on all indexed traits.
1019 */ 100 */
1020#define GNUNET_TESTING_INDEXED_TRAITS(op) \ 101#define GNUNET_TESTING_INDEXED_TRAITS(op) \
1021 op (uint32, const uint32_t) \ 102 op (uint32, const uint32_t) \
1022 op (uint64, const uint64_t) \ 103 op (uint64, const uint64_t) \
1023 op (int64, const int64_t) \ 104 op (int64, const int64_t) \
1024 op (uint, const unsigned int) \ 105 op (uint, const unsigned int) \
1025 op (string, const char) \ 106 op (string, const char) \
1026 op (cmd, const struct GNUNET_TESTING_Command) \
1027 op (uuid, const struct GNUNET_Uuid) \ 107 op (uuid, const struct GNUNET_Uuid) \
1028 op (time, const struct GNUNET_TIME_Absolute) \ 108 op (time, const struct GNUNET_TIME_Absolute) \
1029 op (absolute_time, const struct GNUNET_TIME_Absolute) \ 109 op (absolute_time, const struct GNUNET_TIME_Absolute) \
1030 op (relative_time, const struct GNUNET_TIME_Relative) 110 op (relative_time, const struct GNUNET_TIME_Relative)
1031 111
1032GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT)
1033
1034GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT) 112GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT)
1035 113
114
1036#endif 115#endif