aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 = \
74 test_testing_servicestartup 74 test_testing_servicestartup
75endif 75endif
76 76
77test_testing_helloworld_SOURCES = \ 77test_testing_hello_world_SOURCES = \
78 test_testing_hello_world 78 test_testing_hello_world.c
79test_testing_portreservation_LDADD = \ 79test_testing_hello_world_LDADD = \
80 libgnunettesting.la \ 80 libgnunettesting.la \
81 $(top_builddir)/src/util/libgnunetutil.la 81 $(top_builddir)/src/util/libgnunetutil.la
82 82
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 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
28 29
29/** 30/**
30 * Main function that will tell the interpreter what commands to 31 * Main function to run the test cases.
31 * run. 32 *
33 * @param cls not used.
32 * 34 *
33 * @param cls closure
34 */ 35 */
35static void 36static void
36run (void *cls, 37run (void *cls)
37 struct GNUNET_TESTING_Interpreter *is)
38{ 38{
39 (void *) cls;
39 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 40 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
40 41
41 struct GNUNET_TESTING_Command commands[] = { 42 struct GNUNET_TESTING_Command commands[] = {
42 GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0", 43 GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0",
43 &now), 44 &now),
44 GNUNET_TESTING_cmd_hello_world ("hello-world-0",""), 45 GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""),
45 GNUNET_TESTING_cmd_end () 46 GNUNET_TESTING_cmd_end ()
46 }; 47 };
47 48
48 GNUNET_TESTING_run (is, 49 GNUNET_TESTING_run (NULL,
49 commands, 50 commands,
50 GNUNET_TIME_UNIT_FOREVER_REL); 51 GNUNET_TIME_UNIT_FOREVER_REL);
51} 52}
52 53
53
54int 54int
55main (int argc, 55main (int argc,
56 char *const *argv) 56 char *const *argv)
57{ 57{
58 return GNUNET_TESTING_setup (&run, 58 int rv = 0;
59 NULL, 59
60 NULL, 60 GNUNET_log_setup ("test-hello-world",
61 NULL, 61 "DEBUG",
62 GNUNET_NO); 62 NULL);
63
64 GNUNET_SCHEDULER_run (&run,
65 NULL);
66
67 return rv;
63} 68}
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 @@
29struct HelloWorldState 29struct HelloWorldState
30{ 30{
31 char *message; 31 char *message;
32 const char *birthLabel;
32}; 33};
33 34
34/** 35/**
@@ -43,7 +44,7 @@ hello_world_cleanup (void *cls,
43{ 44{
44 struct HelloWorldState *hs = cls; 45 struct HelloWorldState *hs = cls;
45 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 46 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
46 "Cleaning up message %s", 47 "Cleaning up message %s\n",
47 hs->message); 48 hs->message);
48} 49}
49 50
@@ -78,11 +79,17 @@ hello_world_run (void *cls,
78 struct GNUNET_TESTING_Interpreter *is) 79 struct GNUNET_TESTING_Interpreter *is)
79{ 80{
80 struct HelloWorldState *hs = cls; 81 struct HelloWorldState *hs = cls;
82 const struct GNUNET_TESTING_Command *birth_cmd;
83
84 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
85 "%s\n",
86 hs->message);
87 birth_cmd = GNUNET_TESTING_interpreter_lookup_command (hs->birthLabel);
88 GNUNET_TESTING_get_trait_what_am_i (birth_cmd, &hs->message);
81 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 89 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
82 "%s", 90 "Now I am a %s\n",
83 hs->message); 91 hs->message);
84 GNUNET_TESTING_get_trait_what_am_i (cmd, 92 GNUNET_TESTING_interpreter_next (is);
85 hs->message);
86} 93}
87 94
88/** 95/**
@@ -94,12 +101,14 @@ hello_world_run (void *cls,
94 */ 101 */
95struct GNUNET_TESTING_Command 102struct GNUNET_TESTING_Command
96GNUNET_TESTING_cmd_hello_world (const char *label, 103GNUNET_TESTING_cmd_hello_world (const char *label,
104 const char *birthLabel,
97 char *message) 105 char *message)
98{ 106{
99 struct HelloWorldState *hs; 107 struct HelloWorldState *hs;
100 108
101 hs = GNUNET_new (struct HelloWorldState); 109 hs = GNUNET_new (struct HelloWorldState);
102 hs->message = "Hello World, I am nobody!"; 110 hs->message = "Hello World, I was nobody!";
111 hs->birthLabel = birthLabel;
103 112
104 struct GNUNET_TESTING_Command cmd = { 113 struct GNUNET_TESTING_Command cmd = {
105 .cls = hs, 114 .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,
45{ 45{
46 struct HelloWorldBirthState *hbs = cls; 46 struct HelloWorldBirthState *hbs = cls;
47 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 47 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
48 "Finished birth of %s", 48 "Finished birth of %s\n",
49 hbs->what_am_i); 49 hbs->what_am_i);
50} 50}
51 51
@@ -65,11 +65,13 @@ hello_world_birth_traits (void *cls,
65 unsigned int index) 65 unsigned int index)
66{ 66{
67 struct HelloWorldBirthState *hbs = cls; 67 struct HelloWorldBirthState *hbs = cls;
68 const char *what_am_i = hbs->what_am_i;
69
68 struct GNUNET_TESTING_Trait traits[] = { 70 struct GNUNET_TESTING_Trait traits[] = {
69 { 71 {
70 .index = 0, 72 .index = 0,
71 .trait_name = "what_am_i", 73 .trait_name = "what_am_i",
72 .ptr = (const void *) hbs->what_am_i, 74 .ptr = (const void *) what_am_i,
73 }, 75 },
74 GNUNET_TESTING_trait_end () 76 GNUNET_TESTING_trait_end ()
75 }; 77 };
@@ -100,16 +102,17 @@ hello_world_birth_run (void *cls,
100 102
101 if (0 == relativ.rel_value_us % 10) 103 if (0 == relativ.rel_value_us % 10)
102 { 104 {
103 hbs->what_am_i = "Hello World, I am a creature!"; 105 hbs->what_am_i = "creature!";
104 } 106 }
105 else if (0 == relativ.rel_value_us % 2) 107 else if (0 == relativ.rel_value_us % 2)
106 { 108 {
107 hbs->what_am_i = "Hello World, I am a girl!"; 109 hbs->what_am_i = "girl!";
108 } 110 }
109 else 111 else
110 { 112 {
111 hbs->what_am_i = "Hello World, I am a boy!"; 113 hbs->what_am_i = "boy!";
112 } 114 }
115 GNUNET_TESTING_interpreter_next (is);
113} 116}
114 117
115/** 118/**
@@ -122,9 +125,8 @@ hello_world_birth_run (void *cls,
122 * @return #GNUNET_OK on success. 125 * @return #GNUNET_OK on success.
123 */ 126 */
124int 127int
125GNUNET_TESTING_get_trait_what_am_i (const struct 128GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd,
126 GNUNET_TESTING_Command *cmd, 129 char **what_am_i)
127 char *what_am_i)
128{ 130{
129 return cmd->traits (cmd->cls, 131 return cmd->traits (cmd->cls,
130 (const void **) what_am_i, 132 (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 @@
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30#include "gnunet_testing_ng_lib.h" 30#include "gnunet_testing_ng_lib.h"
31 31
32struct GNUNET_TESTING_Interpreter *is;
33
32/** 34/**
33 * Lookup command by label. 35 * Lookup command by label.
34 * 36 *
35 * @param is interpreter state to search
36 * @param label label to look for 37 * @param label label to look for
37 * @return NULL if command was not found 38 * @return NULL if command was not found
38 */ 39 */
39const struct GNUNET_TESTING_Command * 40const struct GNUNET_TESTING_Command *
40GNUNET_TESTING_interpreter_lookup_command (struct 41GNUNET_TESTING_interpreter_lookup_command (const char *label)
41 GNUNET_TESTING_Interpreter *is,
42 const char *label)
43{ 42{
44 if (NULL == label) 43 if (NULL == label)
45 { 44 {
@@ -203,7 +202,7 @@ GNUNET_TESTING_interpreter_get_current_label (struct
203static void 202static void
204interpreter_run (void *cls) 203interpreter_run (void *cls)
205{ 204{
206 struct GNUNET_TESTING_Interpreter *is = cls; 205 (void) cls;
207 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; 206 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
208 207
209 is->task = NULL; 208 is->task = NULL;
@@ -237,10 +236,10 @@ interpreter_run (void *cls)
237 * 236 *
238 * @param cls the interpreter state. 237 * @param cls the interpreter state.
239 */ 238 */
240/*static void 239static void
241do_shutdown (void *cls) 240do_shutdown (void *cls)
242{ 241{
243 struct GNUNET_TESTING_Interpreter *is = cls; 242 (void) cls;
244 struct GNUNET_TESTING_Command *cmd; 243 struct GNUNET_TESTING_Command *cmd;
245 const char *label; 244 const char *label;
246 245
@@ -269,7 +268,24 @@ do_shutdown (void *cls)
269 is->timeout_task = NULL; 268 is->timeout_task = NULL;
270 } 269 }
271 GNUNET_free (is->commands); 270 GNUNET_free (is->commands);
272}*/ 271}
272
273
274/**
275 * Function run when the test terminates (good or bad) with timeout.
276 *
277 * @param cls NULL
278 */
279static void
280do_timeout (void *cls)
281{
282 (void) cls;
283
284 is->timeout_task = NULL;
285 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
286 "Terminating test due to timeout\n");
287 GNUNET_SCHEDULER_shutdown ();
288}
273 289
274 290
275/** 291/**
@@ -289,17 +305,28 @@ GNUNET_TESTING_run (const char *cfg_filename,
289{ 305{
290 unsigned int i; 306 unsigned int i;
291 307
308 is = GNUNET_new (struct GNUNET_TESTING_Interpreter);
309
310 if (NULL != is->timeout_task)
311 {
312 GNUNET_SCHEDULER_cancel (is->timeout_task);
313 is->timeout_task = NULL;
314 }
292 /* get the number of commands */ 315 /* get the number of commands */
293 for (i = 0; NULL != commands[i].label; i++) 316 for (i = 0; NULL != commands[i].label; i++)
294 ; 317 ;
318 is->commands = GNUNET_new_array (i + 1,
319 struct GNUNET_TESTING_Command);
320 memcpy (is->commands,
321 commands,
322 sizeof (struct GNUNET_TESTING_Command) * i);
295 323
296 324 is->timeout_task = GNUNET_SCHEDULER_add_delayed
297 /*is->timeout_task = GNUNET_SCHEDULER_add_delayed
298 (timeout, 325 (timeout,
299 &do_timeout, 326 &do_timeout,
300 is); 327 is);
301 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, is); 328 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, is);
302 is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is);*/ 329 is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is);
303 return GNUNET_OK; 330 return GNUNET_OK;
304} 331}
305 332