diff options
Diffstat (limited to 'src/include/gnunet_testing_ng_lib.h')
-rw-r--r-- | src/include/gnunet_testing_ng_lib.h | 881 |
1 files changed, 38 insertions, 843 deletions
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index c9f5e3e00..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,401 +27,15 @@ | |||
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 | /* ******************* Generic interpreter logic ************ */ | ||
51 | |||
52 | /** | ||
53 | * Global state of the interpreter, used by a command | ||
54 | * to access information about other commands. | ||
55 | */ | ||
56 | struct GNUNET_TESTING_Interpreter; | ||
57 | |||
58 | /** | ||
59 | * State each asynchronous command must have in its closure. | ||
60 | */ | ||
61 | struct GNUNET_TESTING_AsyncContext | ||
62 | { | ||
63 | |||
64 | /** | ||
65 | * Interpreter we are part of. | ||
66 | */ | ||
67 | struct GNUNET_TESTING_Interpreter *is; | ||
68 | |||
69 | /** | ||
70 | * Function to call when done. | ||
71 | */ | ||
72 | GNUNET_SCHEDULER_TaskCallback cont; | ||
73 | |||
74 | /** | ||
75 | * Closure for @e cont. | ||
76 | */ | ||
77 | void *cont_cls; | ||
78 | |||
79 | /** | ||
80 | * Indication if the command finished (#GNUNET_OK). | ||
81 | * #GNUNET_NO if it did not finish, | ||
82 | * #GNUNET_SYSERR if it failed. | ||
83 | */ | ||
84 | enum GNUNET_GenericReturnValue finished; | ||
85 | }; | ||
86 | |||
87 | |||
88 | /** | ||
89 | * A command to be run by the interpreter. | ||
90 | */ | ||
91 | struct GNUNET_TESTING_Command | ||
92 | { | ||
93 | |||
94 | /** | ||
95 | * Closure for all commands with command-specific context information. | ||
96 | */ | ||
97 | void *cls; | ||
98 | |||
99 | /** | ||
100 | * Label for the command. | ||
101 | */ | ||
102 | const char *label; | ||
103 | |||
104 | /** | ||
105 | * Runs the command. Note that upon return, the interpreter | ||
106 | * will not automatically run the next command, as the command | ||
107 | * may continue asynchronously in other scheduler tasks. Thus, | ||
108 | * the command must ensure to eventually call | ||
109 | * #GNUNET_TESTING_interpreter_next() or | ||
110 | * #GNUNET_TESTING_interpreter_fail(). | ||
111 | * | ||
112 | * If this function creates some asynchronous activity, it should | ||
113 | * initialize @e finish to a function that can be used to wait for | ||
114 | * the asynchronous activity to terminate. | ||
115 | * | ||
116 | * @param cls closure | ||
117 | * @param is interpreter state | ||
118 | */ | ||
119 | void | ||
120 | (*run)(void *cls, | ||
121 | struct GNUNET_TESTING_Interpreter *is); | ||
122 | |||
123 | /** | ||
124 | * Pointer to the asynchronous context in the command's | ||
125 | * closure. Used by the | ||
126 | * #GNUNET_TESTING_async_finish() and | ||
127 | * #GNUNET_TESTING_async_fail() functions. | ||
128 | * | ||
129 | * Must be NULL if a command is synchronous. | ||
130 | */ | ||
131 | struct GNUNET_TESTING_AsyncContext *ac; | ||
132 | |||
133 | /** | ||
134 | * Clean up after the command. Run during forced termination | ||
135 | * (CTRL-C) or test failure or test success. | ||
136 | * | ||
137 | * @param cls closure | ||
138 | */ | ||
139 | void | ||
140 | (*cleanup)(void *cls); | ||
141 | |||
142 | /** | ||
143 | * Extract information from a command that is useful for other | ||
144 | * commands. Can be NULL if a command has no traits. | ||
145 | * | ||
146 | * @param cls closure | ||
147 | * @param[out] ret result (could be anything) | ||
148 | * @param trait name of the trait | ||
149 | * @param index index number of the object to extract. | ||
150 | * @return #GNUNET_OK on success, | ||
151 | * #GNUNET_NO if no trait was found | ||
152 | */ | ||
153 | enum GNUNET_GenericReturnValue | ||
154 | (*traits)(void *cls, | ||
155 | const void **ret, | ||
156 | const char *trait, | ||
157 | unsigned int index); | ||
158 | |||
159 | /** | ||
160 | * When did the execution of this command start? | ||
161 | */ | ||
162 | struct GNUNET_TIME_Absolute start_time; | ||
163 | |||
164 | /** | ||
165 | * When did the execution of this command finish? | ||
166 | */ | ||
167 | struct GNUNET_TIME_Absolute finish_time; | ||
168 | |||
169 | /** | ||
170 | * When did we start the last run of this command? Delta to @e finish_time | ||
171 | * gives the latency for the last successful run. Useful in case @e | ||
172 | * num_tries was positive and the command was run multiple times. In that | ||
173 | * case, the @e start_time gives the time when we first tried to run the | ||
174 | * command, so the difference between @e start_time and @e finish_time would | ||
175 | * be the time all of the @e num_tries took, while the delta to @e | ||
176 | * last_req_time is the time the last (successful) execution took. | ||
177 | */ | ||
178 | struct GNUNET_TIME_Absolute last_req_time; | ||
179 | |||
180 | /** | ||
181 | * In case @e asynchronous_finish is true, how long should we wait for this | ||
182 | * command to complete? If @e finish did not complete after this amount of | ||
183 | * time, the interpreter will fail. Should be set generously to ensure | ||
184 | * tests do not fail on slow systems. | ||
185 | */ | ||
186 | struct GNUNET_TIME_Relative default_timeout; | ||
187 | |||
188 | /** | ||
189 | * How often did we try to execute this command? (In case it is a request | ||
190 | * that is repated.) Note that a command must have some built-in retry | ||
191 | * mechanism for this value to be useful. | ||
192 | */ | ||
193 | unsigned int num_tries; | ||
194 | |||
195 | /** | ||
196 | * If "true", the interpreter should not immediately call | ||
197 | * @e finish, even if @e finish is non-NULL. Otherwise, | ||
198 | * #TALER_TESTING_cmd_finish() must be used | ||
199 | * to ensure that a command actually completed. | ||
200 | */ | ||
201 | bool asynchronous_finish; | ||
202 | |||
203 | }; | ||
204 | |||
205 | |||
206 | /** | ||
207 | * Lookup command by label. | ||
208 | * Only future commands are looked up. | ||
209 | * | ||
210 | * @param is interpreter to lookup command in | ||
211 | * @param label label of the command to lookup. | ||
212 | * @return the command, if it is found, or NULL. | ||
213 | */ | ||
214 | const struct GNUNET_TESTING_Command * | ||
215 | GNUNET_TESTING_interpreter_lookup_future_command ( | ||
216 | struct GNUNET_TESTING_Interpreter *is, | ||
217 | const char *label); | ||
218 | |||
219 | |||
220 | /** | ||
221 | * Lookup command by label. | ||
222 | * | ||
223 | * @param is interpreter to lookup command in | ||
224 | * @param label label of the command to lookup. | ||
225 | * @return the command, if it is found, or NULL. | ||
226 | */ | ||
227 | const struct GNUNET_TESTING_Command * | ||
228 | GNUNET_TESTING_interpreter_lookup_command ( | ||
229 | struct GNUNET_TESTING_Interpreter *is, | ||
230 | const char *label); | ||
231 | |||
232 | |||
233 | /** | ||
234 | * Lookup command by label. | ||
235 | * All commands, first into the past, then into the furture are looked up. | ||
236 | * | ||
237 | * @param is interpreter to lookup command in | ||
238 | * @param label label of the command to lookup. | ||
239 | * @return the command, if it is found, or NULL. | ||
240 | */ | ||
241 | const struct GNUNET_TESTING_Command * | ||
242 | GNUNET_TESTING_interpreter_lookup_command_all ( | ||
243 | struct GNUNET_TESTING_Interpreter *is, | ||
244 | const char *label); | ||
245 | |||
246 | |||
247 | /** | ||
248 | * Obtain label of the command being now run. | ||
249 | * | ||
250 | * @param is interpreter state. | ||
251 | * @return the label. | ||
252 | */ | ||
253 | const char * | ||
254 | GNUNET_TESTING_interpreter_get_current_label ( | ||
255 | struct GNUNET_TESTING_Interpreter *is); | ||
256 | |||
257 | |||
258 | /** | ||
259 | * Current command failed, clean up and fail the test case. | ||
260 | * | ||
261 | * @param is interpreter state. | ||
262 | */ | ||
263 | void | ||
264 | GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is); | ||
265 | |||
266 | |||
267 | /** | ||
268 | * The asynchronous command of @a ac has failed. | ||
269 | * | ||
270 | * @param ac command-specific context | ||
271 | */ | ||
272 | void | ||
273 | GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac); | ||
274 | |||
275 | |||
276 | /** | ||
277 | * The asynchronous command of @a ac has finished. | ||
278 | * | ||
279 | * @param ac command-specific context | ||
280 | */ | ||
281 | void | ||
282 | GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac); | ||
283 | |||
284 | |||
285 | /** | ||
286 | * Create command array terminator. | ||
287 | * | ||
288 | * @return a end-command. | ||
289 | */ | ||
290 | struct GNUNET_TESTING_Command | ||
291 | GNUNET_TESTING_cmd_end (void); | ||
292 | |||
293 | |||
294 | /** | ||
295 | * Turn asynchronous command into non blocking command by setting asynchronous_finish to true. | ||
296 | * | ||
297 | * @param cmd command to make synchronous. | ||
298 | * @return a finish-command. | ||
299 | */ | ||
300 | struct GNUNET_TESTING_Command | ||
301 | GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd); | ||
302 | |||
303 | |||
304 | /** | ||
305 | * Create (synchronous) command that waits for another command to finish. | ||
306 | * If @a cmd_ref did not finish after @a timeout, this command will fail | ||
307 | * the test case. | ||
308 | * | ||
309 | * @param finish_label label for this command | ||
310 | * @param cmd_ref reference to a previous command which we should | ||
311 | * wait for (call `finish()` on) | ||
312 | * @param timeout how long to wait at most for @a cmd_ref to finish | ||
313 | * @return a finish-command. | ||
314 | */ | ||
315 | const struct GNUNET_TESTING_Command | ||
316 | GNUNET_TESTING_cmd_finish (const char *finish_label, | ||
317 | const char *cmd_ref, | ||
318 | struct GNUNET_TIME_Relative timeout); | ||
319 | |||
320 | |||
321 | /** | ||
322 | * Make the instruction pointer point to @a target_label | ||
323 | * only if @a counter is greater than zero. | ||
324 | * | ||
325 | * @param label command label | ||
326 | * @param target_label label of the new instruction pointer's destination after the jump; | ||
327 | * must be before the current instruction | ||
328 | * @param counter counts how many times the rewinding is to happen. | ||
329 | */ | ||
330 | struct GNUNET_TESTING_Command | ||
331 | GNUNET_TESTING_cmd_rewind_ip (const char *label, | ||
332 | const char *target_label, | ||
333 | unsigned int counter); | ||
334 | |||
335 | |||
336 | /** | ||
337 | * Function called with the final result of the test. | ||
338 | * | ||
339 | * @param cls closure | ||
340 | * @param rv #GNUNET_OK if the test passed | ||
341 | */ | ||
342 | typedef void | ||
343 | (*GNUNET_TESTING_ResultCallback)(void *cls, | ||
344 | enum GNUNET_GenericReturnValue rv); | ||
345 | |||
346 | |||
347 | /** | ||
348 | * Run the testsuite. Note, CMDs are copied into | ||
349 | * the interpreter state because they are _usually_ | ||
350 | * defined into the "run" method that returns after | ||
351 | * having scheduled the test interpreter. | ||
352 | * | ||
353 | * @param commands the list of command to execute | ||
354 | * @param timeout how long to wait for each command to execute | ||
355 | * @param rc function to call with the final result | ||
356 | * @param rc_cls closure for @a rc | ||
357 | */ | ||
358 | void | ||
359 | GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands, | ||
360 | struct GNUNET_TIME_Relative timeout, | ||
361 | GNUNET_TESTING_ResultCallback rc, | ||
362 | void *rc_cls); | ||
363 | |||
364 | 30 | ||
365 | /** | 31 | #include "gnunet_util_lib.h" |
366 | * Start a GNUnet scheduler event loop and | ||
367 | * run the testsuite. Return 0 upon success. | ||
368 | * Expected to be called directly from main(). | ||
369 | * | ||
370 | * @param commands the list of command to execute | ||
371 | * @param timeout how long to wait for each command to execute | ||
372 | * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure | ||
373 | */ | ||
374 | int | ||
375 | GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands, | ||
376 | struct GNUNET_TIME_Relative timeout); | ||
377 | |||
378 | |||
379 | /** | ||
380 | * Look for substring in a programs' name. | ||
381 | * | ||
382 | * @param prog program's name to look into | ||
383 | * @param marker chunk to find in @a prog | ||
384 | * // FIXME: this does not belong here! => libgnunetutil, maybe? | ||
385 | * // FIXME: return bool? document return value! | ||
386 | */ | ||
387 | int | ||
388 | GNUNET_TESTING_has_in_name (const char *prog, | ||
389 | const char *marker); | ||
390 | |||
391 | |||
392 | /* ************** Specific interpreter commands ************ */ | ||
393 | |||
394 | |||
395 | /** | ||
396 | * Returns the actual running command. | ||
397 | * | ||
398 | * @param is Global state of the interpreter, used by a command | ||
399 | * to access information about other commands. | ||
400 | * @return The actual running command. | ||
401 | */ | ||
402 | struct GNUNET_TESTING_Command * | ||
403 | GNUNET_TESTING_interpreter_get_current_command ( | ||
404 | struct GNUNET_TESTING_Interpreter *is); | ||
405 | |||
406 | |||
407 | /** | ||
408 | * Check if the command is running. | ||
409 | * | ||
410 | * @param cmd The command to check. | ||
411 | * @return GNUNET_NO if the command is not running, GNUNET_YES if it is running. | ||
412 | */ | ||
413 | enum GNUNET_GenericReturnValue | ||
414 | GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command); | ||
415 | 32 | ||
33 | /* FIXME: legacy test header, to be removed!! */ | ||
34 | #include "gnunet_testing_lib.h" | ||
416 | 35 | ||
417 | /** | 36 | #include "gnunet_testing_plugin.h" |
418 | * Check if a command is finished. | 37 | #include "gnunet_testing_loop_lib.h" |
419 | * | 38 | #include "gnunet_testing_netjail_lib.h" |
420 | * @param cmd The command to check. | ||
421 | * @return GNUNET_NO if the command is not finished, GNUNET_YES if it is finished. | ||
422 | */ | ||
423 | enum GNUNET_GenericReturnValue | ||
424 | GNUNET_TESTING_finished (struct GNUNET_TESTING_Command *command); | ||
425 | 39 | ||
426 | 40 | ||
427 | /** | 41 | /** |
@@ -429,14 +43,12 @@ GNUNET_TESTING_finished (struct GNUNET_TESTING_Command *command); | |||
429 | * | 43 | * |
430 | * @param label command label. | 44 | * @param label command label. |
431 | * @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 |
432 | * @param process_index index of the process trait at @a process_label // FIXME: enum? needed? | ||
433 | * @param signal signal to send to @a process. | 46 | * @param signal signal to send to @a process. |
434 | * @return the command. | 47 | * @return the command. |
435 | */ | 48 | */ |
436 | struct GNUNET_TESTING_Command | 49 | struct GNUNET_TESTING_Command |
437 | GNUNET_TESTING_cmd_signal (const char *label, | 50 | GNUNET_TESTING_cmd_signal (const char *label, |
438 | const char *process_label, | 51 | const char *process_label, |
439 | unsigned int process_index, | ||
440 | int signal); | 52 | int signal); |
441 | 53 | ||
442 | 54 | ||
@@ -453,468 +65,51 @@ GNUNET_TESTING_cmd_sleep (const char *label, | |||
453 | 65 | ||
454 | 66 | ||
455 | /** | 67 | /** |
456 | * Create a "batch" command. Such command takes a end_CMD-terminated array of | 68 | * Command to execute a script synchronously. |
457 | * CMDs and executed them. Once it hits the end CMD, it passes the control to | ||
458 | * the next top-level CMD, regardless of it being another batch or ordinary | ||
459 | * CMD. | ||
460 | * | 69 | * |
461 | * @param label the command label. | 70 | * FIXME: is this accurate? How is this limited to BASH scripts or even scripts? |
462 | * @param batch array of CMDs to execute. | ||
463 | * @return the command. | ||
464 | */ | ||
465 | struct GNUNET_TESTING_Command | ||
466 | GNUNET_TESTING_cmd_batch (const char *label, | ||
467 | struct GNUNET_TESTING_Command *batch); | ||
468 | |||
469 | |||
470 | /** | ||
471 | * Performance counter. | ||
472 | * // FIXME: this might not belong here! | ||
473 | */ | ||
474 | struct GNUNET_TESTING_Timer | ||
475 | { | ||
476 | /** | ||
477 | * For which type of commands. | ||
478 | */ | ||
479 | const char *prefix; | ||
480 | |||
481 | /** | ||
482 | * Total time spend in all commands of this type. | ||
483 | */ | ||
484 | struct GNUNET_TIME_Relative total_duration; | ||
485 | |||
486 | /** | ||
487 | * Total time spend waiting for the *successful* exeuction | ||
488 | * in all commands of this type. | ||
489 | */ | ||
490 | struct GNUNET_TIME_Relative success_latency; | ||
491 | |||
492 | /** | ||
493 | * Number of commands summed up. | ||
494 | */ | ||
495 | unsigned int num_commands; | ||
496 | |||
497 | /** | ||
498 | * Number of retries summed up. | ||
499 | */ | ||
500 | unsigned int num_retries; | ||
501 | }; | ||
502 | |||
503 | |||
504 | /** | ||
505 | * Getting the topology from file. | ||
506 | * | ||
507 | * @param filename The name of the topology file. | ||
508 | * @return The GNUNET_TESTING_NetjailTopology | ||
509 | */ | ||
510 | struct GNUNET_TESTING_NetjailTopology * | ||
511 | GNUNET_TESTING_get_topo_from_file (const char *filename); | ||
512 | |||
513 | |||
514 | /** | ||
515 | * Parse the topology data. | ||
516 | * | ||
517 | * @param data The topology data. | ||
518 | * @return The GNUNET_TESTING_NetjailTopology | ||
519 | */ | ||
520 | struct GNUNET_TESTING_NetjailTopology * | ||
521 | GNUNET_TESTING_get_topo_from_string (char *data); | ||
522 | |||
523 | |||
524 | /** | ||
525 | * Get the connections to other nodes for a specific node. | ||
526 | * | ||
527 | * @param num The specific node we want the connections for. | ||
528 | * @param topology The topology we get the connections from. | ||
529 | * @return The connections of the node. | ||
530 | */ | ||
531 | struct GNUNET_TESTING_NodeConnection * | ||
532 | GNUNET_TESTING_get_connections (unsigned int num, struct | ||
533 | GNUNET_TESTING_NetjailTopology *topology); | ||
534 | |||
535 | |||
536 | /** | ||
537 | * Get the address for a specific communicator from a connection. | ||
538 | * | ||
539 | * @param connection The connection we like to have the address from. | ||
540 | * @param prefix The communicator protocol prefix. | ||
541 | * @return The address of the communicator. | ||
542 | */ | ||
543 | char * | ||
544 | GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection, | ||
545 | char *prefix); | ||
546 | |||
547 | |||
548 | /** | ||
549 | * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology. | ||
550 | * | ||
551 | * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated. | ||
552 | */ | ||
553 | void | ||
554 | GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology); | ||
555 | |||
556 | |||
557 | /** | ||
558 | * Calculate the unique id identifying a node from a given connction. | ||
559 | * | ||
560 | * @param node_connection The connection we calculate the id from. | ||
561 | * @param topology The topology we get all needed information from. | ||
562 | * @return The unique id of the node from the connection. | ||
563 | */ | ||
564 | unsigned int | ||
565 | GNUNET_TESTING_calculate_num (struct | ||
566 | GNUNET_TESTING_NodeConnection *node_connection, | ||
567 | struct GNUNET_TESTING_NetjailTopology *topology); | ||
568 | |||
569 | |||
570 | /** | ||
571 | * Retrieve the public key from the test system with the unique node id. | ||
572 | * | ||
573 | * @param num The unique node id. | ||
574 | * @param tl_system The test system. | ||
575 | * @return The peer identity wrapping the public key. | ||
576 | */ | ||
577 | struct GNUNET_PeerIdentity * | ||
578 | GNUNET_TESTING_get_pub_key (unsigned int num, struct | ||
579 | GNUNET_TESTING_System *tl_system); | ||
580 | |||
581 | |||
582 | /** | ||
583 | * Obtain performance data from the interpreter. | ||
584 | * | ||
585 | * @param timers what commands (by label) to obtain runtimes for | ||
586 | * @return the command | ||
587 | */ | ||
588 | struct GNUNET_TESTING_Command | ||
589 | GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers); | ||
590 | |||
591 | |||
592 | /* *** Generic trait logic for implementing traits ********* */ | ||
593 | |||
594 | /** | ||
595 | * A trait. | ||
596 | */ | ||
597 | struct GNUNET_TESTING_Trait | ||
598 | { | ||
599 | /** | ||
600 | * Index number associated with the trait. This gives the | ||
601 | * possibility to have _multiple_ traits on offer under the | ||
602 | * same name. | ||
603 | */ | ||
604 | unsigned int index; | ||
605 | |||
606 | /** | ||
607 | * Trait type, for example "reserve-pub" or "coin-priv". | ||
608 | */ | ||
609 | const char *trait_name; | ||
610 | |||
611 | /** | ||
612 | * Pointer to the piece of data to offer. | ||
613 | */ | ||
614 | const void *ptr; | ||
615 | }; | ||
616 | |||
617 | |||
618 | /** | ||
619 | * "end" trait. Because traits are offered into arrays, | ||
620 | * this type of trait is used to mark the end of such arrays; | ||
621 | * useful when iterating over those. | ||
622 | */ | ||
623 | struct GNUNET_TESTING_Trait | ||
624 | GNUNET_TESTING_trait_end (void); | ||
625 | |||
626 | |||
627 | /** | ||
628 | * Extract a trait. | ||
629 | * | ||
630 | * @param traits the array of all the traits. | ||
631 | * @param[out] ret where to store the result. | ||
632 | * @param trait type of the trait to extract. | ||
633 | * @param index index number of the trait to extract. | ||
634 | * @return #GNUNET_OK when the trait is found. | ||
635 | */ | ||
636 | enum GNUNET_GenericReturnValue | ||
637 | GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, | ||
638 | const void **ret, | ||
639 | const char *trait, | ||
640 | unsigned int index); | ||
641 | |||
642 | |||
643 | /* ****** Specific traits supported by this component ******* */ | ||
644 | |||
645 | /** | ||
646 | * Obtain location where a command stores a pointer to a process. | ||
647 | * | ||
648 | * @param cmd command to extract trait from. | ||
649 | * @param index which process to pick if @a cmd | ||
650 | * has multiple on offer. -- FIXME: remove? | ||
651 | * @param[out] processp set to the address of the pointer to the | ||
652 | * process. | ||
653 | * @return #GNUNET_OK on success. | ||
654 | */ | ||
655 | enum GNUNET_GenericReturnValue | ||
656 | GNUNET_TESTING_get_trait_process (const struct GNUNET_TESTING_Command *cmd, | ||
657 | unsigned int index, | ||
658 | struct GNUNET_OS_Process ***processp); | ||
659 | |||
660 | |||
661 | /** | ||
662 | * Offer location where a command stores a pointer to a process. | ||
663 | * | ||
664 | * @param index offered location index number, in case there are | ||
665 | * multiple on offer. // FIXME: remove? | ||
666 | * @param processp process location to offer. | ||
667 | * @return the trait. | ||
668 | */ | ||
669 | struct GNUNET_TESTING_Trait | ||
670 | GNUNET_TESTING_make_trait_process (unsigned int index, | ||
671 | struct GNUNET_OS_Process **processp); | ||
672 | |||
673 | |||
674 | /** | ||
675 | * Offer number trait, 32-bit version. | ||
676 | * | 71 | * |
677 | * @param index the number's index number. // FIXME: introduce enum? | 72 | * @param label Label of the command. |
678 | * @param n number to offer. | 73 | * @param script The name of the script. |
679 | */ | 74 | * @param script_argv The arguments of the script. |
680 | struct GNUNET_TESTING_Trait | 75 | */ |
681 | GNUNET_TESTING_make_trait_uint32 (unsigned int index, | 76 | const struct GNUNET_TESTING_Command |
682 | const uint32_t *n); | 77 | GNUNET_TESTING_cmd_exec_bash_script (const char *label, |
683 | 78 | const char *script, | |
684 | 79 | char *const script_argv[], | |
685 | /** | 80 | // FIXME: wtf are these two args here for!? |
686 | * Obtain a "number" value from @a cmd, 32-bit version. | 81 | int argc, |
687 | * | 82 | GNUNET_ChildCompletedCallback cb); |
688 | * @param cmd command to extract the number from. | ||
689 | * @param index the number's index number. // FIXME: introduce enum? | ||
690 | * @param[out] n set to the number coming from @a cmd. | ||
691 | * @return #GNUNET_OK on success. | ||
692 | */ | ||
693 | enum GNUNET_GenericReturnValue | ||
694 | GNUNET_TESTING_get_trait_uint32 (const struct GNUNET_TESTING_Command *cmd, | ||
695 | unsigned int index, | ||
696 | const uint32_t **n); | ||
697 | |||
698 | |||
699 | /** | ||
700 | * Offer number trait, 64-bit version. | ||
701 | * | ||
702 | * @param index the number's index number. // FIXME: introduce enum? | ||
703 | * @param n number to offer. | ||
704 | */ | ||
705 | struct GNUNET_TESTING_Trait | ||
706 | GNUNET_TESTING_make_trait_uint64 (unsigned int index, | ||
707 | const uint64_t *n); | ||
708 | |||
709 | |||
710 | /** | ||
711 | * Obtain a "number" value from @a cmd, 64-bit version. | ||
712 | * | ||
713 | * @param cmd command to extract the number from. | ||
714 | * @param index the number's index number. // FIXME: introduce enum? | ||
715 | * @param[out] n set to the number coming from @a cmd. | ||
716 | * @return #GNUNET_OK on success. | ||
717 | */ | ||
718 | enum GNUNET_GenericReturnValue | ||
719 | GNUNET_TESTING_get_trait_uint64 (const struct GNUNET_TESTING_Command *cmd, | ||
720 | unsigned int index, | ||
721 | const uint64_t **n); | ||
722 | |||
723 | |||
724 | /** | ||
725 | * Offer number trait, 64-bit signed version. | ||
726 | * | ||
727 | * @param index the number's index number. // FIXME: introduce enum? | ||
728 | * @param n number to offer. | ||
729 | */ | ||
730 | struct GNUNET_TESTING_Trait | ||
731 | GNUNET_TESTING_make_trait_int64 (unsigned int index, | ||
732 | const int64_t *n); | ||
733 | |||
734 | |||
735 | /** | ||
736 | * Obtain a "number" value from @a cmd, 64-bit signed version. | ||
737 | * | ||
738 | * @param cmd command to extract the number from. | ||
739 | * @param index the number's index number. // FIXME: introduce enum? | ||
740 | * @param[out] n set to the number coming from @a cmd. | ||
741 | * @return #GNUNET_OK on success. | ||
742 | */ | ||
743 | enum GNUNET_GenericReturnValue | ||
744 | GNUNET_TESTING_get_trait_int64 (const struct GNUNET_TESTING_Command *cmd, | ||
745 | unsigned int index, | ||
746 | const int64_t **n); | ||
747 | |||
748 | |||
749 | /** | ||
750 | * Offer a number. | ||
751 | * | ||
752 | * @param index the number's index number. | ||
753 | * @param n the number to offer. // FIXME: introduce enum? | ||
754 | * @return #GNUNET_OK on success. | ||
755 | */ | ||
756 | struct GNUNET_TESTING_Trait | ||
757 | GNUNET_TESTING_make_trait_uint (unsigned int index, | ||
758 | const unsigned int *i); | ||
759 | |||
760 | |||
761 | /** | ||
762 | * Obtain a number from @a cmd. | ||
763 | * | ||
764 | * @param cmd command to extract the number from. | ||
765 | * @param index the number's index number. // FIXME: introduce enum? | ||
766 | * @param[out] n set to the number coming from @a cmd. | ||
767 | * @return #GNUNET_OK on success. | ||
768 | */ | ||
769 | enum GNUNET_GenericReturnValue | ||
770 | GNUNET_TESTING_get_trait_uint (const struct GNUNET_TESTING_Command *cmd, | ||
771 | unsigned int index, | ||
772 | const unsigned int **n); | ||
773 | |||
774 | /** | ||
775 | * Obtain a string from @a cmd. | ||
776 | * | ||
777 | * @param cmd command to extract the subject from. | ||
778 | * @param index index number associated with the transfer | ||
779 | * subject to offer. // FIXME: introduce enum? | ||
780 | * @param[out] s where to write the offered | ||
781 | * string. | ||
782 | * @return #GNUNET_OK on success. | ||
783 | */ | ||
784 | enum GNUNET_GenericReturnValue | ||
785 | GNUNET_TESTING_get_trait_string ( | ||
786 | const struct GNUNET_TESTING_Command *cmd, | ||
787 | unsigned int index, | ||
788 | const char **s); | ||
789 | |||
790 | |||
791 | /** | ||
792 | * Offer string subject. | ||
793 | * | ||
794 | * @param index index number associated with the transfer | ||
795 | * subject being offered. // FIXME: introduce enum? | ||
796 | * @param s string to offer. | ||
797 | * @return the trait. | ||
798 | */ | ||
799 | struct GNUNET_TESTING_Trait | ||
800 | GNUNET_TESTING_make_trait_string (unsigned int index, | ||
801 | const char *s); | ||
802 | |||
803 | /** | ||
804 | * Offer a command in a trait. | ||
805 | * | ||
806 | * @param index always zero. Commands offering this | ||
807 | * kind of traits do not need this index. For | ||
808 | * example, a "meta" CMD returns always the | ||
809 | * CMD currently being executed. FIXME: remove! | ||
810 | * @param cmd wire details to offer. | ||
811 | * @return the trait. | ||
812 | */ | ||
813 | struct GNUNET_TESTING_Trait | ||
814 | GNUNET_TESTING_make_trait_cmd (unsigned int index, | ||
815 | const struct GNUNET_TESTING_Command *cmd); | ||
816 | |||
817 | |||
818 | /** | ||
819 | * Obtain a command from @a cmd. | ||
820 | * | ||
821 | * @param cmd command to extract the command from. | ||
822 | * @param index always zero. Commands offering this | ||
823 | * kind of traits do not need this index. For | ||
824 | * example, a "meta" CMD returns always the | ||
825 | * CMD currently being executed. FIXME: remove! | ||
826 | * @param[out] _cmd where to write the wire details. | ||
827 | * @return #GNUNET_OK on success. | ||
828 | */ | ||
829 | enum GNUNET_GenericReturnValue | ||
830 | GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, | ||
831 | unsigned int index, | ||
832 | struct GNUNET_TESTING_Command **_cmd); | ||
833 | 83 | ||
834 | 84 | ||
835 | /** | ||
836 | * Obtain a uuid from @a cmd. | ||
837 | * | ||
838 | * @param cmd command to extract the uuid from. | ||
839 | * @param index which amount to pick if @a cmd has multiple | ||
840 | * on offer // FIXME: introduce enum? | ||
841 | * @param[out] uuid where to write the uuid. | ||
842 | * @return #GNUNET_OK on success. | ||
843 | */ | ||
844 | enum GNUNET_GenericReturnValue | ||
845 | GNUNET_TESTING_get_trait_uuid (const struct GNUNET_TESTING_Command *cmd, | ||
846 | unsigned int index, | ||
847 | struct GNUNET_Uuid **uuid); | ||
848 | 85 | ||
849 | 86 | /* ****** Specific traits needed by this component ******* */ | |
850 | /** | ||
851 | * Offer a uuid in a trait. | ||
852 | * | ||
853 | * @param index which uuid to offer, in case there are | ||
854 | * multiple available. // FIXME: introduce enum? | ||
855 | * @param uuid the uuid to offer. | ||
856 | * @return the trait. | ||
857 | */ | ||
858 | struct GNUNET_TESTING_Trait | ||
859 | GNUNET_TESTING_make_trait_uuid (unsigned int index, | ||
860 | const struct GNUNET_Uuid *uuid); | ||
861 | 87 | ||
862 | 88 | ||
863 | /** | 89 | /** |
864 | * Obtain a absolute time from @a cmd. | 90 | * Call #op on all simple traits. |
865 | * | ||
866 | * @param cmd command to extract trait from | ||
867 | * @param index which time stamp to pick if | ||
868 | * @a cmd has multiple on offer // FIXME: introduce enum? | ||
869 | * @param[out] time set to the wanted WTID. | ||
870 | * @return #GNUNET_OK on success | ||
871 | */ | 91 | */ |
872 | enum GNUNET_GenericReturnValue | 92 | #define GNUNET_TESTING_SIMPLE_TRAITS(op, prefix) \ |
873 | GNUNET_TESTING_get_trait_absolute_time ( | 93 | op (prefix, process, struct GNUNET_OS_Process *) |
874 | const struct GNUNET_TESTING_Command *cmd, | ||
875 | unsigned int index, | ||
876 | const struct GNUNET_TIME_Absolute **time); | ||
877 | 94 | ||
878 | 95 | ||
879 | /** | 96 | GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_TESTING) |
880 | * Offer a absolute time. | ||
881 | * | ||
882 | * @param index associate the object with this index | ||
883 | * @param time which object should be returned | ||
884 | * @return the trait. | ||
885 | */ | ||
886 | struct GNUNET_TESTING_Trait | ||
887 | GNUNET_TESTING_make_trait_absolute_time ( | ||
888 | unsigned int index, | ||
889 | const struct GNUNET_TIME_Absolute *time); | ||
890 | |||
891 | 97 | ||
892 | /** | 98 | /** |
893 | * Obtain a relative time from @a cmd. | 99 | * Call #op on all indexed traits. |
894 | * | ||
895 | * @param cmd command to extract trait from | ||
896 | * @param index which time to pick if | ||
897 | * @a cmd has multiple on offer. | ||
898 | * @param[out] time set to the wanted WTID. | ||
899 | * @return #GNUNET_OK on success | ||
900 | */ | 100 | */ |
901 | int | 101 | #define GNUNET_TESTING_INDEXED_TRAITS(op, prefix) \ |
902 | GNUNET_TESTING_get_trait_relative_time ( | 102 | op (prefix, uint32, const uint32_t) \ |
903 | const struct GNUNET_TESTING_Command *cmd, | 103 | op (prefix, uint64, const uint64_t) \ |
904 | unsigned int index, | 104 | op (prefix, int64, const int64_t) \ |
905 | const struct GNUNET_TIME_Relative **time); | 105 | op (prefix, uint, const unsigned int) \ |
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) | ||
906 | 111 | ||
112 | GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT, GNUNET_TESTING) | ||
907 | 113 | ||
908 | /** | ||
909 | * Offer a relative time. | ||
910 | * | ||
911 | * @param index associate the object with this index | ||
912 | * @param time which object should be returned | ||
913 | * @return the trait. | ||
914 | */ | ||
915 | struct GNUNET_TESTING_Trait | ||
916 | GNUNET_TESTING_make_trait_relative_time ( | ||
917 | unsigned int index, | ||
918 | const struct GNUNET_TIME_Relative *time); | ||
919 | 114 | ||
920 | #endif | 115 | #endif |