summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_loop.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-03-15 10:45:45 +0100
committert3sserakt <t3ss@posteo.de>2021-03-15 10:45:45 +0100
commita550f7863bff0792c8972609869d409b77efc1dd (patch)
tree3e176423be8a3bdafb16d8891ebc3befc7fe3ffe /src/testing/testing_api_loop.c
parentb47586e76bc4f3c2c4ab6829028b5dd2f03e702d (diff)
- added hello world test with command style
Diffstat (limited to 'src/testing/testing_api_loop.c')
-rw-r--r--src/testing/testing_api_loop.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 993777de6..f29329a60 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -29,17 +29,16 @@
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+struct GNUNET_TESTING_Interpreter *is;
+
/**
* Lookup command by label.
*
- * @param is interpreter state to search
* @param label label to look for
* @return NULL if command was not found
*/
const struct GNUNET_TESTING_Command *
-GNUNET_TESTING_interpreter_lookup_command (struct
- GNUNET_TESTING_Interpreter *is,
- const char *label)
+GNUNET_TESTING_interpreter_lookup_command (const char *label)
{
if (NULL == label)
{
@@ -203,7 +202,7 @@ GNUNET_TESTING_interpreter_get_current_label (struct
static void
interpreter_run (void *cls)
{
- struct GNUNET_TESTING_Interpreter *is = cls;
+ (void) cls;
struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
is->task = NULL;
@@ -237,10 +236,10 @@ interpreter_run (void *cls)
*
* @param cls the interpreter state.
*/
-/*static void
+static void
do_shutdown (void *cls)
{
- struct GNUNET_TESTING_Interpreter *is = cls;
+ (void) cls;
struct GNUNET_TESTING_Command *cmd;
const char *label;
@@ -269,7 +268,24 @@ do_shutdown (void *cls)
is->timeout_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)
+{
+ (void) cls;
+
+ is->timeout_task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Terminating test due to timeout\n");
+ GNUNET_SCHEDULER_shutdown ();
+}
/**
@@ -289,17 +305,28 @@ GNUNET_TESTING_run (const char *cfg_filename,
{
unsigned int i;
+ is = GNUNET_new (struct GNUNET_TESTING_Interpreter);
+
+ 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);*/
+ is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is);
return GNUNET_OK;
}