aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_start_testsystem_v2.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem_v2.c181
1 files changed, 135 insertions, 46 deletions
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..5e27a7a82 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
@@ -30,6 +30,11 @@
30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec_v2.sh" 30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec_v2.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 */
@@ -116,13 +121,13 @@ struct NetJailState
116 /** 121 /**
117 * The send handle for the helper 122 * The send handle for the helper
118 */ 123 */
119 struct GNUNET_HELPER_SendHandle **shandle; 124 // struct GNUNET_HELPER_SendHandle **shandle;
120 125
121 /** 126 /**
122 * Size of the array NetJailState#shandle. 127 * Size of the array NetJailState#shandle.
123 * 128 *
124 */ 129 */
125 unsigned int n_shandle; 130 // unsigned int n_shandle;
126 131
127 /** 132 /**
128 * The messages send to the helper. 133 * The messages send to the helper.
@@ -151,7 +156,13 @@ struct NetJailState
151 * Number of local tests finished. 156 * Number of local tests finished.
152 * 157 *
153 */ 158 */
154 unsigned int number_of_local_test_finished; 159 unsigned int number_of_local_tests_finished;
160
161 /**
162 * Number of local tests prepared to finish.
163 *
164 */
165 unsigned int number_of_local_tests_prepared;
155 166
156 /** 167 /**
157 * Name of the test case plugin the helper will load. 168 * Name of the test case plugin the helper will load.
@@ -189,6 +200,17 @@ struct TestingSystemCount
189 struct TestingSystemCount *prev; 200 struct TestingSystemCount *prev;
190 201
191 /** 202 /**
203 * The send handle for the helper
204 */
205 struct GNUNET_HELPER_SendHandle *shandle;// **shandle;
206
207 /**
208 * Size of the array NetJailState#shandle.
209 *
210 */
211 // unsigned int n_shandle;
212
213 /**
192 * The number of the test environment. 214 * The number of the test environment.
193 * 215 *
194 */ 216 */
@@ -277,10 +299,9 @@ netjail_exec_traits (void *cls,
277 * @return #GNUNET_OK on success. 299 * @return #GNUNET_OK on success.
278 */ 300 */
279int 301int
280GNUNET_TESTING_get_trait_helper_handles_v2 (const struct 302GNUNET_TESTING_get_trait_helper_handles_v2 (
281 GNUNET_TESTING_Command *cmd, 303 const struct GNUNET_TESTING_Command *cmd,
282 struct GNUNET_HELPER_Handle *** 304 struct GNUNET_HELPER_Handle ***helper)
283 helper)
284{ 305{
285 return cmd->traits (cmd->cls, 306 return cmd->traits (cmd->cls,
286 (const void **) helper, 307 (const void **) helper,
@@ -293,18 +314,19 @@ GNUNET_TESTING_get_trait_helper_handles_v2 (const struct
293 * Continuation function from GNUNET_HELPER_send() 314 * Continuation function from GNUNET_HELPER_send()
294 * 315 *
295 * @param cls closure 316 * @param cls closure
296 * @param result GNUNET_OK on success, 317 * @param result #GNUNET_OK on success,
297 * GNUNET_NO if helper process died 318 * #GNUNET_NO if helper process died
298 * GNUNET_SYSERR during GNUNET_HELPER_stop 319 * #GNUNET_SYSERR during GNUNET_HELPER_stop
299 */ 320 */
300static void 321static void
301clear_msg (void *cls, int result) 322clear_msg (void *cls,
323 int result)
302{ 324{
303 struct TestingSystemCount *tbc = cls; 325 struct TestingSystemCount *tbc = cls;
304 struct NetJailState *ns = tbc->ns; 326 struct NetJailState *ns = tbc->ns;
305 327
306 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]); 328 GNUNET_assert (NULL != tbc->shandle);// [tbc->count - 1]);
307 ns->shandle[tbc->count - 1] = NULL; 329 tbc->shandle = NULL;// [tbc->count - 1] = NULL;
308 GNUNET_free (ns->msg[tbc->count - 1]); 330 GNUNET_free (ns->msg[tbc->count - 1]);
309 ns->msg[tbc->count - 1] = NULL; 331 ns->msg[tbc->count - 1] = NULL;
310} 332}
@@ -323,10 +345,11 @@ clear_msg (void *cls, int result)
323 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 345 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
324 */ 346 */
325static int 347static int
326helper_mst (void *cls, const struct GNUNET_MessageHeader *message) 348helper_mst (void *cls,
349 const struct GNUNET_MessageHeader *message)
327{ 350{
328 struct TestingSystemCount *tbc = cls; 351 // struct TestingSystemCount *tbc = cls;
329 struct NetJailState *ns = tbc->ns; 352 struct NetJailState *ns = cls;// tbc->ns;
330 struct HelperMessage *hp_msg; 353 struct HelperMessage *hp_msg;
331 354
332 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) 355 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
@@ -338,10 +361,18 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
338 { 361 {
339 ns->number_of_peers_started++; 362 ns->number_of_peers_started++;
340 } 363 }
364 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED == ntohs (
365 message->type))
366 {
367 LOG (GNUNET_ERROR_TYPE_DEBUG,
368 "received prepare msg %u\n",
369 ns->number_of_local_tests_prepared);
370 ns->number_of_local_tests_prepared++;
371 }
341 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs ( 372 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
342 message->type)) 373 message->type))
343 { 374 {
344 ns->number_of_local_test_finished++; 375 ns->number_of_local_tests_finished++;
345 } 376 }
346 else 377 else
347 { 378 {
@@ -364,8 +395,10 @@ static void
364exp_cb (void *cls) 395exp_cb (void *cls)
365{ 396{
366 struct NetJailState *ns = cls; 397 struct NetJailState *ns = cls;
398 unsigned int *rv = ns->rv;
399
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); 400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
368 *ns->rv = 1; 401 *rv = 1;
369} 402}
370 403
371 404
@@ -420,6 +453,7 @@ start_helper (struct NetJailState *ns, struct
420 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; 453 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
421 struct GNUNET_TESTING_NetjailNode *node; 454 struct GNUNET_TESTING_NetjailNode *node;
422 struct GNUNET_TESTING_NetjailNamespace *namespace; 455 struct GNUNET_TESTING_NetjailNamespace *namespace;
456 unsigned int *rv = ns->rv;
423 457
424 458
425 if (0 == n) 459 if (0 == n)
@@ -460,7 +494,8 @@ start_helper (struct NetJailState *ns, struct
460 else 494 else
461 tbc->count = (n - 1) * ns->local_m + m + ns->known; 495 tbc->count = (n - 1) * ns->local_m + m + ns->known;
462 496
463 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail, 497 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head,
498 ns->tbcs_tail,
464 tbc); 499 tbc);
465 500
466 501
@@ -469,14 +504,14 @@ start_helper (struct NetJailState *ns, struct
469 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 504 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
470 "No SUID for %s!\n", 505 "No SUID for %s!\n",
471 NETJAIL_EXEC_SCRIPT); 506 NETJAIL_EXEC_SCRIPT);
472 *ns->rv = 1; 507 *rv = 1;
473 } 508 }
474 else if (GNUNET_NO == helper_check) 509 else if (GNUNET_NO == helper_check)
475 { 510 {
476 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 511 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
477 "%s not found!\n", 512 "%s not found!\n",
478 NETJAIL_EXEC_SCRIPT); 513 NETJAIL_EXEC_SCRIPT);
479 *ns->rv = 1; 514 *rv = 1;
480 } 515 }
481 516
482 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( 517 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
@@ -485,7 +520,7 @@ start_helper (struct NetJailState *ns, struct
485 script_argv, 520 script_argv,
486 &helper_mst, 521 &helper_mst,
487 &exp_cb, 522 &exp_cb,
488 tbc)); 523 ns));
489 524
490 helper = ns->helper[tbc->count - 1]; 525 helper = ns->helper[tbc->count - 1];
491 526
@@ -542,19 +577,20 @@ start_helper (struct NetJailState *ns, struct
542 577
543 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); 578 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
544 579
545 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( 580 // GNUNET_array_append (tbc->shandle, tbc->n_shandle,
546 helper, 581 tbc->shandle = GNUNET_HELPER_send (
547 &msg->header, 582 helper,
548 GNUNET_NO, 583 &msg->header,
549 &clear_msg, 584 GNUNET_NO,
550 tbc)); 585 &clear_msg,
586 tbc); // );
551 587
552 if (NULL == ns->shandle[tbc->count - 1]) 588 if (NULL == tbc->shandle)// [tbc->count - 1])
553 { 589 {
554 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 590 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
555 "Send handle is NULL!\n"); 591 "Send handle is NULL!\n");
556 GNUNET_free (msg); 592 GNUNET_free (msg);
557 *ns->rv = 1; 593 *rv = 1;
558 } 594 }
559} 595}
560 596
@@ -595,39 +631,76 @@ netjail_exec_run (void *cls,
595 631
596 632
597static void 633static void
598send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) 634send_message_to_locals (
635 unsigned int i,
636 unsigned int j,
637 struct NetJailState *ns,
638 struct GNUNET_MessageHeader *header
639 )
599{ 640{
600 unsigned int total_number = ns->local_m * ns->global_n + ns->known; 641 // unsigned int total_number = ns->local_m * ns->global_n + ns->known;
601 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
602 size_t msg_length;
603 struct GNUNET_HELPER_Handle *helper; 642 struct GNUNET_HELPER_Handle *helper;
604 struct TestingSystemCount *tbc; 643 struct TestingSystemCount *tbc;
605 644
645 LOG (GNUNET_ERROR_TYPE_DEBUG,
646 "send message to locals\n");
606 tbc = GNUNET_new (struct TestingSystemCount); 647 tbc = GNUNET_new (struct TestingSystemCount);
607 tbc->ns = ns; 648 tbc->ns = ns;
608 // 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. 649 // 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.
609 if (0 == i) 650 if (0 == i)
610 tbc->count = j + total_number; 651 tbc->count = j; // + total_number;
611 else 652 else
612 tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known; 653 tbc->count = (i - 1) * ns->local_m + j + ns->known; // + total_number ;
613 654
614 helper = ns->helper[tbc->count - 1 - total_number]; 655 helper = ns->helper[tbc->count - 1];// - total_number];
615 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
616 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
617 reply->header.type = htons (
618 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
619 reply->header.size = htons ((uint16_t) msg_length);
620 656
621 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header); 657 GNUNET_array_append (ns->msg, ns->n_msg, header);
622 658
623 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( 659 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
624 helper, 660 helper,
625 &reply->header, 661 header,
626 GNUNET_NO, 662 GNUNET_NO,
627 &clear_msg, 663 &clear_msg,
628 tbc); 664 tbc);
629 665
630 GNUNET_array_append (ns->shandle, ns->n_shandle, sh); 666 tbc->shandle = sh;
667 // GNUNET_array_append (tbc->shandle, tbc->n_shandle, sh);
668}
669
670
671static void
672send_all_local_tests_prepared (unsigned int i, unsigned int j, struct
673 NetJailState *ns)
674{
675 struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED *reply;
676 size_t msg_length;
677
678
679 msg_length = sizeof(struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
680 reply = GNUNET_new (struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
681 reply->header.type = htons (
682 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED);
683 reply->header.size = htons ((uint16_t) msg_length);
684
685 send_message_to_locals (i, j, ns, &reply->header);
686}
687
688
689static void
690send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
691{
692
693 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
694 size_t msg_length;
695
696
697 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
698 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
699 reply->header.type = htons (
700 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
701 reply->header.size = htons ((uint16_t) msg_length);
702
703 send_message_to_locals (i, j, ns, &reply->header);
631} 704}
632 705
633 706
@@ -650,12 +723,28 @@ netjail_start_finish (void *cls,
650 unsigned int total_number = ns->local_m * ns->global_n + ns->known; 723 unsigned int total_number = ns->local_m * ns->global_n + ns->known;
651 724
652 725
653 if (ns->number_of_local_test_finished == total_number) 726 if (ns->number_of_local_tests_finished == total_number)
654 { 727 {
655 ret = GNUNET_YES; 728 ret = GNUNET_YES;
656 cont (cont_cls); 729 cont (cont_cls);
657 } 730 }
658 731
732 if (ns->number_of_local_tests_prepared == total_number)
733 {
734 for (int i = 1; i <= ns->known; i++)
735 {
736 send_all_local_tests_prepared (0,i, ns);
737 }
738
739 for (int i = 1; i <= ns->global_n; i++)
740 {
741 for (int j = 1; j <= ns->local_m; j++)
742 {
743 send_all_local_tests_prepared (i,j, ns);
744 }
745 }
746 }
747
659 if (ns->number_of_testsystems_started == total_number) 748 if (ns->number_of_testsystems_started == total_number)
660 { 749 {
661 ns->number_of_testsystems_started = 0; 750 ns->number_of_testsystems_started = 0;