summaryrefslogtreecommitdiff
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
parentb47586e76bc4f3c2c4ab6829028b5dd2f03e702d (diff)
- added hello world test with command style
-rw-r--r--src/testing/Makefile.am6
-rw-r--r--src/testing/test_testing_hello_world.c31
-rw-r--r--src/testing/testing_api_cmd_hello_world.c19
-rw-r--r--src/testing/testing_api_cmd_hello_world_birth.c18
-rw-r--r--src/testing/testing_api_loop.c49
5 files changed, 83 insertions, 40 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index f7aa1f896..33cf62ce7 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -74,9 +74,9 @@ TESTS = \
test_testing_servicestartup
endif
-test_testing_helloworld_SOURCES = \
- test_testing_hello_world
-test_testing_portreservation_LDADD = \
+test_testing_hello_world_SOURCES = \
+ test_testing_hello_world.c
+test_testing_hello_world_LDADD = \
libgnunettesting.la \
$(top_builddir)/src/util/libgnunetutil.la
diff --git a/src/testing/test_testing_hello_world.c b/src/testing/test_testing_hello_world.c
index 2ce7b547d..6300e26a4 100644
--- a/src/testing/test_testing_hello_world.c
+++ b/src/testing/test_testing_hello_world.c
@@ -25,39 +25,44 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_util_lib.h"
/**
- * Main function that will tell the interpreter what commands to
- * run.
+ * Main function to run the test cases.
+ *
+ * @param cls not used.
*
- * @param cls closure
*/
static void
-run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
+run (void *cls)
{
+ (void *) cls;
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
struct GNUNET_TESTING_Command commands[] = {
GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0",
&now),
- GNUNET_TESTING_cmd_hello_world ("hello-world-0",""),
+ GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""),
GNUNET_TESTING_cmd_end ()
};
- GNUNET_TESTING_run (is,
+ GNUNET_TESTING_run (NULL,
commands,
GNUNET_TIME_UNIT_FOREVER_REL);
}
-
int
main (int argc,
char *const *argv)
{
- return GNUNET_TESTING_setup (&run,
- NULL,
- NULL,
- NULL,
- GNUNET_NO);
+ int rv = 0;
+
+ GNUNET_log_setup ("test-hello-world",
+ "DEBUG",
+ NULL);
+
+ GNUNET_SCHEDULER_run (&run,
+ NULL);
+
+ return rv;
}
diff --git a/src/testing/testing_api_cmd_hello_world.c b/src/testing/testing_api_cmd_hello_world.c
index 8aa4a2f1c..8c1d7353d 100644
--- a/src/testing/testing_api_cmd_hello_world.c
+++ b/src/testing/testing_api_cmd_hello_world.c
@@ -29,6 +29,7 @@
struct HelloWorldState
{
char *message;
+ const char *birthLabel;
};
/**
@@ -43,7 +44,7 @@ hello_world_cleanup (void *cls,
{
struct HelloWorldState *hs = cls;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Cleaning up message %s",
+ "Cleaning up message %s\n",
hs->message);
}
@@ -78,11 +79,17 @@ hello_world_run (void *cls,
struct GNUNET_TESTING_Interpreter *is)
{
struct HelloWorldState *hs = cls;
+ const struct GNUNET_TESTING_Command *birth_cmd;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%s\n",
+ hs->message);
+ birth_cmd = GNUNET_TESTING_interpreter_lookup_command (hs->birthLabel);
+ GNUNET_TESTING_get_trait_what_am_i (birth_cmd, &hs->message);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "%s",
+ "Now I am a %s\n",
hs->message);
- GNUNET_TESTING_get_trait_what_am_i (cmd,
- hs->message);
+ GNUNET_TESTING_interpreter_next (is);
}
/**
@@ -94,12 +101,14 @@ hello_world_run (void *cls,
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_hello_world (const char *label,
+ const char *birthLabel,
char *message)
{
struct HelloWorldState *hs;
hs = GNUNET_new (struct HelloWorldState);
- hs->message = "Hello World, I am nobody!";
+ hs->message = "Hello World, I was nobody!";
+ hs->birthLabel = birthLabel;
struct GNUNET_TESTING_Command cmd = {
.cls = hs,
diff --git a/src/testing/testing_api_cmd_hello_world_birth.c b/src/testing/testing_api_cmd_hello_world_birth.c
index 613fc3613..546b30212 100644
--- a/src/testing/testing_api_cmd_hello_world_birth.c
+++ b/src/testing/testing_api_cmd_hello_world_birth.c
@@ -45,7 +45,7 @@ hello_world_birth_cleanup (void *cls,
{
struct HelloWorldBirthState *hbs = cls;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Finished birth of %s",
+ "Finished birth of %s\n",
hbs->what_am_i);
}
@@ -65,11 +65,13 @@ hello_world_birth_traits (void *cls,
unsigned int index)
{
struct HelloWorldBirthState *hbs = cls;
+ const char *what_am_i = hbs->what_am_i;
+
struct GNUNET_TESTING_Trait traits[] = {
{
.index = 0,
.trait_name = "what_am_i",
- .ptr = (const void *) hbs->what_am_i,
+ .ptr = (const void *) what_am_i,
},
GNUNET_TESTING_trait_end ()
};
@@ -100,16 +102,17 @@ hello_world_birth_run (void *cls,
if (0 == relativ.rel_value_us % 10)
{
- hbs->what_am_i = "Hello World, I am a creature!";
+ hbs->what_am_i = "creature!";
}
else if (0 == relativ.rel_value_us % 2)
{
- hbs->what_am_i = "Hello World, I am a girl!";
+ hbs->what_am_i = "girl!";
}
else
{
- hbs->what_am_i = "Hello World, I am a boy!";
+ hbs->what_am_i = "boy!";
}
+ GNUNET_TESTING_interpreter_next (is);
}
/**
@@ -122,9 +125,8 @@ hello_world_birth_run (void *cls,
* @return #GNUNET_OK on success.
*/
int
-GNUNET_TESTING_get_trait_what_am_i (const struct
- GNUNET_TESTING_Command *cmd,
- char *what_am_i)
+GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd,
+ char **what_am_i)
{
return cmd->traits (cmd->cls,
(const void **) what_am_i,
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;
}