aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/gnunet-cmds-helper.c190
-rw-r--r--src/testing/testing_api_cmd_block_until_all_peers_started.c41
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c42
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c42
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c228
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c40
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c25
-rw-r--r--src/testing/testing_api_cmd_send_peer_ready.c25
-rw-r--r--src/testing/testing_api_cmd_system_create.c25
-rw-r--r--src/testing/testing_api_cmd_system_destroy.c6
-rw-r--r--src/testing/testing_api_loop.c44
11 files changed, 413 insertions, 295 deletions
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index 5705f46c2..21ea33888 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -47,7 +47,7 @@
47 47
48/** 48/**
49 * Generic logging shortcut 49 * Generic logging shortcut
50 */ 50testing_api_cmd_block_until_all_peers_started.c */
51#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 51#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
52 52
53/** 53/**
@@ -74,27 +74,71 @@ struct Plugin
74 */ 74 */
75 struct GNUNET_TESTING_PluginFunctions *api; 75 struct GNUNET_TESTING_PluginFunctions *api;
76 76
77 /**
78 * IP address of the specific node the helper is running for.
79 *
80 */
77 char *node_ip; 81 char *node_ip;
78 82
83 /**
84 * Name of the test case plugin.
85 *
86 */
79 char *plugin_name; 87 char *plugin_name;
80 88
89 /**
90 * The number of namespaces
91 *
92 */
81 char *global_n; 93 char *global_n;
82 94
95 /**
96 * The number of local nodes per namespace.
97 *
98 */
83 char *local_m; 99 char *local_m;
84 100
101 /**
102 * The number of the namespace this node is in.
103 *
104 */
85 char *n; 105 char *n;
86 106
107 /**
108 * The number of the node in the namespace.
109 *
110 */
87 char *m; 111 char *m;
88}; 112};
89 113
114/**
115 * Struct with information about a specific node and the whole network namespace setup.
116 *
117 */
90struct NodeIdentifier 118struct NodeIdentifier
91{ 119{
120 /**
121 * The number of the namespace this node is in.
122 *
123 */
92 char *n; 124 char *n;
93 125
126 /**
127 * The number of the node in the namespace.
128 *
129 */
94 char *m; 130 char *m;
95 131
132 /**
133 * The number of namespaces
134 *
135 */
96 char *global_n; 136 char *global_n;
97 137
138 /**
139 * The number of local nodes per namespace.
140 *
141 */
98 char *local_m; 142 char *local_m;
99}; 143};
100 144
@@ -162,11 +206,6 @@ static struct GNUNET_SCHEDULER_Task *read_task_id;
162static struct GNUNET_SCHEDULER_Task *write_task_id; 206static struct GNUNET_SCHEDULER_Task *write_task_id;
163 207
164/** 208/**
165 * Task to kill the child
166 */
167static struct GNUNET_SCHEDULER_Task *child_death_task_id;
168
169/**
170 * Are we done reading messages from stdin? 209 * Are we done reading messages from stdin?
171 */ 210 */
172static int done_reading; 211static int done_reading;
@@ -187,8 +226,6 @@ shutdown_task (void *cls)
187{ 226{
188 227
189 LOG_DEBUG ("Shutting down.\n"); 228 LOG_DEBUG ("Shutting down.\n");
190 LOG (GNUNET_ERROR_TYPE_ERROR,
191 "Shutting down tokenizer!\n");
192 229
193 if (NULL != read_task_id) 230 if (NULL != read_task_id)
194 { 231 {
@@ -204,11 +241,6 @@ shutdown_task (void *cls)
204 GNUNET_free (wc->data); 241 GNUNET_free (wc->data);
205 GNUNET_free (wc); 242 GNUNET_free (wc);
206 } 243 }
207 if (NULL != child_death_task_id)
208 {
209 GNUNET_SCHEDULER_cancel (child_death_task_id);
210 child_death_task_id = NULL;
211 }
212 if (NULL != stdin_fd) 244 if (NULL != stdin_fd)
213 (void) GNUNET_DISK_file_close (stdin_fd); 245 (void) GNUNET_DISK_file_close (stdin_fd);
214 if (NULL != stdout_fd) 246 if (NULL != stdout_fd)
@@ -235,9 +267,6 @@ write_task (void *cls)
235 struct WriteContext *wc = cls; 267 struct WriteContext *wc = cls;
236 ssize_t bytes_wrote; 268 ssize_t bytes_wrote;
237 269
238 LOG (GNUNET_ERROR_TYPE_ERROR,
239 "Writing data!\n");
240
241 GNUNET_assert (NULL != wc); 270 GNUNET_assert (NULL != wc);
242 write_task_id = NULL; 271 write_task_id = NULL;
243 bytes_wrote = GNUNET_DISK_file_write (stdout_fd, 272 bytes_wrote = GNUNET_DISK_file_write (stdout_fd,
@@ -256,12 +285,8 @@ write_task (void *cls)
256 { 285 {
257 GNUNET_free (wc->data); 286 GNUNET_free (wc->data);
258 GNUNET_free (wc); 287 GNUNET_free (wc);
259 LOG (GNUNET_ERROR_TYPE_ERROR,
260 "Written successfully!\n");
261 return; 288 return;
262 } 289 }
263 LOG (GNUNET_ERROR_TYPE_ERROR,
264 "Written data!\n");
265 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 290 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
266 stdout_fd, 291 stdout_fd,
267 &write_task, 292 &write_task,
@@ -270,39 +295,14 @@ write_task (void *cls)
270 295
271 296
272/** 297/**
273 * Task triggered whenever we receive a SIGCHLD (child 298 * Callback to write a message to the master loop.
274 * process died).
275 * 299 *
276 * @param cls closure, NULL if we need to self-restart
277 */ 300 */
278/*static void
279child_death_task (void *cls)
280{
281 const struct GNUNET_DISK_FileHandle *pr;
282 char c[16];
283
284 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
285 child_death_task_id = NULL;
286 // consume the signal
287 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c)));
288 LOG_DEBUG ("Got SIGCHLD\n");
289
290 LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n");
291 child_death_task_id =
292 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
293 pr,
294 &child_death_task,
295 NULL);
296}*/
297
298
299static void 301static void
300write_message (struct GNUNET_MessageHeader *message, size_t msg_length) 302write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
301{ 303{
302 struct WriteContext *wc; 304 struct WriteContext *wc;
303 305
304 LOG (GNUNET_ERROR_TYPE_ERROR,
305 "enter write_message!\n");
306 wc = GNUNET_new (struct WriteContext); 306 wc = GNUNET_new (struct WriteContext);
307 wc->length = msg_length; 307 wc->length = msg_length;
308 wc->data = message; 308 wc->data = message;
@@ -311,38 +311,10 @@ write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
311 stdout_fd, 311 stdout_fd,
312 &write_task, 312 &write_task,
313 wc); 313 wc);
314 LOG (GNUNET_ERROR_TYPE_ERROR,
315 "leave write_message!\n");
316} 314}
317 315
318 316
319/** 317/**
320 * Function to run the test cases.
321 *
322 * @param cls plugin to use.
323 *
324 */
325/*static void
326run_plugin (void *cls)
327{
328 struct Plugin *plugin = cls;
329 char *router_ip;
330 char *node_ip;
331
332 router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m) + 1);
333 strcpy (router_ip, ROUTER_BASE_IP);
334 strcat (router_ip, plugin->m);
335
336 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1);
337 strcat (node_ip, NODE_BASE_IP);
338 strcat (node_ip, plugin->n);
339
340 plugin->api->start_testcase (&write_message, router_ip, node_ip);
341
342}*/
343
344
345/**
346 * Functions with this signature are called whenever a 318 * Functions with this signature are called whenever a
347 * complete message is received by the tokenizer. 319 * complete message is received by the tokenizer.
348 * 320 *
@@ -368,9 +340,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
368 char *router_ip; 340 char *router_ip;
369 char *node_ip; 341 char *node_ip;
370 342
371 LOG (GNUNET_ERROR_TYPE_ERROR,
372 "tokenizer \n");
373
374 msize = ntohs (message->size); 343 msize = ntohs (message->size);
375 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type)) 344 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type))
376 { 345 {
@@ -390,23 +359,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
390 359
391 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd"); 360 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd");
392 361
393 LOG (GNUNET_ERROR_TYPE_ERROR,
394 "plugin_name: %s \n",
395 plugin_name);
396
397 // cmd_binary_process = GNUNET_OS_start_process (
398 /*GNUNET_OS_INHERIT_STD_ERR verbose? ,
399 NULL,
400 NULL,
401 NULL,
402 binary,
403 plugin_name,
404 ni->global_n,
405 ni->local_m,
406 ni->n,
407 ni->m,
408 NULL);*/
409
410 plugin = GNUNET_new (struct Plugin); 362 plugin = GNUNET_new (struct Plugin);
411 plugin->api = GNUNET_PLUGIN_load (plugin_name, 363 plugin->api = GNUNET_PLUGIN_load (plugin_name,
412 NULL); 364 NULL);
@@ -429,51 +381,15 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
429 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m, 381 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
430 plugin->n, plugin->local_m); 382 plugin->n, plugin->local_m);
431 383
432 LOG (GNUNET_ERROR_TYPE_ERROR,
433 "We got here!\n");
434
435 /*if (NULL == cmd_binary_process)
436 {
437 LOG (GNUNET_ERROR_TYPE_ERROR,
438 "Starting plugin failed!\n");
439 return GNUNET_SYSERR;
440 }*/
441
442 LOG (GNUNET_ERROR_TYPE_ERROR,
443 "We got here 2!\n");
444
445 LOG (GNUNET_ERROR_TYPE_ERROR,
446 "global_n: %s local_n: %s n: %s m: %s.\n",
447 ni->global_n,
448 ni->local_m,
449 ni->n,
450 ni->m);
451
452 LOG (GNUNET_ERROR_TYPE_ERROR,
453 "We got here 3!\n");
454
455 GNUNET_free (binary); 384 GNUNET_free (binary);
456 385
457 // done_reading = GNUNET_YES;
458
459 msg_length = sizeof(struct GNUNET_CMDS_HelperReply); 386 msg_length = sizeof(struct GNUNET_CMDS_HelperReply);
460 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply); 387 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply);
461 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY); 388 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY);
462 reply->header.size = htons ((uint16_t) msg_length); 389 reply->header.size = htons ((uint16_t) msg_length);
463 390
464 LOG (GNUNET_ERROR_TYPE_ERROR,
465 "We got here 4!\n");
466
467 write_message ((struct GNUNET_MessageHeader *) reply, msg_length); 391 write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
468 392
469 LOG (GNUNET_ERROR_TYPE_ERROR,
470 "We got here 5!\n");
471
472 /*child_death_task_id = GNUNET_SCHEDULER_add_read_file (
473 GNUNET_TIME_UNIT_FOREVER_REL,
474 GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
475 &child_death_task,
476 NULL);*/
477 return GNUNET_OK; 393 return GNUNET_OK;
478 } 394 }
479 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( 395 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
@@ -514,8 +430,6 @@ read_task (void *cls)
514 if ((GNUNET_SYSERR == sread) || (0 == sread)) 430 if ((GNUNET_SYSERR == sread) || (0 == sread))
515 { 431 {
516 LOG_DEBUG ("STDIN closed\n"); 432 LOG_DEBUG ("STDIN closed\n");
517 LOG (GNUNET_ERROR_TYPE_ERROR,
518 "tokenizer shutting down during reading!\n");
519 GNUNET_SCHEDULER_shutdown (); 433 GNUNET_SCHEDULER_shutdown ();
520 return; 434 return;
521 } 435 }
@@ -529,8 +443,6 @@ read_task (void *cls)
529 return; 443 return;
530 } 444 }
531 LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread); 445 LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread);
532 LOG (GNUNET_ERROR_TYPE_ERROR,
533 "Read %u bytes\n", (unsigned int) sread);
534 /* FIXME: could introduce a GNUNET_MST_read2 to read 446 /* FIXME: could introduce a GNUNET_MST_read2 to read
535 directly from 'stdin_fd' and save a memcpy() here */ 447 directly from 'stdin_fd' and save a memcpy() here */
536 if (GNUNET_OK != 448 if (GNUNET_OK !=
@@ -624,13 +536,6 @@ main (int argc, char **argv)
624 ni->n = argv[3]; 536 ni->n = argv[3];
625 ni->m = argv[4]; 537 ni->m = argv[4];
626 538
627 LOG (GNUNET_ERROR_TYPE_ERROR,
628 "global_n: %s local_n: %s n: %s m: %s.\n",
629 ni->global_n,
630 ni->local_m,
631 ni->n,
632 ni->m);
633
634 status = GNUNET_OK; 539 status = GNUNET_OK;
635 if (NULL == 540 if (NULL ==
636 (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE))) 541 (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
@@ -647,8 +552,7 @@ main (int argc, char **argv)
647 options, 552 options,
648 &run, 553 &run,
649 ni); 554 ni);
650 LOG (GNUNET_ERROR_TYPE_ERROR, 555
651 "run finished\n");
652 GNUNET_SIGNAL_handler_uninstall (shc_chld); 556 GNUNET_SIGNAL_handler_uninstall (shc_chld);
653 shc_chld = NULL; 557 shc_chld = NULL;
654 GNUNET_DISK_pipe_close (sigpipe); 558 GNUNET_DISK_pipe_close (sigpipe);
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 8659fbb46..e9d3f0ed3 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
@@ -32,12 +32,24 @@
32 */ 32 */
33#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
34 34
35/**
36 * Struct with information for callbacks.
37 *
38 */
35struct BlockState 39struct BlockState
36{ 40{
41 /**
42 * Flag to indicate if all peers have started.
43 *
44 */
37 unsigned int *all_peers_started; 45 unsigned int *all_peers_started;
38}; 46};
39 47
40 48
49/**
50 * Trait function of this cmd does nothing.
51 *
52 */
41static int 53static int
42block_until_all_peers_started_traits (void *cls, 54block_until_all_peers_started_traits (void *cls,
43 const void **ret, 55 const void **ret,
@@ -48,6 +60,10 @@ block_until_all_peers_started_traits (void *cls,
48} 60}
49 61
50 62
63/**
64 * The cleanup function of this cmd frees resources the cmd allocated.
65 *
66 */
51static void 67static void
52block_until_all_peers_started_cleanup (void *cls, 68block_until_all_peers_started_cleanup (void *cls,
53 const struct GNUNET_TESTING_Command *cmd) 69 const struct GNUNET_TESTING_Command *cmd)
@@ -58,16 +74,24 @@ block_until_all_peers_started_cleanup (void *cls,
58} 74}
59 75
60 76
77/**
78 * This function does nothing but to start the cmd.
79 *
80 */
61static void 81static void
62block_until_all_peers_started_run (void *cls, 82block_until_all_peers_started_run (void *cls,
63 const struct GNUNET_TESTING_Command *cmd, 83 const struct GNUNET_TESTING_Command *cmd,
64 struct GNUNET_TESTING_Interpreter *is) 84 struct GNUNET_TESTING_Interpreter *is)
65{ 85{
66 LOG (GNUNET_ERROR_TYPE_ERROR, 86 LOG (GNUNET_ERROR_TYPE_DEBUG,
67 "block_until_all_peers_started_run!\n"); 87 "block_until_all_peers_started_run!\n");
68} 88}
69 89
70 90
91/**
92 * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called.
93 *
94 */
71static int 95static int
72block_until_all_peers_started_finish (void *cls, 96block_until_all_peers_started_finish (void *cls,
73 GNUNET_SCHEDULER_TaskCallback cont, 97 GNUNET_SCHEDULER_TaskCallback cont,
@@ -76,20 +100,10 @@ block_until_all_peers_started_finish (void *cls,
76 struct BlockState *bs = cls; 100 struct BlockState *bs = cls;
77 unsigned int *ret = bs->all_peers_started; 101 unsigned int *ret = bs->all_peers_started;
78 102
79 LOG (GNUNET_ERROR_TYPE_ERROR,
80 "We got here 10\n");
81
82 if (GNUNET_YES == *ret) 103 if (GNUNET_YES == *ret)
83 { 104 {
84 LOG (GNUNET_ERROR_TYPE_ERROR,
85 "We do not need to block anymore!\n");
86 cont (cont_cls); 105 cont (cont_cls);
87 } 106 }
88 else
89 {
90 LOG (GNUNET_ERROR_TYPE_ERROR,
91 "You shall not pass!\n");
92 }
93 107
94 return *ret; 108 return *ret;
95} 109}
@@ -99,6 +113,7 @@ block_until_all_peers_started_finish (void *cls,
99 * Create command. 113 * Create command.
100 * 114 *
101 * @param label name for command. 115 * @param label name for command.
116 * @param all_peers_started Flag which will be set from outside.
102 * @return command. 117 * @return command.
103 */ 118 */
104struct GNUNET_TESTING_Command 119struct GNUNET_TESTING_Command
@@ -108,10 +123,6 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
108{ 123{
109 struct BlockState *bs; 124 struct BlockState *bs;
110 125
111 LOG (GNUNET_ERROR_TYPE_ERROR,
112 "we have all_peers_started: %u\n",
113 *all_peers_started);
114
115 bs = GNUNET_new (struct BlockState); 126 bs = GNUNET_new (struct BlockState);
116 bs->all_peers_started = all_peers_started; 127 bs->all_peers_started = all_peers_started;
117 128
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
index 5b74d4e04..383de4c10 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -33,14 +33,31 @@
33 */ 33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35 35
36
37/**
38 * Struct to hold information for callbacks.
39 *
40 */
36struct LocalFinishedState 41struct LocalFinishedState
37{ 42{
43 /**
44 * Callback to write messages to the master loop.
45 *
46 */
38 TESTING_CMD_HELPER_write_cb write_message; 47 TESTING_CMD_HELPER_write_cb write_message;
39 48
49 /**
50 * The message send back to the master loop.
51 *
52 */
40 struct GNUNET_CMDS_LOCAL_FINISHED *reply; 53 struct GNUNET_CMDS_LOCAL_FINISHED *reply;
41}; 54};
42 55
43 56
57/**
58 * Trait function of this cmd does nothing.
59 *
60 */
44static int 61static int
45local_test_finished_traits (void *cls, 62local_test_finished_traits (void *cls,
46 const void **ret, 63 const void **ret,
@@ -51,6 +68,10 @@ local_test_finished_traits (void *cls,
51} 68}
52 69
53 70
71/**
72 * The cleanup function of this cmd frees resources the cmd allocated.
73 *
74 */
54static void 75static void
55local_test_finished_cleanup (void *cls, 76local_test_finished_cleanup (void *cls,
56 const struct GNUNET_TESTING_Command *cmd) 77 const struct GNUNET_TESTING_Command *cmd)
@@ -62,6 +83,10 @@ local_test_finished_cleanup (void *cls,
62} 83}
63 84
64 85
86/**
87 * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED message to the master loop.
88 *
89 */
65static void 90static void
66local_test_finished_run (void *cls, 91local_test_finished_run (void *cls,
67 const struct GNUNET_TESTING_Command *cmd, 92 const struct GNUNET_TESTING_Command *cmd,
@@ -72,28 +97,25 @@ local_test_finished_run (void *cls,
72 struct GNUNET_CMDS_LOCAL_FINISHED *reply; 97 struct GNUNET_CMDS_LOCAL_FINISHED *reply;
73 size_t msg_length; 98 size_t msg_length;
74 99
75 LOG (GNUNET_ERROR_TYPE_ERROR,
76 "We got here 12!\n");
77
78 msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED); 100 msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED);
79 reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED); 101 reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED);
80 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED); 102 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED);
81 reply->header.size = htons ((uint16_t) msg_length); 103 reply->header.size = htons ((uint16_t) msg_length);
82 lfs->reply = reply; 104 lfs->reply = reply;
83 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length); 105 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
84
85 LOG (GNUNET_ERROR_TYPE_ERROR,
86 "We got here 13!\n");
87} 106}
88 107
89 108
109/**
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.
111 *
112 */
90static int 113static int
91local_test_finished_finish (void *cls, 114local_test_finished_finish (void *cls,
92 GNUNET_SCHEDULER_TaskCallback cont, 115 GNUNET_SCHEDULER_TaskCallback cont,
93 void *cont_cls) 116 void *cont_cls)
94{ 117{
95 // This will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method. 118 LOG (GNUNET_ERROR_TYPE_DEBUG,
96 LOG (GNUNET_ERROR_TYPE_ERROR,
97 "Stopping local loop\n"); 119 "Stopping local loop\n");
98 return GNUNET_YES; 120 return GNUNET_YES;
99} 121}
@@ -103,6 +125,7 @@ local_test_finished_finish (void *cls,
103 * Create command. 125 * Create command.
104 * 126 *
105 * @param label name for command. 127 * @param label name for command.
128 * @param write_message Callback to write messages to the master loop.
106 * @return command. 129 * @return command.
107 */ 130 */
108struct GNUNET_TESTING_Command 131struct GNUNET_TESTING_Command
@@ -112,9 +135,6 @@ GNUNET_TESTING_cmd_local_test_finished (const char *label,
112{ 135{
113 struct LocalFinishedState *lfs; 136 struct LocalFinishedState *lfs;
114 137
115 LOG (GNUNET_ERROR_TYPE_ERROR,
116 "We got here 11!\n");
117
118 lfs = GNUNET_new (struct LocalFinishedState); 138 lfs = GNUNET_new (struct LocalFinishedState);
119 lfs->write_message = write_message; 139 lfs->write_message = write_message;
120 140
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index c82392a08..536b356a6 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -29,12 +29,19 @@
29 29
30#define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh" 30#define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh"
31 31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
32struct NetJailState 36struct NetJailState
33{ 37{
38 // Child Wait handle
34 struct GNUNET_ChildWaitHandle *cwh; 39 struct GNUNET_ChildWaitHandle *cwh;
35 40
41 // Number of local nodes in each namespace.
36 char *local_m; 42 char *local_m;
37 43
44 // The number of namespaces.
38 char *global_n; 45 char *global_n;
39 46
40 /** 47 /**
@@ -42,16 +49,15 @@ struct NetJailState
42 */ 49 */
43 struct GNUNET_OS_Process *start_proc; 50 struct GNUNET_OS_Process *start_proc;
44 51
52 // Flag indication if the script finished.
45 unsigned int finished; 53 unsigned int finished;
46}; 54};
47 55
48 56
49/** 57/**
50* 58 * The cleanup function of this cmd frees resources the cmd allocated.
51* 59 *
52* @param cls closure 60 */
53* @param cmd current CMD being cleaned up.
54*/
55static void 61static void
56netjail_start_cleanup (void *cls, 62netjail_start_cleanup (void *cls,
57 const struct GNUNET_TESTING_Command *cmd) 63 const struct GNUNET_TESTING_Command *cmd)
@@ -81,14 +87,9 @@ netjail_start_cleanup (void *cls,
81 87
82 88
83/** 89/**
84* 90 * Trait function of this cmd does nothing.
85* 91 *
86* @param cls closure. 92 */
87* @param[out] ret result
88* @param trait name of the trait.
89* @param index index number of the object to offer.
90* @return #GNUNET_OK on success.
91*/
92static int 93static int
93netjail_start_traits (void *cls, 94netjail_start_traits (void *cls,
94 const void **ret, 95 const void **ret,
@@ -98,6 +99,11 @@ netjail_start_traits (void *cls,
98 return GNUNET_OK; 99 return GNUNET_OK;
99} 100}
100 101
102
103/**
104 * Callback which will be called if the setup script finished.
105 *
106 */
101static void 107static void
102child_completed_callback (void *cls, 108child_completed_callback (void *cls,
103 enum GNUNET_OS_ProcessStatusType type, 109 enum GNUNET_OS_ProcessStatusType type,
@@ -122,7 +128,7 @@ child_completed_callback (void *cls,
122 128
123 129
124/** 130/**
125* Run the "hello world" CMD. 131* The run method starts the script which setup the network namespaces.
126* 132*
127* @param cls closure. 133* @param cls closure.
128* @param cmd CMD being run. 134* @param cmd CMD being run.
@@ -171,6 +177,11 @@ netjail_start_run (void *cls,
171 GNUNET_break (NULL != ns->cwh); 177 GNUNET_break (NULL != ns->cwh);
172} 178}
173 179
180
181/**
182 * This function checks the flag NetJailState#finished, if this cmd finished.
183 *
184 */
174static int 185static int
175netjail_start_finish (void *cls, 186netjail_start_finish (void *cls,
176 GNUNET_SCHEDULER_TaskCallback cont, 187 GNUNET_SCHEDULER_TaskCallback cont,
@@ -189,7 +200,8 @@ netjail_start_finish (void *cls,
189 * Create command. 200 * Create command.
190 * 201 *
191 * @param label name for command. 202 * @param label name for command.
192 * @param binaryname to start. 203 * @param local_m Number of local nodes in each namespace.
204 * @param global_n The number of namespaces.
193 * @return command. 205 * @return command.
194 */ 206 */
195struct GNUNET_TESTING_Command 207struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index 5c2f71168..01bac9b05 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -29,13 +29,21 @@
29 29
30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh" 30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh"
31 31
32struct HelperMessage; 32/**
33 33 * Struct to store messages send/received by the helper into a DLL
34 *
35 */
34struct HelperMessage 36struct HelperMessage
35{ 37{
36 38
39 /**
40 * Kept in a DLL.
41 */
37 struct HelperMessage *next; 42 struct HelperMessage *next;
38 43
44 /**
45 * Kept in a DLL.
46 */
39 struct HelperMessage *prev; 47 struct HelperMessage *prev;
40 48
41 /** 49 /**
@@ -47,27 +55,51 @@ struct HelperMessage
47}; 55};
48 56
49 57
50 58/**
59 * Struct to store information handed over to callbacks.
60 *
61 */
51struct NetJailState 62struct NetJailState
52{ 63{
53 64 /**
65 * Pointer to the return value of the test.
66 *
67 */
54 unsigned int *rv; 68 unsigned int *rv;
55 69
70 /**
71 * Head of the DLL which stores messages received by the helper.
72 *
73 */
56 struct HelperMessage *hp_messages_head; 74 struct HelperMessage *hp_messages_head;
57 75
76 /**
77 * Tail of the DLL which stores messages received by the helper.
78 *
79 */
58 struct HelperMessage *hp_messages_tail; 80 struct HelperMessage *hp_messages_tail;
59 81
60 /** 82 /**
61 * The process handle 83 * Array with handles of helper processes.
62 */ 84 */
63 struct GNUNET_HELPER_Handle **helper; 85 struct GNUNET_HELPER_Handle **helper;
64 86
87 /**
88 * Size of the array NetJailState#helper.
89 *
90 */
65 unsigned int n_helper; 91 unsigned int n_helper;
66 92
67 char *binary_name; 93 /**
68 94 * Number of nodes in a network namespace. //TODO make this a unsigned int
95 *
96 */
69 char *local_m; 97 char *local_m;
70 98
99 /**
100 * Number of network namespaces. //TODO make this a unsigned int
101 *
102 */
71 char *global_n; 103 char *global_n;
72 104
73 /** 105 /**
@@ -75,33 +107,91 @@ struct NetJailState
75 */ 107 */
76 struct GNUNET_HELPER_SendHandle **shandle; 108 struct GNUNET_HELPER_SendHandle **shandle;
77 109
110 /**
111 * Size of the array NetJailState#shandle.
112 *
113 */
78 unsigned int n_shandle; 114 unsigned int n_shandle;
79 115
80 /** 116 /**
81 * The message corresponding to send handle 117 * The messages send to the helper.
82 */ 118 */
83 struct GNUNET_MessageHeader **msg; 119 struct GNUNET_MessageHeader **msg;
84 120
121 /**
122 * Size of the array NetJailState#msg.
123 *
124 */
85 unsigned int n_msg; 125 unsigned int n_msg;
86 126
127 /**
128 * Number of test environments started.
129 *
130 */
87 unsigned int number_of_testsystems_started; 131 unsigned int number_of_testsystems_started;
88 132
133 /**
134 * Number of peers started.
135 *
136 */
89 unsigned int number_of_peers_started; 137 unsigned int number_of_peers_started;
90 138
139 /**
140 * Number of local tests finished.
141 *
142 */
91 unsigned int number_of_local_test_finished; 143 unsigned int number_of_local_test_finished;
92 144
145 /**
146 * Name of the test case plugin the helper will load.
147 *
148 */
93 char *plugin_name; 149 char *plugin_name;
150
151 /**
152 * HEAD of the DLL containing TestingSystemCount.
153 *
154 */
155 struct TestingSystemCount *tbcs_head;
156
157 /**
158 * TAIL of the DLL containing TestingSystemCount.
159 *
160 */
161 struct TestingSystemCount *tbcs_tail;
94}; 162};
95 163
164/**
165 * Struct containing the number of the test environment and the NetJailState which
166 * will be handed to callbacks specific to a test environment.
167 */
96struct TestingSystemCount 168struct TestingSystemCount
97{ 169{
170 /**
171 * Kept in a DLL.
172 */
173 struct TestingSystemCount *next;
174
175 /**
176 * Kept in a DLL.
177 */
178 struct TestingSystemCount *prev;
179
180 /**
181 * The number of the test environment.
182 *
183 */
98 unsigned int count; 184 unsigned int count;
99 185
186 /**
187 * Struct to store information handed over to callbacks.
188 *
189 */
100 struct NetJailState *ns; 190 struct NetJailState *ns;
101}; 191};
102 192
103/** 193/**
104* 194* Code to clean up ressource this cmd used.
105* 195*
106* @param cls closure 196* @param cls closure
107* @param cmd current CMD being cleaned up. 197* @param cmd current CMD being cleaned up.
@@ -111,20 +201,31 @@ netjail_exec_cleanup (void *cls,
111 const struct GNUNET_TESTING_Command *cmd) 201 const struct GNUNET_TESTING_Command *cmd)
112{ 202{
113 struct NetJailState *ns = cls; 203 struct NetJailState *ns = cls;
204 struct HelperMessage *message_pos;
205 struct TestingSystemCount *tbc_pos;
114 206
115 GNUNET_free (ns->binary_name); 207 while (NULL != (message_pos = ns->hp_messages_head))
208 {
209 GNUNET_CONTAINER_DLL_remove (ns->hp_messages_head,
210 ns->hp_messages_tail,
211 message_pos);
212 GNUNET_free (message_pos);
213 }
214 while (NULL != (tbc_pos = ns->tbcs_head))
215 {
216 GNUNET_CONTAINER_DLL_remove (ns->tbcs_head,
217 ns->tbcs_tail,
218 tbc_pos);
219 GNUNET_free (tbc_pos);
220 }
221 GNUNET_free (ns);
116} 222}
117 223
118 224
119/** 225/**
120* 226 * This function prepares an array with traits.
121* 227 *
122* @param cls closure. 228 */
123* @param[out] ret result
124* @param trait name of the trait.
125* @param index index number of the object to offer.
126* @return #GNUNET_OK on success.
127*/
128static int 229static int
129netjail_exec_traits (void *cls, 230netjail_exec_traits (void *cls,
130 const void **ret, 231 const void **ret,
@@ -209,9 +310,6 @@ clear_msg (void *cls, int result)
209 struct TestingSystemCount *tbc = cls; 310 struct TestingSystemCount *tbc = cls;
210 struct NetJailState *ns = tbc->ns; 311 struct NetJailState *ns = tbc->ns;
211 312
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
213 "clear_msg tbc->count: %d\n",
214 tbc->count);
215 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]); 313 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]);
216 ns->shandle[tbc->count - 1] = NULL; 314 ns->shandle[tbc->count - 1] = NULL;
217 GNUNET_free (ns->msg[tbc->count - 1]); 315 GNUNET_free (ns->msg[tbc->count - 1]);
@@ -240,20 +338,12 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
240 338
241 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) 339 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
242 { 340 {
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
244 "helper_mst tbc->count: %d\n",
245 tbc->count);
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "Received message from helper.\n");
248 ns->number_of_testsystems_started++; 341 ns->number_of_testsystems_started++;
249 } 342 }
250 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs ( 343 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs (
251 message->type)) 344 message->type))
252 { 345 {
253 ns->number_of_peers_started++; 346 ns->number_of_peers_started++;
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 "number_of_peers_started: %d\n",
256 ns->number_of_peers_started);
257 } 347 }
258 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs ( 348 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
259 message->type)) 349 message->type))
@@ -272,7 +362,10 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
272 return GNUNET_OK; 362 return GNUNET_OK;
273} 363}
274 364
275 365/**
366 * Callback called if there was an exception during execution of the helper.
367 *
368 */
276static void 369static void
277exp_cb (void *cls) 370exp_cb (void *cls)
278{ 371{
@@ -281,7 +374,14 @@ exp_cb (void *cls)
281 *ns->rv = 1; 374 *ns->rv = 1;
282} 375}
283 376
284 377/**
378 * Function to initialize a init message for the helper.
379 *
380 * @param m_char The actual node in a namespace. //TODO Change this to unsigned int
381 * @param n_char The actual namespace. //TODO Change this to unsigned int
382 * @param plugin_name Name of the test case plugin the helper will load.
383 *
384 */
285static struct GNUNET_CMDS_HelperInit * 385static struct GNUNET_CMDS_HelperInit *
286create_helper_init_msg_ (char *m_char, 386create_helper_init_msg_ (char *m_char,
287 char *n_char, 387 char *n_char,
@@ -294,9 +394,6 @@ create_helper_init_msg_ (char *m_char,
294 GNUNET_assert (NULL != plugin_name); 394 GNUNET_assert (NULL != plugin_name);
295 plugin_name_len = strlen (plugin_name); 395 plugin_name_len = strlen (plugin_name);
296 msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len; 396 msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len;
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
298 "msg_size: %d \n",
299 msg_size);
300 msg = GNUNET_malloc (msg_size); 397 msg = GNUNET_malloc (msg_size);
301 msg->header.size = htons (msg_size); 398 msg->header.size = htons (msg_size);
302 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT); 399 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT);
@@ -308,13 +405,17 @@ create_helper_init_msg_ (char *m_char,
308} 405}
309 406
310 407
408/**
409 * Function which start a single helper process.
410 *
411 */
311static void 412static void
312start_helper (struct NetJailState *ns, struct 413start_helper (struct NetJailState *ns, struct
313 GNUNET_CONFIGURATION_Handle *config, 414 GNUNET_CONFIGURATION_Handle *config,
314 char *m_char, 415 char *m_char,
315 char *n_char) 416 char *n_char)
316{ 417{
317 // struct GNUNET_CONFIGURATION_Handle *cfg; 418 struct GNUNET_HELPER_Handle *helper;
318 struct GNUNET_CMDS_HelperInit *msg; 419 struct GNUNET_CMDS_HelperInit *msg;
319 struct TestingSystemCount *tbc; 420 struct TestingSystemCount *tbc;
320 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, 421 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
@@ -332,15 +433,13 @@ start_helper (struct NetJailState *ns, struct
332 GNUNET_YES, 433 GNUNET_YES,
333 NULL); 434 NULL);
334 435
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "m: %d n: %d\n",
337 m,
338 n);
339
340 tbc = GNUNET_new (struct TestingSystemCount); 436 tbc = GNUNET_new (struct TestingSystemCount);
341 tbc->ns = ns; 437 tbc->ns = ns;
342 tbc->count = (n - 1) * atoi (ns->local_m) + m; 438 tbc->count = (n - 1) * atoi (ns->local_m) + m;
343 439
440 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail,
441 tbc);
442
344 443
345 if (GNUNET_NO == helper_check) 444 if (GNUNET_NO == helper_check)
346 { 445 {
@@ -365,17 +464,7 @@ start_helper (struct NetJailState *ns, struct
365 &exp_cb, 464 &exp_cb,
366 tbc)); 465 tbc));
367 466
368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 467 helper = ns->helper[tbc->count - 1];
369 "First using helper %d %d\n",
370 tbc->count - 1,
371 ns->n_helper);
372 struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1];
373
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "First using helper %d %d %p\n",
376 tbc->count - 1,
377 ns->n_helper,
378 helper);
379 468
380 msg = create_helper_init_msg_ (m_char, 469 msg = create_helper_init_msg_ (m_char,
381 n_char, 470 n_char,
@@ -389,10 +478,6 @@ start_helper (struct NetJailState *ns, struct
389 &clear_msg, 478 &clear_msg,
390 tbc)); 479 tbc));
391 480
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
393 "Message %d send!\n",
394 tbc->count);
395
396 if (NULL == ns->shandle[tbc->count - 1]) 481 if (NULL == ns->shandle[tbc->count - 1])
397 { 482 {
398 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 483 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -404,7 +489,7 @@ start_helper (struct NetJailState *ns, struct
404 489
405 490
406/** 491/**
407* Run the "hello world" CMD. 492* This function starts a helper process for each node.
408* 493*
409* @param cls closure. 494* @param cls closure.
410* @param cmd CMD being run. 495* @param cmd CMD being run.
@@ -434,6 +519,15 @@ netjail_exec_run (void *cls,
434} 519}
435 520
436 521
522/**
523 * This function checks on three different information.
524 *
525 * 1. Did all helpers start. This is only logged.
526 * 2. Did all peer start.
527 * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers.
528 * 3. Did all peers finished the test case. In this case interpreter_next will be called.
529 *
530 */
437static int 531static int
438netjail_start_finish (void *cls, 532netjail_start_finish (void *cls,
439 GNUNET_SCHEDULER_TaskCallback cont, 533 GNUNET_SCHEDULER_TaskCallback cont,
@@ -455,16 +549,11 @@ netjail_start_finish (void *cls,
455 549
456 if (ns->number_of_testsystems_started == total_number) 550 if (ns->number_of_testsystems_started == total_number)
457 { 551 {
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
459 "All helpers started!\n");
460 ns->number_of_testsystems_started = 0; 552 ns->number_of_testsystems_started = 0;
461 } 553 }
462 554
463 if (ns->number_of_peers_started == total_number) 555 if (ns->number_of_peers_started == total_number)
464 { 556 {
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
466 "All peers started!\n");
467
468 for (int i = 1; i <= atoi (ns->global_n); i++) { 557 for (int i = 1; i <= atoi (ns->global_n); i++) {
469 for (int j = 1; j <= atoi (ns->local_m); j++) 558 for (int j = 1; j <= atoi (ns->local_m); j++)
470 { 559 {
@@ -472,11 +561,7 @@ netjail_start_finish (void *cls,
472 tbc->ns = ns; 561 tbc->ns = ns;
473 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone. 562 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
474 tbc->count = (i - 1) * atoi (ns->local_m) + j + total_number; 563 tbc->count = (i - 1) * atoi (ns->local_m) + j + total_number;
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 564
476 "Second using helper %d %d %d\n",
477 tbc->count - 1 - total_number,
478 i,
479 j);
480 helper = ns->helper[tbc->count - 1 - total_number]; 565 helper = ns->helper[tbc->count - 1 - total_number];
481 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED); 566 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
482 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED); 567 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
@@ -494,10 +579,6 @@ netjail_start_finish (void *cls,
494 tbc); 579 tbc);
495 580
496 GNUNET_array_append (ns->shandle, ns->n_shandle, sh); 581 GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
497
498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
499 "All peers started message %d send!\n",
500 tbc->count);
501 } 582 }
502 } 583 }
503 ns->number_of_peers_started = 0; 584 ns->number_of_peers_started = 0;
@@ -509,8 +590,11 @@ netjail_start_finish (void *cls,
509/** 590/**
510 * Create command. 591 * Create command.
511 * 592 *
512 * @param label name for command. 593 * @param label Name for the command.
513 * @param binaryname to exec. 594 * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int
595 * @param global_n Number of network namespaces. //TODO make this a unsigned int
596 * @param plugin_name Name of the test case plugin the helper will load.
597 * @param rv Pointer to the return value of the test.
514 * @return command. 598 * @return command.
515 */ 599 */
516struct GNUNET_TESTING_Command 600struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c
index 710b4fbf4..99084d9af 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -30,12 +30,19 @@
30 30
31#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh" 31#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh"
32 32
33// Child Wait handle
33struct GNUNET_ChildWaitHandle *cwh; 34struct GNUNET_ChildWaitHandle *cwh;
34 35
36/**
37 * Struct to hold information for callbacks.
38 *
39 */
35struct NetJailState 40struct NetJailState
36{ 41{
42 // Number of local nodes in each namespace.
37 char *local_m; 43 char *local_m;
38 44
45 // The number of namespaces.
39 char *global_n; 46 char *global_n;
40 47
41 /** 48 /**
@@ -43,16 +50,15 @@ struct NetJailState
43 */ 50 */
44 struct GNUNET_OS_Process *stop_proc; 51 struct GNUNET_OS_Process *stop_proc;
45 52
53 // Flag indication if the script finished.
46 unsigned int finished; 54 unsigned int finished;
47}; 55};
48 56
49 57
50/** 58/**
51* 59 * The cleanup function of this cmd frees resources the cmd allocated.
52* 60 *
53* @param cls closure 61 */
54* @param cmd current CMD being cleaned up.
55*/
56static void 62static void
57netjail_stop_cleanup (void *cls, 63netjail_stop_cleanup (void *cls,
58 const struct GNUNET_TESTING_Command *cmd) 64 const struct GNUNET_TESTING_Command *cmd)
@@ -78,14 +84,9 @@ netjail_stop_cleanup (void *cls,
78 84
79 85
80/** 86/**
81* 87 * Trait function of this cmd does nothing.
82* 88 *
83* @param cls closure. 89 */
84* @param[out] ret result
85* @param trait name of the trait.
86* @param index index number of the object to offer.
87* @return #GNUNET_OK on success.
88*/
89static int 90static int
90netjail_stop_traits (void *cls, 91netjail_stop_traits (void *cls,
91 const void **ret, 92 const void **ret,
@@ -96,6 +97,10 @@ netjail_stop_traits (void *cls,
96} 97}
97 98
98 99
100/**
101 * Callback which will be called if the setup script finished.
102 *
103 */
99static void 104static void
100child_completed_callback (void *cls, 105child_completed_callback (void *cls,
101 enum GNUNET_OS_ProcessStatusType type, 106 enum GNUNET_OS_ProcessStatusType type,
@@ -118,7 +123,7 @@ child_completed_callback (void *cls,
118 123
119 124
120/** 125/**
121* Run the "hello world" CMD. 126* The run method starts the script which deletes the network namespaces.
122* 127*
123* @param cls closure. 128* @param cls closure.
124* @param cmd CMD being run. 129* @param cmd CMD being run.
@@ -169,6 +174,10 @@ netjail_stop_run (void *cls,
169} 174}
170 175
171 176
177/**
178 * This function checks the flag NetJailState#finished, if this cmd finished.
179 *
180 */
172static int 181static int
173netjail_stop_finish (void *cls, 182netjail_stop_finish (void *cls,
174 GNUNET_SCHEDULER_TaskCallback cont, 183 GNUNET_SCHEDULER_TaskCallback cont,
@@ -188,7 +197,8 @@ netjail_stop_finish (void *cls,
188 * Create command. 197 * Create command.
189 * 198 *
190 * @param label name for command. 199 * @param label name for command.
191 * @param binaryname to stop. 200 * @param local_m Number of local nodes in each namespace.
201 * @param global_n The number of namespaces.
192 * @return command. 202 * @return command.
193 */ 203 */
194struct GNUNET_TESTING_Command 204struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index bed9f3ebf..d6e733e05 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -28,6 +28,10 @@
28#include "testing_cmds.h" 28#include "testing_cmds.h"
29 29
30 30
31/**
32 * Struct to store information handed over to callbacks.
33 *
34 */
31struct StopHelperState 35struct StopHelperState
32{ 36{
33 37
@@ -45,7 +49,7 @@ struct StopHelperState
45 49
46 50
47/** 51/**
48* 52* Code to clean up ressource this cmd used.
49* 53*
50* @param cls closure 54* @param cls closure
51* @param cmd current CMD being cleaned up. 55* @param cmd current CMD being cleaned up.
@@ -59,14 +63,9 @@ stop_testing_system_cleanup (void *cls,
59 63
60 64
61/** 65/**
62* 66 * Trait function of this cmd does nothing.
63* 67 *
64* @param cls closure. 68 */
65* @param[out] ret result
66* @param trait name of the trait.
67* @param index index number of the object to offer.
68* @return #GNUNET_OK on success.
69*/
70static int 69static int
71stop_testing_system_traits (void *cls, 70stop_testing_system_traits (void *cls,
72 const void **ret, 71 const void **ret,
@@ -78,7 +77,7 @@ stop_testing_system_traits (void *cls,
78 77
79 78
80/** 79/**
81* Run the "hello world" CMD. 80* This function stops the helper process for each node.
82* 81*
83* @param cls closure. 82* @param cls closure.
84* @param cmd CMD being run. 83* @param cmd CMD being run.
@@ -110,9 +109,11 @@ stop_testing_system_run (void *cls,
110 109
111/** 110/**
112 * Create command. 111 * Create command.
113 * 112 * @param helper_start_label label of the cmd to start the test system.
114 * @param label name for command. 113 * @param label name for command.
115 * @param binaryname to exec. 114 * @param .
115 * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int
116 * @param global_n Number of network namespaces. //TODO make this a unsigned int
116 * @return command. 117 * @return command.
117 */ 118 */
118struct GNUNET_TESTING_Command 119struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c
index afe28de77..016837214 100644
--- a/src/testing/testing_api_cmd_send_peer_ready.c
+++ b/src/testing/testing_api_cmd_send_peer_ready.c
@@ -29,14 +29,30 @@
29#include "testing_cmds.h" 29#include "testing_cmds.h"
30 30
31 31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
32struct SendPeerReadyState 36struct SendPeerReadyState
33{ 37{
38 /**
39 * Callback to write messages to the master loop.
40 *
41 */
34 TESTING_CMD_HELPER_write_cb write_message; 42 TESTING_CMD_HELPER_write_cb write_message;
35 43
44 /**
45 * The message send back to the master loop.
46 *
47 */
36 struct GNUNET_CMDS_PEER_STARTED *reply; 48 struct GNUNET_CMDS_PEER_STARTED *reply;
37}; 49};
38 50
39 51
52/**
53 * Trait function of this cmd does nothing.
54 *
55 */
40static int 56static int
41send_peer_ready_traits (void *cls, 57send_peer_ready_traits (void *cls,
42 const void **ret, 58 const void **ret,
@@ -47,6 +63,10 @@ send_peer_ready_traits (void *cls,
47} 63}
48 64
49 65
66/**
67 * The cleanup function of this cmd frees resources the cmd allocated.
68 *
69 */
50static void 70static void
51send_peer_ready_cleanup (void *cls, 71send_peer_ready_cleanup (void *cls,
52 const struct GNUNET_TESTING_Command *cmd) 72 const struct GNUNET_TESTING_Command *cmd)
@@ -58,6 +78,10 @@ send_peer_ready_cleanup (void *cls,
58} 78}
59 79
60 80
81/**
82 * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED message to the master loop.
83 *
84 */
61static void 85static void
62send_peer_ready_run (void *cls, 86send_peer_ready_run (void *cls,
63 const struct GNUNET_TESTING_Command *cmd, 87 const struct GNUNET_TESTING_Command *cmd,
@@ -80,6 +104,7 @@ send_peer_ready_run (void *cls,
80 * Create command. 104 * Create command.
81 * 105 *
82 * @param label name for command. 106 * @param label name for command.
107 * @param write_message Callback to write messages to the master loop.
83 * @return command. 108 * @return command.
84 */ 109 */
85struct GNUNET_TESTING_Command 110struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
index 2007b4ef3..f3a0b1a4c 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -28,6 +28,10 @@
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_lib.h"
30 30
31/**
32 * Struct to hold information for callbacks.
33 *
34 */
31struct TestSystemState 35struct TestSystemState
32{ 36{
33 struct GNUNET_TESTING_System *test_system; 37 struct GNUNET_TESTING_System *test_system;
@@ -36,6 +40,10 @@ struct TestSystemState
36}; 40};
37 41
38 42
43/**
44 * The run method of this cmd will setup a test environment for a node.
45 *
46 */
39static void 47static void
40system_create_run (void *cls, 48system_create_run (void *cls,
41 const struct GNUNET_TESTING_Command *cmd, 49 const struct GNUNET_TESTING_Command *cmd,
@@ -54,6 +62,11 @@ system_create_run (void *cls,
54 "system created\n"); 62 "system created\n");
55} 63}
56 64
65
66/**
67 * This function prepares an array with traits.
68 *
69 */
57static int 70static int
58system_create_traits (void *cls, 71system_create_traits (void *cls,
59 const void **ret, 72 const void **ret,
@@ -79,6 +92,12 @@ system_create_traits (void *cls,
79} 92}
80 93
81 94
95/**
96 * Function to get the trait with struct GNUNET_TESTING_System
97 *
98 * @param[out] test_system The struct GNUNET_TESTING_System.
99 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
100 */
82int 101int
83GNUNET_TESTING_get_trait_test_system (const struct 102GNUNET_TESTING_get_trait_test_system (const struct
84 GNUNET_TESTING_Command *cmd, 103 GNUNET_TESTING_Command *cmd,
@@ -91,13 +110,16 @@ GNUNET_TESTING_get_trait_test_system (const struct
91} 110}
92 111
93 112
113/**
114 * The cleanup function of this cmd frees resources the cmd allocated.
115 *
116 */
94static void 117static void
95system_create_cleanup (void *cls, 118system_create_cleanup (void *cls,
96 const struct GNUNET_TESTING_Command *cmd) 119 const struct GNUNET_TESTING_Command *cmd)
97{ 120{
98 struct TestSystemState *tss = cls; 121 struct TestSystemState *tss = cls;
99 122
100 GNUNET_free (tss->test_system);
101 GNUNET_free (tss); 123 GNUNET_free (tss);
102} 124}
103 125
@@ -106,6 +128,7 @@ system_create_cleanup (void *cls,
106 * Create command. 128 * Create command.
107 * 129 *
108 * @param label name for command. 130 * @param label name for command.
131 * @param label name for the test environment directory.
109 * @return command. 132 * @return command.
110 */ 133 */
111struct GNUNET_TESTING_Command 134struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c
index e94d8dad0..5ed0c2fd2 100644
--- a/src/testing/testing_api_cmd_system_destroy.c
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -53,16 +53,10 @@ system_destroy_run (void *cls,
53 const struct GNUNET_TESTING_Command *system_cmd; 53 const struct GNUNET_TESTING_Command *system_cmd;
54 struct GNUNET_TESTING_System *tl_system; 54 struct GNUNET_TESTING_System *tl_system;
55 55
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
57 "system destroy\n");
58
59 system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label); 56 system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label);
60 GNUNET_TESTING_get_trait_test_system (system_cmd, 57 GNUNET_TESTING_get_trait_test_system (system_cmd,
61 &tl_system); 58 &tl_system);
62 GNUNET_TESTING_system_destroy (tl_system, GNUNET_YES); 59 GNUNET_TESTING_system_destroy (tl_system, GNUNET_YES);
63
64 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
65 "system destroyed\n");
66} 60}
67 61
68 62
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index f4fa4e17e..0c24c0e26 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -35,6 +35,7 @@
35 35
36struct GNUNET_TESTING_Interpreter *is; 36struct GNUNET_TESTING_Interpreter *is;
37 37
38
38/** 39/**
39 * Closure used to sync an asynchronous with an synchronous command. 40 * Closure used to sync an asynchronous with an synchronous command.
40 */ 41 */
@@ -57,6 +58,7 @@ struct SyncTaskClosure
57 struct GNUNET_TESTING_Interpreter *is; 58 struct GNUNET_TESTING_Interpreter *is;
58}; 59};
59 60
61
60/** 62/**
61* Closure used to run the finish task. 63* Closure used to run the finish task.
62*/ 64*/
@@ -74,6 +76,7 @@ struct FinishTaskClosure
74 struct GNUNET_TESTING_Interpreter *is; 76 struct GNUNET_TESTING_Interpreter *is;
75}; 77};
76 78
79
77/** 80/**
78 * Lookup command by label. 81 * Lookup command by label.
79 * 82 *
@@ -185,6 +188,10 @@ interpreter_next (void *cls)
185} 188}
186 189
187 190
191/**
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 */
188static void 195static void
189run_finish_task_next (void *cls) 196run_finish_task_next (void *cls)
190{ 197{
@@ -212,6 +219,12 @@ run_finish_task_next (void *cls)
212} 219}
213 220
214 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 */
215static void 228static void
216run_finish_task_sync (void *cls) 229run_finish_task_sync (void *cls)
217{ 230{
@@ -248,13 +261,17 @@ run_finish_task_sync (void *cls)
248 } 261 }
249 else 262 else
250 { 263 {
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 264 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
252 "Sync task finished with an error.\n"); 265 "Sync task finished with an error.\n");
253 GNUNET_TESTING_interpreter_fail (); 266 GNUNET_TESTING_interpreter_fail ();
254 } 267 }
255} 268}
256 269
257 270
271/**
272 * run method of the command created by the interpreter to wait for another command to finish.
273 *
274 */
258static void 275static void
259start_finish_on_ref (void *cls, 276start_finish_on_ref (void *cls,
260 const struct GNUNET_TESTING_Command *cmd, 277 const struct GNUNET_TESTING_Command *cmd,
@@ -277,6 +294,17 @@ start_finish_on_ref (void *cls,
277} 294}
278 295
279 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 */
280const struct GNUNET_TESTING_Command 308const struct GNUNET_TESTING_Command
281GNUNET_TESTING_cmd_finish (const char *finish_label, 309GNUNET_TESTING_cmd_finish (const char *finish_label,
282 const char *cmd_ref, 310 const char *cmd_ref,
@@ -340,7 +368,7 @@ GNUNET_TESTING_interpreter_fail ()
340 while (GNUNET_TESTING_cmd_is_batch (cmd)) 368 while (GNUNET_TESTING_cmd_is_batch (cmd))
341 { 369 {
342 cmd = GNUNET_TESTING_cmd_batch_get_current (cmd); 370 cmd = GNUNET_TESTING_cmd_batch_get_current (cmd);
343 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
344 "Batch is at command `%s'\n", 372 "Batch is at command `%s'\n",
345 cmd->label); 373 cmd->label);
346 } 374 }
@@ -354,7 +382,7 @@ GNUNET_TESTING_interpreter_fail ()
354 382
355 if (NULL == cmd->label) 383 if (NULL == cmd->label)
356 { 384 {
357 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
358 "Failed at command `%s'\n", 386 "Failed at command `%s'\n",
359 cmd->label); 387 cmd->label);
360 388
@@ -415,7 +443,7 @@ interpreter_run (void *cls)
415 if (NULL == cmd->label) 443 if (NULL == cmd->label)
416 { 444 {
417 445
418 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419 "Running command END %p\n", 447 "Running command END %p\n",
420 is); 448 is);
421 is->result = GNUNET_OK; 449 is->result = GNUNET_OK;
@@ -424,7 +452,7 @@ interpreter_run (void *cls)
424 } 452 }
425 else if (NULL != cmd) 453 else if (NULL != cmd)
426 { 454 {
427 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
428 "Running command `%s' %p\n", 456 "Running command `%s' %p\n",
429 cmd->label, 457 cmd->label,
430 is); 458 is);
@@ -478,8 +506,14 @@ do_shutdown (void *cls)
478 for (unsigned int j = 0; 506 for (unsigned int j = 0;
479 NULL != (cmd = &is->commands[j])->label; 507 NULL != (cmd = &is->commands[j])->label;
480 j++) { 508 j++) {
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "Cleaning up cmd %s\n",
511 cmd->label);
481 cmd->cleanup (cmd->cls, 512 cmd->cleanup (cmd->cls,
482 cmd); 513 cmd);
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
515 "Cleaned up cmd %s\n",
516 cmd->label);
483 } 517 }
484 518
485 if (NULL != is->finish_task) 519 if (NULL != is->finish_task)