aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_start_testsystem.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-08-24 11:56:13 +0200
committert3sserakt <t3ss@posteo.de>2021-08-24 11:56:13 +0200
commit5ddaa3f8eb5e01882540f21ddf237f3a41311e8a (patch)
tree765617baebf4366c9584d71863c3077f5d107d49 /src/testing/testing_api_cmd_netjail_start_testsystem.c
parent9d5a8c05f3a33c49fd97e5b8ef99d58b96704c6d (diff)
downloadgnunet-5ddaa3f8eb5e01882540f21ddf237f3a41311e8a.tar.gz
gnunet-5ddaa3f8eb5e01882540f21ddf237f3a41311e8a.zip
- fixed mem leaks, added code doc, formatting, removed trace logs
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_start_testsystem.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c228
1 files changed, 156 insertions, 72 deletions
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