From 1816cee6455627543262711524837164bbf48385 Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Mon, 6 Dec 2021 14:20:25 +0100 Subject: fixed timeout for netjail tests, removed duplicated function declaration from header, using GNUNET_TESTING_get_trait_batch_cmds in loop, fixed tng service shutdown logic, added missing GNUNET_SERVICE_client_continue, changed default log level for udp backchannel test to debug --- src/testing/gnunet-cmds-helper.c | 11 ------ .../testing_api_cmd_netjail_start_testsystem.c | 45 +++++++++++++++++++++- .../testing_api_cmd_netjail_stop_testsystem.c | 2 +- src/testing/testing_api_loop.c | 12 +++--- 4 files changed, 50 insertions(+), 20 deletions(-) (limited to 'src/testing') diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c index 5ff7c04ea..f6f079802 100644 --- a/src/testing/gnunet-cmds-helper.c +++ b/src/testing/gnunet-cmds-helper.c @@ -185,11 +185,6 @@ static struct GNUNET_OS_Process *cmd_binary_process;*/ */ struct Plugin *plugin; -/** - * Handle to the testing system - */ -static struct GNUNET_TESTING_System *test_system; - /** * Our message stream tokenizer */ @@ -262,12 +257,6 @@ shutdown_task (void *cls) (void) GNUNET_DISK_file_close (stdout_fd); GNUNET_MST_destroy (tokenizer); tokenizer = NULL; - - if (NULL != test_system) - { - GNUNET_TESTING_system_destroy (test_system, GNUNET_YES); - test_system = NULL; - } } diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index 04d7eef44..9f39fbfda 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c @@ -30,6 +30,8 @@ #define NETJAIL_EXEC_SCRIPT "netjail_exec.sh" +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) + /** * Generic logging shortcut */ @@ -152,6 +154,16 @@ struct NetJailState * String with topology data or name of topology file. */ char *topology_data; + + /** + * Time after this cmd has to finish. + */ + struct GNUNET_TIME_Relative timeout; + + /** + * Timeout task. + */ + struct GNUNET_SCHEDULER_Task *timeout_task; }; /** @@ -393,6 +405,7 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) ns->number_of_local_tests_finished++; if (ns->number_of_local_tests_finished == total_number) { + GNUNET_SCHEDULER_cancel (ns->timeout_task); GNUNET_TESTING_async_finish (&ns->ac); } break; @@ -489,6 +502,7 @@ exp_cb (void *cls) struct TestingSystemCount *tbc = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); + GNUNET_SCHEDULER_cancel (tbc->ns->timeout_task); GNUNET_TESTING_async_fail (&(tbc->ns->ac)); } @@ -695,6 +709,25 @@ start_helper (struct NetJailState *ns, } +/** + * Function run when the cmd terminates (good or bad) with timeout. + * + * @param cls the interpreter state + */ +static void +do_timeout (void *cls) +{ + struct NetJailState *ns = cls; + struct GNUNET_TESTING_Command *cmd; + + ns->timeout_task = NULL; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Terminating cmd due to global timeout\n"); + cmd = GNUNET_TESTING_interpreter_get_current_command (ns->is); + GNUNET_TESTING_async_finish (cmd->ac); +} + + /** * This function starts a helper process for each node. * @@ -725,6 +758,13 @@ netjail_exec_run (void *cls, i); } } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Adding timeout %s\n", + GNUNET_STRINGS_relative_time_to_string (ns->timeout, GNUNET_NO)); + ns->timeout_task + = GNUNET_SCHEDULER_add_delayed (ns->timeout, + &do_timeout, + ns); } @@ -735,6 +775,7 @@ netjail_exec_run (void *cls, * @param topology The complete topology information. * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data. * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology. + * @param timeout Before this timeout is reached this cmd MUST finish. * @return command. */ struct GNUNET_TESTING_Command @@ -742,7 +783,8 @@ GNUNET_TESTING_cmd_netjail_start_testing_system ( const char *label, struct GNUNET_TESTING_NetjailTopology *topology, unsigned int *read_file, - char *topology_data) + char *topology_data, + struct GNUNET_TIME_Relative timeout) { struct NetJailState *ns; @@ -754,6 +796,7 @@ GNUNET_TESTING_cmd_netjail_start_testing_system ( ns->topology = topology; ns->read_file = read_file; ns->topology_data = topology_data; + ns->timeout = GNUNET_TIME_relative_subtract (timeout, TIMEOUT); struct GNUNET_TESTING_Command cmd = { .cls = ns, diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c index 2e42056dc..4215beef6 100644 --- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c @@ -118,7 +118,7 @@ stop_testing_system_run (void *cls, + j + shs->known - 1], - GNUNET_YES); + GNUNET_NO); } } } diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index 36e9da220..95d6b88e6 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c @@ -122,21 +122,19 @@ get_command (struct GNUNET_TESTING_Interpreter *is, if (GNUNET_TESTING_cmd_is_batch_ (cmd)) { -#define BATCH_INDEX 1 - const struct GNUNET_TESTING_Command *batch; + struct GNUNET_TESTING_Command **batch; struct GNUNET_TESTING_Command *current; const struct GNUNET_TESTING_Command *icmd; const struct GNUNET_TESTING_Command *match; current = GNUNET_TESTING_cmd_batch_get_current_ (cmd); GNUNET_assert (GNUNET_OK == - GNUNET_TESTING_get_trait_cmd (cmd, - BATCH_INDEX, - &batch)); + GNUNET_TESTING_get_trait_batch_cmds (cmd, + &batch)); /* We must do the loop forward, but we can find the last match */ match = NULL; for (unsigned int j = 0; - NULL != (icmd = &batch[j])->label; + NULL != (icmd = &(*batch)[j])->label; j++) { if (current == icmd) @@ -383,7 +381,7 @@ interpreter_run (void *cls) finish_test (is); return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running command `%s'\n", cmd->label); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, -- cgit v1.2.3