diff options
Diffstat (limited to 'src/include/gnunet_testing_ng_lib.h')
-rw-r--r-- | src/include/gnunet_testing_ng_lib.h | 100 |
1 files changed, 41 insertions, 59 deletions
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index 31665f8f7..363c7ff0c 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h | |||
@@ -279,15 +279,16 @@ struct GNUNET_TESTING_Command | |||
279 | * the asynchronous activity to terminate. | 279 | * the asynchronous activity to terminate. |
280 | * | 280 | * |
281 | * @param cls closure | 281 | * @param cls closure |
282 | * @param cmd command being run | 282 | * @param is interpreter state |
283 | * @param i interpreter state | ||
284 | */ | 283 | */ |
285 | void | 284 | void |
286 | (*run)(void *cls, | 285 | (*run)(void *cls, |
287 | const struct GNUNET_TESTING_Command *cmd, | 286 | struct GNUNET_TESTING_Interpreter *is); |
288 | struct GNUNET_TESTING_Interpreter *i); | ||
289 | 287 | ||
290 | /** | 288 | /** |
289 | * FIXME: logic is basically always the same! | ||
290 | * => Refactor API to avoid duplication! | ||
291 | * | ||
291 | * Wait for any asynchronous execution of @e run to conclude, | 292 | * Wait for any asynchronous execution of @e run to conclude, |
292 | * then call finish_cont. Finish may only be called once per command. | 293 | * then call finish_cont. Finish may only be called once per command. |
293 | * | 294 | * |
@@ -297,27 +298,24 @@ struct GNUNET_TESTING_Command | |||
297 | * @param cls closure | 298 | * @param cls closure |
298 | * @param cont function to call upon completion, can be NULL | 299 | * @param cont function to call upon completion, can be NULL |
299 | * @param cont_cls closure for @a cont | 300 | * @param cont_cls closure for @a cont |
301 | * @return | ||
302 | * #GNUNET_NO if the command is still running and @a cont will be called later | ||
303 | * #GNUNET_OK if the command completed successfully and @a cont was called | ||
304 | * #GNUNET_SYSERR if the operation @a cont was NOT called | ||
300 | */ | 305 | */ |
301 | int | 306 | enum GNUNET_GenericReturnValue |
302 | (*finish)(void *cls, | 307 | (*finish)(void *cls, |
303 | GNUNET_SCHEDULER_TaskCallback cont, | 308 | GNUNET_SCHEDULER_TaskCallback cont, |
304 | void *cont_cls); | 309 | void *cont_cls); |
305 | 310 | ||
306 | /** | 311 | /** |
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 | 312 | * Clean up after the command. Run during forced termination |
313 | * (CTRL-C) or test failure or test success. | 313 | * (CTRL-C) or test failure or test success. |
314 | * | 314 | * |
315 | * @param cls closure | 315 | * @param cls closure |
316 | * @param cmd command being cleaned up | ||
317 | */ | 316 | */ |
318 | void | 317 | void |
319 | (*cleanup)(void *cls, | 318 | (*cleanup)(void *cls); |
320 | const struct GNUNET_TESTING_Command *cmd); | ||
321 | 319 | ||
322 | /** | 320 | /** |
323 | * Extract information from a command that is useful for other | 321 | * Extract information from a command that is useful for other |
@@ -327,9 +325,10 @@ struct GNUNET_TESTING_Command | |||
327 | * @param[out] ret result (could be anything) | 325 | * @param[out] ret result (could be anything) |
328 | * @param trait name of the trait | 326 | * @param trait name of the trait |
329 | * @param index index number of the object to extract. | 327 | * @param index index number of the object to extract. |
330 | * @return #GNUNET_OK on success | 328 | * @return #GNUNET_OK on success, |
329 | * #GNUNET_NO if no trait was found | ||
331 | */ | 330 | */ |
332 | int | 331 | enum GNUNET_GenericReturnValue |
333 | (*traits)(void *cls, | 332 | (*traits)(void *cls, |
334 | const void **ret, | 333 | const void **ret, |
335 | const char *trait, | 334 | const char *trait, |
@@ -383,40 +382,15 @@ struct GNUNET_TESTING_Command | |||
383 | 382 | ||
384 | 383 | ||
385 | /** | 384 | /** |
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. | 385 | * Lookup command by label. |
414 | * | 386 | * |
387 | * @param is interpreter to lookup command in | ||
415 | * @param label label of the command to lookup. | 388 | * @param label label of the command to lookup. |
416 | * @return the command, if it is found, or NULL. | 389 | * @return the command, if it is found, or NULL. |
417 | */ | 390 | */ |
418 | const struct GNUNET_TESTING_Command * | 391 | const struct GNUNET_TESTING_Command * |
419 | GNUNET_TESTING_interpreter_lookup_command ( | 392 | GNUNET_TESTING_interpreter_lookup_command ( |
393 | struct GNUNET_TESTING_Interpreter *is, | ||
420 | const char *label); | 394 | const char *label); |
421 | 395 | ||
422 | 396 | ||
@@ -437,7 +411,7 @@ GNUNET_TESTING_interpreter_get_current_label ( | |||
437 | * @param is interpreter state. | 411 | * @param is interpreter state. |
438 | */ | 412 | */ |
439 | void | 413 | void |
440 | GNUNET_TESTING_interpreter_fail (); | 414 | GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is); |
441 | 415 | ||
442 | 416 | ||
443 | /** | 417 | /** |
@@ -455,8 +429,8 @@ GNUNET_TESTING_cmd_end (void); | |||
455 | * @param cmd command to make synchronous. | 429 | * @param cmd command to make synchronous. |
456 | * @return a finish-command. | 430 | * @return a finish-command. |
457 | */ | 431 | */ |
458 | const struct GNUNET_TESTING_Command | 432 | struct GNUNET_TESTING_Command |
459 | GNUNET_TESTING_cmd_make_unblocking (const struct GNUNET_TESTING_Command cmd); | 433 | GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd); |
460 | 434 | ||
461 | 435 | ||
462 | /** | 436 | /** |
@@ -492,19 +466,10 @@ GNUNET_TESTING_cmd_rewind_ip (const char *label, | |||
492 | 466 | ||
493 | 467 | ||
494 | /** | 468 | /** |
495 | * Wait until we receive SIGCHLD signal. Then obtain the process trait of the | 469 | * Run the testsuite. Note, CMDs are copied into |
496 | * current command, wait on the the zombie and continue with the next command. | 470 | * the interpreter state because they are _usually_ |
497 | * | 471 | * defined into the "run" method that returns after |
498 | * @param is interpreter state. | 472 | * having scheduled the test interpreter. |
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 | * | 473 | * |
509 | * @param cfg_name name of configuration file to use | 474 | * @param cfg_name name of configuration file to use |
510 | * @param commands the list of command to execute | 475 | * @param commands the list of command to execute |
@@ -513,13 +478,29 @@ GNUNET_TESTING_cmd_rewind_ip (const char *label, | |||
513 | * non-GNUNET_OK codes are #GNUNET_SYSERR most of the | 478 | * non-GNUNET_OK codes are #GNUNET_SYSERR most of the |
514 | * times. | 479 | * times. |
515 | */ | 480 | */ |
516 | int | 481 | enum GNUNET_GenericReturnValue |
517 | GNUNET_TESTING_run (const char *cfg_filename, | 482 | GNUNET_TESTING_run (const char *cfg_filename, |
518 | struct GNUNET_TESTING_Command *commands, | 483 | struct GNUNET_TESTING_Command *commands, |
519 | struct GNUNET_TIME_Relative timeout); | 484 | struct GNUNET_TIME_Relative timeout); |
520 | 485 | ||
521 | 486 | ||
522 | /** | 487 | /** |
488 | * Start a GNUnet scheduler event loop and | ||
489 | * run the testsuite. Return 0 upon success. | ||
490 | * Expected to be called directly from main(). | ||
491 | * | ||
492 | * @param cfg_name name of configuration file to use | ||
493 | * @param commands the list of command to execute | ||
494 | * @param timeout how long to wait for each command to execute | ||
495 | * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure | ||
496 | */ | ||
497 | int | ||
498 | GNUNET_TESTING_main (const char *cfg_filename, | ||
499 | struct GNUNET_TESTING_Command *commands, | ||
500 | struct GNUNET_TIME_Relative timeout); | ||
501 | |||
502 | |||
503 | /** | ||
523 | * Look for substring in a programs' name. | 504 | * Look for substring in a programs' name. |
524 | * | 505 | * |
525 | * @param prog program's name to look into | 506 | * @param prog program's name to look into |
@@ -1191,4 +1172,5 @@ struct GNUNET_TESTING_Command | |||
1191 | GNUNET_TESTING_cmd_local_test_finished (const char *label, | 1172 | GNUNET_TESTING_cmd_local_test_finished (const char *label, |
1192 | TESTING_CMD_HELPER_write_cb | 1173 | TESTING_CMD_HELPER_write_cb |
1193 | write_message); | 1174 | write_message); |
1175 | |||
1194 | #endif | 1176 | #endif |