summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-03-08 11:18:18 +0100
committert3sserakt <t3ss@posteo.de>2021-03-08 11:18:18 +0100
commit3583e51e3c4a6fb4bac331996891a7f7cd42f9cf (patch)
tree9f41ce5bebd44fbb6747eda7525e9d7b91060399
parent79e9673137f1c94644bf9ef781e08c53c2e3901f (diff)
- Just make it compile again.
-rw-r--r--src/include/gnunet_testing_ng_lib.h15
-rw-r--r--src/testing/testing_api_loop.c368
2 files changed, 26 insertions, 357 deletions
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index bfdce7557..0cc768d19 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -27,6 +27,7 @@
#ifndef GNUNET_TESTING_NG_LIB_H
#define GNUNET_TESTING_NG_LIB_H
+#include "gnunet_util_lib.h"
#include "gnunet_scheduler_lib.h"
@@ -760,4 +761,18 @@ struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_hello_world (const char *label,
char *message);
+/**
+ * Offer data from trait
+ *
+ * @param cmd command to extract the url from.
+ * @param pt which url is to be picked, in case
+ * multiple are offered.
+ * @param[out] url where to write the url.
+ * @return #GNUNET_OK on success.
+ */
+int
+GNUNET_TESTING_get_trait_what_am_i (const struct
+ GNUNET_TESTING_Command *cmd,
+ char *what_am_i);
+
#endif
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 724c09c7a..993777de6 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -30,12 +30,6 @@
#include "gnunet_testing_ng_lib.h"
/**
- * Pipe used to communicate child death via signal.
- * Must be global, as used in signal handler!
- */
-static struct GNUNET_DISK_PipeHandle *sigpipe;
-
-/**
* Lookup command by label.
*
* @param is interpreter state to search
@@ -243,7 +237,7 @@ interpreter_run (void *cls)
*
* @param cls the interpreter state.
*/
-static void
+/*static void
do_shutdown (void *cls)
{
struct GNUNET_TESTING_Interpreter *is = cls;
@@ -274,145 +268,8 @@ do_shutdown (void *cls)
GNUNET_SCHEDULER_cancel (is->timeout_task);
is->timeout_task = NULL;
}
- if (NULL != is->child_death_task)
- {
- GNUNET_SCHEDULER_cancel (is->child_death_task);
- is->child_death_task = NULL;
- }
GNUNET_free (is->commands);
-}
-
-
-/**
- * Function run when the test terminates (good or bad) with timeout.
- *
- * @param cls NULL
- */
-static void
-do_timeout (void *cls)
-{
- struct GNUNET_TESTING_Interpreter *is = cls;
-
- is->timeout_task = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Terminating test due to timeout\n");
- GNUNET_SCHEDULER_shutdown ();
-}
-
-
-/**
- * Task triggered whenever we receive a SIGCHLD (child
- * process died).
- *
- * @param cls closure
- */
-static void
-maint_child_death (void *cls)
-{
- struct GNUNET_TESTING_Interpreter *is = cls;
- struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
- const struct GNUNET_DISK_FileHandle *pr;
- struct GNUNET_OS_Process **processp;
- char c[16];
- enum GNUNET_OS_ProcessStatusType type;
- unsigned long code;
-
- if (GNUNET_TESTING_cmd_is_batch (cmd))
- {
- struct GNUNET_TESTING_Command *batch_cmd;
-
- GNUNET_assert (GNUNET_OK ==
- GNUNET_TESTING_get_trait_cmd (cmd,
- 0,
- &batch_cmd));
- cmd = batch_cmd;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got SIGCHLD for `%s'.\n",
- cmd->label);
- is->child_death_task = NULL;
- pr = GNUNET_DISK_pipe_handle (sigpipe,
- GNUNET_DISK_PIPE_END_READ);
- GNUNET_break (0 <
- GNUNET_DISK_file_read (pr,
- &c,
- sizeof (c)));
- if (GNUNET_OK !=
- GNUNET_TESTING_get_trait_process (cmd,
- 0,
- &processp))
- {
- GNUNET_break (0);
- GNUNET_TESTING_interpreter_fail (is);
- return;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got the dead child process handle, waiting for termination ...\n");
- GNUNET_OS_process_wait_status (*processp,
- &type,
- &code);
- GNUNET_OS_process_destroy (*processp);
- *processp = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "... definitively terminated\n");
- switch (type)
- {
- case GNUNET_OS_PROCESS_UNKNOWN:
- GNUNET_break (0);
- GNUNET_TESTING_interpreter_fail (is);
- return;
- case GNUNET_OS_PROCESS_RUNNING:
- GNUNET_break (0);
- GNUNET_TESTING_interpreter_fail (is);
- return;
- case GNUNET_OS_PROCESS_STOPPED:
- GNUNET_break (0);
- GNUNET_TESTING_interpreter_fail (is);
- return;
- case GNUNET_OS_PROCESS_EXITED:
- if (0 != code)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Process exited with unexpected status %u\n",
- (unsigned int) code);
- GNUNET_TESTING_interpreter_fail (is);
- return;
- }
- break;
- case GNUNET_OS_PROCESS_SIGNALED:
- GNUNET_break (0);
- GNUNET_TESTING_interpreter_fail (is);
- return;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dead child, go on with next command.\n");
- GNUNET_TESTING_interpreter_next (is);
-}
-
-
-/**
- * Wait until we receive SIGCHLD signal.
- * Then obtain the process trait of the current
- * command, wait on the the zombie and continue
- * with the next command.
- */
-void
-GNUNET_TESTING_wait_for_sigchld (struct GNUNET_TESTING_Interpreter *is)
-{
- const struct GNUNET_DISK_FileHandle *pr;
-
- GNUNET_assert (NULL == is->child_death_task);
- pr = GNUNET_DISK_pipe_handle (sigpipe,
- GNUNET_DISK_PIPE_END_READ);
- is->child_death_task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- pr,
- &maint_child_death,
- is);
-}
+}*/
/**
@@ -425,228 +282,25 @@ GNUNET_TESTING_wait_for_sigchld (struct GNUNET_TESTING_Interpreter *is)
* @param commands the list of command to execute
* @param timeout how long to wait
*/
-void
-GNUNET_TESTING_run2 (struct GNUNET_TESTING_Interpreter *is,
- struct GNUNET_TESTING_Command *commands,
- struct GNUNET_TIME_Relative timeout)
+int
+GNUNET_TESTING_run (const char *cfg_filename,
+ struct GNUNET_TESTING_Command *commands,
+ struct GNUNET_TIME_Relative timeout)
{
unsigned int i;
- if (NULL != is->timeout_task)
- {
- GNUNET_SCHEDULER_cancel (is->timeout_task);
- is->timeout_task = NULL;
- }
/* get the number of commands */
for (i = 0; NULL != commands[i].label; i++)
;
- is->commands = GNUNET_new_array (i + 1,
- struct GNUNET_TESTING_Command);
- memcpy (is->commands,
- commands,
- sizeof (struct GNUNET_TESTING_Command) * i);
- is->timeout_task = GNUNET_SCHEDULER_add_delayed
+
+
+ /*is->timeout_task = GNUNET_SCHEDULER_add_delayed
(timeout,
&do_timeout,
is);
GNUNET_SCHEDULER_add_shutdown (&do_shutdown, is);
- is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is);
-}
-
-
-/**
- * Run the testsuite. Note, CMDs are copied into
- * the interpreter state because they are _usually_
- * defined into the "run" method that returns after
- * having scheduled the test interpreter.
- *
- * @param is the interpreter state
- * @param commands the list of command to execute
- */
-void
-GNUNET_TESTING_run (struct GNUNET_TESTING_Interpreter *is,
- struct GNUNET_TESTING_Command *commands)
-{
- GNUNET_TESTING_run2 (is,
- commands,
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES,
- 5));
-}
-
-
-/**
- * Information used by the wrapper around the main
- * "run" method.
- */
-struct MainContext
-{
- /**
- * Main "run" method.
- */
- GNUNET_TESTING_Main main_cb;
-
- /**
- * Closure for @e main_cb.
- */
- void *main_cb_cls;
-
- /**
- * Interpreter state.
- */
- struct GNUNET_TESTING_Interpreter *is;
-};
-
-
-/**
- * Signal handler called for SIGCHLD. Triggers the
- * respective handler by writing to the trigger pipe.
- */
-static void
-sighandler_child_death (void)
-{
- static char c;
- int old_errno = errno; /* back-up errno */
-
- GNUNET_break (1 == GNUNET_DISK_file_write
- (GNUNET_DISK_pipe_handle (sigpipe,
- GNUNET_DISK_PIPE_END_WRITE),
- &c, sizeof (c)));
- errno = old_errno; /* restore errno */
-}
-
-
-/**
- * Initialize scheduler loop and curl context for the testcase,
- * and responsible to run the "run" method.
- *
- * @param cls closure, typically the "run" method, the
- * interpreter state and a closure for "run".
- */
-static void
-main_wrapper_exchange_agnostic (void *cls)
-{
- struct MainContext *main_ctx = cls;
-
- main_ctx->main_cb (main_ctx->main_cb_cls,
- main_ctx->is);
-}
-
-
-/**
- * Function run when the test is aborted before we launch the actual
- * interpreter. Cleans up our state.
- *
- * @param cls the main context
- */
-static void
-do_abort (void *cls)
-{
- struct MainContext *main_ctx = cls;
- struct GNUNET_TESTING_Interpreter *is = main_ctx->is;
-
- is->timeout_task = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Executing abort prior to interpreter launch\n");
-}
-
-
-/**
- * Initialize scheduler loop and curl context for the testcase,
- * and responsible to run the "run" method.
- *
- * @param cls a `struct MainContext *`
- */
-static void
-main_wrapper_exchange_connect (void *cls)
-{
- struct MainContext *main_ctx = cls;
- struct GNUNET_TESTING_Interpreter *is = main_ctx->is;
- char *exchange_url;
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (is->cfg,
- "exchange",
- "BASE_URL",
- &exchange_url))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "BASE_URL");
- return;
- }
- is->timeout_task = GNUNET_SCHEDULER_add_shutdown (&do_abort,
- main_ctx);
- is->working = GNUNET_YES;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Starting main test loop\n");
- main_ctx->main_cb (main_ctx->main_cb_cls,
- is);
-}
-
-
-/**
- * Install signal handlers plus schedules the main wrapper
- * around the "run" method.
- *
- * @param main_cb the "run" method which contains all the
- * commands.
- * @param main_cb_cls a closure for "run", typically NULL.
- * @param cfg configuration to use
- * @param exchanged exchange process handle: will be put in the
- * state as some commands - e.g. revoke - need to send
- * signal to it, for example to let it know to reload the
- * key state.. if NULL, the interpreter will run without
- * trying to connect to the exchange first.
- * @param exchange_connect #GNUNET_YES if the test should connect
- * to the exchange, #GNUNET_NO otherwise
- * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
- * non-GNUNET_OK codes are #GNUNET_SYSERR most of the
- * times.
- */
-int
-GNUNET_TESTING_setup (GNUNET_TESTING_Main main_cb,
- void *main_cb_cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_OS_Process *exchanged,
- int exchange_connect)
-{
- struct GNUNET_TESTING_Interpreter is;
- struct MainContext main_ctx = {
- .main_cb = main_cb,
- .main_cb_cls = main_cb_cls,
- /* needed to init the curl ctx */
- .is = &is,
- };
- struct GNUNET_SIGNAL_Context *shc_chld;
-
- memset (&is,
- 0,
- sizeof (is));
- is.exchanged = exchanged;
- is.cfg = cfg;
- sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE);
- GNUNET_assert (NULL != sigpipe);
- shc_chld = GNUNET_SIGNAL_handler_install
- (GNUNET_SIGCHLD,
- &sighandler_child_death);
-
-
- /* Blocking */
- if (GNUNET_YES == exchange_connect)
- GNUNET_SCHEDULER_run (&main_wrapper_exchange_connect,
- &main_ctx);
- else
- GNUNET_SCHEDULER_run (&main_wrapper_exchange_agnostic,
- &main_ctx);
- if (NULL != is.final_cleanup_cb)
- is.final_cleanup_cb (is.final_cleanup_cb_cls);
- GNUNET_SIGNAL_handler_uninstall (shc_chld);
- GNUNET_DISK_pipe_close (sigpipe);
- sigpipe = NULL;
- GNUNET_free (is.auditor_url);
- GNUNET_free (is.exchange_url);
- return is.result;
+ is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is);*/
+ return GNUNET_OK;
}