From bd8f79f628b254f4f02c08284ba65d23486d6127 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 8 Oct 2021 21:50:34 +0200 Subject: -clean up testing-NG finish logic --- ...testing_api_cmd_block_until_all_peers_started.c | 56 ++--------- .../testing_api_cmd_block_until_external_trigger.c | 57 ++--------- src/testing/testing_api_cmd_finish.c | 112 +++++++-------------- src/testing/testing_api_cmd_local_test_finished.c | 34 +------ src/testing/testing_api_cmd_netjail_start.c | 62 ++++-------- .../testing_api_cmd_netjail_start_testsystem.c | 31 ++++-- .../testing_api_cmd_netjail_start_testsystem_v2.c | 8 +- src/testing/testing_api_cmd_netjail_start_v2.c | 55 ++-------- src/testing/testing_api_cmd_netjail_stop.c | 45 ++------- src/testing/testing_api_cmd_netjail_stop_v2.c | 64 +++--------- src/testing/testing_api_loop.c | 53 +++++++--- 11 files changed, 176 insertions(+), 401 deletions(-) (limited to 'src/testing') diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c index fb51c1066..8a47a7ce0 100644 --- a/src/testing/testing_api_cmd_block_until_all_peers_started.c +++ b/src/testing/testing_api_cmd_block_until_all_peers_started.c @@ -46,20 +46,6 @@ struct BlockState }; -/** - * Trait function of this cmd does nothing. - * - */ -static int -block_until_all_peers_started_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_OK; -} - - /** * The cleanup function of this cmd frees resources the cmd allocated. * @@ -86,27 +72,6 @@ block_until_all_peers_started_run (void *cls, } -/** - * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called. - * - */ -static int -block_until_all_peers_started_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct BlockState *bs = cls; - unsigned int *ret = bs->all_peers_started; - - if (GNUNET_YES == *ret) - { - cont (cont_cls); - } - - return *ret; -} - - /** * Create command. * @@ -123,15 +88,14 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label, bs = GNUNET_new (struct BlockState); bs->all_peers_started = all_peers_started; - - struct GNUNET_TESTING_Command cmd = { - .cls = bs, - .label = label, - .run = &block_until_all_peers_started_run, - .finish = &block_until_all_peers_started_finish, - .cleanup = &block_until_all_peers_started_cleanup, - .traits = &block_until_all_peers_started_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = bs, + .label = label, + .run = &block_until_all_peers_started_run, + .cleanup = &block_until_all_peers_started_cleanup + }; + + return cmd; + } } diff --git a/src/testing/testing_api_cmd_block_until_external_trigger.c b/src/testing/testing_api_cmd_block_until_external_trigger.c index d69040b75..b416fa595 100644 --- a/src/testing/testing_api_cmd_block_until_external_trigger.c +++ b/src/testing/testing_api_cmd_block_until_external_trigger.c @@ -40,26 +40,11 @@ struct BlockState { /** * Flag to indicate if all peers have started. - * */ unsigned int *stop_blocking; }; -/** - * Trait function of this cmd does nothing. - * - */ -static int -block_until_all_peers_started_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - /** * The cleanup function of this cmd frees resources the cmd allocated. * @@ -86,27 +71,6 @@ block_until_all_peers_started_run (void *cls, } -/** - * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called. - * - */ -static int -block_until_all_peers_started_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct BlockState *bs = cls; - unsigned int *ret = bs->stop_blocking; - - if (GNUNET_YES == *ret) - { - cont (cont_cls); - } - - return *ret; -} - - /** * Create command. * @@ -123,15 +87,14 @@ GNUNET_TESTING_cmd_block_until_external_trigger (const char *label, bs = GNUNET_new (struct BlockState); bs->stop_blocking = stop_blocking; - - struct GNUNET_TESTING_Command cmd = { - .cls = bs, - .label = label, - .run = &block_until_all_peers_started_run, - .finish = &block_until_all_peers_started_finish, - .cleanup = &block_until_all_peers_started_cleanup, - .traits = &block_until_all_peers_started_traits - }; - - return cmd; + { + struct GNUNET_TESTING_Command cmd = { + .cls = bs, + .label = label, + .run = &block_until_all_peers_started_run, + .cleanup = &block_until_all_peers_started_cleanup, + }; + + return cmd; + } } diff --git a/src/testing/testing_api_cmd_finish.c b/src/testing/testing_api_cmd_finish.c index 2bcefd803..3ac0871a5 100644 --- a/src/testing/testing_api_cmd_finish.c +++ b/src/testing/testing_api_cmd_finish.c @@ -47,35 +47,24 @@ struct FinishState */ struct GNUNET_SCHEDULER_Task *finish_task; - /** - * Interpreter we are part of. - */ - struct GNUNET_TESTING_Interpreter *is; - /** * Function to call when done. */ - GNUNET_SCHEDULER_TaskCallback cont; - - /** - * Closure for @e cont. - */ - void *cont_cls; + struct GNUNET_TESTING_AsyncContext ac; /** * How long to wait until finish fails hard? */ struct GNUNET_TIME_Relative timeout; - /** - * Set to #GNUNET_OK if the @a async_label command finished on time - */ - enum GNUNET_GenericReturnValue finished; - }; /** + * Function called when the command we are waiting on + * is finished. Hence we are finished, too. + * + * @param cls a `struct FinishState` being notified */ static void done_finish (void *cls) @@ -84,15 +73,15 @@ done_finish (void *cls) GNUNET_SCHEDULER_cancel (finish_state->finish_task); finish_state->finish_task = NULL; - finish_state->finished = GNUNET_YES; - if (NULL != finish_state->cont) - { - finish_state->cont (finish_state->cont_cls); - } + GNUNET_TESTING_async_finish (&finish_state->ac); } /** + * Function triggered if the command we are waiting + * for did not complete on time. + * + * @param cls our `struct FinishState` */ static void timeout_finish (void *cls) @@ -103,8 +92,7 @@ timeout_finish (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout waiting for command `%s' to finish\n", finish_state->async_label); - finish_state->finished = GNUNET_SYSERR; - GNUNET_TESTING_interpreter_fail (finish_state->is); + GNUNET_TESTING_async_fail (&finish_state->ac); } @@ -114,13 +102,13 @@ timeout_finish (void *cls) * */ static void -run_finish_on_ref (void *cls, - struct GNUNET_TESTING_Interpreter *is) +run_finish (void *cls, + struct GNUNET_TESTING_Interpreter *is) { struct FinishState *finish_state = cls; const struct GNUNET_TESTING_Command *async_cmd; + struct GNUNET_TESTING_AsyncContext *aac; - finish_state->is = is; async_cmd = GNUNET_TESTING_interpreter_lookup_command (is, finish_state->async_label); @@ -132,7 +120,7 @@ run_finish_on_ref (void *cls, GNUNET_TESTING_interpreter_fail (is); return; } - if ( (NULL == async_cmd->finish) || + if ( (NULL == (aac = async_cmd->ac)) || (! async_cmd->asynchronous_finish) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -141,71 +129,40 @@ run_finish_on_ref (void *cls, GNUNET_TESTING_interpreter_fail (is); return; } + if (GNUNET_NO != aac->finished) + { + /* Command is already finished, so are we! */ + GNUNET_TESTING_async_finish (&finish_state->ac); + return; + } finish_state->finish_task = GNUNET_SCHEDULER_add_delayed (finish_state->timeout, &timeout_finish, finish_state); - async_cmd->finish (async_cmd->cls, - &done_finish, - finish_state); + aac->cont = &done_finish; + aac->cont_cls = finish_state; } /** - * Wait for any asynchronous execution of @e run to conclude, - * then call finish_cont. Finish may only be called once per command. + * Cleanup state of a finish command. * - * This member may be NULL if this command is a synchronous command, - * and also should be set to NULL once the command has finished. - * - * @param cls closure - * @param cont function to call upon completion, can be NULL - * @param cont_cls closure for @a cont - * @return - * #GNUNET_NO if the command is still running and @a cont will be called later - * #GNUNET_OK if the command completed successfully and @a cont was called - * #GNUNET_SYSERR if the operation @a cont was NOT called + * @param cls a `struct FinishState` to clean up */ -static enum GNUNET_GenericReturnValue -finish_finish_on_ref (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) +static void +cleanup_finish (void *cls) { struct FinishState *finish_state = cls; - switch (finish_state->finished) + if (NULL != finish_state->finish_task) { - case GNUNET_OK: - cont (cont_cls); - break; - case GNUNET_SYSERR: - GNUNET_break (0); - break; - case GNUNET_NO: - if (NULL != finish_state->cont) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - finish_state->cont = cont; - finish_state->cont_cls = cont_cls; - break; + GNUNET_SCHEDULER_cancel (finish_state->finish_task); + finish_state->finish_task = NULL; } - return finish_state->finished; + GNUNET_free (finish_state); } -/** - * Create (synchronous) command that waits for another command to finish. - * If @a cmd_ref did not finish after @a timeout, this command will fail - * the test case. - * - * @param finish_label label for this command - * @param cmd_ref reference to a previous command which we should - * wait for (call `finish()` on) - * @param timeout how long to wait at most for @a cmd_ref to finish - * @return a finish-command. - */ const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_finish (const char *finish_label, const char *cmd_ref, @@ -220,8 +177,9 @@ GNUNET_TESTING_cmd_finish (const char *finish_label, struct GNUNET_TESTING_Command cmd = { .cls = finish_state, .label = finish_label, - .run = &run_finish_on_ref, - .finish = &finish_finish_on_ref + .run = &run_finish, + .ac = &finish_state->ac, + .cleanup = &cleanup_finish }; return cmd; @@ -234,7 +192,7 @@ GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd) { /* do not permit this function to be used on a finish command! */ - GNUNET_assert (cmd.run != &run_finish_on_ref); + GNUNET_assert (cmd.run != &run_finish); cmd.asynchronous_finish = true; return cmd; } diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c index da4aff80f..0e7e214dc 100644 --- a/src/testing/testing_api_cmd_local_test_finished.c +++ b/src/testing/testing_api_cmd_local_test_finished.c @@ -40,6 +40,7 @@ */ struct LocalFinishedState { + /** * Callback to write messages to the master loop. * @@ -54,20 +55,6 @@ struct LocalFinishedState }; -/** - * Trait function of this cmd does nothing. - * - */ -static enum GNUNET_GenericReturnValue -local_test_finished_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - /** * The cleanup function of this cmd frees resources the cmd allocated. * @@ -104,23 +91,6 @@ local_test_finished_run (void *cls, } -/** - * This finish function will stop the local loop without shutting down the - * scheduler, because we do not call the continuation, which is the - * interpreter_next method. - * - */ -static enum GNUNET_GenericReturnValue -local_test_finished_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Stopping local loop\n"); - return GNUNET_YES; -} - - /** * Create command. * @@ -142,9 +112,7 @@ GNUNET_TESTING_cmd_local_test_finished ( .cls = lfs, .label = label, .run = &local_test_finished_run, - .finish = &local_test_finished_finish, .cleanup = &local_test_finished_cleanup, - .traits = &local_test_finished_traits }; return cmd; diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c index 1815b64d2..4b5592524 100644 --- a/src/testing/testing_api_cmd_netjail_start.c +++ b/src/testing/testing_api_cmd_netjail_start.c @@ -35,6 +35,11 @@ */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + // Child Wait handle struct GNUNET_ChildWaitHandle *cwh; @@ -67,7 +72,6 @@ netjail_start_cleanup (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "netjail_start_cleanup!\n"); - if (NULL != ns->cwh) { GNUNET_wait_child_cancel (ns->cwh); @@ -87,20 +91,6 @@ netjail_start_cleanup (void *cls) } -/** - * Trait function of this cmd does nothing. - * - */ -static enum GNUNET_GenericReturnValue -netjail_start_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - /** * Callback which will be called if the setup script finished. * @@ -112,18 +102,18 @@ child_completed_callback (void *cls, { struct NetJailState *ns = cls; + GNUNET_OS_process_destroy (ns->start_proc); + ns->start_proc = NULL; if (0 == exit_code) { - ns->finished = GNUNET_YES; + GNUNET_TESTING_async_finish (&ns->ac); } else { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Child completed with an error!\n"); - ns->finished = GNUNET_SYSERR; + GNUNET_TESTING_async_fail (&ns->ac); } - GNUNET_OS_process_destroy (ns->start_proc); - ns->start_proc = NULL; } @@ -138,10 +128,12 @@ netjail_start_run (void *cls, struct GNUNET_TESTING_Interpreter *is) { struct NetJailState *ns = cls; - char *const script_argv[] = {NETJAIL_START_SCRIPT, - ns->local_m, - ns->global_n, - NULL}; + char *const script_argv[] = { + NETJAIL_START_SCRIPT, + ns->local_m, + ns->global_n, + NULL + }; unsigned int helper_check = GNUNET_OS_check_helper_binary ( NETJAIL_START_SCRIPT, GNUNET_YES, @@ -176,25 +168,6 @@ netjail_start_run (void *cls, } -/** - * This function checks the flag NetJailState#finished, if this cmd finished. - * - */ -static enum GNUNET_GenericReturnValue -netjail_start_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct NetJailState *ns = cls; - - if (ns->finished) - { - cont (cont_cls); - } - return ns->finished; -} - - /** * Create command. * @@ -218,9 +191,8 @@ GNUNET_TESTING_cmd_netjail_start (const char *label, .cls = ns, .label = label, .run = &netjail_start_run, - .finish = &netjail_start_finish, - .cleanup = &netjail_start_cleanup, - .traits = &netjail_start_traits + .ac = &ns->ac, + .cleanup = &netjail_start_cleanup }; return cmd; diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index 1222ae54b..4224a5736 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c @@ -61,6 +61,11 @@ struct HelperMessage */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + /** * Pointer to the return value of the test. * @@ -399,14 +404,16 @@ start_helper (struct NetJailState *ns, struct struct GNUNET_HELPER_Handle *helper; struct GNUNET_CMDS_HelperInit *msg; struct TestingSystemCount *tbc; - char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, - m_char, - n_char, - GNUNET_OS_get_libexec_binary_path ( - HELPER_CMDS_BINARY), - ns->global_n, - ns->local_m, - NULL}; + char *const script_argv[] = { + NETJAIL_EXEC_SCRIPT, + m_char, + n_char, + GNUNET_OS_get_libexec_binary_path ( + HELPER_CMDS_BINARY), + ns->global_n, + ns->local_m, + NULL + }; unsigned int m = atoi (m_char); unsigned int n = atoi (n_char); unsigned int helper_check = GNUNET_OS_check_helper_binary ( @@ -436,8 +443,9 @@ start_helper (struct NetJailState *ns, struct NETJAIL_EXEC_SCRIPT); *ns->rv = 1; } - - GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( + GNUNET_array_append (ns->helper, + ns->n_helper, + GNUNET_HELPER_start ( GNUNET_YES, NETJAIL_EXEC_SCRIPT, script_argv, @@ -508,6 +516,7 @@ netjail_exec_run (void *cls, * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers. * 3. Did all peers finished the test case. In this case interpreter_next will be called. * + * => FIXME: must change _completely_. */ static int netjail_start_finish (void *cls, @@ -598,7 +607,7 @@ GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, .cls = ns, .label = label, .run = &netjail_exec_run, - .finish = &netjail_start_finish, + .ac = &ns->ac, .cleanup = &netjail_exec_cleanup, .traits = &netjail_exec_traits }; diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c index bb9421aa7..d319b73b4 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c @@ -61,6 +61,11 @@ struct HelperMessage */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + /** * The complete topology information. */ @@ -637,6 +642,7 @@ send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) * 3. Did all peers finished the test case. In this case interpreter_next will be called. * */ +// FIXME: must change completely! static int netjail_start_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, @@ -708,7 +714,7 @@ GNUNET_TESTING_cmd_netjail_start_testing_system_v2 (const char *label, .cls = ns, .label = label, .run = &netjail_exec_run, - .finish = &netjail_start_finish, + .ac = &ns->ac, .cleanup = &netjail_exec_cleanup, .traits = &netjail_exec_traits }; diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c index faabed98e..69d5e6a45 100644 --- a/src/testing/testing_api_cmd_netjail_start_v2.c +++ b/src/testing/testing_api_cmd_netjail_start_v2.c @@ -35,6 +35,11 @@ */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + // Child Wait handle struct GNUNET_ChildWaitHandle *cwh; @@ -85,20 +90,6 @@ netjail_start_cleanup (void *cls) } -/** - * Trait function of this cmd does nothing. - * - */ -static enum GNUNET_GenericReturnValue -netjail_start_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - /** * Callback which will be called if the setup script finished. * @@ -110,19 +101,19 @@ child_completed_callback (void *cls, { struct NetJailState *ns = cls; + GNUNET_OS_process_destroy (ns->start_proc); + ns->start_proc = NULL; if (0 == exit_code) { - ns->finished = GNUNET_YES; + GNUNET_TESTING_async_finish (&ns->ac); } else { // FIXME: log status code GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Child completed with an error!\n"); - ns->finished = GNUNET_SYSERR; + GNUNET_TESTING_async_fail (&ns->ac); } - GNUNET_OS_process_destroy (ns->start_proc); - ns->start_proc = NULL; } @@ -192,29 +183,6 @@ netjail_start_run (void *cls, } -/** - * This function checks the flag NetJailState - * - * FIXME: fix comment! - * #finished, if this cmd finished. - * - */ -static enum GNUNET_GenericReturnValue -netjail_start_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct NetJailState *ns = cls; - - if (GNUNET_NO != ns->finished) - { - cont (cont_cls); - } - // FIXME: cont should be called later in the else case! - return ns->finished; -} - - /** * Create command. * @@ -235,9 +203,8 @@ GNUNET_TESTING_cmd_netjail_start_v2 (const char *label, .cls = ns, .label = label, .run = &netjail_start_run, - .finish = &netjail_start_finish, - .cleanup = &netjail_start_cleanup, - .traits = &netjail_start_traits + .ac = &ns->ac, + .cleanup = &netjail_start_cleanup }; return cmd; diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c index c93e5cca3..8c78b5e93 100644 --- a/src/testing/testing_api_cmd_netjail_stop.c +++ b/src/testing/testing_api_cmd_netjail_stop.c @@ -39,6 +39,11 @@ struct GNUNET_ChildWaitHandle *cwh; */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + // Number of local nodes in each namespace. char *local_m; @@ -50,8 +55,6 @@ struct NetJailState */ struct GNUNET_OS_Process *stop_proc; - // Flag indication if the script finished. - unsigned int finished; }; @@ -108,16 +111,17 @@ child_completed_callback (void *cls, struct NetJailState *ns = cls; cwh = NULL; + GNUNET_OS_process_destroy (ns->stop_proc); + ns->stop_proc = NULL; if (0 == exit_code) { - ns->finished = GNUNET_YES; + GNUNET_TESTING_async_finish (&ns->ac); } else { - ns->finished = GNUNET_SYSERR; + // FIXME: log exit code! + GNUNET_TESTING_async_fail (&ns->ac); } - GNUNET_OS_process_destroy (ns->stop_proc); - ns->stop_proc = NULL; } @@ -174,33 +178,6 @@ netjail_stop_run (void *cls, } -/** - * This function checks the flag NetJailState#finished, if this cmd finished. - * - */ -static enum GNUNET_GenericReturnValue -netjail_stop_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct NetJailState *ns = cls; - - if (ns->finished) - { - cont (cont_cls); - } - return ns->finished; -} - - -/** - * Create command. - * - * @param label name for command. - * @param local_m Number of local nodes in each namespace. - * @param global_n The number of namespaces. - * @return command. - */ struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_stop (const char *label, char *local_m, @@ -216,7 +193,7 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label, .cls = ns, .label = label, .run = &netjail_stop_run, - .finish = &netjail_stop_finish, + .ac = &ns->ac, .cleanup = &netjail_stop_cleanup, .traits = &netjail_stop_traits }; diff --git a/src/testing/testing_api_cmd_netjail_stop_v2.c b/src/testing/testing_api_cmd_netjail_stop_v2.c index 348e8c9f7..a0e2657cb 100644 --- a/src/testing/testing_api_cmd_netjail_stop_v2.c +++ b/src/testing/testing_api_cmd_netjail_stop_v2.c @@ -39,6 +39,11 @@ static struct GNUNET_ChildWaitHandle *cwh; */ struct NetJailState { + /** + * Context for our asynchronous completion. + */ + struct GNUNET_TESTING_AsyncContext ac; + /** * Configuration file for the test topology. */ @@ -49,8 +54,6 @@ struct NetJailState */ struct GNUNET_OS_Process *stop_proc; - // Flag indication if the script finished. - enum GNUNET_GenericReturnValue finished; }; @@ -81,20 +84,6 @@ netjail_stop_cleanup (void *cls) } -/** - * Trait function of this cmd does nothing. - * - */ -static enum GNUNET_GenericReturnValue -netjail_stop_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_NO; -} - - /** * Callback which will be called if the setup script finished. * @@ -106,17 +95,17 @@ child_completed_callback (void *cls, { struct NetJailState *ns = cls; - cwh = NULL; + cwh = NULL; // WTF? globals!?!?! + GNUNET_OS_process_destroy (ns->stop_proc); + ns->stop_proc = NULL; if (0 == exit_code) { - ns->finished = GNUNET_YES; + GNUNET_TESTING_async_finish (&ns->ac); } else { - ns->finished = GNUNET_SYSERR; + GNUNET_TESTING_async_fail (&ns->ac); } - GNUNET_OS_process_destroy (ns->stop_proc); - ns->stop_proc = NULL; } @@ -132,6 +121,7 @@ netjail_stop_run (void *cls, { struct NetJailState *ns = cls; char *pid; + GNUNET_asprintf (&pid, "%u", getpid ()); @@ -170,36 +160,9 @@ netjail_stop_run (void *cls, &child_completed_callback, ns); GNUNET_break (NULL != cwh); - } -/** - * This function checks the flag NetJailState#finished, if this cmd finished. - * - */ -static enum GNUNET_GenericReturnValue -netjail_stop_finish (void *cls, - GNUNET_SCHEDULER_TaskCallback cont, - void *cont_cls) -{ - struct NetJailState *ns = cls; - - if (ns->finished) - { - cont (cont_cls); - } - return ns->finished; -} - - -/** - * Create command. - * - * @param label name for command. - * @param topology_config Configuration file for the test topology. - * @return command. - */ struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label, char *topology_config) @@ -213,9 +176,8 @@ GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label, .cls = ns, .label = label, .run = &netjail_stop_run, - .finish = &netjail_stop_finish, - .cleanup = &netjail_stop_cleanup, - .traits = &netjail_stop_traits + .ac = &ns->ac, + .cleanup = &netjail_stop_cleanup }; return cmd; diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index b21e01fcc..e0cb3fcda 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c @@ -46,7 +46,7 @@ struct GNUNET_TESTING_Interpreter * Closure for @e rc. */ void *rc_cls; - + /** * Commands the interpreter will run. */ @@ -294,7 +294,7 @@ interpreter_run (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running command END\n"); is->result = GNUNET_OK; - GNUNET_SCHEDULER_shutdown (); + finish_test (is); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -304,17 +304,19 @@ interpreter_run (void *cls) = cmd->last_req_time = GNUNET_TIME_absolute_get (); cmd->num_tries = 1; - cmd->run (cmd->cls, - is); - if ( (NULL != cmd->finish) && - (! cmd->asynchronous_finish) ) + if (NULL != cmd->ac) { - cmd->finish (cmd->cls, - &interpreter_next, - is); + cmd->ac->is = is; + cmd->ac->cont = &interpreter_next; + cmd->ac->cont_cls = is; + cmd->ac->finished = GNUNET_NO; } - else + cmd->run (cmd->cls, + is); + if ( (cmd->asynchronous_finish) && + (NULL != cmd->ac->cont) ) { + cmd->ac->cont = NULL; interpreter_next (is); } } @@ -380,12 +382,12 @@ struct MainParams /** * Global timeout for the test. - */ + */ struct GNUNET_TIME_Relative timeout; /** * Set to #EXIT_FAILURE on error. - */ + */ int rv; }; @@ -444,4 +446,31 @@ GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands, } +void +GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac) +{ + GNUNET_assert (GNUNET_NO == ac->finished); + ac->finished = GNUNET_SYSERR; + GNUNET_TESTING_interpreter_fail (ac->is); + if (NULL != ac->cont) + { + ac->cont (ac->cont_cls); + ac->cont = NULL; + } +} + + +void +GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac) +{ + GNUNET_assert (GNUNET_NO == ac->finished); + ac->finished = GNUNET_OK; + if (NULL != ac->cont) + { + ac->cont (ac->cont_cls); + ac->cont = NULL; + } +} + + /* end of testing_api_loop.c */ -- cgit v1.2.3