aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_start_testsystem.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-10-25 14:49:05 +0200
committert3sserakt <t3ss@posteo.de>2021-10-25 14:49:05 +0200
commit1609d627e509043a946f611d7589105cfae2364d (patch)
treed6022bea17730f96c7d87b0a1c8f602717edb25d /src/testing/testing_api_cmd_netjail_start_testsystem.c
parent513f23e74650db9408267e82ef8bcb8f770d1015 (diff)
downloadgnunet-1609d627e509043a946f611d7589105cfae2364d.tar.gz
gnunet-1609d627e509043a946f611d7589105cfae2364d.zip
changes to reflect the changes in testing_api_loop.c
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_start_testsystem.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c185
1 files changed, 147 insertions, 38 deletions
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index a1d71c436..9b567a01f 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -30,6 +30,11 @@
30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh" 30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh"
31 31
32/** 32/**
33 * Generic logging shortcut
34 */
35#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
36
37/**
33 * Struct to store messages send/received by the helper into a DLL 38 * Struct to store messages send/received by the helper into a DLL
34 * 39 *
35 */ 40 */
@@ -121,13 +126,13 @@ struct NetJailState
121 /** 126 /**
122 * The send handle for the helper 127 * The send handle for the helper
123 */ 128 */
124 struct GNUNET_HELPER_SendHandle **shandle; 129 // struct GNUNET_HELPER_SendHandle **shandle;
125 130
126 /** 131 /**
127 * Size of the array NetJailState#shandle. 132 * Size of the array NetJailState#shandle.
128 * 133 *
129 */ 134 */
130 unsigned int n_shandle; 135 // unsigned int n_shandle;
131 136
132 /** 137 /**
133 * The messages send to the helper. 138 * The messages send to the helper.
@@ -156,7 +161,13 @@ struct NetJailState
156 * Number of local tests finished. 161 * Number of local tests finished.
157 * 162 *
158 */ 163 */
159 unsigned int number_of_local_test_finished; 164 unsigned int number_of_local_tests_finished;
165
166 /**
167 * Number of local tests prepared to finish.
168 *
169 */
170 unsigned int number_of_local_tests_prepared;
160 171
161 /** 172 /**
162 * Name of the test case plugin the helper will load. 173 * Name of the test case plugin the helper will load.
@@ -194,6 +205,17 @@ struct TestingSystemCount
194 struct TestingSystemCount *prev; 205 struct TestingSystemCount *prev;
195 206
196 /** 207 /**
208 * The send handle for the helper
209 */
210 struct GNUNET_HELPER_SendHandle *shandle;// **shandle;
211
212 /**
213 * Size of the array NetJailState#shandle.
214 *
215 */
216 // unsigned int n_shandle;
217
218 /**
197 * The number of the test environment. 219 * The number of the test environment.
198 * 220 *
199 */ 221 */
@@ -306,47 +328,85 @@ clear_msg (void *cls, int result)
306 struct TestingSystemCount *tbc = cls; 328 struct TestingSystemCount *tbc = cls;
307 struct NetJailState *ns = tbc->ns; 329 struct NetJailState *ns = tbc->ns;
308 330
309 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]); 331 GNUNET_assert (NULL != tbc->shandle);// [tbc->count - 1]);
310 ns->shandle[tbc->count - 1] = NULL; 332 tbc->shandle = NULL;// [tbc->count - 1] = NULL;
311 GNUNET_free (ns->msg[tbc->count - 1]); 333 GNUNET_free (ns->msg[tbc->count - 1]);
312 ns->msg[tbc->count - 1] = NULL; 334 ns->msg[tbc->count - 1] = NULL;
313} 335}
314 336
315 337
316static void 338static void
317send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) 339send_message_to_locals (
340 unsigned int i,
341 unsigned int j,
342 struct NetJailState *ns,
343 struct GNUNET_MessageHeader *header
344 )
318{ 345{
319 unsigned int total_number = ns->local_m * ns->global_n + ns->known; 346 // unsigned int total_number = ns->local_m * ns->global_n + ns->known;
320 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
321 size_t msg_length;
322 struct GNUNET_HELPER_Handle *helper; 347 struct GNUNET_HELPER_Handle *helper;
323 struct TestingSystemCount *tbc; 348 struct TestingSystemCount *tbc;
324 349
350 LOG (GNUNET_ERROR_TYPE_DEBUG,
351 "send message of type %u to locals\n",
352 header->type);
325 tbc = GNUNET_new (struct TestingSystemCount); 353 tbc = GNUNET_new (struct TestingSystemCount);
326 tbc->ns = ns; 354 tbc->ns = ns;
327 // 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. 355 // 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.
328 if (0 == i) 356 if (0 == i)
329 tbc->count = j + total_number; 357 tbc->count = j; // + total_number;
330 else 358 else
331 tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known; 359 tbc->count = (i - 1) * ns->local_m + j + ns->known; // + total_number ;
332 360
333 helper = ns->helper[tbc->count - 1 - total_number]; 361 helper = ns->helper[tbc->count - 1];// - total_number];
334 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
335 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
336 reply->header.type = htons (
337 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
338 reply->header.size = htons ((uint16_t) msg_length);
339 362
340 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header); 363 GNUNET_array_append (ns->msg, ns->n_msg, header);
341 364
342 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( 365 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
343 helper, 366 helper,
344 &reply->header, 367 header,
345 GNUNET_NO, 368 GNUNET_NO,
346 &clear_msg, 369 &clear_msg,
347 tbc); 370 tbc);
348 371
349 GNUNET_array_append (ns->shandle, ns->n_shandle, sh); 372 tbc->shandle = sh;
373 // GNUNET_array_append (tbc->shandle, tbc->n_shandle, sh);
374}
375
376
377static void
378send_all_local_tests_prepared (unsigned int i, unsigned int j, struct
379 NetJailState *ns)
380{
381 struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED *reply;
382 size_t msg_length;
383
384
385 msg_length = sizeof(struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
386 reply = GNUNET_new (struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
387 reply->header.type = htons (
388 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED);
389 reply->header.size = htons ((uint16_t) msg_length);
390
391 send_message_to_locals (i, j, ns, &reply->header);
392}
393
394
395static void
396send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
397{
398
399 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
400 size_t msg_length;
401
402
403 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
404 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
405 reply->header.type = htons (
406 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
407 reply->header.size = htons ((uint16_t) msg_length);
408
409 send_message_to_locals (i, j, ns, &reply->header);
350} 410}
351 411
352 412
@@ -365,11 +425,22 @@ send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
365static int 425static int
366helper_mst (void *cls, const struct GNUNET_MessageHeader *message) 426helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
367{ 427{
368 struct TestingSystemCount *tbc = cls; 428 // struct TestingSystemCount *tbc = cls;
369 struct NetJailState *ns = tbc->ns; 429 struct NetJailState *ns = cls;// tbc->ns;
370 struct HelperMessage *hp_msg; 430 struct HelperMessage *hp_msg;
371 unsigned int total_number = ns->local_m * ns->global_n + ns->known; 431 unsigned int total_number = ns->local_m * ns->global_n + ns->known;
372 432
433 LOG (GNUNET_ERROR_TYPE_DEBUG,
434 "total %u sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n",
435 total_number,
436 ns->number_of_testsystems_started,
437 ns->number_of_peers_started,
438 ns->number_of_local_tests_prepared,
439 ns->number_of_local_tests_finished,
440 ns->local_m,
441 ns->global_n,
442 ns->known);
443
373 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) 444 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
374 { 445 {
375 ns->number_of_testsystems_started++; 446 ns->number_of_testsystems_started++;
@@ -395,11 +466,31 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
395 ns->number_of_peers_started = 0; 466 ns->number_of_peers_started = 0;
396 } 467 }
397 } 468 }
469 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED == ntohs (
470 message->type))
471 {
472 ns->number_of_local_tests_prepared++;
473 if (ns->number_of_local_tests_prepared == total_number)
474 {
475 for (int i = 1; i <= ns->known; i++)
476 {
477 send_all_local_tests_prepared (0,i, ns);
478 }
479
480 for (int i = 1; i <= ns->global_n; i++)
481 {
482 for (int j = 1; j <= ns->local_m; j++)
483 {
484 send_all_local_tests_prepared (i,j, ns);
485 }
486 }
487 }
488 }
398 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs ( 489 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
399 message->type)) 490 message->type))
400 { 491 {
401 ns->number_of_local_test_finished++; 492 ns->number_of_local_tests_finished++;
402 if (ns->number_of_local_test_finished == total_number) 493 if (ns->number_of_local_tests_finished == total_number)
403 { 494 {
404 GNUNET_TESTING_async_finish (&ns->ac); 495 GNUNET_TESTING_async_finish (&ns->ac);
405 } 496 }
@@ -477,8 +568,13 @@ start_helper (struct NetJailState *ns, struct
477 struct GNUNET_HELPER_Handle *helper; 568 struct GNUNET_HELPER_Handle *helper;
478 struct GNUNET_CMDS_HelperInit *msg; 569 struct GNUNET_CMDS_HelperInit *msg;
479 struct TestingSystemCount *tbc; 570 struct TestingSystemCount *tbc;
480 char *m_char, *n_char, *global_n_char, *local_m_char, *known_char, *node_id, 571 char *m_char;
481 *plugin; 572 char *n_char;
573 char *global_n_char;
574 char *local_m_char;
575 char *known_char;
576 char *node_id;
577 char *plugin;
482 pid_t pid; 578 pid_t pid;
483 unsigned int script_num; 579 unsigned int script_num;
484 struct GNUNET_ShortHashCode *hkey; 580 struct GNUNET_ShortHashCode *hkey;
@@ -486,6 +582,7 @@ start_helper (struct NetJailState *ns, struct
486 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; 582 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
487 struct GNUNET_TESTING_NetjailNode *node; 583 struct GNUNET_TESTING_NetjailNode *node;
488 struct GNUNET_TESTING_NetjailNamespace *namespace; 584 struct GNUNET_TESTING_NetjailNamespace *namespace;
585 unsigned int *rv = ns->rv;
489 586
490 587
491 if (0 == n) 588 if (0 == n)
@@ -526,7 +623,8 @@ start_helper (struct NetJailState *ns, struct
526 else 623 else
527 tbc->count = (n - 1) * ns->local_m + m + ns->known; 624 tbc->count = (n - 1) * ns->local_m + m + ns->known;
528 625
529 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail, 626 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head,
627 ns->tbcs_tail,
530 tbc); 628 tbc);
531 629
532 630
@@ -535,23 +633,33 @@ start_helper (struct NetJailState *ns, struct
535 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 633 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
536 "No SUID for %s!\n", 634 "No SUID for %s!\n",
537 NETJAIL_EXEC_SCRIPT); 635 NETJAIL_EXEC_SCRIPT);
538 GNUNET_TESTING_interpreter_fail (ns->ac.is); 636 *rv = 1;
539 } 637 }
540 else if (GNUNET_NO == helper_check) 638 else if (GNUNET_NO == helper_check)
541 { 639 {
542 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 640 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
543 "%s not found!\n", 641 "%s not found!\n",
544 NETJAIL_EXEC_SCRIPT); 642 NETJAIL_EXEC_SCRIPT);
545 GNUNET_TESTING_interpreter_fail (ns->ac.is); 643 *rv = 1;
546 } 644 }
547 645
646 LOG (GNUNET_ERROR_TYPE_DEBUG,
647 "sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n",
648 ns->number_of_testsystems_started,
649 ns->number_of_peers_started,
650 ns->number_of_local_tests_prepared,
651 ns->number_of_local_tests_finished,
652 ns->local_m,
653 ns->global_n,
654 ns->known);
655
548 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( 656 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
549 GNUNET_YES, 657 GNUNET_YES,
550 NETJAIL_EXEC_SCRIPT, 658 NETJAIL_EXEC_SCRIPT,
551 script_argv, 659 script_argv,
552 &helper_mst, 660 &helper_mst,
553 &exp_cb, 661 &exp_cb,
554 tbc)); 662 ns));
555 663
556 helper = ns->helper[tbc->count - 1]; 664 helper = ns->helper[tbc->count - 1];
557 665
@@ -608,19 +716,20 @@ start_helper (struct NetJailState *ns, struct
608 716
609 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); 717 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
610 718
611 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( 719 // GNUNET_array_append (tbc->shandle, tbc->n_shandle,
612 helper, 720 tbc->shandle = GNUNET_HELPER_send (
613 &msg->header, 721 helper,
614 GNUNET_NO, 722 &msg->header,
615 &clear_msg, 723 GNUNET_NO,
616 tbc)); 724 &clear_msg,
725 tbc); // );
617 726
618 if (NULL == ns->shandle[tbc->count - 1]) 727 if (NULL == tbc->shandle)// [tbc->count - 1])
619 { 728 {
620 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 729 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
621 "Send handle is NULL!\n"); 730 "Send handle is NULL!\n");
622 GNUNET_free (msg); 731 GNUNET_free (msg);
623 GNUNET_TESTING_interpreter_fail (ns->ac.is); 732 *rv = 1;
624 } 733 }
625} 734}
626 735