aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-10-04 12:15:43 +0200
committerChristian Grothoff <christian@grothoff.org>2021-10-04 12:15:43 +0200
commitf146e80752e73247acb9d6c7463188a82d26a774 (patch)
tree13ed03d817ce04daa133507778ac6a1b71bf147f /src
parent7ecc3a03a0670a1620c603502c9958b95e6dc1d0 (diff)
downloadgnunet-f146e80752e73247acb9d6c7463188a82d26a774.tar.gz
gnunet-f146e80752e73247acb9d6c7463188a82d26a774.zip
-taking a first stab at cleaning up the testing mess
Diffstat (limited to 'src')
-rw-r--r--src/dhtu/Makefile.am15
-rw-r--r--src/dhtu/test_dhtu_ip.c39
-rw-r--r--src/dhtu/testing_dhtu_cmd_send.c170
-rw-r--r--src/include/gnunet_testing_ng_lib.h100
-rw-r--r--src/testing/Makefile.am1
-rw-r--r--src/testing/testing_api_cmd_batch.c22
-rw-r--r--src/testing/testing_api_cmd_block_until_all_peers_started.c4
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c6
-rw-r--r--src/testing/testing_api_cmd_hello_world.c65
-rw-r--r--src/testing/testing_api_cmd_hello_world_birth.c10
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c49
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c47
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c5
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem_v2.c5
-rw-r--r--src/testing/testing_api_cmd_netjail_start_v2.c20
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c49
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c35
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c32
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_v2.c42
-rw-r--r--src/testing/testing_api_cmd_send_peer_ready.c29
-rw-r--r--src/testing/testing_api_cmd_system_create.c4
-rw-r--r--src/testing/testing_api_cmd_system_destroy.c33
-rw-r--r--src/testing/testing_api_loop.c388
-rw-r--r--src/testing/testing_api_trait_cmd.c2
-rw-r--r--src/testing/testing_api_traits.c2
25 files changed, 555 insertions, 619 deletions
diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am
index 61ca84ee3..772bee60a 100644
--- a/src/dhtu/Makefile.am
+++ b/src/dhtu/Makefile.am
@@ -41,6 +41,21 @@ libgnunet_plugin_dhtu_gnunet_la_LDFLAGS = \
41 $(GN_PLUGIN_LDFLAGS) 41 $(GN_PLUGIN_LDFLAGS)
42 42
43 43
44lib_LTLIBRARIES = \
45 libgnunettestingdhtu.la
46
47libgnunettestingdhtu_la_SOURCES = \
48 testing_dhtu_cmd_send.c
49libgnunettestingdhtu_la_LIBADD = \
50 $(top_builddir)/src/testing/libgnunettesting.la \
51 $(top_builddir)/src/util/libgnunetutil.la \
52 $(LTLIBINTL)
53libgnunettestingdhtu_la_LDFLAGS = \
54 $(GN_LIB_LDFLAGS) \
55 -version-info 0:0:0
56
57
58
44test_dhtu_ip_SOURCES = \ 59test_dhtu_ip_SOURCES = \
45 test_dhtu_ip.c 60 test_dhtu_ip.c
46test_dhtu_ip_LDADD = \ 61test_dhtu_ip_LDADD = \
diff --git a/src/dhtu/test_dhtu_ip.c b/src/dhtu/test_dhtu_ip.c
index f350905b8..eb886e994 100644
--- a/src/dhtu/test_dhtu_ip.c
+++ b/src/dhtu/test_dhtu_ip.c
@@ -32,20 +32,9 @@
32#define CONFIG_FILE "test_dhtu_ip.conf" 32#define CONFIG_FILE "test_dhtu_ip.conf"
33 33
34 34
35/** 35int
36 * Return value of the test. 36main (int argc,
37 * 37 char *const *argv)
38 */
39static int rv;
40
41
42/**
43 * Main function to run the test cases.
44 *
45 * @param cls not used.
46 */
47static void
48run (void *cls)
49{ 38{
50 struct GNUNET_TESTING_Command commands[] = { 39 struct GNUNET_TESTING_Command commands[] = {
51 GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start", 40 GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
@@ -55,23 +44,7 @@ run (void *cls)
55 GNUNET_TESTING_cmd_end () 44 GNUNET_TESTING_cmd_end ()
56 }; 45 };
57 46
58 (void) cls; 47 return GNUNET_TESTING_main (NULL,
59 if (GNUNET_OK != 48 commands,
60 GNUNET_TESTING_run (NULL, /* config file */ 49 TIMEOUT);
61 commands,
62 TIMEOUT))
63 {
64 GNUNET_break (0);
65 rv = EXIT_FAILURE;
66 }
67}
68
69
70int
71main (int argc,
72 char *const *argv)
73{
74 GNUNET_SCHEDULER_run (&run,
75 NULL);
76 return rv;
77} 50}
diff --git a/src/dhtu/testing_dhtu_cmd_send.c b/src/dhtu/testing_dhtu_cmd_send.c
new file mode 100644
index 000000000..129a31205
--- /dev/null
+++ b/src/dhtu/testing_dhtu_cmd_send.c
@@ -0,0 +1,170 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing/testing_dhtu_cmd_send.c
23 * @brief use DHTU to send a message
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28
29
30/**
31 * State for the 'send' command.
32 */
33struct SendState
34{
35
36 /**
37 * Function to call when done.
38 */
39 GNUNET_SCHEDULER_TaskCallback cont;
40
41 /**
42 * Closure for @e cont.
43 */
44 void *cont_cls;
45
46 enum GNUNET_GenericReturnValue finished;
47};
48
49
50/**
51 *
52 *
53 * @param cls a `struct SendState`
54 */
55static void
56send_cleanup (void *cls)
57{
58 struct SendState *ss = cls;
59
60 GNUNET_free (ss);
61}
62
63
64/**
65 * Return trains of the ``send`` command.
66 *
67 * @param cls closure.
68 * @param[out] ret result
69 * @param trait name of the trait.
70 * @param index index number of the object to offer.
71 * @return #GNUNET_OK on success.
72 * #GNUNET_NO if no trait was found
73 */
74static enum GNUNET_GenericReturnValue
75send_traits (void *cls,
76 const void **ret,
77 const char *trait,
78 unsigned int index)
79{
80 return GNUNET_NO;
81}
82
83
84/**
85 * Run the 'send' command.
86 *
87 * @param cls closure.
88 * @param is interpreter state.
89 */
90static void
91send_run (void *cls,
92 struct GNUNET_TESTING_Interpreter *is)
93{
94 struct SendState *ss = cls;
95
96#if 0
97 other_cmd = GNUNET_TESTING_interpreter_lookup_command (ss->other_label);
98 GNUNET_TESTING_get_trait_XXX (other_cmd,
99 &data);
100#endif
101 ss->finished = GNUNET_OK;
102}
103
104
105/**
106 * This function checks the flag NetJailState#finished, if this cmd finished.
107 *
108 * @param cls a `struct SendState`
109 * @param cont function to call upon completion, can be NULL
110 * @param cont_cls closure for @a cont
111 * @return
112 * #GNUNET_NO if the command is still running and @a cont will be called later
113 * #GNUNET_OK if the command completed successfully and @a cont was called
114 * #GNUNET_SYSERR if the operation @a cont was NOT called
115 */
116static enum GNUNET_GenericReturnValue
117send_finish (void *cls,
118 GNUNET_SCHEDULER_TaskCallback cont,
119 void *cont_cls)
120{
121 struct SendState *ss = cls;
122
123 switch (ss->finished)
124 {
125 case GNUNET_OK:
126 cont (cont_cls);
127 break;
128 case GNUNET_SYSERR:
129 GNUNET_break (0);
130 break;
131 case GNUNET_NO:
132 if (NULL != ss->cont)
133 {
134 GNUNET_break (0);
135 return GNUNET_SYSERR;
136 }
137 ss->cont = cont;
138 ss->cont_cls = cont_cls;
139 break;
140 }
141 return ss->finished;
142}
143
144
145/**
146 * Create 'send' command.
147 *
148 * @param label name for command.
149 * @return command.
150 */
151struct GNUNET_TESTING_Command
152GNUNET_TESTING_DHTU_cmd_send (const char *label)
153{
154 struct SendState *ss;
155
156 ss = GNUNET_new (struct SendState);
157
158 {
159 struct GNUNET_TESTING_Command cmd = {
160 .cls = ss,
161 .label = label,
162 .run = &send_run,
163 .finish = &send_finish,
164 .cleanup = &send_cleanup,
165 .traits = &send_traits
166 };
167
168 return cmd;
169 }
170}
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 31665f8f7..363c7ff0c 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -279,15 +279,16 @@ struct GNUNET_TESTING_Command
279 * the asynchronous activity to terminate. 279 * the asynchronous activity to terminate.
280 * 280 *
281 * @param cls closure 281 * @param cls closure
282 * @param cmd command being run 282 * @param is interpreter state
283 * @param i interpreter state
284 */ 283 */
285 void 284 void
286 (*run)(void *cls, 285 (*run)(void *cls,
287 const struct GNUNET_TESTING_Command *cmd, 286 struct GNUNET_TESTING_Interpreter *is);
288 struct GNUNET_TESTING_Interpreter *i);
289 287
290 /** 288 /**
289 * FIXME: logic is basically always the same!
290 * => Refactor API to avoid duplication!
291 *
291 * Wait for any asynchronous execution of @e run to conclude, 292 * Wait for any asynchronous execution of @e run to conclude,
292 * then call finish_cont. Finish may only be called once per command. 293 * then call finish_cont. Finish may only be called once per command.
293 * 294 *
@@ -297,27 +298,24 @@ struct GNUNET_TESTING_Command
297 * @param cls closure 298 * @param cls closure
298 * @param cont function to call upon completion, can be NULL 299 * @param cont function to call upon completion, can be NULL
299 * @param cont_cls closure for @a cont 300 * @param cont_cls closure for @a cont
301 * @return
302 * #GNUNET_NO if the command is still running and @a cont will be called later
303 * #GNUNET_OK if the command completed successfully and @a cont was called
304 * #GNUNET_SYSERR if the operation @a cont was NOT called
300 */ 305 */
301 int 306 enum GNUNET_GenericReturnValue
302 (*finish)(void *cls, 307 (*finish)(void *cls,
303 GNUNET_SCHEDULER_TaskCallback cont, 308 GNUNET_SCHEDULER_TaskCallback cont,
304 void *cont_cls); 309 void *cont_cls);
305 310
306 /** 311 /**
307 * Task for running the finish function.
308 */
309 struct GNUNET_SCHEDULER_Task *finish_task;
310
311 /**
312 * Clean up after the command. Run during forced termination 312 * Clean up after the command. Run during forced termination
313 * (CTRL-C) or test failure or test success. 313 * (CTRL-C) or test failure or test success.
314 * 314 *
315 * @param cls closure 315 * @param cls closure
316 * @param cmd command being cleaned up
317 */ 316 */
318 void 317 void
319 (*cleanup)(void *cls, 318 (*cleanup)(void *cls);
320 const struct GNUNET_TESTING_Command *cmd);
321 319
322 /** 320 /**
323 * Extract information from a command that is useful for other 321 * Extract information from a command that is useful for other
@@ -327,9 +325,10 @@ struct GNUNET_TESTING_Command
327 * @param[out] ret result (could be anything) 325 * @param[out] ret result (could be anything)
328 * @param trait name of the trait 326 * @param trait name of the trait
329 * @param index index number of the object to extract. 327 * @param index index number of the object to extract.
330 * @return #GNUNET_OK on success 328 * @return #GNUNET_OK on success,
329 * #GNUNET_NO if no trait was found
331 */ 330 */
332 int 331 enum GNUNET_GenericReturnValue
333 (*traits)(void *cls, 332 (*traits)(void *cls,
334 const void **ret, 333 const void **ret,
335 const char *trait, 334 const char *trait,
@@ -383,40 +382,15 @@ struct GNUNET_TESTING_Command
383 382
384 383
385/** 384/**
386 * Struct to use for command-specific context information closure of a command waiting
387 * for another command.
388 */
389struct SyncState
390{
391 /**
392 * Closure for all commands with command-specific context information.
393 */
394 void *cls;
395
396 /**
397 * The asynchronous command the synchronous command of this closure waits for.
398 */
399 const struct GNUNET_TESTING_Command *async_cmd;
400
401 /**
402 * Task for running the finish method of the asynchronous task the command is waiting for.
403 */
404 struct GNUNET_SCHEDULER_Task *finish_task;
405
406 /**
407 * When did the execution of this commands finish function start?
408 */
409 struct GNUNET_TIME_Absolute start_finish_time;
410};
411
412/**
413 * Lookup command by label. 385 * Lookup command by label.
414 * 386 *
387 * @param is interpreter to lookup command in
415 * @param label label of the command to lookup. 388 * @param label label of the command to lookup.
416 * @return the command, if it is found, or NULL. 389 * @return the command, if it is found, or NULL.
417 */ 390 */
418const struct GNUNET_TESTING_Command * 391const struct GNUNET_TESTING_Command *
419GNUNET_TESTING_interpreter_lookup_command ( 392GNUNET_TESTING_interpreter_lookup_command (
393 struct GNUNET_TESTING_Interpreter *is,
420 const char *label); 394 const char *label);
421 395
422 396
@@ -437,7 +411,7 @@ GNUNET_TESTING_interpreter_get_current_label (
437 * @param is interpreter state. 411 * @param is interpreter state.
438 */ 412 */
439void 413void
440GNUNET_TESTING_interpreter_fail (); 414GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is);
441 415
442 416
443/** 417/**
@@ -455,8 +429,8 @@ GNUNET_TESTING_cmd_end (void);
455 * @param cmd command to make synchronous. 429 * @param cmd command to make synchronous.
456 * @return a finish-command. 430 * @return a finish-command.
457 */ 431 */
458const struct GNUNET_TESTING_Command 432struct GNUNET_TESTING_Command
459GNUNET_TESTING_cmd_make_unblocking (const struct GNUNET_TESTING_Command cmd); 433GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd);
460 434
461 435
462/** 436/**
@@ -492,19 +466,10 @@ GNUNET_TESTING_cmd_rewind_ip (const char *label,
492 466
493 467
494/** 468/**
495 * Wait until we receive SIGCHLD signal. Then obtain the process trait of the 469 * Run the testsuite. Note, CMDs are copied into
496 * current command, wait on the the zombie and continue with the next command. 470 * the interpreter state because they are _usually_
497 * 471 * defined into the "run" method that returns after
498 * @param is interpreter state. 472 * having scheduled the test interpreter.
499 */
500// void
501// GNUNET_TESTING_wait_for_sigchld (struct GNUNET_TESTING_Interpreter *is);
502// => replace with child_management.c
503
504
505/**
506 * Start scheduling loop with signal handlers and run the
507 * test suite with the @a commands.
508 * 473 *
509 * @param cfg_name name of configuration file to use 474 * @param cfg_name name of configuration file to use
510 * @param commands the list of command to execute 475 * @param commands the list of command to execute
@@ -513,13 +478,29 @@ GNUNET_TESTING_cmd_rewind_ip (const char *label,
513 * non-GNUNET_OK codes are #GNUNET_SYSERR most of the 478 * non-GNUNET_OK codes are #GNUNET_SYSERR most of the
514 * times. 479 * times.
515 */ 480 */
516int 481enum GNUNET_GenericReturnValue
517GNUNET_TESTING_run (const char *cfg_filename, 482GNUNET_TESTING_run (const char *cfg_filename,
518 struct GNUNET_TESTING_Command *commands, 483 struct GNUNET_TESTING_Command *commands,
519 struct GNUNET_TIME_Relative timeout); 484 struct GNUNET_TIME_Relative timeout);
520 485
521 486
522/** 487/**
488 * Start a GNUnet scheduler event loop and
489 * run the testsuite. Return 0 upon success.
490 * Expected to be called directly from main().
491 *
492 * @param cfg_name name of configuration file to use
493 * @param commands the list of command to execute
494 * @param timeout how long to wait for each command to execute
495 * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure
496 */
497int
498GNUNET_TESTING_main (const char *cfg_filename,
499 struct GNUNET_TESTING_Command *commands,
500 struct GNUNET_TIME_Relative timeout);
501
502
503/**
523 * Look for substring in a programs' name. 504 * Look for substring in a programs' name.
524 * 505 *
525 * @param prog program's name to look into 506 * @param prog program's name to look into
@@ -1191,4 +1172,5 @@ struct GNUNET_TESTING_Command
1191GNUNET_TESTING_cmd_local_test_finished (const char *label, 1172GNUNET_TESTING_cmd_local_test_finished (const char *label,
1192 TESTING_CMD_HELPER_write_cb 1173 TESTING_CMD_HELPER_write_cb
1193 write_message); 1174 write_message);
1175
1194#endif 1176#endif
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index efb22b279..3e0d4d443 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -44,6 +44,7 @@ libgnunet_test_testing_plugin_testcmd_la_LDFLAGS = \
44 44
45libgnunettesting_la_SOURCES = \ 45libgnunettesting_la_SOURCES = \
46 testing_api_cmd_local_test_finished.c \ 46 testing_api_cmd_local_test_finished.c \
47 testing_api_cmd_finish.c \
47 testing_api_cmd_send_peer_ready.c \ 48 testing_api_cmd_send_peer_ready.c \
48 testing_api_cmd_block_until_all_peers_started.c \ 49 testing_api_cmd_block_until_all_peers_started.c \
49 testing_api_cmd_block_until_external_trigger.c \ 50 testing_api_cmd_block_until_external_trigger.c \
diff --git a/src/testing/testing_api_cmd_batch.c b/src/testing/testing_api_cmd_batch.c
index af260f80d..e39489616 100644
--- a/src/testing/testing_api_cmd_batch.c
+++ b/src/testing/testing_api_cmd_batch.c
@@ -39,6 +39,11 @@ struct BatchState
39 struct GNUNET_TESTING_Command *batch; 39 struct GNUNET_TESTING_Command *batch;
40 40
41 /** 41 /**
42 * Our label.
43 */
44 const char *label;
45
46 /**
42 * Internal command pointer. 47 * Internal command pointer.
43 */ 48 */
44 unsigned int batch_ip; 49 unsigned int batch_ip;
@@ -49,12 +54,10 @@ struct BatchState
49 * Run the command. 54 * Run the command.
50 * 55 *
51 * @param cls closure. 56 * @param cls closure.
52 * @param cmd the command being executed.
53 * @param is the interpreter state. 57 * @param is the interpreter state.
54 */ 58 */
55static void 59static void
56batch_run (void *cls, 60batch_run (void *cls,
57 const struct GNUNET_TESTING_Command *cmd,
58 struct GNUNET_TESTING_Interpreter *is) 61 struct GNUNET_TESTING_Interpreter *is)
59{ 62{
60 struct BatchState *bs = cls; 63 struct BatchState *bs = cls;
@@ -69,7 +72,7 @@ batch_run (void *cls,
69 { 72 {
70 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 73 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
71 "Exiting from batch: %s\n", 74 "Exiting from batch: %s\n",
72 cmd->label); 75 bs->label);
73 return; 76 return;
74 } 77 }
75 bs->batch[bs->batch_ip].start_time 78 bs->batch[bs->batch_ip].start_time
@@ -77,7 +80,6 @@ batch_run (void *cls,
77 = GNUNET_TIME_absolute_get (); 80 = GNUNET_TIME_absolute_get ();
78 bs->batch[bs->batch_ip].num_tries = 1; 81 bs->batch[bs->batch_ip].num_tries = 1;
79 bs->batch[bs->batch_ip].run (bs->batch[bs->batch_ip].cls, 82 bs->batch[bs->batch_ip].run (bs->batch[bs->batch_ip].cls,
80 &bs->batch[bs->batch_ip],
81 is); 83 is);
82} 84}
83 85
@@ -87,20 +89,16 @@ batch_run (void *cls,
87 * cancel a pending operation thereof. 89 * cancel a pending operation thereof.
88 * 90 *
89 * @param cls closure. 91 * @param cls closure.
90 * @param cmd the command which is being cleaned up.
91 */ 92 */
92static void 93static void
93batch_cleanup (void *cls, 94batch_cleanup (void *cls)
94 const struct GNUNET_TESTING_Command *cmd)
95{ 95{
96 struct BatchState *bs = cls; 96 struct BatchState *bs = cls;
97 97
98 (void) cmd;
99 for (unsigned int i = 0; 98 for (unsigned int i = 0;
100 NULL != bs->batch[i].label; 99 NULL != bs->batch[i].label;
101 i++) 100 i++)
102 bs->batch[i].cleanup (bs->batch[i].cls, 101 bs->batch[i].cleanup (bs->batch[i].cls);
103 &bs->batch[i]);
104 GNUNET_free (bs->batch); 102 GNUNET_free (bs->batch);
105 GNUNET_free (bs); 103 GNUNET_free (bs);
106} 104}
@@ -115,7 +113,7 @@ batch_cleanup (void *cls,
115 * @param index index number of the object to offer. 113 * @param index index number of the object to offer.
116 * @return #GNUNET_OK on success. 114 * @return #GNUNET_OK on success.
117 */ 115 */
118static int 116static enum GNUNET_GenericReturnValue
119batch_traits (void *cls, 117batch_traits (void *cls,
120 const void **ret, 118 const void **ret,
121 const char *trait, 119 const char *trait,
@@ -162,7 +160,7 @@ GNUNET_TESTING_cmd_batch (const char *label,
162 unsigned int i; 160 unsigned int i;
163 161
164 bs = GNUNET_new (struct BatchState); 162 bs = GNUNET_new (struct BatchState);
165 163 bs->label = label;
166 /* Get number of commands. */ 164 /* Get number of commands. */
167 for (i = 0; NULL != batch[i].label; i++) 165 for (i = 0; NULL != batch[i].label; i++)
168 /* noop */ 166 /* noop */
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 e9d3f0ed3..fb51c1066 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
@@ -65,8 +65,7 @@ block_until_all_peers_started_traits (void *cls,
65 * 65 *
66 */ 66 */
67static void 67static void
68block_until_all_peers_started_cleanup (void *cls, 68block_until_all_peers_started_cleanup (void *cls)
69 const struct GNUNET_TESTING_Command *cmd)
70{ 69{
71 struct BlockState *bs = cls; 70 struct BlockState *bs = cls;
72 71
@@ -80,7 +79,6 @@ block_until_all_peers_started_cleanup (void *cls,
80 */ 79 */
81static void 80static void
82block_until_all_peers_started_run (void *cls, 81block_until_all_peers_started_run (void *cls,
83 const struct GNUNET_TESTING_Command *cmd,
84 struct GNUNET_TESTING_Interpreter *is) 82 struct GNUNET_TESTING_Interpreter *is)
85{ 83{
86 LOG (GNUNET_ERROR_TYPE_DEBUG, 84 LOG (GNUNET_ERROR_TYPE_DEBUG,
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 2439afeaf..d69040b75 100644
--- a/src/testing/testing_api_cmd_block_until_external_trigger.c
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -56,7 +56,7 @@ block_until_all_peers_started_traits (void *cls,
56 const char *trait, 56 const char *trait,
57 unsigned int index) 57 unsigned int index)
58{ 58{
59 return GNUNET_OK; 59 return GNUNET_NO;
60} 60}
61 61
62 62
@@ -65,8 +65,7 @@ block_until_all_peers_started_traits (void *cls,
65 * 65 *
66 */ 66 */
67static void 67static void
68block_until_all_peers_started_cleanup (void *cls, 68block_until_all_peers_started_cleanup (void *cls)
69 const struct GNUNET_TESTING_Command *cmd)
70{ 69{
71 struct BlockState *bs = cls; 70 struct BlockState *bs = cls;
72 71
@@ -80,7 +79,6 @@ block_until_all_peers_started_cleanup (void *cls,
80 */ 79 */
81static void 80static void
82block_until_all_peers_started_run (void *cls, 81block_until_all_peers_started_run (void *cls,
83 const struct GNUNET_TESTING_Command *cmd,
84 struct GNUNET_TESTING_Interpreter *is) 82 struct GNUNET_TESTING_Interpreter *is)
85{ 83{
86 LOG (GNUNET_ERROR_TYPE_DEBUG, 84 LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/testing/testing_api_cmd_hello_world.c b/src/testing/testing_api_cmd_hello_world.c
index 4347ac818..73dcd6dff 100644
--- a/src/testing/testing_api_cmd_hello_world.c
+++ b/src/testing/testing_api_cmd_hello_world.c
@@ -32,50 +32,51 @@ struct HelloWorldState
32 const char *birthLabel; 32 const char *birthLabel;
33}; 33};
34 34
35
35/** 36/**
36* 37 *
37* 38 *
38* @param cls closure 39 * @param cls closure
39* @param cmd current CMD being cleaned up. 40 */
40*/
41static void 41static void
42hello_world_cleanup (void *cls, 42hello_world_cleanup (void *cls)
43 const struct GNUNET_TESTING_Command *cmd)
44{ 43{
45 struct HelloWorldState *hs = cls; 44 struct HelloWorldState *hs = cls;
45
46 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 46 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
47 "Cleaning up message %s\n", 47 "Cleaning up message %s\n",
48 hs->message); 48 hs->message);
49 GNUNET_free (hs);
49} 50}
50 51
52
51/** 53/**
52* 54 *
53* 55 *
54* @param cls closure. 56 * @param cls closure.
55* @param[out] ret result 57 * @param[out] ret result
56* @param trait name of the trait. 58 * @param trait name of the trait.
57* @param index index number of the object to offer. 59 * @param index index number of the object to offer.
58* @return #GNUNET_OK on success. 60 * @return #GNUNET_OK on success.
59*/ 61 */
60static int 62static enum GNUNET_GenericReturnValue
61hello_world_traits (void *cls, 63hello_world_traits (void *cls,
62 const void **ret, 64 const void **ret,
63 const char *trait, 65 const char *trait,
64 unsigned int index) 66 unsigned int index)
65{ 67{
66 return GNUNET_OK; 68 return GNUNET_NO;
67} 69}
68 70
71
69/** 72/**
70* Run the "hello world" CMD. 73* Run the "hello world" CMD.
71* 74*
72* @param cls closure. 75* @param cls closure.
73* @param cmd CMD being run.
74* @param is interpreter state. 76* @param is interpreter state.
75*/ 77*/
76static void 78static void
77hello_world_run (void *cls, 79hello_world_run (void *cls,
78 const struct GNUNET_TESTING_Command *cmd,
79 struct GNUNET_TESTING_Interpreter *is) 80 struct GNUNET_TESTING_Interpreter *is)
80{ 81{
81 struct HelloWorldState *hs = cls; 82 struct HelloWorldState *hs = cls;
@@ -84,13 +85,16 @@ hello_world_run (void *cls,
84 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 85 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
85 "%s\n", 86 "%s\n",
86 hs->message); 87 hs->message);
87 birth_cmd = GNUNET_TESTING_interpreter_lookup_command (hs->birthLabel); 88 birth_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
88 GNUNET_TESTING_get_trait_what_am_i (birth_cmd, &hs->message); 89 hs->birthLabel);
90 GNUNET_TESTING_get_trait_what_am_i (birth_cmd,
91 &hs->message);
89 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 92 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
90 "Now I am a %s\n", 93 "Now I am a %s\n",
91 hs->message); 94 hs->message);
92} 95}
93 96
97
94/** 98/**
95 * Create command. 99 * Create command.
96 * 100 *
@@ -108,14 +112,15 @@ GNUNET_TESTING_cmd_hello_world (const char *label,
108 hs = GNUNET_new (struct HelloWorldState); 112 hs = GNUNET_new (struct HelloWorldState);
109 hs->message = "Hello World, I was nobody!"; 113 hs->message = "Hello World, I was nobody!";
110 hs->birthLabel = birthLabel; 114 hs->birthLabel = birthLabel;
115 {
116 struct GNUNET_TESTING_Command cmd = {
117 .cls = hs,
118 .label = label,
119 .run = &hello_world_run,
120 .cleanup = &hello_world_cleanup,
121 .traits = &hello_world_traits
122 };
111 123
112 struct GNUNET_TESTING_Command cmd = { 124 return cmd;
113 .cls = hs, 125 }
114 .label = label,
115 .run = &hello_world_run,
116 .cleanup = &hello_world_cleanup,
117 .traits = &hello_world_traits
118 };
119
120 return cmd;
121} 126}
diff --git a/src/testing/testing_api_cmd_hello_world_birth.c b/src/testing/testing_api_cmd_hello_world_birth.c
index 9d60059a5..8415b99f0 100644
--- a/src/testing/testing_api_cmd_hello_world_birth.c
+++ b/src/testing/testing_api_cmd_hello_world_birth.c
@@ -40,8 +40,7 @@ struct HelloWorldBirthState
40* @param cmd current CMD being cleaned up. 40* @param cmd current CMD being cleaned up.
41*/ 41*/
42static void 42static void
43hello_world_birth_cleanup (void *cls, 43hello_world_birth_cleanup (void *cls)
44 const struct GNUNET_TESTING_Command *cmd)
45{ 44{
46 struct HelloWorldBirthState *hbs = cls; 45 struct HelloWorldBirthState *hbs = cls;
47 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 46 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -49,6 +48,7 @@ hello_world_birth_cleanup (void *cls,
49 hbs->what_am_i); 48 hbs->what_am_i);
50} 49}
51 50
51
52/** 52/**
53* 53*
54* 54*
@@ -82,6 +82,7 @@ hello_world_birth_traits (void *cls,
82 index); 82 index);
83} 83}
84 84
85
85/** 86/**
86* Run the "hello world" CMD. 87* Run the "hello world" CMD.
87* 88*
@@ -91,14 +92,13 @@ hello_world_birth_traits (void *cls,
91*/ 92*/
92static void 93static void
93hello_world_birth_run (void *cls, 94hello_world_birth_run (void *cls,
94 const struct GNUNET_TESTING_Command *cmd,
95 struct GNUNET_TESTING_Interpreter *is) 95 struct GNUNET_TESTING_Interpreter *is)
96{ 96{
97 struct HelloWorldBirthState *hbs = cls; 97 struct HelloWorldBirthState *hbs = cls;
98 struct GNUNET_TIME_Relative relative; 98 struct GNUNET_TIME_Relative relative;
99 99
100 relative = GNUNET_TIME_absolute_get_difference (*hbs->date, 100 relative = GNUNET_TIME_absolute_get_difference (*hbs->date,
101 GNUNET_TIME_absolute_get ()); 101 GNUNET_TIME_absolute_get ());
102 102
103 if (0 == relative.rel_value_us % 10) 103 if (0 == relative.rel_value_us % 10)
104 { 104 {
@@ -114,6 +114,7 @@ hello_world_birth_run (void *cls,
114 } 114 }
115} 115}
116 116
117
117/** 118/**
118 * Offer data from trait 119 * Offer data from trait
119 * 120 *
@@ -131,6 +132,7 @@ GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd,
131 (unsigned int) 0); 132 (unsigned int) 0);
132} 133}
133 134
135
134/** 136/**
135 * Create command. 137 * Create command.
136 * 138 *
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
index 383de4c10..da4aff80f 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file testing_api_cmd_block_until_all_peers_started.c 22 * @file testing_api_cmd_local_test_finished.c
23 * @brief cmd to block the interpreter loop until all peers started. 23 * @brief cmd to block the interpreter loop until all peers started.
24 * @author t3sserakt 24 * @author t3sserakt
25 */ 25 */
@@ -58,13 +58,13 @@ struct LocalFinishedState
58 * Trait function of this cmd does nothing. 58 * Trait function of this cmd does nothing.
59 * 59 *
60 */ 60 */
61static int 61static enum GNUNET_GenericReturnValue
62local_test_finished_traits (void *cls, 62local_test_finished_traits (void *cls,
63 const void **ret, 63 const void **ret,
64 const char *trait, 64 const char *trait,
65 unsigned int index) 65 unsigned int index)
66{ 66{
67 return GNUNET_OK; 67 return GNUNET_NO;
68} 68}
69 69
70 70
@@ -73,8 +73,7 @@ local_test_finished_traits (void *cls,
73 * 73 *
74 */ 74 */
75static void 75static void
76local_test_finished_cleanup (void *cls, 76local_test_finished_cleanup (void *cls)
77 const struct GNUNET_TESTING_Command *cmd)
78{ 77{
79 struct LocalFinishedState *lfs = cls; 78 struct LocalFinishedState *lfs = cls;
80 79
@@ -89,11 +88,9 @@ local_test_finished_cleanup (void *cls,
89 */ 88 */
90static void 89static void
91local_test_finished_run (void *cls, 90local_test_finished_run (void *cls,
92 const struct GNUNET_TESTING_Command *cmd,
93 struct GNUNET_TESTING_Interpreter *is) 91 struct GNUNET_TESTING_Interpreter *is)
94{ 92{
95 struct LocalFinishedState *lfs = cls; 93 struct LocalFinishedState *lfs = cls;
96
97 struct GNUNET_CMDS_LOCAL_FINISHED *reply; 94 struct GNUNET_CMDS_LOCAL_FINISHED *reply;
98 size_t msg_length; 95 size_t msg_length;
99 96
@@ -102,15 +99,18 @@ local_test_finished_run (void *cls,
102 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED); 99 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED);
103 reply->header.size = htons ((uint16_t) msg_length); 100 reply->header.size = htons ((uint16_t) msg_length);
104 lfs->reply = reply; 101 lfs->reply = reply;
105 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length); 102 lfs->write_message ((struct GNUNET_MessageHeader *) reply,
103 msg_length);
106} 104}
107 105
108 106
109/** 107/**
110 * 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. 108 * This finish function will stop the local loop without shutting down the
109 * scheduler, because we do not call the continuation, which is the
110 * interpreter_next method.
111 * 111 *
112 */ 112 */
113static int 113static enum GNUNET_GenericReturnValue
114local_test_finished_finish (void *cls, 114local_test_finished_finish (void *cls,
115 GNUNET_SCHEDULER_TaskCallback cont, 115 GNUNET_SCHEDULER_TaskCallback cont,
116 void *cont_cls) 116 void *cont_cls)
@@ -129,23 +129,24 @@ local_test_finished_finish (void *cls,
129 * @return command. 129 * @return command.
130 */ 130 */
131struct GNUNET_TESTING_Command 131struct GNUNET_TESTING_Command
132GNUNET_TESTING_cmd_local_test_finished (const char *label, 132GNUNET_TESTING_cmd_local_test_finished (
133 TESTING_CMD_HELPER_write_cb 133 const char *label,
134 write_message) 134 TESTING_CMD_HELPER_write_cb write_message)
135{ 135{
136 struct LocalFinishedState *lfs; 136 struct LocalFinishedState *lfs;
137 137
138 lfs = GNUNET_new (struct LocalFinishedState); 138 lfs = GNUNET_new (struct LocalFinishedState);
139 lfs->write_message = write_message; 139 lfs->write_message = write_message;
140 140 {
141 struct GNUNET_TESTING_Command cmd = { 141 struct GNUNET_TESTING_Command cmd = {
142 .cls = lfs, 142 .cls = lfs,
143 .label = label, 143 .label = label,
144 .run = &local_test_finished_run, 144 .run = &local_test_finished_run,
145 .finish = &local_test_finished_finish, 145 .finish = &local_test_finished_finish,
146 .cleanup = &local_test_finished_cleanup, 146 .cleanup = &local_test_finished_cleanup,
147 .traits = &local_test_finished_traits 147 .traits = &local_test_finished_traits
148 }; 148 };
149 149
150 return cmd; 150 return cmd;
151 }
151} 152}
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index 536b356a6..1815b64d2 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -49,8 +49,10 @@ struct NetJailState
49 */ 49 */
50 struct GNUNET_OS_Process *start_proc; 50 struct GNUNET_OS_Process *start_proc;
51 51
52 // Flag indication if the script finished. 52 /**
53 unsigned int finished; 53 * Flag indication if the script finished.
54 */
55 enum GNUNET_GenericReturnValue finished;
54}; 56};
55 57
56 58
@@ -59,8 +61,7 @@ struct NetJailState
59 * 61 *
60 */ 62 */
61static void 63static void
62netjail_start_cleanup (void *cls, 64netjail_start_cleanup (void *cls)
63 const struct GNUNET_TESTING_Command *cmd)
64{ 65{
65 struct NetJailState *ns = cls; 66 struct NetJailState *ns = cls;
66 67
@@ -90,13 +91,13 @@ netjail_start_cleanup (void *cls,
90 * Trait function of this cmd does nothing. 91 * Trait function of this cmd does nothing.
91 * 92 *
92 */ 93 */
93static int 94static enum GNUNET_GenericReturnValue
94netjail_start_traits (void *cls, 95netjail_start_traits (void *cls,
95 const void **ret, 96 const void **ret,
96 const char *trait, 97 const char *trait,
97 unsigned int index) 98 unsigned int index)
98{ 99{
99 return GNUNET_OK; 100 return GNUNET_NO;
100} 101}
101 102
102 103
@@ -126,17 +127,14 @@ child_completed_callback (void *cls,
126} 127}
127 128
128 129
129
130/** 130/**
131* The run method starts the script which setup the network namespaces. 131* The run method starts the script which setup the network namespaces.
132* 132*
133* @param cls closure. 133* @param cls closure.
134* @param cmd CMD being run.
135* @param is interpreter state. 134* @param is interpreter state.
136*/ 135*/
137static void 136static void
138netjail_start_run (void *cls, 137netjail_start_run (void *cls,
139 const struct GNUNET_TESTING_Command *cmd,
140 struct GNUNET_TESTING_Interpreter *is) 138 struct GNUNET_TESTING_Interpreter *is)
141{ 139{
142 struct NetJailState *ns = cls; 140 struct NetJailState *ns = cls;
@@ -154,14 +152,14 @@ netjail_start_run (void *cls,
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 "No SUID for %s!\n", 153 "No SUID for %s!\n",
156 NETJAIL_START_SCRIPT); 154 NETJAIL_START_SCRIPT);
157 GNUNET_TESTING_interpreter_fail (); 155 GNUNET_TESTING_interpreter_fail (is);
158 } 156 }
159 else if (GNUNET_NO == helper_check) 157 else if (GNUNET_NO == helper_check)
160 { 158 {
161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
162 "%s not found!\n", 160 "%s not found!\n",
163 NETJAIL_START_SCRIPT); 161 NETJAIL_START_SCRIPT);
164 GNUNET_TESTING_interpreter_fail (); 162 GNUNET_TESTING_interpreter_fail (is);
165 } 163 }
166 164
167 ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, 165 ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
@@ -182,7 +180,7 @@ netjail_start_run (void *cls,
182 * This function checks the flag NetJailState#finished, if this cmd finished. 180 * This function checks the flag NetJailState#finished, if this cmd finished.
183 * 181 *
184 */ 182 */
185static int 183static enum GNUNET_GenericReturnValue
186netjail_start_finish (void *cls, 184netjail_start_finish (void *cls,
187 GNUNET_SCHEDULER_TaskCallback cont, 185 GNUNET_SCHEDULER_TaskCallback cont,
188 void *cont_cls) 186 void *cont_cls)
@@ -196,6 +194,7 @@ netjail_start_finish (void *cls,
196 return ns->finished; 194 return ns->finished;
197} 195}
198 196
197
199/** 198/**
200 * Create command. 199 * Create command.
201 * 200 *
@@ -214,16 +213,16 @@ GNUNET_TESTING_cmd_netjail_start (const char *label,
214 ns = GNUNET_new (struct NetJailState); 213 ns = GNUNET_new (struct NetJailState);
215 ns->local_m = local_m; 214 ns->local_m = local_m;
216 ns->global_n = global_n; 215 ns->global_n = global_n;
217 ns->finished = GNUNET_NO; 216 {
218 217 struct GNUNET_TESTING_Command cmd = {
219 struct GNUNET_TESTING_Command cmd = { 218 .cls = ns,
220 .cls = ns, 219 .label = label,
221 .label = label, 220 .run = &netjail_start_run,
222 .run = &netjail_start_run, 221 .finish = &netjail_start_finish,
223 .finish = &netjail_start_finish, 222 .cleanup = &netjail_start_cleanup,
224 .cleanup = &netjail_start_cleanup, 223 .traits = &netjail_start_traits
225 .traits = &netjail_start_traits 224 };
226 }; 225
227 226 return cmd;
228 return cmd; 227 }
229} 228}
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index 531621eb5..1222ae54b 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -194,11 +194,9 @@ struct TestingSystemCount
194* Code to clean up resource this cmd used. 194* Code to clean up resource this cmd used.
195* 195*
196* @param cls closure 196* @param cls closure
197* @param cmd current CMD being cleaned up.
198*/ 197*/
199static void 198static void
200netjail_exec_cleanup (void *cls, 199netjail_exec_cleanup (void *cls)
201 const struct GNUNET_TESTING_Command *cmd)
202{ 200{
203 struct NetJailState *ns = cls; 201 struct NetJailState *ns = cls;
204 struct HelperMessage *message_pos; 202 struct HelperMessage *message_pos;
@@ -480,7 +478,6 @@ start_helper (struct NetJailState *ns, struct
480*/ 478*/
481static void 479static void
482netjail_exec_run (void *cls, 480netjail_exec_run (void *cls,
483 const struct GNUNET_TESTING_Command *cmd,
484 struct GNUNET_TESTING_Interpreter *is) 481 struct GNUNET_TESTING_Interpreter *is)
485{ 482{
486 char str_m[12]; 483 char str_m[12];
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 ccb3f5ae8..bb9421aa7 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
@@ -205,11 +205,9 @@ struct TestingSystemCount
205* Code to clean up resource this cmd used. 205* Code to clean up resource this cmd used.
206* 206*
207* @param cls closure 207* @param cls closure
208* @param cmd current CMD being cleaned up.
209*/ 208*/
210static void 209static void
211netjail_exec_cleanup (void *cls, 210netjail_exec_cleanup (void *cls)
212 const struct GNUNET_TESTING_Command *cmd)
213{ 211{
214 struct NetJailState *ns = cls; 212 struct NetJailState *ns = cls;
215 struct HelperMessage *message_pos; 213 struct HelperMessage *message_pos;
@@ -568,7 +566,6 @@ start_helper (struct NetJailState *ns, struct
568*/ 566*/
569static void 567static void
570netjail_exec_run (void *cls, 568netjail_exec_run (void *cls,
571 const struct GNUNET_TESTING_Command *cmd,
572 struct GNUNET_TESTING_Interpreter *is) 569 struct GNUNET_TESTING_Interpreter *is)
573{ 570{
574 struct NetJailState *ns = cls; 571 struct NetJailState *ns = cls;
diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c
index 9123148a7..faabed98e 100644
--- a/src/testing/testing_api_cmd_netjail_start_v2.c
+++ b/src/testing/testing_api_cmd_netjail_start_v2.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file testing/testing_api_cmd_hello_world.c 22 * @file testing/testing_api_cmd_netjail_start_v2.c
23 * @brief Command to start the netjail script. 23 * @brief Command to start the netjail script.
24 * @author t3sserakt 24 * @author t3sserakt
25 */ 25 */
@@ -59,8 +59,7 @@ struct NetJailState
59 * 59 *
60 */ 60 */
61static void 61static void
62netjail_start_cleanup (void *cls, 62netjail_start_cleanup (void *cls)
63 const struct GNUNET_TESTING_Command *cmd)
64{ 63{
65 struct NetJailState *ns = cls; 64 struct NetJailState *ns = cls;
66 65
@@ -90,13 +89,13 @@ netjail_start_cleanup (void *cls,
90 * Trait function of this cmd does nothing. 89 * Trait function of this cmd does nothing.
91 * 90 *
92 */ 91 */
93static int 92static enum GNUNET_GenericReturnValue
94netjail_start_traits (void *cls, 93netjail_start_traits (void *cls,
95 const void **ret, 94 const void **ret,
96 const char *trait, 95 const char *trait,
97 unsigned int index) 96 unsigned int index)
98{ 97{
99 return GNUNET_OK; 98 return GNUNET_NO;
100} 99}
101 100
102 101
@@ -127,17 +126,14 @@ child_completed_callback (void *cls,
127} 126}
128 127
129 128
130
131/** 129/**
132* The run method starts the script which setup the network namespaces. 130* The run method starts the script which setup the network namespaces.
133* 131*
134* @param cls closure. 132* @param cls closure.
135* @param cmd CMD being run.
136* @param is interpreter state. 133* @param is interpreter state.
137*/ 134*/
138static void 135static void
139netjail_start_run (void *cls, 136netjail_start_run (void *cls,
140 const struct GNUNET_TESTING_Command *cmd,
141 struct GNUNET_TESTING_Interpreter *is) 137 struct GNUNET_TESTING_Interpreter *is)
142{ 138{
143 struct NetJailState *ns = cls; 139 struct NetJailState *ns = cls;
@@ -157,7 +153,7 @@ netjail_start_run (void *cls,
157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
158 "No SUID for %s!\n", 154 "No SUID for %s!\n",
159 NETJAIL_START_SCRIPT); 155 NETJAIL_START_SCRIPT);
160 GNUNET_TESTING_interpreter_fail (); 156 GNUNET_TESTING_interpreter_fail (is);
161 return; 157 return;
162 } 158 }
163 if (GNUNET_SYSERR == helper_check) 159 if (GNUNET_SYSERR == helper_check)
@@ -165,7 +161,7 @@ netjail_start_run (void *cls,
165 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
166 "%s not found!\n", 162 "%s not found!\n",
167 NETJAIL_START_SCRIPT); 163 NETJAIL_START_SCRIPT);
168 GNUNET_TESTING_interpreter_fail (); 164 GNUNET_TESTING_interpreter_fail (is);
169 return; 165 return;
170 } 166 }
171 167
@@ -180,7 +176,7 @@ netjail_start_run (void *cls,
180 pid, 176 pid,
181 NULL 177 NULL
182 }; 178 };
183 179
184 ns->start_proc 180 ns->start_proc
185 = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, 181 = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
186 NULL, 182 NULL,
@@ -198,7 +194,7 @@ netjail_start_run (void *cls,
198 194
199/** 195/**
200 * This function checks the flag NetJailState 196 * This function checks the flag NetJailState
201 * 197 *
202 * FIXME: fix comment! 198 * FIXME: fix comment!
203 * #finished, if this cmd finished. 199 * #finished, if this cmd finished.
204 * 200 *
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c
index 99084d9af..c93e5cca3 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file testing/testing_api_cmd_hello_world.c 22 * @file testing/testing_api_cmd_netjail_stop.c
23 * @brief Command to stop the netjail script. 23 * @brief Command to stop the netjail script.
24 * @author t3sserakt 24 * @author t3sserakt
25 */ 25 */
@@ -60,8 +60,7 @@ struct NetJailState
60 * 60 *
61 */ 61 */
62static void 62static void
63netjail_stop_cleanup (void *cls, 63netjail_stop_cleanup (void *cls)
64 const struct GNUNET_TESTING_Command *cmd)
65{ 64{
66 struct NetJailState *ns = cls; 65 struct NetJailState *ns = cls;
67 66
@@ -87,13 +86,13 @@ netjail_stop_cleanup (void *cls,
87 * Trait function of this cmd does nothing. 86 * Trait function of this cmd does nothing.
88 * 87 *
89 */ 88 */
90static int 89static enum GNUNET_GenericReturnValue
91netjail_stop_traits (void *cls, 90netjail_stop_traits (void *cls,
92 const void **ret, 91 const void **ret,
93 const char *trait, 92 const char *trait,
94 unsigned int index) 93 unsigned int index)
95{ 94{
96 return GNUNET_OK; 95 return GNUNET_NO;
97} 96}
98 97
99 98
@@ -131,14 +130,15 @@ child_completed_callback (void *cls,
131*/ 130*/
132static void 131static void
133netjail_stop_run (void *cls, 132netjail_stop_run (void *cls,
134 const struct GNUNET_TESTING_Command *cmd,
135 struct GNUNET_TESTING_Interpreter *is) 133 struct GNUNET_TESTING_Interpreter *is)
136{ 134{
137 struct NetJailState *ns = cls; 135 struct NetJailState *ns = cls;
138 char *const script_argv[] = {NETJAIL_STOP_SCRIPT, 136 char *const script_argv[] = {
139 ns->local_m, 137 NETJAIL_STOP_SCRIPT,
140 ns->global_n, 138 ns->local_m,
141 NULL}; 139 ns->global_n,
140 NULL
141 };
142 unsigned int helper_check = GNUNET_OS_check_helper_binary ( 142 unsigned int helper_check = GNUNET_OS_check_helper_binary (
143 NETJAIL_STOP_SCRIPT, 143 NETJAIL_STOP_SCRIPT,
144 GNUNET_YES, 144 GNUNET_YES,
@@ -149,14 +149,14 @@ netjail_stop_run (void *cls,
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 "No SUID for %s!\n", 150 "No SUID for %s!\n",
151 NETJAIL_STOP_SCRIPT); 151 NETJAIL_STOP_SCRIPT);
152 GNUNET_TESTING_interpreter_fail (); 152 GNUNET_TESTING_interpreter_fail (is);
153 } 153 }
154 else if (GNUNET_NO == helper_check) 154 else if (GNUNET_NO == helper_check)
155 { 155 {
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
157 "%s not found!\n", 157 "%s not found!\n",
158 NETJAIL_STOP_SCRIPT); 158 NETJAIL_STOP_SCRIPT);
159 GNUNET_TESTING_interpreter_fail (); 159 GNUNET_TESTING_interpreter_fail (is);
160 } 160 }
161 161
162 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, 162 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
@@ -178,7 +178,7 @@ netjail_stop_run (void *cls,
178 * This function checks the flag NetJailState#finished, if this cmd finished. 178 * This function checks the flag NetJailState#finished, if this cmd finished.
179 * 179 *
180 */ 180 */
181static int 181static enum GNUNET_GenericReturnValue
182netjail_stop_finish (void *cls, 182netjail_stop_finish (void *cls,
183 GNUNET_SCHEDULER_TaskCallback cont, 183 GNUNET_SCHEDULER_TaskCallback cont,
184 void *cont_cls) 184 void *cont_cls)
@@ -211,15 +211,16 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label,
211 ns = GNUNET_new (struct NetJailState); 211 ns = GNUNET_new (struct NetJailState);
212 ns->local_m = local_m; 212 ns->local_m = local_m;
213 ns->global_n = global_n; 213 ns->global_n = global_n;
214 214 {
215 struct GNUNET_TESTING_Command cmd = { 215 struct GNUNET_TESTING_Command cmd = {
216 .cls = ns, 216 .cls = ns,
217 .label = label, 217 .label = label,
218 .run = &netjail_stop_run, 218 .run = &netjail_stop_run,
219 .finish = &netjail_stop_finish, 219 .finish = &netjail_stop_finish,
220 .cleanup = &netjail_stop_cleanup, 220 .cleanup = &netjail_stop_cleanup,
221 .traits = &netjail_stop_traits 221 .traits = &netjail_stop_traits
222 }; 222 };
223 223
224 return cmd; 224 return cmd;
225 }
225} 226}
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index 0ae82a26a..04b0e4e94 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -55,10 +55,8 @@ struct StopHelperState
55* @param cmd current CMD being cleaned up. 55* @param cmd current CMD being cleaned up.
56*/ 56*/
57static void 57static void
58stop_testing_system_cleanup (void *cls, 58stop_testing_system_cleanup (void *cls)
59 const struct GNUNET_TESTING_Command *cmd)
60{ 59{
61
62} 60}
63 61
64 62
@@ -66,13 +64,13 @@ stop_testing_system_cleanup (void *cls,
66 * Trait function of this cmd does nothing. 64 * Trait function of this cmd does nothing.
67 * 65 *
68 */ 66 */
69static int 67static enum GNUNET_GenericReturnValue
70stop_testing_system_traits (void *cls, 68stop_testing_system_traits (void *cls,
71 const void **ret, 69 const void **ret,
72 const char *trait, 70 const char *trait,
73 unsigned int index) 71 unsigned int index)
74{ 72{
75 return GNUNET_OK; 73 return GNUNET_NO;
76} 74}
77 75
78 76
@@ -80,12 +78,10 @@ stop_testing_system_traits (void *cls,
80* This function stops the helper process for each node. 78* This function stops the helper process for each node.
81* 79*
82* @param cls closure. 80* @param cls closure.
83* @param cmd CMD being run.
84* @param is interpreter state. 81* @param is interpreter state.
85*/ 82*/
86static void 83static void
87stop_testing_system_run (void *cls, 84stop_testing_system_run (void *cls,
88 const struct GNUNET_TESTING_Command *cmd,
89 struct GNUNET_TESTING_Interpreter *is) 85 struct GNUNET_TESTING_Interpreter *is)
90{ 86{
91 struct StopHelperState *shs = cls; 87 struct StopHelperState *shs = cls;
@@ -93,6 +89,7 @@ stop_testing_system_run (void *cls,
93 const struct GNUNET_TESTING_Command *start_helper_cmd; 89 const struct GNUNET_TESTING_Command *start_helper_cmd;
94 90
95 start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command ( 91 start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (
92 is,
96 shs->helper_start_label); 93 shs->helper_start_label);
97 GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd, 94 GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd,
98 &helper); 95 &helper);
@@ -121,8 +118,7 @@ struct GNUNET_TESTING_Command
121GNUNET_TESTING_cmd_stop_testing_system (const char *label, 118GNUNET_TESTING_cmd_stop_testing_system (const char *label,
122 const char *helper_start_label, 119 const char *helper_start_label,
123 char *local_m, 120 char *local_m,
124 char *global_n 121 char *global_n)
125 )
126{ 122{
127 struct StopHelperState *shs; 123 struct StopHelperState *shs;
128 124
@@ -130,14 +126,15 @@ GNUNET_TESTING_cmd_stop_testing_system (const char *label,
130 shs->helper_start_label = helper_start_label; 126 shs->helper_start_label = helper_start_label;
131 shs->local_m = local_m; 127 shs->local_m = local_m;
132 shs->global_n = global_n; 128 shs->global_n = global_n;
133 129 {
134 struct GNUNET_TESTING_Command cmd = { 130 struct GNUNET_TESTING_Command cmd = {
135 .cls = shs, 131 .cls = shs,
136 .label = label, 132 .label = label,
137 .run = &stop_testing_system_run, 133 .run = &stop_testing_system_run,
138 .cleanup = &stop_testing_system_cleanup, 134 .cleanup = &stop_testing_system_cleanup,
139 .traits = &stop_testing_system_traits 135 .traits = &stop_testing_system_traits
140 }; 136 };
141 137
142 return cmd; 138 return cmd;
139 }
143} 140}
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
index 8eccc5764..65eb85d9a 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
@@ -52,11 +52,9 @@ struct StopHelperState
52* Code to clean up resource this cmd used. 52* Code to clean up resource this cmd used.
53* 53*
54* @param cls closure 54* @param cls closure
55* @param cmd current CMD being cleaned up.
56*/ 55*/
57static void 56static void
58stop_testing_system_cleanup (void *cls, 57stop_testing_system_cleanup (void *cls)
59 const struct GNUNET_TESTING_Command *cmd)
60{ 58{
61 59
62} 60}
@@ -66,13 +64,13 @@ stop_testing_system_cleanup (void *cls,
66 * Trait function of this cmd does nothing. 64 * Trait function of this cmd does nothing.
67 * 65 *
68 */ 66 */
69static int 67static enum GNUNET_GenericReturnValue
70stop_testing_system_traits (void *cls, 68stop_testing_system_traits (void *cls,
71 const void **ret, 69 const void **ret,
72 const char *trait, 70 const char *trait,
73 unsigned int index) 71 unsigned int index)
74{ 72{
75 return GNUNET_OK; 73 return GNUNET_NO;
76} 74}
77 75
78 76
@@ -80,12 +78,10 @@ stop_testing_system_traits (void *cls,
80* This function stops the helper process for each node. 78* This function stops the helper process for each node.
81* 79*
82* @param cls closure. 80* @param cls closure.
83* @param cmd CMD being run.
84* @param is interpreter state. 81* @param is interpreter state.
85*/ 82*/
86static void 83static void
87stop_testing_system_run (void *cls, 84stop_testing_system_run (void *cls,
88 const struct GNUNET_TESTING_Command *cmd,
89 struct GNUNET_TESTING_Interpreter *is) 85 struct GNUNET_TESTING_Interpreter *is)
90{ 86{
91 struct StopHelperState *shs = cls; 87 struct StopHelperState *shs = cls;
@@ -93,6 +89,7 @@ stop_testing_system_run (void *cls,
93 const struct GNUNET_TESTING_Command *start_helper_cmd; 89 const struct GNUNET_TESTING_Command *start_helper_cmd;
94 90
95 start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command ( 91 start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (
92 is,
96 shs->helper_start_label); 93 shs->helper_start_label);
97 GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd, 94 GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd,
98 &helper); 95 &helper);
@@ -130,14 +127,15 @@ GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label,
130 shs->helper_start_label = helper_start_label; 127 shs->helper_start_label = helper_start_label;
131 shs->local_m = topology->nodes_m; 128 shs->local_m = topology->nodes_m;
132 shs->global_n = topology->namespaces_n; 129 shs->global_n = topology->namespaces_n;
133 130 {
134 struct GNUNET_TESTING_Command cmd = { 131 struct GNUNET_TESTING_Command cmd = {
135 .cls = shs, 132 .cls = shs,
136 .label = label, 133 .label = label,
137 .run = &stop_testing_system_run, 134 .run = &stop_testing_system_run,
138 .cleanup = &stop_testing_system_cleanup, 135 .cleanup = &stop_testing_system_cleanup,
139 .traits = &stop_testing_system_traits 136 .traits = &stop_testing_system_traits
140 }; 137 };
141 138
142 return cmd; 139 return cmd;
140 }
143} 141}
diff --git a/src/testing/testing_api_cmd_netjail_stop_v2.c b/src/testing/testing_api_cmd_netjail_stop_v2.c
index 8c1f3cedd..348e8c9f7 100644
--- a/src/testing/testing_api_cmd_netjail_stop_v2.c
+++ b/src/testing/testing_api_cmd_netjail_stop_v2.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file testing/testing_api_cmd_hello_world.c 22 * @file testing/testing_api_cmd_netjail_stop_v2.c
23 * @brief Command to stop the netjail script. 23 * @brief Command to stop the netjail script.
24 * @author t3sserakt 24 * @author t3sserakt
25 */ 25 */
@@ -50,7 +50,7 @@ struct NetJailState
50 struct GNUNET_OS_Process *stop_proc; 50 struct GNUNET_OS_Process *stop_proc;
51 51
52 // Flag indication if the script finished. 52 // Flag indication if the script finished.
53 unsigned int finished; 53 enum GNUNET_GenericReturnValue finished;
54}; 54};
55 55
56 56
@@ -59,8 +59,7 @@ struct NetJailState
59 * 59 *
60 */ 60 */
61static void 61static void
62netjail_stop_cleanup (void *cls, 62netjail_stop_cleanup (void *cls)
63 const struct GNUNET_TESTING_Command *cmd)
64{ 63{
65 struct NetJailState *ns = cls; 64 struct NetJailState *ns = cls;
66 65
@@ -86,13 +85,13 @@ netjail_stop_cleanup (void *cls,
86 * Trait function of this cmd does nothing. 85 * Trait function of this cmd does nothing.
87 * 86 *
88 */ 87 */
89static int 88static enum GNUNET_GenericReturnValue
90netjail_stop_traits (void *cls, 89netjail_stop_traits (void *cls,
91 const void **ret, 90 const void **ret,
92 const char *trait, 91 const char *trait,
93 unsigned int index) 92 unsigned int index)
94{ 93{
95 return GNUNET_OK; 94 return GNUNET_NO;
96} 95}
97 96
98 97
@@ -125,12 +124,10 @@ child_completed_callback (void *cls,
125* The run method starts the script which deletes the network namespaces. 124* The run method starts the script which deletes the network namespaces.
126* 125*
127* @param cls closure. 126* @param cls closure.
128* @param cmd CMD being run.
129* @param is interpreter state. 127* @param is interpreter state.
130*/ 128*/
131static void 129static void
132netjail_stop_run (void *cls, 130netjail_stop_run (void *cls,
133 const struct GNUNET_TESTING_Command *cmd,
134 struct GNUNET_TESTING_Interpreter *is) 131 struct GNUNET_TESTING_Interpreter *is)
135{ 132{
136 struct NetJailState *ns = cls; 133 struct NetJailState *ns = cls;
@@ -152,14 +149,14 @@ netjail_stop_run (void *cls,
152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
153 "No SUID for %s!\n", 150 "No SUID for %s!\n",
154 NETJAIL_STOP_SCRIPT); 151 NETJAIL_STOP_SCRIPT);
155 GNUNET_TESTING_interpreter_fail (); 152 GNUNET_TESTING_interpreter_fail (is);
156 } 153 }
157 else if (GNUNET_NO == helper_check) 154 else if (GNUNET_NO == helper_check)
158 { 155 {
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 "%s not found!\n", 157 "%s not found!\n",
161 NETJAIL_STOP_SCRIPT); 158 NETJAIL_STOP_SCRIPT);
162 GNUNET_TESTING_interpreter_fail (); 159 GNUNET_TESTING_interpreter_fail (is);
163 } 160 }
164 161
165 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, 162 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
@@ -181,7 +178,7 @@ netjail_stop_run (void *cls,
181 * This function checks the flag NetJailState#finished, if this cmd finished. 178 * This function checks the flag NetJailState#finished, if this cmd finished.
182 * 179 *
183 */ 180 */
184static int 181static enum GNUNET_GenericReturnValue
185netjail_stop_finish (void *cls, 182netjail_stop_finish (void *cls,
186 GNUNET_SCHEDULER_TaskCallback cont, 183 GNUNET_SCHEDULER_TaskCallback cont,
187 void *cont_cls) 184 void *cont_cls)
@@ -211,15 +208,16 @@ GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label,
211 208
212 ns = GNUNET_new (struct NetJailState); 209 ns = GNUNET_new (struct NetJailState);
213 ns->topology_config = topology_config; 210 ns->topology_config = topology_config;
214 211 {
215 struct GNUNET_TESTING_Command cmd = { 212 struct GNUNET_TESTING_Command cmd = {
216 .cls = ns, 213 .cls = ns,
217 .label = label, 214 .label = label,
218 .run = &netjail_stop_run, 215 .run = &netjail_stop_run,
219 .finish = &netjail_stop_finish, 216 .finish = &netjail_stop_finish,
220 .cleanup = &netjail_stop_cleanup, 217 .cleanup = &netjail_stop_cleanup,
221 .traits = &netjail_stop_traits 218 .traits = &netjail_stop_traits
222 }; 219 };
223 220
224 return cmd; 221 return cmd;
222 }
225} 223}
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c
index 016837214..8b4c11deb 100644
--- a/src/testing/testing_api_cmd_send_peer_ready.c
+++ b/src/testing/testing_api_cmd_send_peer_ready.c
@@ -53,13 +53,13 @@ struct SendPeerReadyState
53 * Trait function of this cmd does nothing. 53 * Trait function of this cmd does nothing.
54 * 54 *
55 */ 55 */
56static int 56static enum GNUNET_GenericReturnValue
57send_peer_ready_traits (void *cls, 57send_peer_ready_traits (void *cls,
58 const void **ret, 58 const void **ret,
59 const char *trait, 59 const char *trait,
60 unsigned int index) 60 unsigned int index)
61{ 61{
62 return GNUNET_OK; 62 return GNUNET_NO;
63} 63}
64 64
65 65
@@ -68,8 +68,7 @@ send_peer_ready_traits (void *cls,
68 * 68 *
69 */ 69 */
70static void 70static void
71send_peer_ready_cleanup (void *cls, 71send_peer_ready_cleanup (void *cls)
72 const struct GNUNET_TESTING_Command *cmd)
73{ 72{
74 struct SendPeerReadyState *sprs = cls; 73 struct SendPeerReadyState *sprs = cls;
75 74
@@ -84,7 +83,6 @@ send_peer_ready_cleanup (void *cls,
84 */ 83 */
85static void 84static void
86send_peer_ready_run (void *cls, 85send_peer_ready_run (void *cls,
87 const struct GNUNET_TESTING_Command *cmd,
88 struct GNUNET_TESTING_Interpreter *is) 86 struct GNUNET_TESTING_Interpreter *is)
89{ 87{
90 struct SendPeerReadyState *sprs = cls; 88 struct SendPeerReadyState *sprs = cls;
@@ -115,14 +113,15 @@ GNUNET_TESTING_cmd_send_peer_ready (const char *label,
115 113
116 sprs = GNUNET_new (struct SendPeerReadyState); 114 sprs = GNUNET_new (struct SendPeerReadyState);
117 sprs->write_message = write_message; 115 sprs->write_message = write_message;
118 116 {
119 struct GNUNET_TESTING_Command cmd = { 117 struct GNUNET_TESTING_Command cmd = {
120 .cls = sprs, 118 .cls = sprs,
121 .label = label, 119 .label = label,
122 .run = &send_peer_ready_run, 120 .run = &send_peer_ready_run,
123 .cleanup = &send_peer_ready_cleanup, 121 .cleanup = &send_peer_ready_cleanup,
124 .traits = &send_peer_ready_traits 122 .traits = &send_peer_ready_traits
125 }; 123 };
126 124
127 return cmd; 125 return cmd;
126 }
128} 127}
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
index f3a0b1a4c..820adf1bd 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -46,7 +46,6 @@ struct TestSystemState
46 */ 46 */
47static void 47static void
48system_create_run (void *cls, 48system_create_run (void *cls,
49 const struct GNUNET_TESTING_Command *cmd,
50 struct GNUNET_TESTING_Interpreter *is) 49 struct GNUNET_TESTING_Interpreter *is)
51{ 50{
52 struct TestSystemState *tss = cls; 51 struct TestSystemState *tss = cls;
@@ -115,8 +114,7 @@ GNUNET_TESTING_get_trait_test_system (const struct
115 * 114 *
116 */ 115 */
117static void 116static void
118system_create_cleanup (void *cls, 117system_create_cleanup (void *cls)
119 const struct GNUNET_TESTING_Command *cmd)
120{ 118{
121 struct TestSystemState *tss = cls; 119 struct TestSystemState *tss = cls;
122 120
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c
index 5ed0c2fd2..338123d91 100644
--- a/src/testing/testing_api_cmd_system_destroy.c
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -46,17 +46,18 @@ struct TestSystemState
46 */ 46 */
47static void 47static void
48system_destroy_run (void *cls, 48system_destroy_run (void *cls,
49 const struct GNUNET_TESTING_Command *cmd,
50 struct GNUNET_TESTING_Interpreter *is) 49 struct GNUNET_TESTING_Interpreter *is)
51{ 50{
52 struct TestSystemState *tss = cls; 51 struct TestSystemState *tss = cls;
53 const struct GNUNET_TESTING_Command *system_cmd; 52 const struct GNUNET_TESTING_Command *system_cmd;
54 struct GNUNET_TESTING_System *tl_system; 53 struct GNUNET_TESTING_System *tl_system;
55 54
56 system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label); 55 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
56 tss->create_label);
57 GNUNET_TESTING_get_trait_test_system (system_cmd, 57 GNUNET_TESTING_get_trait_test_system (system_cmd,
58 &tl_system); 58 &tl_system);
59 GNUNET_TESTING_system_destroy (tl_system, GNUNET_YES); 59 GNUNET_TESTING_system_destroy (tl_system,
60 GNUNET_YES);
60} 61}
61 62
62 63
@@ -65,8 +66,7 @@ system_destroy_run (void *cls,
65 * 66 *
66 */ 67 */
67static void 68static void
68system_destroy_cleanup (void *cls, 69system_destroy_cleanup (void *cls)
69 const struct GNUNET_TESTING_Command *cmd)
70{ 70{
71 struct TestSystemState *tss = cls; 71 struct TestSystemState *tss = cls;
72 72
@@ -78,7 +78,7 @@ system_destroy_cleanup (void *cls,
78 * Trait function of this cmd does nothing. 78 * Trait function of this cmd does nothing.
79 * 79 *
80 */ 80 */
81static int 81static enum GNUNET_GenericReturnValue
82system_destroy_traits (void *cls, 82system_destroy_traits (void *cls,
83 const void **ret, 83 const void **ret,
84 const char *trait, 84 const char *trait,
@@ -103,14 +103,15 @@ GNUNET_TESTING_cmd_system_destroy (const char *label,
103 103
104 tss = GNUNET_new (struct TestSystemState); 104 tss = GNUNET_new (struct TestSystemState);
105 tss->create_label = create_label; 105 tss->create_label = create_label;
106 106 {
107 struct GNUNET_TESTING_Command cmd = { 107 struct GNUNET_TESTING_Command cmd = {
108 .cls = tss, 108 .cls = tss,
109 .label = label, 109 .label = label,
110 .run = &system_destroy_run, 110 .run = &system_destroy_run,
111 .cleanup = &system_destroy_cleanup, 111 .cleanup = &system_destroy_cleanup,
112 .traits = &system_destroy_traits 112 .traits = &system_destroy_traits
113 }; 113 };
114 114
115 return cmd; 115 return cmd;
116 }
116} 117}
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 0c24c0e26..1c8eb1db6 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -24,67 +24,29 @@
24 * @author Christian Grothoff (GNU Taler testing) 24 * @author Christian Grothoff (GNU Taler testing)
25 * @author Marcello Stanisci (GNU Taler testing) 25 * @author Marcello Stanisci (GNU Taler testing)
26 * @author t3sserakt 26 * @author t3sserakt
27*/ 27 *
28 * FIXME:
29 * - interpreter failure is NOT returned properly yet!
30 * - abuse of shutdown logic for interpreter termination
31 * => API design flaw to be fixed!
32 */
28#include "platform.h" 33#include "platform.h"
29#include "gnunet_util_lib.h" 34#include "gnunet_util_lib.h"
30#include "gnunet_testing_ng_lib.h" 35#include "gnunet_testing_ng_lib.h"
31#include "testing.h" 36#include "testing.h"
32 37
33#define CHECK_FINISHED_PERIOD \
34 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
35
36struct GNUNET_TESTING_Interpreter *is;
37
38
39/**
40 * Closure used to sync an asynchronous with an synchronous command.
41 */
42struct SyncTaskClosure
43{
44
45 /**
46 * The asynchronous command the synchronous command waits for.
47 */
48 const struct GNUNET_TESTING_Command *async_cmd;
49
50 /**
51 * The synchronous command that waits for the asynchronous command.
52 */
53 const struct GNUNET_TESTING_Command *sync_cmd;
54
55 /**
56 * The interpreter of the test.
57 */
58 struct GNUNET_TESTING_Interpreter *is;
59};
60
61
62/**
63* Closure used to run the finish task.
64*/
65struct FinishTaskClosure
66{
67
68 /**
69 * The asynchronous command the synchronous command waits for.
70 */
71 const struct GNUNET_TESTING_Command *cmd;
72
73 /**
74 * The interpreter of the test.
75 */
76 struct GNUNET_TESTING_Interpreter *is;
77};
78
79 38
80/** 39/**
81 * Lookup command by label. 40 * Lookup command by label.
82 * 41 *
42 * @param is interpreter to lookup command in
83 * @param label label to look for 43 * @param label label to look for
84 * @return NULL if command was not found 44 * @return NULL if command was not found
85 */ 45 */
86const struct GNUNET_TESTING_Command * 46const struct GNUNET_TESTING_Command *
87GNUNET_TESTING_interpreter_lookup_command (const char *label) 47GNUNET_TESTING_interpreter_lookup_command (
48 struct GNUNET_TESTING_Interpreter *is,
49 const char *label)
88{ 50{
89 if (NULL == label) 51 if (NULL == label)
90 { 52 {
@@ -189,210 +151,35 @@ interpreter_next (void *cls)
189 151
190 152
191/** 153/**
192 * This function checks if the finish function of a command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called.
193 *
194 */
195static void
196run_finish_task_next (void *cls)
197{
198 struct FinishTaskClosure *ftc = cls;
199 const struct GNUNET_TESTING_Command *cmd = ftc->cmd;
200 struct GNUNET_TESTING_Interpreter *is = ftc->is;
201 unsigned int finished = cmd->finish (cmd->cls, &interpreter_next, is);
202
203 if (GNUNET_YES == finished)
204 {
205 is->finish_task = NULL;
206 }
207 else if (GNUNET_NO == finished)
208 {
209 is->finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD,
210 &run_finish_task_next, ftc);
211 }
212 else
213 {
214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
215 "Next task finished with an error.\n");
216 GNUNET_TESTING_interpreter_fail ();
217 }
218
219}
220
221
222/**
223 * This function checks if the finish function of an asynchronous command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called.
224 *
225 * //TODO run_finish_task_next and this function can be merged.
226 *
227 */
228static void
229run_finish_task_sync (void *cls)
230{
231 struct SyncTaskClosure *stc = cls;
232 const struct GNUNET_TESTING_Command *cmd = stc->async_cmd;
233 const struct GNUNET_TESTING_Command *sync_cmd = stc->sync_cmd;
234 struct FinishTaskClosure *ftc;
235 struct SyncState *sync_state = sync_cmd->cls;
236 struct GNUNET_SCHEDULER_Task *finish_task = sync_state->finish_task;
237 unsigned int finished = cmd->finish (cmd->cls, &interpreter_next, is);
238
239 GNUNET_assert (NULL != finish_task);
240 ftc = GNUNET_new (struct FinishTaskClosure);
241 ftc->cmd = stc->sync_cmd;
242 ftc->is = stc->is;
243 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
244 if (cmd->default_timeout.rel_value_us < now.abs_value_us
245 - sync_state->start_finish_time.abs_value_us)
246 {
247 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
248 "The command with label %s did not finish its asynchronous task in time.\n",
249 cmd->label);
250 GNUNET_TESTING_interpreter_fail ();
251 }
252
253 if (GNUNET_YES == finished)
254 {
255 finish_task = NULL;
256 }
257 else if (GNUNET_NO == finished)
258 {
259 finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD,
260 &run_finish_task_sync, stc);
261 }
262 else
263 {
264 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
265 "Sync task finished with an error.\n");
266 GNUNET_TESTING_interpreter_fail ();
267 }
268}
269
270
271/**
272 * run method of the command created by the interpreter to wait for another command to finish.
273 *
274 */
275static void
276start_finish_on_ref (void *cls,
277 const struct GNUNET_TESTING_Command *cmd,
278 struct GNUNET_TESTING_Interpreter *is)
279{
280 struct SyncState *sync_state = cls;
281 struct SyncTaskClosure *stc;
282 const struct GNUNET_TESTING_Command *async_cmd;
283
284 async_cmd = sync_state->async_cmd;
285 stc = GNUNET_new (struct SyncTaskClosure);
286 stc->async_cmd = async_cmd;
287 stc->sync_cmd = cmd;
288 stc->is = is;
289 sync_state->start_finish_time = GNUNET_TIME_absolute_get ();
290 sync_state->finish_task = GNUNET_SCHEDULER_add_delayed (
291 CHECK_FINISHED_PERIOD,
292 &run_finish_task_sync,
293 stc);
294}
295
296
297/**
298 * Create (synchronous) command that waits for another command to finish.
299 * If @a cmd_ref did not finish after @a timeout, this command will fail
300 * the test case.
301 *
302 * @param finish_label label for this command
303 * @param cmd_ref reference to a previous command which we should
304 * wait for (call `finish()` on)
305 * @param timeout how long to wait at most for @a cmd_ref to finish
306 * @return a finish-command.
307 */
308const struct GNUNET_TESTING_Command
309GNUNET_TESTING_cmd_finish (const char *finish_label,
310 const char *cmd_ref,
311 struct GNUNET_TIME_Relative timeout)
312{
313 const struct GNUNET_TESTING_Command *async_cmd;
314 struct SyncState *sync_state;
315
316 async_cmd = GNUNET_TESTING_interpreter_lookup_command (cmd_ref);
317 sync_state = GNUNET_new (struct SyncState);
318 sync_state->async_cmd = async_cmd;
319
320 struct GNUNET_TESTING_Command cmd = {
321 .cls = sync_state,
322 .label = finish_label,
323 .run = &start_finish_on_ref,
324 .asynchronous_finish = GNUNET_NO
325 };
326
327 return cmd;
328}
329
330
331const struct GNUNET_TESTING_Command
332GNUNET_TESTING_cmd_make_unblocking (const struct GNUNET_TESTING_Command cmd)
333{
334
335 GNUNET_assert (NULL != cmd.finish);
336 const struct GNUNET_TESTING_Command async_cmd = {
337 .cls = cmd.cls,
338 .label = cmd.label,
339 .run = cmd.run,
340 .cleanup = cmd.cleanup,
341 .traits = cmd.traits,
342 .finish = cmd.finish,
343 .asynchronous_finish = GNUNET_YES
344 };
345
346 return async_cmd;
347}
348
349
350/**
351 * Current command failed, clean up and fail the test case. 154 * Current command failed, clean up and fail the test case.
352 * 155 *
353 * @param is interpreter of the test 156 * @param is interpreter of the test
354 */ 157 */
355void 158void
356GNUNET_TESTING_interpreter_fail () 159GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is)
357{ 160{
358 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; 161 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
359 162
360 if (GNUNET_SYSERR == is->result) 163 if (GNUNET_SYSERR == is->result)
361 return; /* ignore, we already failed! */ 164 return; /* ignore, we already failed! */
362
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
364 "interpreter_fail!\n");
365
366 if (NULL != cmd) 165 if (NULL != cmd)
367 { 166 {
167 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
168 "Failed at command `%s'\n",
169 cmd->label);
368 while (GNUNET_TESTING_cmd_is_batch (cmd)) 170 while (GNUNET_TESTING_cmd_is_batch (cmd))
369 { 171 {
370 cmd = GNUNET_TESTING_cmd_batch_get_current (cmd); 172 cmd = GNUNET_TESTING_cmd_batch_get_current (cmd);
371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
372 "Batch is at command `%s'\n", 174 "Failed in batch at command `%s'\n",
373 cmd->label); 175 cmd->label);
374 } 176 }
375
376 } 177 }
377 else 178 else
378 { 179 {
379 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 180 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
380 "cmd is NULL.\n"); 181 "Failed with CMD being NULL!\n");
381 }
382
383 if (NULL == cmd->label)
384 {
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
386 "Failed at command `%s'\n",
387 cmd->label);
388
389 }
390 else
391 {
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
393 "cmd->label is NULL.\n");
394 } 182 }
395
396 is->result = GNUNET_SYSERR; 183 is->result = GNUNET_SYSERR;
397 GNUNET_SCHEDULER_shutdown (); 184 GNUNET_SCHEDULER_shutdown ();
398} 185}
@@ -406,8 +193,9 @@ GNUNET_TESTING_interpreter_fail ()
406struct GNUNET_TESTING_Command 193struct GNUNET_TESTING_Command
407GNUNET_TESTING_cmd_end (void) 194GNUNET_TESTING_cmd_end (void)
408{ 195{
409 static struct GNUNET_TESTING_Command cmd; 196 static struct GNUNET_TESTING_Command cmd = {
410 cmd.label = NULL; 197 .label = NULL
198 };
411 199
412 return cmd; 200 return cmd;
413} 201}
@@ -417,8 +205,8 @@ GNUNET_TESTING_cmd_end (void)
417 * Obtain current label. 205 * Obtain current label.
418 */ 206 */
419const char * 207const char *
420GNUNET_TESTING_interpreter_get_current_label (struct 208GNUNET_TESTING_interpreter_get_current_label (
421 GNUNET_TESTING_Interpreter *is) 209 struct GNUNET_TESTING_Interpreter *is)
422{ 210{
423 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; 211 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
424 212
@@ -434,46 +222,36 @@ GNUNET_TESTING_interpreter_get_current_label (struct
434static void 222static void
435interpreter_run (void *cls) 223interpreter_run (void *cls)
436{ 224{
437 struct FinishTaskClosure *ftc;
438 struct GNUNET_TESTING_Interpreter *is = cls; 225 struct GNUNET_TESTING_Interpreter *is = cls;
439 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; 226 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
440 227
441 is->task = NULL; 228 is->task = NULL;
442
443 if (NULL == cmd->label) 229 if (NULL == cmd->label)
444 { 230 {
445
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
447 "Running command END %p\n", 232 "Running command END\n");
448 is);
449 is->result = GNUNET_OK; 233 is->result = GNUNET_OK;
450 GNUNET_SCHEDULER_shutdown (); 234 GNUNET_SCHEDULER_shutdown ();
451 return; 235 return;
452 } 236 }
453 else if (NULL != cmd) 237 if (NULL != cmd)
454 { 238 {
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
456 "Running command `%s' %p\n", 240 "Running command `%s'\n",
457 cmd->label, 241 cmd->label);
458 is);
459 } 242 }
460 cmd->start_time 243 cmd->start_time
461 = cmd->last_req_time 244 = cmd->last_req_time
462 = GNUNET_TIME_absolute_get (); 245 = GNUNET_TIME_absolute_get ();
463 cmd->num_tries = 1; 246 cmd->num_tries = 1;
464 cmd->run (cmd->cls, 247 cmd->run (cmd->cls,
465 cmd,
466 is); 248 is);
467 if ((NULL != cmd->finish) && (GNUNET_NO == cmd->asynchronous_finish)) 249 if ( (NULL != cmd->finish) &&
250 (! cmd->asynchronous_finish) )
468 { 251 {
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 252 cmd->finish (cmd->cls,
470 "Next task will not be called directly!\n"); 253 &interpreter_next,
471 ftc = GNUNET_new (struct FinishTaskClosure); 254 is);
472 ftc->cmd = cmd;
473 ftc->is = is;
474 is->finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD,
475 &run_finish_task_next,
476 ftc);
477 } 255 }
478 else 256 else
479 { 257 {
@@ -491,37 +269,33 @@ interpreter_run (void *cls)
491static void 269static void
492do_shutdown (void *cls) 270do_shutdown (void *cls)
493{ 271{
494 (void) cls; 272 struct GNUNET_TESTING_Interpreter *is = cls;
495 struct GNUNET_TESTING_Command *cmd; 273 struct GNUNET_TESTING_Command *cmd;
496 const char *label; 274 const char *label;
497 275
498 label = is->commands[is->ip].label; 276 label = is->commands[is->ip].label;
499 if (NULL == label) 277 if (NULL == label)
500 label = "END"; 278 label = "END";
501
502 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 279 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
503 "Executing shutdown at `%s'\n", 280 "Executing shutdown at `%s'\n",
504 label); 281 label);
505
506 for (unsigned int j = 0; 282 for (unsigned int j = 0;
507 NULL != (cmd = &is->commands[j])->label; 283 NULL != (cmd = &is->commands[j])->label;
508 j++) { 284 j++)
285 {
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "Cleaning up cmd %s\n", 287 "Cleaning up cmd %s\n",
511 cmd->label); 288 cmd->label);
512 cmd->cleanup (cmd->cls, 289 cmd->cleanup (cmd->cls);
513 cmd);
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
515 "Cleaned up cmd %s\n", 291 "Cleaned up cmd %s\n",
516 cmd->label); 292 cmd->label);
517 } 293 }
518
519 if (NULL != is->finish_task) 294 if (NULL != is->finish_task)
520 { 295 {
521 GNUNET_SCHEDULER_cancel (is->finish_task); 296 GNUNET_SCHEDULER_cancel (is->finish_task);
522 cmd->finish_task = NULL; 297 is->finish_task = NULL;
523 } 298 }
524
525 if (NULL != is->task) 299 if (NULL != is->task)
526 { 300 {
527 GNUNET_SCHEDULER_cancel (is->task); 301 GNUNET_SCHEDULER_cancel (is->task);
@@ -533,18 +307,19 @@ do_shutdown (void *cls)
533 is->timeout_task = NULL; 307 is->timeout_task = NULL;
534 } 308 }
535 GNUNET_free (is->commands); 309 GNUNET_free (is->commands);
310 GNUNET_free (is);
536} 311}
537 312
538 313
539/** 314/**
540 * Function run when the test terminates (good or bad) with timeout. 315 * Function run when the test terminates (good or bad) with timeout.
541 * 316 *
542 * @param cls NULL 317 * @param cls the interpreter state
543 */ 318 */
544static void 319static void
545do_timeout (void *cls) 320do_timeout (void *cls)
546{ 321{
547 (void) cls; 322 struct GNUNET_TESTING_Interpreter *is = cls;
548 323
549 is->timeout_task = NULL; 324 is->timeout_task = NULL;
550 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 325 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -553,30 +328,15 @@ do_timeout (void *cls)
553} 328}
554 329
555 330
556/** 331enum GNUNET_GenericReturnValue
557 * Run the testsuite. Note, CMDs are copied into
558 * the interpreter state because they are _usually_
559 * defined into the "run" method that returns after
560 * having scheduled the test interpreter.
561 *
562 * @param is the interpreter state
563 * @param commands the list of command to execute
564 * @param timeout how long to wait
565 */
566int
567GNUNET_TESTING_run (const char *cfg_filename, 332GNUNET_TESTING_run (const char *cfg_filename,
568 struct GNUNET_TESTING_Command *commands, 333 struct GNUNET_TESTING_Command *commands,
569 struct GNUNET_TIME_Relative timeout) 334 struct GNUNET_TIME_Relative timeout)
570{ 335{
336 struct GNUNET_TESTING_Interpreter *is;
571 unsigned int i; 337 unsigned int i;
572 338
573 is = GNUNET_new (struct GNUNET_TESTING_Interpreter); 339 is = GNUNET_new (struct GNUNET_TESTING_Interpreter);
574
575 if (NULL != is->timeout_task)
576 {
577 GNUNET_SCHEDULER_cancel (is->timeout_task);
578 is->timeout_task = NULL;
579 }
580 /* get the number of commands */ 340 /* get the number of commands */
581 for (i = 0; NULL != commands[i].label; i++) 341 for (i = 0; NULL != commands[i].label; i++)
582 ; 342 ;
@@ -585,15 +345,67 @@ GNUNET_TESTING_run (const char *cfg_filename,
585 memcpy (is->commands, 345 memcpy (is->commands,
586 commands, 346 commands,
587 sizeof (struct GNUNET_TESTING_Command) * i); 347 sizeof (struct GNUNET_TESTING_Command) * i);
588 348 is->timeout_task
589 is->timeout_task = GNUNET_SCHEDULER_add_delayed 349 = GNUNET_SCHEDULER_add_delayed (timeout,
590 (timeout, 350 &do_timeout,
591 &do_timeout, 351 is);
592 is); 352 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
593 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, is); 353 is);
594 is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is); 354 is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,
355 is);
595 return GNUNET_OK; 356 return GNUNET_OK;
596} 357}
597 358
598 359
360/**
361 * Closure for #loop_run().
362 */
363struct MainParams
364{
365 const char *cfg_filename;
366 struct GNUNET_TESTING_Command *commands;
367 struct GNUNET_TIME_Relative timeout;
368 int rv;
369};
370
371
372/**
373 * Main function to run the test cases.
374 *
375 * @param cls a `struct MainParams *`
376 */
377static void
378loop_run (void *cls)
379{
380 struct MainParams *mp = cls;
381
382 if (GNUNET_OK !=
383 GNUNET_TESTING_run (mp->cfg_filename,
384 mp->commands,
385 mp->timeout))
386 {
387 GNUNET_break (0);
388 mp->rv = EXIT_FAILURE;
389 }
390}
391
392
393int
394GNUNET_TESTING_main (const char *cfg_filename,
395 struct GNUNET_TESTING_Command *commands,
396 struct GNUNET_TIME_Relative timeout)
397{
398 struct MainParams mp = {
399 .cfg_filename = cfg_filename,
400 .commands = commands,
401 .timeout = timeout,
402 .rv = EXIT_SUCCESS
403 };
404
405 GNUNET_SCHEDULER_run (&loop_run,
406 &mp);
407 return mp.rv;
408}
409
410
599/* end of testing_api_loop.c */ 411/* end of testing_api_loop.c */
diff --git a/src/testing/testing_api_trait_cmd.c b/src/testing/testing_api_trait_cmd.c
index 886baee5b..7afa8b264 100644
--- a/src/testing/testing_api_trait_cmd.c
+++ b/src/testing/testing_api_trait_cmd.c
@@ -41,7 +41,7 @@
41 * @param[out] _cmd where to write the wire details. 41 * @param[out] _cmd where to write the wire details.
42 * @return #GNUNET_OK on success. 42 * @return #GNUNET_OK on success.
43 */ 43 */
44int 44enum GNUNET_GenericReturnValue
45GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, 45GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd,
46 unsigned int index, 46 unsigned int index,
47 struct GNUNET_TESTING_Command **_cmd) 47 struct GNUNET_TESTING_Command **_cmd)
diff --git a/src/testing/testing_api_traits.c b/src/testing/testing_api_traits.c
index 66626833d..2f836ddfa 100644
--- a/src/testing/testing_api_traits.c
+++ b/src/testing/testing_api_traits.c
@@ -55,7 +55,7 @@ GNUNET_TESTING_trait_end ()
55 * @param index index number of the object to extract. 55 * @param index index number of the object to extract.
56 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. 56 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
57 */ 57 */
58int 58enum GNUNET_GenericReturnValue
59GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, 59GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
60 const void **ret, 60 const void **ret,
61 const char *trait, 61 const char *trait,