diff options
Diffstat (limited to 'src/include/gnunet_testing_ng_lib.h')
-rw-r--r-- | src/include/gnunet_testing_ng_lib.h | 1155 |
1 files changed, 38 insertions, 1117 deletions
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index 31665f8f7..407f50bb7 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021, 2023 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -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 |
@@ -27,524 +27,28 @@ | |||
27 | #ifndef GNUNET_TESTING_NG_LIB_H | 27 | #ifndef GNUNET_TESTING_NG_LIB_H |
28 | #define GNUNET_TESTING_NG_LIB_H | 28 | #define GNUNET_TESTING_NG_LIB_H |
29 | 29 | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_testing_plugin.h" | ||
32 | #include "gnunet_testing_lib.h" | ||
33 | |||
34 | |||
35 | /* ********************* Helper functions ********************* */ | ||
36 | |||
37 | /** | ||
38 | * Print failing line number and trigger shutdown. Useful | ||
39 | * quite any time after the command "run" method has been called. | ||
40 | */ | ||
41 | #define GNUNET_TESTING_FAIL(is) \ | ||
42 | do \ | ||
43 | { \ | ||
44 | GNUNET_break (0); \ | ||
45 | GNUNET_TESTING_interpreter_fail (is); \ | ||
46 | return; \ | ||
47 | } while (0) | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Router of a network namespace. | ||
52 | */ | ||
53 | struct GNUNET_TESTING_NetjailRouter | ||
54 | { | ||
55 | /** | ||
56 | * Will tcp be forwarded? | ||
57 | */ | ||
58 | unsigned int tcp_port; | ||
59 | |||
60 | /** | ||
61 | * Will udp be forwarded? | ||
62 | */ | ||
63 | unsigned int udp_port; | ||
64 | }; | ||
65 | |||
66 | /** | ||
67 | * Enum for the different types of nodes. | ||
68 | */ | ||
69 | enum GNUNET_TESTING_NODE_TYPE | ||
70 | { | ||
71 | /** | ||
72 | * Node in a subnet. | ||
73 | */ | ||
74 | GNUNET_TESTING_SUBNET_NODE, | ||
75 | |||
76 | /** | ||
77 | * Global known node. | ||
78 | */ | ||
79 | GNUNET_TESTING_GLOBAL_NODE | ||
80 | }; | ||
81 | |||
82 | struct GNUNET_TESTING_ADDRESS_PREFIX | ||
83 | { | ||
84 | /** | ||
85 | * Pointer to the previous prefix in the DLL. | ||
86 | */ | ||
87 | struct GNUNET_TESTING_ADDRESS_PREFIX *prev; | ||
88 | |||
89 | /** | ||
90 | * Pointer to the next prefix in the DLL. | ||
91 | */ | ||
92 | struct GNUNET_TESTING_ADDRESS_PREFIX *next; | ||
93 | |||
94 | /** | ||
95 | * The address prefix. | ||
96 | */ | ||
97 | char *address_prefix; | ||
98 | }; | ||
99 | |||
100 | struct GNUNET_TESTING_NetjailNode; | ||
101 | |||
102 | /** | ||
103 | * Connection to another node. | ||
104 | */ | ||
105 | struct GNUNET_TESTING_NodeConnection | ||
106 | { | ||
107 | /** | ||
108 | * Pointer to the previous connection in the DLL. | ||
109 | */ | ||
110 | struct GNUNET_TESTING_NodeConnection *prev; | ||
111 | |||
112 | /** | ||
113 | * Pointer to the next connection in the DLL. | ||
114 | */ | ||
115 | struct GNUNET_TESTING_NodeConnection *next; | ||
116 | |||
117 | /** | ||
118 | * The number of the subnet of the node this connection points to. This is 0, | ||
119 | * if the node is a global known node. | ||
120 | */ | ||
121 | unsigned int namespace_n; | ||
122 | |||
123 | /** | ||
124 | * The number of the node this connection points to. | ||
125 | */ | ||
126 | unsigned int node_n; | ||
127 | |||
128 | /** | ||
129 | * The type of the node this connection points to. | ||
130 | */ | ||
131 | enum GNUNET_TESTING_NODE_TYPE node_type; | ||
132 | |||
133 | /** | ||
134 | * The node which establish the connection | ||
135 | */ | ||
136 | struct GNUNET_TESTING_NetjailNode *node; | ||
137 | |||
138 | /** | ||
139 | * Head of the DLL with the address prefixes for the protocolls this node is reachable. | ||
140 | */ | ||
141 | struct GNUNET_TESTING_ADDRESS_PREFIX *address_prefixes_head; | ||
142 | |||
143 | /** | ||
144 | * Tail of the DLL with the address prefixes for the protocolls this node is reachable. | ||
145 | */ | ||
146 | struct GNUNET_TESTING_ADDRESS_PREFIX *address_prefixes_tail; | ||
147 | }; | ||
148 | |||
149 | /** | ||
150 | * Node in the netjail topology. | ||
151 | */ | ||
152 | struct GNUNET_TESTING_NetjailNode | ||
153 | { | ||
154 | /** | ||
155 | * Plugin for the test case to be run on this node. | ||
156 | */ | ||
157 | char *plugin; | ||
158 | |||
159 | /** | ||
160 | * Flag indicating if this node is a global known node. | ||
161 | */ | ||
162 | unsigned int is_global; | ||
163 | |||
164 | /** | ||
165 | * The number of the namespace this node is running in. | ||
166 | */ | ||
167 | unsigned int namespace_n; | ||
168 | |||
169 | /** | ||
170 | * The number of this node in the namespace. | ||
171 | */ | ||
172 | unsigned int node_n; | ||
173 | |||
174 | /** | ||
175 | * Head of the DLL with the connections which shall be established to other nodes. | ||
176 | */ | ||
177 | struct GNUNET_TESTING_NodeConnection *node_connections_head; | ||
178 | |||
179 | /** | ||
180 | * Tail of the DLL with the connections which shall be established to other nodes. | ||
181 | */ | ||
182 | struct GNUNET_TESTING_NodeConnection *node_connections_tail; | ||
183 | }; | ||
184 | |||
185 | |||
186 | /** | ||
187 | * Namespace in a topology. | ||
188 | */ | ||
189 | struct GNUNET_TESTING_NetjailNamespace | ||
190 | { | ||
191 | /** | ||
192 | * The number of the namespace. | ||
193 | */ | ||
194 | unsigned int namespace_n; | ||
195 | |||
196 | /** | ||
197 | * Router of the namespace. | ||
198 | */ | ||
199 | struct GNUNET_TESTING_NetjailRouter *router; | ||
200 | |||
201 | /** | ||
202 | * Hash map containing the nodes in this namespace. | ||
203 | */ | ||
204 | struct GNUNET_CONTAINER_MultiShortmap *nodes; | ||
205 | }; | ||
206 | |||
207 | /** | ||
208 | * Toplogy of our netjail setup. | ||
209 | */ | ||
210 | struct GNUNET_TESTING_NetjailTopology | ||
211 | { | ||
212 | |||
213 | /** | ||
214 | * Default plugin for the test case to be run on nodes. | ||
215 | */ | ||
216 | char *plugin; | ||
217 | |||
218 | /** | ||
219 | * Number of namespaces. | ||
220 | */ | ||
221 | unsigned int namespaces_n; | ||
222 | |||
223 | /** | ||
224 | * Number of nodes per namespace. | ||
225 | */ | ||
226 | unsigned int nodes_m; | ||
227 | |||
228 | /** | ||
229 | * Number of global known nodes per namespace. | ||
230 | */ | ||
231 | unsigned int nodes_x; | ||
232 | |||
233 | /** | ||
234 | * Hash map containing the namespaces (for natted nodes) of the topology. | ||
235 | */ | ||
236 | struct GNUNET_CONTAINER_MultiShortmap *map_namespaces; | ||
237 | |||
238 | /** | ||
239 | * Hash map containing the global known nodes which are not natted. | ||
240 | */ | ||
241 | struct GNUNET_CONTAINER_MultiShortmap *map_globals; | ||
242 | }; | ||
243 | |||
244 | |||
245 | /* ******************* Generic interpreter logic ************ */ | ||
246 | |||
247 | /** | ||
248 | * Global state of the interpreter, used by a command | ||
249 | * to access information about other commands. | ||
250 | */ | ||
251 | struct GNUNET_TESTING_Interpreter; | ||
252 | |||
253 | /** | ||
254 | * A command to be run by the interpreter. | ||
255 | */ | ||
256 | struct GNUNET_TESTING_Command | ||
257 | { | ||
258 | |||
259 | /** | ||
260 | * Closure for all commands with command-specific context information. | ||
261 | */ | ||
262 | void *cls; | ||
263 | |||
264 | /** | ||
265 | * Label for the command. | ||
266 | */ | ||
267 | const char *label; | ||
268 | |||
269 | /** | ||
270 | * Runs the command. Note that upon return, the interpreter | ||
271 | * will not automatically run the next command, as the command | ||
272 | * may continue asynchronously in other scheduler tasks. Thus, | ||
273 | * the command must ensure to eventually call | ||
274 | * #GNUNET_TESTING_interpreter_next() or | ||
275 | * #GNUNET_TESTING_interpreter_fail(). | ||
276 | * | ||
277 | * If this function creates some asynchronous activity, it should | ||
278 | * initialize @e finish to a function that can be used to wait for | ||
279 | * the asynchronous activity to terminate. | ||
280 | * | ||
281 | * @param cls closure | ||
282 | * @param cmd command being run | ||
283 | * @param i interpreter state | ||
284 | */ | ||
285 | void | ||
286 | (*run)(void *cls, | ||
287 | const struct GNUNET_TESTING_Command *cmd, | ||
288 | struct GNUNET_TESTING_Interpreter *i); | ||
289 | |||
290 | /** | ||
291 | * Wait for any asynchronous execution of @e run to conclude, | ||
292 | * then call finish_cont. Finish may only be called once per command. | ||
293 | * | ||
294 | * This member may be NULL if this command is a synchronous command, | ||
295 | * and also should be set to NULL once the command has finished. | ||
296 | * | ||
297 | * @param cls closure | ||
298 | * @param cont function to call upon completion, can be NULL | ||
299 | * @param cont_cls closure for @a cont | ||
300 | */ | ||
301 | int | ||
302 | (*finish)(void *cls, | ||
303 | GNUNET_SCHEDULER_TaskCallback cont, | ||
304 | void *cont_cls); | ||
305 | |||
306 | /** | ||
307 | * Task for running the finish function. | ||
308 | */ | ||
309 | struct GNUNET_SCHEDULER_Task *finish_task; | ||
310 | |||
311 | /** | ||
312 | * Clean up after the command. Run during forced termination | ||
313 | * (CTRL-C) or test failure or test success. | ||
314 | * | ||
315 | * @param cls closure | ||
316 | * @param cmd command being cleaned up | ||
317 | */ | ||
318 | void | ||
319 | (*cleanup)(void *cls, | ||
320 | const struct GNUNET_TESTING_Command *cmd); | ||
321 | |||
322 | /** | ||
323 | * Extract information from a command that is useful for other | ||
324 | * commands. | ||
325 | * | ||
326 | * @param cls closure | ||
327 | * @param[out] ret result (could be anything) | ||
328 | * @param trait name of the trait | ||
329 | * @param index index number of the object to extract. | ||
330 | * @return #GNUNET_OK on success | ||
331 | */ | ||
332 | int | ||
333 | (*traits)(void *cls, | ||
334 | const void **ret, | ||
335 | const char *trait, | ||
336 | unsigned int index); | ||
337 | |||
338 | /** | ||
339 | * When did the execution of this command start? | ||
340 | */ | ||
341 | struct GNUNET_TIME_Absolute start_time; | ||
342 | |||
343 | /** | ||
344 | * When did the execution of this command finish? | ||
345 | */ | ||
346 | struct GNUNET_TIME_Absolute finish_time; | ||
347 | |||
348 | /** | ||
349 | * When did we start the last run of this command? Delta to @e finish_time | ||
350 | * gives the latency for the last successful run. Useful in case @e | ||
351 | * num_tries was positive and the command was run multiple times. In that | ||
352 | * case, the @e start_time gives the time when we first tried to run the | ||
353 | * command, so the difference between @e start_time and @e finish_time would | ||
354 | * be the time all of the @e num_tries took, while the delta to @e | ||
355 | * last_req_time is the time the last (successful) execution took. | ||
356 | */ | ||
357 | struct GNUNET_TIME_Absolute last_req_time; | ||
358 | |||
359 | /** | ||
360 | * How often did we try to execute this command? (In case it is a request | ||
361 | * that is repated.) Note that a command must have some built-in retry | ||
362 | * mechanism for this value to be useful. | ||
363 | */ | ||
364 | unsigned int num_tries; | ||
365 | |||
366 | /** | ||
367 | * In case @e asynchronous_finish is true, how long should we wait for this | ||
368 | * command to complete? If @e finish did not complete after this amount of | ||
369 | * time, the interpreter will fail. Should be set generously to ensure | ||
370 | * tests do not fail on slow systems. | ||
371 | */ | ||
372 | struct GNUNET_TIME_Relative default_timeout; | ||
373 | |||
374 | /** | ||
375 | * If "true", the interpreter should not immediately call | ||
376 | * @e finish, even if @e finish is non-NULL. Otherwise, | ||
377 | * #TALER_TESTING_cmd_finish() must be used | ||
378 | * to ensure that a command actually completed. | ||
379 | */ | ||
380 | bool asynchronous_finish; | ||
381 | |||
382 | }; | ||
383 | |||
384 | |||
385 | /** | ||
386 | * Struct to use for command-specific context information closure of a command waiting | ||
387 | * for another command. | ||
388 | */ | ||
389 | struct SyncState | ||
390 | { | ||
391 | /** | ||
392 | * Closure for all commands with command-specific context information. | ||
393 | */ | ||
394 | void *cls; | ||
395 | |||
396 | /** | ||
397 | * The asynchronous command the synchronous command of this closure waits for. | ||
398 | */ | ||
399 | const struct GNUNET_TESTING_Command *async_cmd; | ||
400 | |||
401 | /** | ||
402 | * Task for running the finish method of the asynchronous task the command is waiting for. | ||
403 | */ | ||
404 | struct GNUNET_SCHEDULER_Task *finish_task; | ||
405 | |||
406 | /** | ||
407 | * When did the execution of this commands finish function start? | ||
408 | */ | ||
409 | struct GNUNET_TIME_Absolute start_finish_time; | ||
410 | }; | ||
411 | |||
412 | /** | ||
413 | * Lookup command by label. | ||
414 | * | ||
415 | * @param label label of the command to lookup. | ||
416 | * @return the command, if it is found, or NULL. | ||
417 | */ | ||
418 | const struct GNUNET_TESTING_Command * | ||
419 | GNUNET_TESTING_interpreter_lookup_command ( | ||
420 | const char *label); | ||
421 | |||
422 | |||
423 | /** | ||
424 | * Obtain label of the command being now run. | ||
425 | * | ||
426 | * @param is interpreter state. | ||
427 | * @return the label. | ||
428 | */ | ||
429 | const char * | ||
430 | GNUNET_TESTING_interpreter_get_current_label ( | ||
431 | struct GNUNET_TESTING_Interpreter *is); | ||
432 | |||
433 | |||
434 | /** | ||
435 | * Current command failed, clean up and fail the test case. | ||
436 | * | ||
437 | * @param is interpreter state. | ||
438 | */ | ||
439 | void | ||
440 | GNUNET_TESTING_interpreter_fail (); | ||
441 | |||
442 | |||
443 | /** | ||
444 | * Create command array terminator. | ||
445 | * | ||
446 | * @return a end-command. | ||
447 | */ | ||
448 | struct GNUNET_TESTING_Command | ||
449 | GNUNET_TESTING_cmd_end (void); | ||
450 | |||
451 | |||
452 | /** | ||
453 | * Turn asynchronous command into non blocking command by setting asynchronous_finish to true. | ||
454 | * | ||
455 | * @param cmd command to make synchronous. | ||
456 | * @return a finish-command. | ||
457 | */ | ||
458 | const struct GNUNET_TESTING_Command | ||
459 | GNUNET_TESTING_cmd_make_unblocking (const struct GNUNET_TESTING_Command cmd); | ||
460 | |||
461 | |||
462 | /** | ||
463 | * Create (synchronous) command that waits for another command to finish. | ||
464 | * If @a cmd_ref did not finish after @a timeout, this command will fail | ||
465 | * the test case. | ||
466 | * | ||
467 | * @param finish_label label for this command | ||
468 | * @param cmd_ref reference to a previous command which we should | ||
469 | * wait for (call `finish()` on) | ||
470 | * @param timeout how long to wait at most for @a cmd_ref to finish | ||
471 | * @return a finish-command. | ||
472 | */ | ||
473 | const struct GNUNET_TESTING_Command | ||
474 | GNUNET_TESTING_cmd_finish (const char *finish_label, | ||
475 | const char *cmd_ref, | ||
476 | struct GNUNET_TIME_Relative timeout); | ||
477 | |||
478 | |||
479 | /** | ||
480 | * Make the instruction pointer point to @a target_label | ||
481 | * only if @a counter is greater than zero. | ||
482 | * | ||
483 | * @param label command label | ||
484 | * @param target_label label of the new instruction pointer's destination after the jump; | ||
485 | * must be before the current instruction | ||
486 | * @param counter counts how many times the rewinding is to happen. | ||
487 | */ | ||
488 | struct GNUNET_TESTING_Command | ||
489 | GNUNET_TESTING_cmd_rewind_ip (const char *label, | ||
490 | const char *target_label, | ||
491 | unsigned int counter); | ||
492 | |||
493 | |||
494 | /** | ||
495 | * Wait until we receive SIGCHLD signal. Then obtain the process trait of the | ||
496 | * current command, wait on the the zombie and continue with the next command. | ||
497 | * | ||
498 | * @param is interpreter state. | ||
499 | */ | ||
500 | // void | ||
501 | // GNUNET_TESTING_wait_for_sigchld (struct GNUNET_TESTING_Interpreter *is); | ||
502 | // => replace with child_management.c | ||
503 | |||
504 | |||
505 | /** | ||
506 | * Start scheduling loop with signal handlers and run the | ||
507 | * test suite with the @a commands. | ||
508 | * | ||
509 | * @param cfg_name name of configuration file to use | ||
510 | * @param commands the list of command to execute | ||
511 | * @param timeout how long to wait for each command to execute | ||
512 | * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise. | ||
513 | * non-GNUNET_OK codes are #GNUNET_SYSERR most of the | ||
514 | * times. | ||
515 | */ | ||
516 | int | ||
517 | GNUNET_TESTING_run (const char *cfg_filename, | ||
518 | struct GNUNET_TESTING_Command *commands, | ||
519 | struct GNUNET_TIME_Relative timeout); | ||
520 | 30 | ||
31 | #include "gnunet_util_lib.h" | ||
521 | 32 | ||
522 | /** | 33 | /* FIXME: legacy test header, to be removed!! */ |
523 | * Look for substring in a programs' name. | 34 | #include "gnunet_testing_lib.h" |
524 | * | ||
525 | * @param prog program's name to look into | ||
526 | * @param marker chunk to find in @a prog | ||
527 | */ | ||
528 | int | ||
529 | GNUNET_TESTING_has_in_name (const char *prog, | ||
530 | const char *marker); | ||
531 | 35 | ||
36 | #include "gnunet_testing_plugin.h" | ||
37 | #include "gnunet_testing_loop_lib.h" | ||
38 | #include "gnunet_testing_netjail_lib.h" | ||
532 | 39 | ||
533 | /* ************** Specific interpreter commands ************ */ | ||
534 | 40 | ||
535 | /** | 41 | /** |
536 | * Create a "signal" CMD. | 42 | * Create a "signal" CMD. |
537 | * | 43 | * |
538 | * @param label command label. | 44 | * @param label command label. |
539 | * @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 |
540 | * @param process_index index of the process trait at @a process_label | ||
541 | * @param signal signal to send to @a process. | 46 | * @param signal signal to send to @a process. |
542 | * @return the command. | 47 | * @return the command. |
543 | */ | 48 | */ |
544 | struct GNUNET_TESTING_Command | 49 | struct GNUNET_TESTING_Command |
545 | GNUNET_TESTING_cmd_signal (const char *label, | 50 | GNUNET_TESTING_cmd_signal (const char *label, |
546 | const char *process_label, | 51 | const char *process_label, |
547 | unsigned int process_index, | ||
548 | int signal); | 52 | int signal); |
549 | 53 | ||
550 | 54 | ||
@@ -561,634 +65,51 @@ GNUNET_TESTING_cmd_sleep (const char *label, | |||
561 | 65 | ||
562 | 66 | ||
563 | /** | 67 | /** |
564 | * Create a "batch" command. Such command takes a end_CMD-terminated array of | 68 | * Command to execute a script synchronously. |
565 | * CMDs and executed them. Once it hits the end CMD, it passes the control to | ||
566 | * the next top-level CMD, regardless of it being another batch or ordinary | ||
567 | * CMD. | ||
568 | * | 69 | * |
569 | * @param label the command label. | 70 | * FIXME: is this accurate? How is this limited to BASH scripts or even scripts? |
570 | * @param batch array of CMDs to execute. | ||
571 | * @return the command. | ||
572 | */ | ||
573 | struct GNUNET_TESTING_Command | ||
574 | GNUNET_TESTING_cmd_batch (const char *label, | ||
575 | struct GNUNET_TESTING_Command *batch); | ||
576 | |||
577 | |||
578 | /** | ||
579 | * Test if this command is a batch command. | ||
580 | * | 71 | * |
581 | * @return false if not, true if it is a batch command | 72 | * @param label Label of the command. |
582 | */ | 73 | * @param script The name of the script. |
583 | // TODO: figure out if this needs to be exposed in the public API. | 74 | * @param script_argv The arguments of the script. |
584 | int | 75 | */ |
585 | GNUNET_TESTING_cmd_is_batch (const struct GNUNET_TESTING_Command *cmd); | 76 | const struct GNUNET_TESTING_Command |
586 | 77 | GNUNET_TESTING_cmd_exec_bash_script (const char *label, | |
587 | 78 | const char *script, | |
588 | /** | 79 | char *const script_argv[], |
589 | * Advance internal pointer to next command. | 80 | // FIXME: wtf are these two args here for!? |
590 | * | 81 | int argc, |
591 | * @param is interpreter state. | 82 | GNUNET_ChildCompletedCallback cb); |
592 | */ | ||
593 | // TODO: figure out if this needs to be exposed in the public API. | ||
594 | void | ||
595 | GNUNET_TESTING_cmd_batch_next (struct GNUNET_TESTING_Interpreter *is); | ||
596 | |||
597 | |||
598 | /** | ||
599 | * Obtain what command the batch is at. | ||
600 | * | ||
601 | * @return cmd current batch command | ||
602 | */ | ||
603 | // TODO: figure out if this needs to be exposed in the public API. | ||
604 | struct GNUNET_TESTING_Command * | ||
605 | GNUNET_TESTING_cmd_batch_get_current (const struct GNUNET_TESTING_Command *cmd); | ||
606 | |||
607 | |||
608 | /** | ||
609 | * Set what command the batch should be at. | ||
610 | * | ||
611 | * @param cmd current batch command | ||
612 | * @param new_ip where to move the IP | ||
613 | */ | ||
614 | // TODO: figure out if this needs to be exposed in the public API. | ||
615 | void | ||
616 | GNUNET_TESTING_cmd_batch_set_current (const struct GNUNET_TESTING_Command *cmd, | ||
617 | unsigned int new_ip); | ||
618 | |||
619 | |||
620 | /** | ||
621 | * Performance counter. | ||
622 | */ | ||
623 | struct GNUNET_TESTING_Timer | ||
624 | { | ||
625 | /** | ||
626 | * For which type of commands. | ||
627 | */ | ||
628 | const char *prefix; | ||
629 | |||
630 | /** | ||
631 | * Total time spend in all commands of this type. | ||
632 | */ | ||
633 | struct GNUNET_TIME_Relative total_duration; | ||
634 | |||
635 | /** | ||
636 | * Total time spend waiting for the *successful* exeuction | ||
637 | * in all commands of this type. | ||
638 | */ | ||
639 | struct GNUNET_TIME_Relative success_latency; | ||
640 | |||
641 | /** | ||
642 | * Number of commands summed up. | ||
643 | */ | ||
644 | unsigned int num_commands; | ||
645 | |||
646 | /** | ||
647 | * Number of retries summed up. | ||
648 | */ | ||
649 | unsigned int num_retries; | ||
650 | }; | ||
651 | |||
652 | |||
653 | /** | ||
654 | * Getting the topology from file. | ||
655 | * | ||
656 | * @param filename The name of the topology file. | ||
657 | * @return The GNUNET_TESTING_NetjailTopology | ||
658 | */ | ||
659 | struct GNUNET_TESTING_NetjailTopology * | ||
660 | GNUNET_TESTING_get_topo_from_file (const char *filename); | ||
661 | |||
662 | |||
663 | /** | ||
664 | * Obtain performance data from the interpreter. | ||
665 | * | ||
666 | * @param timers what commands (by label) to obtain runtimes for | ||
667 | * @return the command | ||
668 | */ | ||
669 | struct GNUNET_TESTING_Command | ||
670 | GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers); | ||
671 | |||
672 | |||
673 | /* *** Generic trait logic for implementing traits ********* */ | ||
674 | |||
675 | /** | ||
676 | * A trait. | ||
677 | */ | ||
678 | struct GNUNET_TESTING_Trait | ||
679 | { | ||
680 | /** | ||
681 | * Index number associated with the trait. This gives the | ||
682 | * possibility to have _multiple_ traits on offer under the | ||
683 | * same name. | ||
684 | */ | ||
685 | unsigned int index; | ||
686 | |||
687 | /** | ||
688 | * Trait type, for example "reserve-pub" or "coin-priv". | ||
689 | */ | ||
690 | const char *trait_name; | ||
691 | |||
692 | /** | ||
693 | * Pointer to the piece of data to offer. | ||
694 | */ | ||
695 | const void *ptr; | ||
696 | }; | ||
697 | |||
698 | |||
699 | /** | ||
700 | * "end" trait. Because traits are offered into arrays, | ||
701 | * this type of trait is used to mark the end of such arrays; | ||
702 | * useful when iterating over those. | ||
703 | */ | ||
704 | struct GNUNET_TESTING_Trait | ||
705 | GNUNET_TESTING_trait_end (void); | ||
706 | |||
707 | |||
708 | /** | ||
709 | * Extract a trait. | ||
710 | * | ||
711 | * @param traits the array of all the traits. | ||
712 | * @param[out] ret where to store the result. | ||
713 | * @param trait type of the trait to extract. | ||
714 | * @param index index number of the trait to extract. | ||
715 | * @return #GNUNET_OK when the trait is found. | ||
716 | */ | ||
717 | int | ||
718 | GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, | ||
719 | const void **ret, | ||
720 | const char *trait, | ||
721 | unsigned int index); | ||
722 | |||
723 | |||
724 | /* ****** Specific traits supported by this component ******* */ | ||
725 | |||
726 | /** | ||
727 | * Obtain location where a command stores a pointer to a process. | ||
728 | * | ||
729 | * @param cmd command to extract trait from. | ||
730 | * @param index which process to pick if @a cmd | ||
731 | * has multiple on offer. | ||
732 | * @param[out] processp set to the address of the pointer to the | ||
733 | * process. | ||
734 | * @return #GNUNET_OK on success. | ||
735 | */ | ||
736 | int | ||
737 | GNUNET_TESTING_get_trait_process (const struct GNUNET_TESTING_Command *cmd, | ||
738 | unsigned int index, | ||
739 | struct GNUNET_OS_Process ***processp); | ||
740 | |||
741 | |||
742 | /** | ||
743 | * Offer location where a command stores a pointer to a process. | ||
744 | * | ||
745 | * @param index offered location index number, in case there are | ||
746 | * multiple on offer. | ||
747 | * @param processp process location to offer. | ||
748 | * @return the trait. | ||
749 | */ | ||
750 | struct GNUNET_TESTING_Trait | ||
751 | GNUNET_TESTING_make_trait_process (unsigned int index, | ||
752 | struct GNUNET_OS_Process **processp); | ||
753 | |||
754 | |||
755 | /** | ||
756 | * Offer number trait, 32-bit version. | ||
757 | * | ||
758 | * @param index the number's index number. | ||
759 | * @param n number to offer. | ||
760 | */ | ||
761 | struct GNUNET_TESTING_Trait | ||
762 | GNUNET_TESTING_make_trait_uint32 (unsigned int index, | ||
763 | const uint32_t *n); | ||
764 | |||
765 | |||
766 | /** | ||
767 | * Obtain a "number" value from @a cmd, 32-bit version. | ||
768 | * | ||
769 | * @param cmd command to extract the number from. | ||
770 | * @param index the number's index number. | ||
771 | * @param[out] n set to the number coming from @a cmd. | ||
772 | * @return #GNUNET_OK on success. | ||
773 | */ | ||
774 | int | ||
775 | GNUNET_TESTING_get_trait_uint32 (const struct GNUNET_TESTING_Command *cmd, | ||
776 | unsigned int index, | ||
777 | const uint32_t **n); | ||
778 | |||
779 | |||
780 | /** | ||
781 | * Offer number trait, 64-bit version. | ||
782 | * | ||
783 | * @param index the number's index number. | ||
784 | * @param n number to offer. | ||
785 | */ | ||
786 | struct GNUNET_TESTING_Trait | ||
787 | GNUNET_TESTING_make_trait_uint64 (unsigned int index, | ||
788 | const uint64_t *n); | ||
789 | |||
790 | |||
791 | /** | ||
792 | * Obtain a "number" value from @a cmd, 64-bit version. | ||
793 | * | ||
794 | * @param cmd command to extract the number from. | ||
795 | * @param index the number's index number. | ||
796 | * @param[out] n set to the number coming from @a cmd. | ||
797 | * @return #GNUNET_OK on success. | ||
798 | */ | ||
799 | int | ||
800 | GNUNET_TESTING_get_trait_uint64 (const struct GNUNET_TESTING_Command *cmd, | ||
801 | unsigned int index, | ||
802 | const uint64_t **n); | ||
803 | |||
804 | |||
805 | /** | ||
806 | * Offer number trait, 64-bit signed version. | ||
807 | * | ||
808 | * @param index the number's index number. | ||
809 | * @param n number to offer. | ||
810 | */ | ||
811 | struct GNUNET_TESTING_Trait | ||
812 | GNUNET_TESTING_make_trait_int64 (unsigned int index, | ||
813 | const int64_t *n); | ||
814 | |||
815 | |||
816 | /** | ||
817 | * Obtain a "number" value from @a cmd, 64-bit signed version. | ||
818 | * | ||
819 | * @param cmd command to extract the number from. | ||
820 | * @param index the number's index number. | ||
821 | * @param[out] n set to the number coming from @a cmd. | ||
822 | * @return #GNUNET_OK on success. | ||
823 | */ | ||
824 | int | ||
825 | GNUNET_TESTING_get_trait_int64 (const struct GNUNET_TESTING_Command *cmd, | ||
826 | unsigned int index, | ||
827 | const int64_t **n); | ||
828 | |||
829 | |||
830 | /** | ||
831 | * Offer a number. | ||
832 | * | ||
833 | * @param index the number's index number. | ||
834 | * @param n the number to offer. | ||
835 | * @return #GNUNET_OK on success. | ||
836 | */ | ||
837 | struct GNUNET_TESTING_Trait | ||
838 | GNUNET_TESTING_make_trait_uint (unsigned int index, | ||
839 | const unsigned int *i); | ||
840 | |||
841 | |||
842 | /** | ||
843 | * Obtain a number from @a cmd. | ||
844 | * | ||
845 | * @param cmd command to extract the number from. | ||
846 | * @param index the number's index number. | ||
847 | * @param[out] n set to the number coming from @a cmd. | ||
848 | * @return #GNUNET_OK on success. | ||
849 | */ | ||
850 | int | ||
851 | GNUNET_TESTING_get_trait_uint (const struct GNUNET_TESTING_Command *cmd, | ||
852 | unsigned int index, | ||
853 | const unsigned int **n); | ||
854 | |||
855 | /** | ||
856 | * Obtain a string from @a cmd. | ||
857 | * | ||
858 | * @param cmd command to extract the subject from. | ||
859 | * @param index index number associated with the transfer | ||
860 | * subject to offer. | ||
861 | * @param[out] s where to write the offered | ||
862 | * string. | ||
863 | * @return #GNUNET_OK on success. | ||
864 | */ | ||
865 | int | ||
866 | GNUNET_TESTING_get_trait_string ( | ||
867 | const struct GNUNET_TESTING_Command *cmd, | ||
868 | unsigned int index, | ||
869 | const char **s); | ||
870 | |||
871 | |||
872 | /** | ||
873 | * Offer string subject. | ||
874 | * | ||
875 | * @param index index number associated with the transfer | ||
876 | * subject being offered. | ||
877 | * @param s string to offer. | ||
878 | * @return the trait. | ||
879 | */ | ||
880 | struct GNUNET_TESTING_Trait | ||
881 | GNUNET_TESTING_make_trait_string (unsigned int index, | ||
882 | const char *s); | ||
883 | |||
884 | /** | ||
885 | * Offer a command in a trait. | ||
886 | * | ||
887 | * @param index always zero. Commands offering this | ||
888 | * kind of traits do not need this index. For | ||
889 | * example, a "meta" CMD returns always the | ||
890 | * CMD currently being executed. | ||
891 | * @param cmd wire details to offer. | ||
892 | * | ||
893 | * @return the trait. | ||
894 | */ | ||
895 | struct GNUNET_TESTING_Trait | ||
896 | GNUNET_TESTING_make_trait_cmd (unsigned int index, | ||
897 | const struct GNUNET_TESTING_Command *cmd); | ||
898 | |||
899 | |||
900 | /** | ||
901 | * Obtain a command from @a cmd. | ||
902 | * | ||
903 | * @param cmd command to extract the command from. | ||
904 | * @param index always zero. Commands offering this | ||
905 | * kind of traits do not need this index. For | ||
906 | * example, a "meta" CMD returns always the | ||
907 | * CMD currently being executed. | ||
908 | * @param[out] _cmd where to write the wire details. | ||
909 | * @return #GNUNET_OK on success. | ||
910 | */ | ||
911 | int | ||
912 | GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, | ||
913 | unsigned int index, | ||
914 | struct GNUNET_TESTING_Command **_cmd); | ||
915 | |||
916 | |||
917 | /** | ||
918 | * Obtain a uuid from @a cmd. | ||
919 | * | ||
920 | * @param cmd command to extract the uuid from. | ||
921 | * @param index which amount to pick if @a cmd has multiple | ||
922 | * on offer | ||
923 | * @param[out] uuid where to write the uuid. | ||
924 | * @return #GNUNET_OK on success. | ||
925 | */ | ||
926 | int | ||
927 | GNUNET_TESTING_get_trait_uuid (const struct GNUNET_TESTING_Command *cmd, | ||
928 | unsigned int index, | ||
929 | struct GNUNET_Uuid **uuid); | ||
930 | |||
931 | |||
932 | /** | ||
933 | * Offer a uuid in a trait. | ||
934 | * | ||
935 | * @param index which uuid to offer, in case there are | ||
936 | * multiple available. | ||
937 | * @param uuid the uuid to offer. | ||
938 | * | ||
939 | * @return the trait. | ||
940 | */ | ||
941 | struct GNUNET_TESTING_Trait | ||
942 | GNUNET_TESTING_make_trait_uuid (unsigned int index, | ||
943 | const struct GNUNET_Uuid *uuid); | ||
944 | |||
945 | |||
946 | /** | ||
947 | * Obtain a absolute time from @a cmd. | ||
948 | * | ||
949 | * @param cmd command to extract trait from | ||
950 | * @param index which time stamp to pick if | ||
951 | * @a cmd has multiple on offer. | ||
952 | * @param[out] time set to the wanted WTID. | ||
953 | * @return #GNUNET_OK on success | ||
954 | */ | ||
955 | int | ||
956 | GNUNET_TESTING_get_trait_absolute_time ( | ||
957 | const struct GNUNET_TESTING_Command *cmd, | ||
958 | unsigned int index, | ||
959 | const struct GNUNET_TIME_Absolute **time); | ||
960 | |||
961 | |||
962 | /** | ||
963 | * Offer a absolute time. | ||
964 | * | ||
965 | * @param index associate the object with this index | ||
966 | * @param time which object should be returned | ||
967 | * @return the trait. | ||
968 | */ | ||
969 | struct GNUNET_TESTING_Trait | ||
970 | GNUNET_TESTING_make_trait_absolute_time ( | ||
971 | unsigned int index, | ||
972 | const struct GNUNET_TIME_Absolute *time); | ||
973 | |||
974 | |||
975 | /** | ||
976 | * Obtain a relative time from @a cmd. | ||
977 | * | ||
978 | * @param cmd command to extract trait from | ||
979 | * @param index which time to pick if | ||
980 | * @a cmd has multiple on offer. | ||
981 | * @param[out] time set to the wanted WTID. | ||
982 | * @return #GNUNET_OK on success | ||
983 | */ | ||
984 | int | ||
985 | GNUNET_TESTING_get_trait_relative_time ( | ||
986 | const struct GNUNET_TESTING_Command *cmd, | ||
987 | unsigned int index, | ||
988 | const struct GNUNET_TIME_Relative **time); | ||
989 | |||
990 | |||
991 | /** | ||
992 | * Offer a relative time. | ||
993 | * | ||
994 | * @param index associate the object with this index | ||
995 | * @param time which object should be returned | ||
996 | * @return the trait. | ||
997 | */ | ||
998 | struct GNUNET_TESTING_Trait | ||
999 | GNUNET_TESTING_make_trait_relative_time ( | ||
1000 | unsigned int index, | ||
1001 | const struct GNUNET_TIME_Relative *time); | ||
1002 | |||
1003 | |||
1004 | /** | ||
1005 | * Create command. | ||
1006 | * | ||
1007 | * @param label name for command. | ||
1008 | * @param now when the command was started. | ||
1009 | * @return command. | ||
1010 | */ | ||
1011 | struct GNUNET_TESTING_Command | ||
1012 | GNUNET_TESTING_cmd_hello_world_birth (const char *label, | ||
1013 | struct GNUNET_TIME_Absolute *now); | ||
1014 | |||
1015 | /** | ||
1016 | * Create command. | ||
1017 | * | ||
1018 | * @param label name for command. | ||
1019 | * @param message initial message. | ||
1020 | * @return command. | ||
1021 | */ | ||
1022 | struct GNUNET_TESTING_Command | ||
1023 | GNUNET_TESTING_cmd_hello_world (const char *label, | ||
1024 | const char *birthLabel, | ||
1025 | char *message); | ||
1026 | |||
1027 | /** | ||
1028 | * Offer data from trait | ||
1029 | * | ||
1030 | * @param cmd command to extract the url from. | ||
1031 | * @param pt which url is to be picked, in case | ||
1032 | * multiple are offered. | ||
1033 | * @param[out] url where to write the url. | ||
1034 | * @return #GNUNET_OK on success. | ||
1035 | */ | ||
1036 | int | ||
1037 | GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd, | ||
1038 | char **what_am_i); | ||
1039 | |||
1040 | |||
1041 | int | ||
1042 | GNUNET_TESTING_get_trait_test_system (const struct | ||
1043 | GNUNET_TESTING_Command *cmd, | ||
1044 | struct GNUNET_TESTING_System **test_system); | ||
1045 | |||
1046 | |||
1047 | struct GNUNET_TESTING_Command | ||
1048 | GNUNET_TESTING_cmd_system_create (const char *label, | ||
1049 | const char *testdir); | ||
1050 | |||
1051 | |||
1052 | struct GNUNET_TESTING_Command | ||
1053 | GNUNET_TESTING_cmd_system_destroy (const char *label, | ||
1054 | const char *create_label); | ||
1055 | |||
1056 | |||
1057 | /** | ||
1058 | * Create command. | ||
1059 | * | ||
1060 | * @param label name for command. | ||
1061 | * @param local_m Number of local nodes in each namespace. | ||
1062 | * @param global_n The number of namespaces. | ||
1063 | * @return command. | ||
1064 | */ | ||
1065 | struct GNUNET_TESTING_Command | ||
1066 | GNUNET_TESTING_cmd_netjail_start (const char *label, | ||
1067 | char *local_m, | ||
1068 | char *global_n); | ||
1069 | |||
1070 | /** | ||
1071 | * Create command. | ||
1072 | * | ||
1073 | * @param label name for command. | ||
1074 | * @param topology_config Configuration file for the test topology. | ||
1075 | * @return command. | ||
1076 | */ | ||
1077 | struct GNUNET_TESTING_Command | ||
1078 | GNUNET_TESTING_cmd_netjail_start_v2 (const char *label, | ||
1079 | char *topology_config); | ||
1080 | |||
1081 | |||
1082 | /** | ||
1083 | * Create command. | ||
1084 | * | ||
1085 | * @param label name for command. | ||
1086 | * @param binaryname to exec. | ||
1087 | * @return command. | ||
1088 | */ | ||
1089 | struct GNUNET_TESTING_Command | ||
1090 | GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, | ||
1091 | char *local_m, | ||
1092 | char *global_n, | ||
1093 | char *plugin_name, | ||
1094 | unsigned int *rv); | ||
1095 | |||
1096 | |||
1097 | /** | ||
1098 | * Create command. | ||
1099 | * | ||
1100 | * @param label Name for the command. | ||
1101 | * @param topology_config Configuration file for the test topology. | ||
1102 | * @param rv Pointer to the return value of the test. | ||
1103 | * @return command. | ||
1104 | */ | ||
1105 | struct GNUNET_TESTING_Command | ||
1106 | GNUNET_TESTING_cmd_netjail_start_testing_system_v2 (const char *label, | ||
1107 | const char *topology_config, | ||
1108 | unsigned int *rv); | ||
1109 | |||
1110 | 83 | ||
1111 | /** | ||
1112 | * Create command. | ||
1113 | * | ||
1114 | * @param label name for command. | ||
1115 | * @param binaryname to stop. | ||
1116 | * @return command. | ||
1117 | */ | ||
1118 | struct GNUNET_TESTING_Command | ||
1119 | GNUNET_TESTING_cmd_netjail_stop (const char *label, | ||
1120 | char *local_m, | ||
1121 | char *global_n); | ||
1122 | 84 | ||
1123 | 85 | ||
1124 | /** | 86 | /* ****** Specific traits needed by this component ******* */ |
1125 | * Create command. | ||
1126 | * | ||
1127 | * @param label name for command. | ||
1128 | * @param topology_config Configuration file for the test topology. | ||
1129 | * @return command. | ||
1130 | */ | ||
1131 | struct GNUNET_TESTING_Command | ||
1132 | GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label, | ||
1133 | char *topology_config); | ||
1134 | 87 | ||
1135 | 88 | ||
1136 | struct GNUNET_TESTING_Command | ||
1137 | GNUNET_TESTING_cmd_stop_testing_system (const char *label, | ||
1138 | const char *helper_start_label, | ||
1139 | char *local_m, | ||
1140 | char *global_n); | ||
1141 | |||
1142 | /** | 89 | /** |
1143 | * Create command. | 90 | * Call #op on all simple traits. |
1144 | * | ||
1145 | * @param label name for command. | ||
1146 | * @param topology_config Configuration file for the test topology. | ||
1147 | * @return command. | ||
1148 | */ | 91 | */ |
1149 | struct GNUNET_TESTING_Command | 92 | #define GNUNET_TESTING_SIMPLE_TRAITS(op, prefix) \ |
1150 | GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label, | 93 | op (prefix, process, struct GNUNET_OS_Process *) |
1151 | const char *helper_start_label, | ||
1152 | const char *topology_config); | ||
1153 | |||
1154 | 94 | ||
1155 | int | ||
1156 | GNUNET_TESTING_get_trait_helper_handles (const struct | ||
1157 | GNUNET_TESTING_Command *cmd, | ||
1158 | struct GNUNET_HELPER_Handle ***helper); | ||
1159 | 95 | ||
96 | GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_TESTING) | ||
1160 | 97 | ||
1161 | /** | 98 | /** |
1162 | * Offer handles to testing cmd helper from trait | 99 | * Call #op on all indexed traits. |
1163 | * | ||
1164 | * @param cmd command to extract the message from. | ||
1165 | * @param pt pointer to message. | ||
1166 | * @return #GNUNET_OK on success. | ||
1167 | */ | 100 | */ |
1168 | int | 101 | #define GNUNET_TESTING_INDEXED_TRAITS(op, prefix) \ |
1169 | GNUNET_TESTING_get_trait_helper_handles_v2 (const struct | 102 | op (prefix, uint32, const uint32_t) \ |
1170 | GNUNET_TESTING_Command *cmd, | 103 | op (prefix, uint64, const uint64_t) \ |
1171 | struct GNUNET_HELPER_Handle *** | 104 | op (prefix, int64, const int64_t) \ |
1172 | helper); | 105 | op (prefix, uint, const unsigned int) \ |
1173 | 106 | op (prefix, string, const char) \ | |
107 | op (prefix, uuid, const struct GNUNET_Uuid) \ | ||
108 | op (prefix, time, const struct GNUNET_TIME_Absolute) \ | ||
109 | op (prefix, absolute_time, const struct GNUNET_TIME_Absolute) \ | ||
110 | op (prefix, relative_time, const struct GNUNET_TIME_Relative) | ||
1174 | 111 | ||
1175 | struct GNUNET_TESTING_Command | 112 | GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT, GNUNET_TESTING) |
1176 | GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label, | ||
1177 | unsigned int * | ||
1178 | all_peers_started); | ||
1179 | 113 | ||
1180 | 114 | ||
1181 | struct GNUNET_TESTING_Command | ||
1182 | GNUNET_TESTING_cmd_block_until_external_trigger (const char *label, | ||
1183 | unsigned int * | ||
1184 | stop_blocking); | ||
1185 | |||
1186 | struct GNUNET_TESTING_Command | ||
1187 | GNUNET_TESTING_cmd_send_peer_ready (const char *label, | ||
1188 | TESTING_CMD_HELPER_write_cb write_message); | ||
1189 | |||
1190 | struct GNUNET_TESTING_Command | ||
1191 | GNUNET_TESTING_cmd_local_test_finished (const char *label, | ||
1192 | TESTING_CMD_HELPER_write_cb | ||
1193 | write_message); | ||
1194 | #endif | 115 | #endif |