aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_start_testsystem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_start_testsystem.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c248
1 files changed, 167 insertions, 81 deletions
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index 98de0698a..4b2fbcc56 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -27,6 +27,7 @@
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testing_netjail_lib.h" 28#include "gnunet_testing_netjail_lib.h"
29#include "testing_cmds.h" 29#include "testing_cmds.h"
30#include "gnunet_testing_barrier.h"
30 31
31#define NETJAIL_EXEC_SCRIPT "netjail_exec.sh" 32#define NETJAIL_EXEC_SCRIPT "netjail_exec.sh"
32 33
@@ -167,12 +168,17 @@ struct NetJailState
167}; 168};
168 169
169/** 170/**
170 * Struct containing the number of the test environment and the NetJailState which 171 * Struct containing the number of the netjail node and the NetJailState which
171 * will be handed to callbacks specific to a test environment. 172 * will be handed to callbacks specific to a test environment.
172 */ 173 */
173struct TestingSystemCount 174struct TestingSystemCount
174{ 175{
175 /** 176 /**
177 * The plugin correlated to this netjail node.
178 */
179 struct Plugin *plugin;
180
181 /**
176 * Kept in a DLL. 182 * Kept in a DLL.
177 */ 183 */
178 struct TestingSystemCount *next; 184 struct TestingSystemCount *next;
@@ -188,12 +194,6 @@ struct TestingSystemCount
188 struct GNUNET_HELPER_SendHandle *shandle; 194 struct GNUNET_HELPER_SendHandle *shandle;
189 195
190 /** 196 /**
191 * The number of the test environment.
192 *
193 */
194 unsigned int count;
195
196 /**
197 * Struct to store information handed over to callbacks. 197 * Struct to store information handed over to callbacks.
198 * 198 *
199 */ 199 */
@@ -214,7 +214,7 @@ static void
214netjail_exec_cleanup (void *cls) 214netjail_exec_cleanup (void *cls)
215{ 215{
216 struct NetJailState *ns = cls; 216 struct NetJailState *ns = cls;
217 217 GNUNET_TESTING_delete_barriers (ns->is);
218 GNUNET_free (ns); 218 GNUNET_free (ns);
219} 219}
220 220
@@ -259,10 +259,10 @@ clear_msg (void *cls, int result)
259 struct TestingSystemCount *tbc = cls; 259 struct TestingSystemCount *tbc = cls;
260 260
261 GNUNET_assert (NULL != tbc->shandle); 261 GNUNET_assert (NULL != tbc->shandle);
262 /*GNUNET_free (tbc->shandle); 262 //GNUNET_free (tbc->shandle);
263 tbc->shandle = NULL;*/ 263 GNUNET_free (tbc->plugin);
264 GNUNET_free (tbc->msg); 264 tbc->shandle = NULL;
265 tbc->msg = NULL; 265 GNUNET_free (tbc);
266} 266}
267 267
268 268
@@ -276,19 +276,19 @@ send_message_to_locals (
276{ 276{
277 const struct GNUNET_HELPER_Handle *helper; 277 const struct GNUNET_HELPER_Handle *helper;
278 struct TestingSystemCount *tbc; 278 struct TestingSystemCount *tbc;
279 unsigned int count;
279 280
280 LOG (GNUNET_ERROR_TYPE_DEBUG, 281 LOG (GNUNET_ERROR_TYPE_DEBUG,
281 "send message of type %u to locals\n", 282 "send message of type %u to locals\n",
282 header->type); 283 header->type);
283 tbc = GNUNET_new (struct TestingSystemCount); 284 tbc = GNUNET_new (struct TestingSystemCount);
284 tbc->ns = ns; 285 tbc->ns = ns;
285 // 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.
286 if (0 == i) 286 if (0 == i)
287 tbc->count = j; // + total_number; 287 count = j;
288 else 288 else
289 tbc->count = (i - 1) * ns->local_m + j + ns->known; // + total_number ; 289 count = (i - 1) * ns->local_m + j + ns->known;
290 290
291 helper = ns->helper[tbc->count - 1];// - total_number]; 291 helper = ns->helper[count - 1];
292 292
293 293
294 294
@@ -304,15 +304,32 @@ send_message_to_locals (
304 304
305 305
306static void 306static void
307send_barrier_advanced (struct GNUNET_TESTING_CommandBarrierReached *rm,
308 unsigned int i,
309 unsigned int j,
310 struct NetJailState *ns)
311{
312 struct GNUNET_TESTING_CommandBarrierAdvanced *adm = GNUNET_new (struct GNUNET_TESTING_CommandBarrierAdvanced);
313 size_t msg_length = sizeof(struct GNUNET_TESTING_CommandAllLocalTestsPrepared);
314
315 adm->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
316 adm->header.size = htons ((uint16_t) msg_length);
317 adm->barrier_name = rm->barrier_name;
318 send_message_to_locals (i, j, ns, &adm->header);
319 GNUNET_free (adm);
320}
321
322
323static void
307send_all_local_tests_prepared (unsigned int i, unsigned int j, struct 324send_all_local_tests_prepared (unsigned int i, unsigned int j, struct
308 NetJailState *ns) 325 NetJailState *ns)
309{ 326{
310 struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED *reply; 327 struct GNUNET_TESTING_CommandAllLocalTestsPrepared *reply;
311 size_t msg_length; 328 size_t msg_length;
312 329
313 330
314 msg_length = sizeof(struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED); 331 msg_length = sizeof(struct GNUNET_TESTING_CommandAllLocalTestsPrepared);
315 reply = GNUNET_new (struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED); 332 reply = GNUNET_new (struct GNUNET_TESTING_CommandAllLocalTestsPrepared);
316 reply->header.type = htons ( 333 reply->header.type = htons (
317 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED); 334 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED);
318 reply->header.size = htons ((uint16_t) msg_length); 335 reply->header.size = htons ((uint16_t) msg_length);
@@ -325,13 +342,11 @@ send_all_local_tests_prepared (unsigned int i, unsigned int j, struct
325static void 342static void
326send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) 343send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
327{ 344{
328 345 struct GNUNET_TESTING_CommandAllPeersStarted *reply;
329 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
330 size_t msg_length; 346 size_t msg_length;
331 347
332 348 msg_length = sizeof(struct GNUNET_TESTING_CommandAllPeersStarted);
333 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED); 349 reply = GNUNET_new (struct GNUNET_TESTING_CommandAllPeersStarted);
334 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
335 reply->header.type = htons ( 350 reply->header.type = htons (
336 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED); 351 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
337 reply->header.size = htons ((uint16_t) msg_length); 352 reply->header.size = htons ((uint16_t) msg_length);
@@ -341,6 +356,44 @@ send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
341} 356}
342 357
343 358
359void
360barrier_attached (struct NetJailState *ns, const struct GNUNET_MessageHeader *message)
361{
362 struct GNUNET_TESTING_CommandBarrierAttached *am;
363 struct GNUNET_TESTING_NetjailNode *node;
364 struct GNUNET_TESTING_Barrier *barrier;
365
366 am = (struct GNUNET_TESTING_CommandBarrierAttached *) message;
367 barrier = GNUNET_TESTING_get_barrier (ns->is, am->barrier_name);
368 GNUNET_assert (NULL != barrier && GNUNET_NO == barrier->shadow);
369 node = GNUNET_TESTING_barrier_get_node (barrier->nodes, am->node_number);
370 if (NULL == node)
371 {
372 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
373 node->node_number = am->node_number;
374 GNUNET_TESTING_barrier_add_node (barrier->nodes, node);
375 }
376 node->expected_reaches = node->expected_reaches + am->expected_reaches;
377 barrier->expected_reaches = barrier->expected_reaches + am->expected_reaches;
378}
379
380
381void
382barrier_reached (struct NetJailState *ns, const struct GNUNET_MessageHeader *message)
383{
384 struct GNUNET_TESTING_CommandBarrierReached *rm = (struct GNUNET_TESTING_CommandBarrierReached *) message;
385 struct GNUNET_TESTING_Barrier *barrier = GNUNET_TESTING_get_barrier (ns->is, rm->barrier_name);
386 struct GNUNET_TESTING_NetjailNode *node;
387
388 GNUNET_assert (NULL != barrier && GNUNET_NO == barrier->shadow);
389 barrier->reached++;
390 if (GNUNET_TESTING_can_barrier_advance (barrier))
391 {
392 GNUNET_TESTING_finish_attached_cmds (ns->is, barrier);
393 }
394}
395
396
344/** 397/**
345 * Functions with this signature are called whenever a 398 * Functions with this signature are called whenever a
346 * complete message is received by the tokenizer. 399 * complete message is received by the tokenizer.
@@ -356,63 +409,68 @@ send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
356static int 409static int
357helper_mst (void *cls, const struct GNUNET_MessageHeader *message) 410helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
358{ 411{
359 // struct TestingSystemCount *tbc = cls;
360 struct NetJailState *ns = cls; 412 struct NetJailState *ns = cls;
361 unsigned int total_number = ns->local_m * ns->global_n + ns->known; 413 unsigned int total_number = ns->local_m * ns->global_n + ns->known;
362 uint16_t message_type = ntohs (message->type); 414 uint16_t message_type = ntohs (message->type);
363 415
364 switch (message_type) 416 switch (message_type)
365 { 417 {
366 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY: 418 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED:
367 ns->number_of_testsystems_started++; 419 barrier_attached (ns, message);
368 break; 420 break;
369 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED: 421 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED:
370 ns->number_of_peers_started++; 422 barrier_reached (ns, message);
371 if (ns->number_of_peers_started == total_number) 423 break;
372 { 424 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY:
373 for (int i = 1; i <= ns->known; i++) 425 ns->number_of_testsystems_started++;
374 { 426 break;
375 send_all_peers_started (0,i, ns); 427 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED:
376 } 428 ns->number_of_peers_started++;
377 for (int i = 1; i <= ns->global_n; i++) 429 if (ns->number_of_peers_started == total_number)
378 { 430 {
379 for (int j = 1; j <= ns->local_m; j++) 431 for (int i = 1; i <= ns->known; i++)
432 {
433 send_all_peers_started (0,i, ns);
434 }
435 for (int i = 1; i <= ns->global_n; i++)
380 { 436 {
381 send_all_peers_started (i,j, ns); 437 for (int j = 1; j <= ns->local_m; j++)
438 {
439 send_all_peers_started (i,j, ns);
440 }
382 } 441 }
442 ns->number_of_peers_started = 0;
383 } 443 }
384 ns->number_of_peers_started = 0; 444 break;
385 } 445 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED:
386 break; 446 ns->number_of_local_tests_prepared++;
387 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED: 447 if (ns->number_of_local_tests_prepared == total_number)
388 ns->number_of_local_tests_prepared++;
389 if (ns->number_of_local_tests_prepared == total_number)
390 {
391 for (int i = 1; i <= ns->known; i++)
392 { 448 {
393 send_all_local_tests_prepared (0,i, ns); 449 for (int i = 1; i <= ns->known; i++)
394 } 450 {
451 send_all_local_tests_prepared (0,i, ns);
452 }
395 453
396 for (int i = 1; i <= ns->global_n; i++) 454 for (int i = 1; i <= ns->global_n; i++)
397 {
398 for (int j = 1; j <= ns->local_m; j++)
399 { 455 {
400 send_all_local_tests_prepared (i,j, ns); 456 for (int j = 1; j <= ns->local_m; j++)
457 {
458 send_all_local_tests_prepared (i,j, ns);
459 }
401 } 460 }
402 } 461 }
403 } 462 break;
404 break; 463 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED:
405 case GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED: 464 ns->number_of_local_tests_finished++;
406 ns->number_of_local_tests_finished++; 465 if (ns->number_of_local_tests_finished == total_number)
407 if (ns->number_of_local_tests_finished == total_number) 466 {
408 { 467 GNUNET_SCHEDULER_cancel (ns->timeout_task);
409 GNUNET_SCHEDULER_cancel (ns->timeout_task); 468 GNUNET_TESTING_async_finish (&ns->ac);
410 GNUNET_TESTING_async_finish (&ns->ac); 469 }
411 } 470 break;
412 break; 471 default:
413 default: 472 // We received a message we can not handle.
414 // We received a message we can not handle. 473 GNUNET_assert (0);
415 GNUNET_assert (0);
416 } 474 }
417 475
418 LOG (GNUNET_ERROR_TYPE_DEBUG, 476 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -454,16 +512,16 @@ exp_cb (void *cls)
454 * @param plugin_name Name of the test case plugin the helper will load. 512 * @param plugin_name Name of the test case plugin the helper will load.
455 * 513 *
456 */ 514 */
457static struct GNUNET_CMDS_HelperInit * 515static struct GNUNET_TESTING_CommandHelperInit *
458create_helper_init_msg_ (const char *plugin_name) 516create_helper_init_msg_ (const char *plugin_name)
459{ 517{
460 struct GNUNET_CMDS_HelperInit *msg; 518 struct GNUNET_TESTING_CommandHelperInit *msg;
461 uint16_t plugin_name_len; 519 uint16_t plugin_name_len;
462 uint16_t msg_size; 520 uint16_t msg_size;
463 521
464 GNUNET_assert (NULL != plugin_name); 522 GNUNET_assert (NULL != plugin_name);
465 plugin_name_len = strlen (plugin_name); 523 plugin_name_len = strlen (plugin_name);
466 msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len; 524 msg_size = sizeof(struct GNUNET_TESTING_CommandHelperInit) + plugin_name_len;
467 msg = GNUNET_malloc (msg_size); 525 msg = GNUNET_malloc (msg_size);
468 msg->header.size = htons (msg_size); 526 msg->header.size = htons (msg_size);
469 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT); 527 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT);
@@ -484,8 +542,9 @@ start_helper (struct NetJailState *ns,
484 unsigned int m, 542 unsigned int m,
485 unsigned int n) 543 unsigned int n)
486{ 544{
545 struct Plugin *plugin;
487 struct GNUNET_HELPER_Handle *helper; 546 struct GNUNET_HELPER_Handle *helper;
488 struct GNUNET_CMDS_HelperInit *msg; 547 struct GNUNET_TESTING_CommandHelperInit *msg;
489 struct TestingSystemCount *tbc; 548 struct TestingSystemCount *tbc;
490 char *m_char; 549 char *m_char;
491 char *n_char; 550 char *n_char;
@@ -493,7 +552,7 @@ start_helper (struct NetJailState *ns,
493 char *local_m_char; 552 char *local_m_char;
494 char *known_char; 553 char *known_char;
495 char *node_id; 554 char *node_id;
496 char *plugin; 555 char *plugin_name;
497 char *read_file; 556 char *read_file;
498 pid_t pid; 557 pid_t pid;
499 unsigned int script_num; 558 unsigned int script_num;
@@ -501,10 +560,13 @@ start_helper (struct NetJailState *ns,
501 struct GNUNET_HashCode hc; 560 struct GNUNET_HashCode hc;
502 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; 561 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
503 struct GNUNET_TESTING_NetjailNode *node; 562 struct GNUNET_TESTING_NetjailNode *node;
563 struct GNUNET_TESTING_NetjailNode *barrier_node;
504 struct GNUNET_TESTING_NetjailNamespace *namespace; 564 struct GNUNET_TESTING_NetjailNamespace *namespace;
505 char *data_dir; 565 char *data_dir;
506 char *script_name; 566 char *script_name;
507 567 struct GNUNET_TESTING_Barrier *barriers;
568 struct GNUNET_TESTING_Barrier *pos;
569 struct GNUNET_TESTING_Barrier *barrier;
508 570
509 if (0 == n) 571 if (0 == n)
510 script_num = m - 1; 572 script_num = m - 1;
@@ -579,11 +641,12 @@ start_helper (struct NetJailState *ns,
579 GNUNET_array_append (ns->helper, ns->n_helper, helper); 641 GNUNET_array_append (ns->helper, ns->n_helper, helper);
580 } 642 }
581 643
582 tbc->count = ns->n_helper; 644 GNUNET_TESTING_add_netjail_helper (ns->is,
583 hkey = GNUNET_new (struct GNUNET_ShortHashCode); 645 helper);
584 646
585 plugin = topology->plugin; 647 plugin_name = topology->plugin;
586 648
649 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
587 if (0 == m) 650 if (0 == m)
588 { 651 {
589 652
@@ -597,7 +660,7 @@ start_helper (struct NetJailState *ns,
597 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals, 660 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
598 hkey); 661 hkey);
599 if (NULL != node->plugin) 662 if (NULL != node->plugin)
600 plugin = node->plugin; 663 plugin_name = node->plugin;
601 } 664 }
602 665
603 } 666 }
@@ -622,24 +685,47 @@ start_helper (struct NetJailState *ns,
622 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes, 685 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
623 hkey); 686 hkey);
624 if (NULL != node->plugin) 687 if (NULL != node->plugin)
625 plugin = node->plugin; 688 plugin_name = node->plugin;
626 } 689 }
627 } 690 }
628 691
629 692
630 } 693 }
631 694
632 msg = create_helper_init_msg_ (plugin); 695 plugin = GNUNET_new (struct Plugin);
696 plugin->api = GNUNET_PLUGIN_load (plugin_name,
697 NULL);
698 barriers = plugin->api->get_waiting_for_barriers ();
699
700
701 for (pos = barriers; NULL != pos; pos = pos->next)
702 {
703 barrier = GNUNET_TESTING_get_barrier (ns->is, pos->name);
704 if (NULL == barrier || GNUNET_YES == barrier->shadow)
705 {
706 GNUNET_TESTING_barrier_add (ns->is, pos);
707 barrier = pos;
708 barrier->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
709 }
710 GNUNET_assert (NULL != node);
711 barrier_node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
712 barrier_node->node_number = node->node_number;
713 barrier_node->expected_reaches = pos->expected_reaches;
714 barrier->expected_reaches = barrier->expected_reaches + pos->expected_reaches;
715 GNUNET_TESTING_barrier_add_node (barrier->nodes, node);
716 }
717 tbc->plugin = plugin;
718
719 msg = create_helper_init_msg_ (plugin_name);
633 720
634 // GNUNET_array_append (tbc->shandle, tbc->n_shandle,
635 tbc->shandle = GNUNET_HELPER_send ( 721 tbc->shandle = GNUNET_HELPER_send (
636 helper, 722 helper,
637 &msg->header, 723 &msg->header,
638 GNUNET_NO, 724 GNUNET_NO,
639 &clear_msg, 725 &clear_msg,
640 tbc); // ); 726 tbc);
641 727
642 if (NULL == tbc->shandle)// [tbc->count - 1]) 728 if (NULL == tbc->shandle)
643 { 729 {
644 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 730 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
645 "Send handle is NULL!\n"); 731 "Send handle is NULL!\n");