summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-10-08 21:50:34 +0200
committerChristian Grothoff <christian@grothoff.org>2021-10-08 21:50:34 +0200
commitbd8f79f628b254f4f02c08284ba65d23486d6127 (patch)
tree8729cfd715433db91b0fbb72d0aac164082b7f24 /src
parent6ef071b8ccea72da6a9e1eee6483c326b6ebc082 (diff)
-clean up testing-NG finish logic
Diffstat (limited to 'src')
-rw-r--r--src/dhtu/testing_dhtu_cmd_send.c60
-rw-r--r--src/include/gnunet_testing_ng_lib.h81
-rw-r--r--src/testing/testing_api_cmd_block_until_all_peers_started.c56
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c57
-rw-r--r--src/testing/testing_api_cmd_finish.c112
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c34
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c62
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c31
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem_v2.c8
-rw-r--r--src/testing/testing_api_cmd_netjail_start_v2.c55
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c45
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_v2.c64
-rw-r--r--src/testing/testing_api_loop.c53
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c49
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v2.c24
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v3.c48
-rw-r--r--src/transport/transport_api_cmd_start_peer.c42
-rw-r--r--src/transport/transport_api_cmd_start_peer_v2.c1
-rw-r--r--src/transport/transport_api_cmd_start_peer_v3.c1
19 files changed, 288 insertions, 595 deletions
diff --git a/src/dhtu/testing_dhtu_cmd_send.c b/src/dhtu/testing_dhtu_cmd_send.c
index 129a31205..e620e329e 100644
--- a/src/dhtu/testing_dhtu_cmd_send.c
+++ b/src/dhtu/testing_dhtu_cmd_send.c
@@ -34,16 +34,10 @@ struct SendState
{
/**
- * Function to call when done.
+ * Mandatory context for async commands.
*/
- GNUNET_SCHEDULER_TaskCallback cont;
+ struct GNUNET_TESTING_AsyncContext ac;
- /**
- * Closure for @e cont.
- */
- void *cont_cls;
-
- enum GNUNET_GenericReturnValue finished;
};
@@ -98,56 +92,10 @@ send_run (void *cls,
GNUNET_TESTING_get_trait_XXX (other_cmd,
&data);
#endif
- ss->finished = GNUNET_OK;
+ GNUNET_TESTING_async_finish (&ss->ac);
}
-/**
- * This function checks the flag NetJailState#finished, if this cmd finished.
- *
- * @param cls a `struct SendState`
- * @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
- */
-static enum GNUNET_GenericReturnValue
-send_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- struct SendState *ss = cls;
-
- switch (ss->finished)
- {
- case GNUNET_OK:
- cont (cont_cls);
- break;
- case GNUNET_SYSERR:
- GNUNET_break (0);
- break;
- case GNUNET_NO:
- if (NULL != ss->cont)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- ss->cont = cont;
- ss->cont_cls = cont_cls;
- break;
- }
- return ss->finished;
-}
-
-
-/**
- * Create 'send' command.
- *
- * @param label name for command.
- * @return command.
- */
struct GNUNET_TESTING_Command
GNUNET_TESTING_DHTU_cmd_send (const char *label)
{
@@ -160,7 +108,7 @@ GNUNET_TESTING_DHTU_cmd_send (const char *label)
.cls = ss,
.label = label,
.run = &send_run,
- .finish = &send_finish,
+ .ac = &ss->ac,
.cleanup = &send_cleanup,
.traits = &send_traits
};
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 4ef9aac18..0cab64504 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -82,7 +82,7 @@ enum GNUNET_TESTING_NODE_TYPE
};
- // FIXME: this does not belong here!
+// FIXME: this does not belong here!
struct GNUNET_TESTING_ADDRESS_PREFIX
{
/**
@@ -261,6 +261,36 @@ struct GNUNET_TESTING_NetjailTopology
struct GNUNET_TESTING_Interpreter;
/**
+ * State each asynchronous command must have in its closure.
+ */
+struct GNUNET_TESTING_AsyncContext
+{
+
+ /**
+ * 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;
+
+ /**
+ * Indication if the command finished (#GNUNET_OK).
+ * #GNUNET_NO if it is still running,
+ * #GNUNET_SYSERR if it failed.
+ */
+ enum GNUNET_GenericReturnValue finished;
+};
+
+
+/**
* A command to be run by the interpreter.
*/
struct GNUNET_TESTING_Command
@@ -296,27 +326,14 @@ struct GNUNET_TESTING_Command
struct GNUNET_TESTING_Interpreter *is);
/**
- * FIXME: logic is basically always the same!
- * => Refactor API to avoid duplication!
+ * Pointer to the asynchronous context in the command's
+ * closure. Used by the
+ * #GNUNET_TESTING_async_finish() and
+ * #GNUNET_TESTING_async_fail() functions.
*
- * Wait for any asynchronous execution of @e run to conclude,
- * then call finish_cont. Finish may only be called once per 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
+ * Must be NULL if a command is synchronous.
*/
- enum GNUNET_GenericReturnValue
- (*finish)(void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls);
+ struct GNUNET_TESTING_AsyncContext *ac;
/**
* Clean up after the command. Run during forced termination
@@ -328,11 +345,8 @@ struct GNUNET_TESTING_Command
(*cleanup)(void *cls);
/**
- * FIXME: logic is often the same!
- * => Think about refactoring API to reduce duplication!
- *
* Extract information from a command that is useful for other
- * commands.
+ * commands. Can be NULL if a command has no traits.
*
* @param cls closure
* @param[out] ret result (could be anything)
@@ -428,6 +442,24 @@ GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is);
/**
+ * The asynchronous command of @a ac has failed.
+ *
+ * @param ac command-specific context
+ */
+void
+GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac);
+
+
+/**
+ * The asynchronous command of @a ac has finished.
+ *
+ * @param ac command-specific context
+ */
+void
+GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac);
+
+
+/**
* Create command array terminator.
*
* @return a end-command.
@@ -1116,7 +1148,6 @@ GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label,
const char *topology_config);
-
// FIXME: document!
enum GNUNET_GenericReturnValue
GNUNET_TESTING_get_trait_helper_handles (const struct
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
@@ -47,20 +47,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.
*
*/
@@ -87,27 +73,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.
*
* @param label name for 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,27 +40,12 @@ 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.
*
*/
@@ -87,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->stop_blocking;
-
- if (GNUNET_YES == *ret)
- {
- cont (cont_cls);
- }
-
- return *ret;
-}
-
-
-/**
* Create command.
*
* @param label name for 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
@@ -48,34 +48,23 @@ 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.
*
@@ -55,20 +56,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.
*
*/
@@ -105,23 +92,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.
*
* @param label name for 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);
@@ -88,20 +92,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,
@@ -177,25 +169,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.
*
* @param label name for 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
@@ -62,6 +62,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
@@ -62,6 +62,11 @@ struct HelperMessage
struct NetJailState
{
/**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
* The complete topology information.
*/
struct GNUNET_TESTING_NetjailTopology *topology;
@@ -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;
@@ -86,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.
*
*/
@@ -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;
}
@@ -193,29 +184,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.
*
* @param label name for 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
@@ -40,6 +40,11 @@ static struct GNUNET_ChildWaitHandle *cwh;
struct NetJailState
{
/**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
* Configuration file for the test topology.
*/
char *topology_config;
@@ -49,8 +54,6 @@ struct NetJailState
*/
struct GNUNET_OS_Process *stop_proc;
- // Flag indication if the script finished.
- enum GNUNET_GenericReturnValue finished;
};
@@ -82,20 +85,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 */
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index ddf1c3872..82194ff15 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -42,6 +42,11 @@
*/
struct ConnectPeersState
{
+ /**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
// Label of the cmd which started the test system.
const char *create_label;
@@ -183,6 +188,7 @@ connect_peers_run (void *cls,
* The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer.
*
*/
+// FIXME: this needs a complete rewrite!
static int
connect_peers_finish (void *cls,
GNUNET_SCHEDULER_TaskCallback cont,
@@ -222,20 +228,6 @@ connect_peers_finish (void *cls,
/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-connect_peers_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.
*
*/
@@ -249,13 +241,6 @@ connect_peers_cleanup (void *cls)
}
-/**
- * Create command.
- *
- * @param label name for command.
- * @param start_peer_label Label of the cmd to start a peer.
- * @return command.
- */
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
const char *start_peer_label,
@@ -269,15 +254,15 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
cps->num = num;
cps->create_label = create_label;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = cps,
- .label = label,
- .run = &connect_peers_run,
- .finish = &connect_peers_finish,
- .cleanup = &connect_peers_cleanup,
- .traits = &connect_peers_traits
- };
-
- return cmd;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = cps,
+ .label = label,
+ .run = &connect_peers_run,
+ .ac = &cps->ac,
+ .cleanup = &connect_peers_cleanup
+ };
+
+ return cmd;
+ }
}
diff --git a/src/transport/transport_api_cmd_connecting_peers_v2.c b/src/transport/transport_api_cmd_connecting_peers_v2.c
index 8ef556946..8d0f74916 100644
--- a/src/transport/transport_api_cmd_connecting_peers_v2.c
+++ b/src/transport/transport_api_cmd_connecting_peers_v2.c
@@ -44,6 +44,11 @@
*/
struct ConnectPeersState
{
+ /**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
// Label of the cmd which started the test system.
const char *create_label;
@@ -185,20 +190,6 @@ connect_peers_finish (void *cls,
/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-connect_peers_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.
*
*/
@@ -237,9 +228,8 @@ GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
.cls = cps,
.label = label,
.run = &connect_peers_run,
- .finish = &connect_peers_finish,
- .cleanup = &connect_peers_cleanup,
- .traits = &connect_peers_traits
+ .ac = &cps->ac,
+ .cleanup = &connect_peers_cleanup
};
return cmd;
diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c
index a73d81064..ae32a087a 100644
--- a/src/transport/transport_api_cmd_connecting_peers_v3.c
+++ b/src/transport/transport_api_cmd_connecting_peers_v3.c
@@ -59,6 +59,11 @@
struct ConnectPeersState
{
/**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
* The testing system of this node.
*/
struct GNUNET_TESTING_System *tl_system;
@@ -448,20 +453,6 @@ connect_peers_finish (void *cls,
/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-connect_peers_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.
*
*/
@@ -475,13 +466,6 @@ connect_peers_cleanup (void *cls)
}
-/**
- * Create command.
- *
- * @param label name for command.
- * @param start_peer_label Label of the cmd to start a peer.
- * @return command.
- */
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
const char *start_peer_label,
@@ -498,15 +482,15 @@ GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
cps->create_label = create_label;
cps->topology = topology;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = cps,
- .label = label,
- .run = &connect_peers_run,
- .finish = &connect_peers_finish,
- .cleanup = &connect_peers_cleanup,
- .traits = &connect_peers_traits
- };
-
- return cmd;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = cps,
+ .label = label,
+ .run = &connect_peers_run,
+ .ac = &cps->ac,
+ .cleanup = &connect_peers_cleanup
+ };
+
+ return cmd;
+ }
}
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index 8a53ed22c..44fc68807 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -51,6 +51,7 @@ hello_iter_cb (void *cb_cls,
const char *emsg)
{
struct StartPeerState *sps = cb_cls;
+
if (NULL == record)
{
sps->pic = NULL;
@@ -90,26 +91,6 @@ retrieve_hello (void *cls)
/**
- * This function checks StartPeerState#finished, which is set when the hello was retrieved.
- *
- */
-static int
-start_peer_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- struct StartPeerState *sps = cls;
-
- if (GNUNET_YES == sps->finished)
- {
- cont (cont_cls);
- }
-
- return sps->finished;
-}
-
-
-/**
* Disconnect callback for the connection to the core service.
*
*/
@@ -597,14 +578,15 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
i * sizeof(struct GNUNET_MQ_MessageHandler));
}
- struct GNUNET_TESTING_Command cmd = {
- .cls = sps,
- .label = label,
- .run = &start_peer_run,
- .finish = &start_peer_finish,
- .cleanup = &start_peer_cleanup,
- .traits = &start_peer_traits
- };
-
- return cmd;
+ {
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = sps,
+ .label = label,
+ .run = &start_peer_run,
+ .cleanup = &start_peer_cleanup,
+ .traits = &start_peer_traits
+ };
+
+ return cmd;
+ }
}
diff --git a/src/transport/transport_api_cmd_start_peer_v2.c b/src/transport/transport_api_cmd_start_peer_v2.c
index 2ab58574a..94799eddd 100644
--- a/src/transport/transport_api_cmd_start_peer_v2.c
+++ b/src/transport/transport_api_cmd_start_peer_v2.c
@@ -597,7 +597,6 @@ GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label,
.cls = sps,
.label = label,
.run = &start_peer_run,
- .finish = &start_peer_finish,
.cleanup = &start_peer_cleanup,
.traits = &start_peer_traits
};
diff --git a/src/transport/transport_api_cmd_start_peer_v3.c b/src/transport/transport_api_cmd_start_peer_v3.c
index fa6300ef5..1a19ce60e 100644
--- a/src/transport/transport_api_cmd_start_peer_v3.c
+++ b/src/transport/transport_api_cmd_start_peer_v3.c
@@ -609,7 +609,6 @@ GNUNET_TRANSPORT_cmd_start_peer_v3 (const char *label,
.cls = sps,
.label = label,
.run = &start_peer_run,
- .finish = &start_peer_finish,
.cleanup = &start_peer_cleanup,
.traits = &start_peer_traits
};