diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-09-09 12:22:31 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-09-09 12:22:31 +0000 |
commit | de547f838e21de9f847c0b357c41cbfa6ecbe967 (patch) | |
tree | 35da1aed63ed018249ec58941447bacd758adfff /src | |
parent | a3efd7521e99175689c589a128240f2c84c55c45 (diff) | |
download | gnunet-de547f838e21de9f847c0b357c41cbfa6ecbe967.tar.gz gnunet-de547f838e21de9f847c0b357c41cbfa6ecbe967.zip |
- barriers test case; more fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_testbed_service.h | 5 | ||||
-rw-r--r-- | src/testbed/Makefile.am | 9 | ||||
-rw-r--r-- | src/testbed/gnunet-service-test-barriers.c | 106 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 4 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed_barriers.c | 50 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed_barriers.h | 16 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_barriers.c | 106 | ||||
-rwxr-xr-x | src/testbed/test_testbed_api_barriers.py | 8 | ||||
-rw-r--r-- | src/testbed/testbed.conf.in | 9 | ||||
-rw-r--r-- | src/testbed/testbed.h | 4 | ||||
-rw-r--r-- | src/testbed/testbed_api_barriers.c | 38 | ||||
-rw-r--r-- | src/testbed/testbed_api_testbed.c | 15 |
12 files changed, 334 insertions, 36 deletions
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h index 9c09e5689..48d3440ab 100644 --- a/src/include/gnunet_testbed_service.h +++ b/src/include/gnunet_testbed_service.h | |||
@@ -1556,7 +1556,7 @@ struct GNUNET_TESTBED_BarrierWaitHandle; | |||
1556 | */ | 1556 | */ |
1557 | typedef void (*GNUNET_TESTBED_barrier_wait_cb) (void *cls, | 1557 | typedef void (*GNUNET_TESTBED_barrier_wait_cb) (void *cls, |
1558 | const char *name, | 1558 | const char *name, |
1559 | int estatus); | 1559 | int status); |
1560 | 1560 | ||
1561 | 1561 | ||
1562 | /** | 1562 | /** |
@@ -1577,7 +1577,8 @@ GNUNET_TESTBED_barrier_wait (const char *name, | |||
1577 | 1577 | ||
1578 | 1578 | ||
1579 | /** | 1579 | /** |
1580 | * Cancel a barrier wait handle | 1580 | * Cancel a barrier wait handle. Should not be called in or after the callback |
1581 | * given to GNUNET_TESTBED_barrier_wait() has been called. | ||
1581 | * | 1582 | * |
1582 | * @param h the barrier wait handle | 1583 | * @param h the barrier wait handle |
1583 | */ | 1584 | */ |
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index b3779ec21..9fb3eb3c0 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am | |||
@@ -49,7 +49,8 @@ gnunet_service_testbed_SOURCES = \ | |||
49 | gnunet-service-testbed_cpustatus.c \ | 49 | gnunet-service-testbed_cpustatus.c \ |
50 | gnunet-service-testbed_meminfo.c \ | 50 | gnunet-service-testbed_meminfo.c \ |
51 | gnunet-service-testbed_meminfo.h \ | 51 | gnunet-service-testbed_meminfo.h \ |
52 | gnunet-service-testbed_barriers.c | 52 | gnunet-service-testbed_barriers.c \ |
53 | gnunet-service-testbed_barriers.h | ||
53 | gnunet_service_testbed_LDADD = $(XLIB) \ | 54 | gnunet_service_testbed_LDADD = $(XLIB) \ |
54 | $(top_builddir)/src/util/libgnunetutil.la \ | 55 | $(top_builddir)/src/util/libgnunetutil.la \ |
55 | $(top_builddir)/src/core/libgnunetcore.la \ | 56 | $(top_builddir)/src/core/libgnunetcore.la \ |
@@ -362,7 +363,8 @@ test_testbed_api_peer_reconfiguration_LDADD = \ | |||
362 | libgnunettestbed.la | 363 | libgnunettestbed.la |
363 | 364 | ||
364 | test_testbed_api_barriers_SOURCES = \ | 365 | test_testbed_api_barriers_SOURCES = \ |
365 | test_testbed_api_barriers.c | 366 | test_testbed_api_barriers.c \ |
367 | test_testbed_api_barriers.h | ||
366 | test_testbed_api_barriers_LDADD = \ | 368 | test_testbed_api_barriers_LDADD = \ |
367 | $(top_builddir)/src/util/libgnunetutil.la \ | 369 | $(top_builddir)/src/util/libgnunetutil.la \ |
368 | libgnunettestbed.la | 370 | libgnunettestbed.la |
@@ -373,7 +375,8 @@ buildvars.py: buildvars.py.in Makefile | |||
373 | $(do_subst) < $(srcdir)/buildvars.py.in > $@ | 375 | $(do_subst) < $(srcdir)/buildvars.py.in > $@ |
374 | 376 | ||
375 | gnunet_service_test_barriers_SOURCES = \ | 377 | gnunet_service_test_barriers_SOURCES = \ |
376 | gnunet-service-test-barriers.c | 378 | gnunet-service-test-barriers.c \ |
379 | test_testbed_api_barriers.h | ||
377 | gnunet_service_test_barriers_LDADD = \ | 380 | gnunet_service_test_barriers_LDADD = \ |
378 | $(top_builddir)/src/util/libgnunetutil.la \ | 381 | $(top_builddir)/src/util/libgnunetutil.la \ |
379 | libgnunettestbed.la | 382 | libgnunettestbed.la |
diff --git a/src/testbed/gnunet-service-test-barriers.c b/src/testbed/gnunet-service-test-barriers.c index 84c6bde68..52528d523 100644 --- a/src/testbed/gnunet-service-test-barriers.c +++ b/src/testbed/gnunet-service-test-barriers.c | |||
@@ -25,8 +25,110 @@ | |||
25 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | 25 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_testbed_service.h" | ||
31 | #include "test_testbed_api_barriers.h" | ||
28 | 32 | ||
29 | int main () | 33 | /** |
34 | * logging short hand | ||
35 | */ | ||
36 | #define LOG(type,...) \ | ||
37 | GNUNET_log (type, __VA_ARGS__); | ||
38 | |||
39 | /** | ||
40 | * Our barrier wait handle | ||
41 | */ | ||
42 | struct GNUNET_TESTBED_BarrierWaitHandle *wh; | ||
43 | |||
44 | |||
45 | /** | ||
46 | * Dummy task callback to keep us running forever | ||
47 | * | ||
48 | * @param cls NULL | ||
49 | * @param tc scheduler task context | ||
50 | */ | ||
51 | static void | ||
52 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
53 | { | ||
54 | if (NULL != wh) | ||
55 | GNUNET_TESTBED_barrier_wait_cancel (wh); | ||
56 | wh = NULL; | ||
57 | } | ||
58 | |||
59 | |||
60 | /** | ||
61 | * Functions of this type are to be given as acallback argumetn to | ||
62 | * GNUNET_TESTBED_barrier_wait(). The callback will be called when the barrier | ||
63 | * corresponding given in GNUNET_TESTBED_barrier_wait() is crossed or cancelled. | ||
64 | * | ||
65 | * @param cls NULL | ||
66 | * @param name the barrier name | ||
67 | * @param status GNUNET_SYSERR in case of error while waiting for the barrier; | ||
68 | * GNUNET_OK if the barrier is crossed | ||
69 | */ | ||
70 | static void | ||
71 | barrier_wait_cb (void *cls, const char *name, int status) | ||
72 | { | ||
73 | GNUNET_break (NULL == cls); | ||
74 | wh = NULL; | ||
75 | GNUNET_break (GNUNET_OK == status); | ||
76 | } | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Task to wait for the barrier | ||
81 | * | ||
82 | * @param cls NULL | ||
83 | * @param tc scheduler task context | ||
84 | * @return | ||
85 | */ | ||
86 | static void | ||
87 | do_wait (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
88 | { | ||
89 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
90 | return; | ||
91 | wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, &barrier_wait_cb, NULL); | ||
92 | GNUNET_break (NULL != wh); | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
97 | * Main run function. | ||
98 | * | ||
99 | * @param cls NULL | ||
100 | * @param args arguments passed to GNUNET_PROGRAM_run | ||
101 | * @param cfgfile the path to configuration file | ||
102 | * @param cfg the configuration file handle | ||
103 | */ | ||
104 | static void | ||
105 | run (void *cls, char *const *args, const char *cfgfile, | ||
106 | const struct GNUNET_CONFIGURATION_Handle *config) | ||
107 | { | ||
108 | unsigned int rsec; | ||
109 | |||
110 | rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 10); | ||
111 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
112 | (GNUNET_TIME_UNIT_SECONDS, rsec), | ||
113 | &do_wait, NULL); | ||
114 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
115 | &do_shutdown, NULL); | ||
116 | } | ||
117 | |||
118 | |||
119 | |||
120 | /** | ||
121 | * Main | ||
122 | */ | ||
123 | int main (int argc, char **argv) | ||
30 | { | 124 | { |
31 | return 0; | 125 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
126 | GNUNET_GETOPT_OPTION_END | ||
127 | }; | ||
128 | int ret; | ||
129 | |||
130 | ret = | ||
131 | GNUNET_PROGRAM_run (argc, argv, | ||
132 | "test-barriers", "nohelp", options, &run, NULL); | ||
133 | return ret; | ||
32 | } | 134 | } |
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index ed76b3fef..0373f4196 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -824,12 +824,13 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
824 | GNUNET_free (mq_entry); | 824 | GNUNET_free (mq_entry); |
825 | } | 825 | } |
826 | GNUNET_free_non_null (hostname); | 826 | GNUNET_free_non_null (hostname); |
827 | GNUNET_CONFIGURATION_destroy (GST_config); | ||
828 | /* Free hello cache */ | 827 | /* Free hello cache */ |
829 | GST_cache_clear (); | 828 | GST_cache_clear (); |
830 | GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds); | 829 | GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds); |
831 | GST_opq_openfds = NULL; | 830 | GST_opq_openfds = NULL; |
832 | GST_stats_destroy (); | 831 | GST_stats_destroy (); |
832 | GST_barriers_destroy (); | ||
833 | GNUNET_CONFIGURATION_destroy (GST_config); | ||
833 | } | 834 | } |
834 | 835 | ||
835 | 836 | ||
@@ -942,6 +943,7 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
942 | &shutdown_task, NULL); | 943 | &shutdown_task, NULL); |
943 | LOG_DEBUG ("Testbed startup complete\n"); | 944 | LOG_DEBUG ("Testbed startup complete\n"); |
944 | GST_stats_init (GST_config); | 945 | GST_stats_init (GST_config); |
946 | GST_barriers_init (GST_config); | ||
945 | } | 947 | } |
946 | 948 | ||
947 | 949 | ||
diff --git a/src/testbed/gnunet-service-testbed_barriers.c b/src/testbed/gnunet-service-testbed_barriers.c index 894bf1056..693396ef6 100644 --- a/src/testbed/gnunet-service-testbed_barriers.c +++ b/src/testbed/gnunet-service-testbed_barriers.c | |||
@@ -42,6 +42,17 @@ | |||
42 | ((barrier->quorum * GST_num_local_peers) <= (barrier->nreached * 100)) | 42 | ((barrier->quorum * GST_num_local_peers) <= (barrier->nreached * 100)) |
43 | 43 | ||
44 | 44 | ||
45 | #ifdef LOG | ||
46 | #undef LOG | ||
47 | #endif | ||
48 | |||
49 | /** | ||
50 | * Logging shorthand | ||
51 | */ | ||
52 | #define LOG(kind,...) \ | ||
53 | GNUNET_log_from (kind, "testbed-barriers", __VA_ARGS__) | ||
54 | |||
55 | |||
45 | /** | 56 | /** |
46 | * Barrier | 57 | * Barrier |
47 | */ | 58 | */ |
@@ -392,16 +403,18 @@ send_client_status_msg (struct GNUNET_SERVER_Client *client, | |||
392 | uint16_t msize; | 403 | uint16_t msize; |
393 | 404 | ||
394 | GNUNET_assert ((NULL == emsg) || (BARRIER_STATUS_ERROR == status)); | 405 | GNUNET_assert ((NULL == emsg) || (BARRIER_STATUS_ERROR == status)); |
395 | name_len = strlen (name) + 1; | 406 | name_len = strlen (name); |
396 | msize = sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) | 407 | msize = sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) |
397 | + name_len | 408 | + (name_len + 1) |
398 | + (NULL == emsg) ? 0 : strlen (emsg) + 1; | 409 | + ((NULL == emsg) ? 0 : (strlen (emsg) + 1)); |
399 | msg = GNUNET_malloc (msize); | 410 | msg = GNUNET_malloc (msize); |
411 | msg->header.size = htons (msize); | ||
412 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); | ||
400 | msg->status = htons (status); | 413 | msg->status = htons (status); |
401 | msg->name_len = htons ((uint16_t) name_len); | 414 | msg->name_len = htons ((uint16_t) name_len); |
402 | (void) memcpy (msg->data, name, name_len); | 415 | (void) memcpy (msg->data, name, name_len); |
403 | if (NULL != emsg) | 416 | if (NULL != emsg) |
404 | (void) memcpy (msg->data + name_len, emsg, strlen (emsg) + 1); | 417 | (void) memcpy (msg->data + name_len + 1, emsg, strlen (emsg)); |
405 | GST_queue_message (client, &msg->header); | 418 | GST_queue_message (client, &msg->header); |
406 | } | 419 | } |
407 | 420 | ||
@@ -444,7 +457,7 @@ notify_task_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
444 | msg = GNUNET_malloc (msize); | 457 | msg = GNUNET_malloc (msize); |
445 | msg->header.size = htons (msize); | 458 | msg->header.size = htons (msize); |
446 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); | 459 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); |
447 | msg->status = 0; | 460 | msg->status = htons (BARRIER_STATUS_CROSSED); |
448 | msg->name_len = htons (name_len); | 461 | msg->name_len = htons (name_len); |
449 | (void) memcpy (msg->data, barrier->name, name_len); | 462 | (void) memcpy (msg->data, barrier->name, name_len); |
450 | msg->data[name_len] = '\0'; | 463 | msg->data[name_len] = '\0'; |
@@ -453,8 +466,6 @@ notify_task_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
453 | dup_msg = GNUNET_copy_message (&msg->header); | 466 | dup_msg = GNUNET_copy_message (&msg->header); |
454 | queue_message (client_ctx, dup_msg); | 467 | queue_message (client_ctx, dup_msg); |
455 | GNUNET_CONTAINER_DLL_remove (barrier->head, barrier->tail, client_ctx); | 468 | GNUNET_CONTAINER_DLL_remove (barrier->head, barrier->tail, client_ctx); |
456 | GNUNET_SERVER_client_set_user_context_ (client_ctx->client, NULL, 0); | ||
457 | GNUNET_free (client_ctx); | ||
458 | } | 469 | } |
459 | } | 470 | } |
460 | 471 | ||
@@ -501,7 +512,8 @@ handle_barrier_wait (void *cls, struct GNUNET_SERVER_Client *client, | |||
501 | name = GNUNET_malloc (name_len + 1); | 512 | name = GNUNET_malloc (name_len + 1); |
502 | name[name_len] = '\0'; | 513 | name[name_len] = '\0'; |
503 | (void) memcpy (name, msg->name, name_len); | 514 | (void) memcpy (name, msg->name, name_len); |
504 | GNUNET_CRYPTO_hash (name, name_len - 1, &key); | 515 | LOG_DEBUG ("Received BARRIER_WAIT for barrier `%s'\n", name); |
516 | GNUNET_CRYPTO_hash (name, name_len, &key); | ||
505 | if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key))) | 517 | if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key))) |
506 | { | 518 | { |
507 | GNUNET_break (0); | 519 | GNUNET_break (0); |
@@ -517,9 +529,14 @@ handle_barrier_wait (void *cls, struct GNUNET_SERVER_Client *client, | |||
517 | GNUNET_SERVER_client_keep (client); | 529 | GNUNET_SERVER_client_keep (client); |
518 | client_ctx->barrier = barrier; | 530 | client_ctx->barrier = barrier; |
519 | GNUNET_CONTAINER_DLL_insert_tail (barrier->head, barrier->tail, client_ctx); | 531 | GNUNET_CONTAINER_DLL_insert_tail (barrier->head, barrier->tail, client_ctx); |
520 | barrier->nreached++; | 532 | } |
521 | if (LOCAL_QUORUM_REACHED (barrier)) | 533 | barrier->nreached++; |
522 | notify_task_cb (barrier, NULL); | 534 | if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) |
535 | && (LOCAL_QUORUM_REACHED (barrier))) | ||
536 | { | ||
537 | barrier->status = BARRIER_STATUS_CROSSED; | ||
538 | send_barrier_status_msg (barrier, NULL); | ||
539 | notify_task_cb (barrier, NULL); | ||
523 | } | 540 | } |
524 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 541 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
525 | } | 542 | } |
@@ -538,6 +555,8 @@ disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) | |||
538 | { | 555 | { |
539 | struct ClientCtx *client_ctx; | 556 | struct ClientCtx *client_ctx; |
540 | 557 | ||
558 | if (NULL == client) | ||
559 | return; | ||
541 | client_ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx); | 560 | client_ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientCtx); |
542 | if (NULL == client_ctx) | 561 | if (NULL == client_ctx) |
543 | return; /* We only set user context for locally | 562 | return; /* We only set user context for locally |
@@ -548,6 +567,8 @@ disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) | |||
548 | 567 | ||
549 | /** | 568 | /** |
550 | * Function to initialise barrriers component | 569 | * Function to initialise barrriers component |
570 | * | ||
571 | * @param cfg the configuration to use for initialisation | ||
551 | */ | 572 | */ |
552 | void | 573 | void |
553 | GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg) | 574 | GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg) |
@@ -571,7 +592,7 @@ GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg) | |||
571 | * Function to stop the barrier service | 592 | * Function to stop the barrier service |
572 | */ | 593 | */ |
573 | void | 594 | void |
574 | GST_barriers_stop () | 595 | GST_barriers_destroy () |
575 | { | 596 | { |
576 | GNUNET_assert (NULL != barrier_map); | 597 | GNUNET_assert (NULL != barrier_map); |
577 | GNUNET_CONTAINER_multihashmap_destroy (barrier_map); | 598 | GNUNET_CONTAINER_multihashmap_destroy (barrier_map); |
@@ -719,9 +740,10 @@ GST_handle_barrier_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
719 | name = GNUNET_malloc (name_len + 1); | 740 | name = GNUNET_malloc (name_len + 1); |
720 | (void) memcpy (name, msg->name, name_len); | 741 | (void) memcpy (name, msg->name, name_len); |
721 | GNUNET_CRYPTO_hash (name, name_len, &hash); | 742 | GNUNET_CRYPTO_hash (name, name_len, &hash); |
743 | LOG_DEBUG ("Received BARRIER_INIT for barrier `%s'\n", name); | ||
722 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (barrier_map, &hash)) | 744 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (barrier_map, &hash)) |
723 | { | 745 | { |
724 | 746 | ||
725 | send_client_status_msg (client, name, BARRIER_STATUS_ERROR, | 747 | send_client_status_msg (client, name, BARRIER_STATUS_ERROR, |
726 | "A barrier with the same name already exists"); | 748 | "A barrier with the same name already exists"); |
727 | GNUNET_free (name); | 749 | GNUNET_free (name); |
@@ -762,6 +784,8 @@ GST_handle_barrier_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
762 | if (NULL == barrier->whead) /* No further propagation */ | 784 | if (NULL == barrier->whead) /* No further propagation */ |
763 | { | 785 | { |
764 | barrier->status = BARRIER_STATUS_INITIALISED; | 786 | barrier->status = BARRIER_STATUS_INITIALISED; |
787 | LOG_DEBUG ("Sending BARRIER_STATUS_INITIALISED for barrier `%s'\n", | ||
788 | barrier->name); | ||
765 | send_barrier_status_msg (barrier, NULL); | 789 | send_barrier_status_msg (barrier, NULL); |
766 | }else | 790 | }else |
767 | barrier->tout_task = GNUNET_SCHEDULER_add_delayed (MESSAGE_SEND_TIMEOUT (30), | 791 | barrier->tout_task = GNUNET_SCHEDULER_add_delayed (MESSAGE_SEND_TIMEOUT (30), |
diff --git a/src/testbed/gnunet-service-testbed_barriers.h b/src/testbed/gnunet-service-testbed_barriers.h index a58ff33b8..ed1b339b0 100644 --- a/src/testbed/gnunet-service-testbed_barriers.h +++ b/src/testbed/gnunet-service-testbed_barriers.h | |||
@@ -28,6 +28,22 @@ | |||
28 | #define GNUNET_SERVER_TESTBED_BARRIERS_H_ | 28 | #define GNUNET_SERVER_TESTBED_BARRIERS_H_ |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Function to initialise barrriers component | ||
32 | * | ||
33 | * @param cfg the configuration to use for initialisation | ||
34 | */ | ||
35 | void | ||
36 | GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg); | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Function to stop the barrier service | ||
41 | */ | ||
42 | void | ||
43 | GST_barriers_destroy (); | ||
44 | |||
45 | |||
46 | /** | ||
31 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT messages. This | 47 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT messages. This |
32 | * message should always come from a parent controller or the testbed API if we | 48 | * message should always come from a parent controller or the testbed API if we |
33 | * are the root controller. | 49 | * are the root controller. |
diff --git a/src/testbed/test_testbed_api_barriers.c b/src/testbed/test_testbed_api_barriers.c index b40fbc87a..35fda4b31 100644 --- a/src/testbed/test_testbed_api_barriers.c +++ b/src/testbed/test_testbed_api_barriers.c | |||
@@ -27,12 +27,31 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_testbed_service.h" | 29 | #include "gnunet_testbed_service.h" |
30 | #include "test_testbed_api_barriers.h" | ||
31 | |||
32 | |||
33 | /** | ||
34 | * logging short hand | ||
35 | */ | ||
36 | #define LOG(type,...) \ | ||
37 | GNUNET_log (type, __VA_ARGS__); | ||
30 | 38 | ||
31 | /** | 39 | /** |
32 | * Number of peers we start in this test case | 40 | * Number of peers we start in this test case |
33 | */ | 41 | */ |
34 | #define NUM_PEERS 3 | 42 | #define NUM_PEERS 3 |
35 | 43 | ||
44 | |||
45 | /** | ||
46 | * Our barrier | ||
47 | */ | ||
48 | struct GNUNET_TESTBED_Barrier *barrier; | ||
49 | |||
50 | /** | ||
51 | * Identifier for the shutdown task | ||
52 | */ | ||
53 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; | ||
54 | |||
36 | /** | 55 | /** |
37 | * Result of this test case | 56 | * Result of this test case |
38 | */ | 57 | */ |
@@ -40,6 +59,75 @@ static int result; | |||
40 | 59 | ||
41 | 60 | ||
42 | /** | 61 | /** |
62 | * Shutdown this test case when it takes too long | ||
63 | * | ||
64 | * @param cls NULL | ||
65 | * @param tc scheduler task context | ||
66 | */ | ||
67 | static void | ||
68 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
69 | { | ||
70 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; | ||
71 | if (NULL != barrier) | ||
72 | { | ||
73 | GNUNET_TESTBED_barrier_cancel (barrier); | ||
74 | barrier = NULL; | ||
75 | } | ||
76 | |||
77 | GNUNET_SCHEDULER_shutdown (); | ||
78 | } | ||
79 | |||
80 | |||
81 | /** | ||
82 | * Functions of this type are to be given as callback argument to | ||
83 | * GNUNET_TESTBED_barrier_init(). The callback will be called when status | ||
84 | * information is available for the barrier. | ||
85 | * | ||
86 | * @param cls the closure given to GNUNET_TESTBED_barrier_init() | ||
87 | * @param name the name of the barrier | ||
88 | * @param barrier the barrier handle | ||
89 | * @param status status of the barrier; GNUNET_OK if the barrier is crossed; | ||
90 | * GNUNET_SYSERR upon error | ||
91 | * @param emsg if the status were to be GNUNET_SYSERR, this parameter has the | ||
92 | * error messsage | ||
93 | */ | ||
94 | static void | ||
95 | barrier_cb (void *cls, | ||
96 | const char *name, | ||
97 | struct GNUNET_TESTBED_Barrier *_barrier, | ||
98 | enum GNUNET_TESTBED_BarrierStatus status, | ||
99 | const char *emsg) | ||
100 | { | ||
101 | static enum GNUNET_TESTBED_BarrierStatus old_status; | ||
102 | |||
103 | GNUNET_assert (NULL == cls); | ||
104 | GNUNET_assert (_barrier == barrier); | ||
105 | switch (status) | ||
106 | { | ||
107 | case BARRIER_STATUS_INITIALISED: | ||
108 | LOG (GNUNET_ERROR_TYPE_INFO, "Barrier initialised\n"); | ||
109 | old_status = status; | ||
110 | return; | ||
111 | case BARRIER_STATUS_ERROR: | ||
112 | LOG (GNUNET_ERROR_TYPE_ERROR, "Barrier initialisation failed: %s", | ||
113 | (NULL == emsg) ? "unknown reason" : emsg); | ||
114 | barrier = NULL; | ||
115 | GNUNET_SCHEDULER_shutdown (); | ||
116 | return; | ||
117 | case BARRIER_STATUS_CROSSED: | ||
118 | LOG (GNUNET_ERROR_TYPE_INFO, "Barrier crossed\n"); | ||
119 | if (old_status == BARRIER_STATUS_INITIALISED) | ||
120 | result = GNUNET_OK; | ||
121 | barrier = NULL; | ||
122 | GNUNET_SCHEDULER_shutdown (); | ||
123 | return; | ||
124 | default: | ||
125 | GNUNET_assert (0); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | |||
130 | /** | ||
43 | * Signature of a main function for a testcase. | 131 | * Signature of a main function for a testcase. |
44 | * | 132 | * |
45 | * @param cls closure | 133 | * @param cls closure |
@@ -59,6 +147,7 @@ test_master (void *cls, | |||
59 | unsigned int links_succeeded, | 147 | unsigned int links_succeeded, |
60 | unsigned int links_failed) | 148 | unsigned int links_failed) |
61 | { | 149 | { |
150 | struct GNUNET_TESTBED_Controller *c; | ||
62 | 151 | ||
63 | GNUNET_assert (NULL == cls); | 152 | GNUNET_assert (NULL == cls); |
64 | if (NULL == peers_) | 153 | if (NULL == peers_) |
@@ -67,13 +156,14 @@ test_master (void *cls, | |||
67 | return; | 156 | return; |
68 | } | 157 | } |
69 | GNUNET_assert (NUM_PEERS == num_peers); | 158 | GNUNET_assert (NUM_PEERS == num_peers); |
70 | 159 | c = GNUNET_TESTBED_run_get_controller_handle (h); | |
71 | result = GNUNET_OK; | 160 | barrier = GNUNET_TESTBED_barrier_init (c, TEST_BARRIER_NAME, 100, |
72 | GNUNET_SCHEDULER_shutdown (); | 161 | &barrier_cb, NULL); |
73 | /* shutdown_task = */ | 162 | shutdown_task = |
74 | /* GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply */ | 163 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
75 | /* (GNUNET_TIME_UNIT_SECONDS, 300), */ | 164 | (GNUNET_TIME_UNIT_SECONDS, |
76 | /* do_shutdown, NULL); */ | 165 | 10 * (NUM_PEERS + 1)), |
166 | &do_shutdown, NULL); | ||
77 | } | 167 | } |
78 | 168 | ||
79 | 169 | ||
@@ -87,7 +177,7 @@ main (int argc, char **argv) | |||
87 | 177 | ||
88 | result = GNUNET_SYSERR; | 178 | result = GNUNET_SYSERR; |
89 | event_mask = 0; | 179 | event_mask = 0; |
90 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", | 180 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_barriers", |
91 | "test_testbed_api_barriers.conf", NUM_PEERS, | 181 | "test_testbed_api_barriers.conf", NUM_PEERS, |
92 | event_mask, NULL, NULL, | 182 | event_mask, NULL, NULL, |
93 | &test_master, NULL); | 183 | &test_master, NULL); |
diff --git a/src/testbed/test_testbed_api_barriers.py b/src/testbed/test_testbed_api_barriers.py index 17b6ab1e5..cc2a94743 100755 --- a/src/testbed/test_testbed_api_barriers.py +++ b/src/testbed/test_testbed_api_barriers.py | |||
@@ -24,7 +24,6 @@ | |||
24 | 24 | ||
25 | 25 | ||
26 | import subprocess | 26 | import subprocess |
27 | import shutil | ||
28 | import os | 27 | import os |
29 | import sys | 28 | import sys |
30 | from buildvars import libexecdir | 29 | from buildvars import libexecdir |
@@ -37,7 +36,12 @@ else: | |||
37 | test_testbed_api_barriers = './test_testbed_api_barriers' | 36 | test_testbed_api_barriers = './test_testbed_api_barriers' |
38 | 37 | ||
39 | # copy gnunet-service-test-barriers service to gnunet's libexec dir | 38 | # copy gnunet-service-test-barriers service to gnunet's libexec dir |
40 | shutil.copy (service, libexecdir) | 39 | ret = subprocess.call (['libtool', '--mode=install', 'install', |
40 | service, libexecdir], | ||
41 | shell=False, executable='libtool') | ||
42 | if ret is not 0: | ||
43 | print "could not install test daemon" | ||
44 | sys.exit (ret); | ||
41 | 45 | ||
42 | # start the testcase binary | 46 | # start the testcase binary |
43 | ret = subprocess.call (test_testbed_api_barriers, shell=False) | 47 | ret = subprocess.call (test_testbed_api_barriers, shell=False) |
diff --git a/src/testbed/testbed.conf.in b/src/testbed/testbed.conf.in index dcd8829a1..f3f437d33 100644 --- a/src/testbed/testbed.conf.in +++ b/src/testbed/testbed.conf.in | |||
@@ -92,3 +92,12 @@ UNIXPATH = /tmp/gnunet-gnunet-testbed-logger.sock | |||
92 | DIR = /tmp | 92 | DIR = /tmp |
93 | UNIX_MATCH_UID = YES | 93 | UNIX_MATCH_UID = YES |
94 | UNIX_MATCH_GID = YES | 94 | UNIX_MATCH_GID = YES |
95 | |||
96 | |||
97 | [testbed-barrier] | ||
98 | AUTOSTART = NO | ||
99 | @UNIXONLY@ PORT = 2103 | ||
100 | HOSTNAME = localhost | ||
101 | UNIXPATH = /tmp/gnunet-service-testbed-barrier.sock | ||
102 | UNIX_MATCH_UID = YES | ||
103 | UNIX_MATCH_GID = YES | ||
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h index 32dcd6ddd..f9635ea25 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h | |||
@@ -832,12 +832,12 @@ struct GNUNET_TESTBED_BarrierStatusMsg | |||
832 | /** | 832 | /** |
833 | * status. Use enumerated values of enum BarrierStatus | 833 | * status. Use enumerated values of enum BarrierStatus |
834 | */ | 834 | */ |
835 | uint16_t status; | 835 | uint16_t status GNUNET_PACKED; |
836 | 836 | ||
837 | /** | 837 | /** |
838 | * strlen of the barrier name | 838 | * strlen of the barrier name |
839 | */ | 839 | */ |
840 | uint16_t name_len; | 840 | uint16_t name_len GNUNET_PACKED; |
841 | 841 | ||
842 | /** | 842 | /** |
843 | * the barrier name (NULL terminated) concatenated with an error message (NULL | 843 | * the barrier name (NULL terminated) concatenated with an error message (NULL |
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c index dee6bd704..96fd3be66 100644 --- a/src/testbed/testbed_api_barriers.c +++ b/src/testbed/testbed_api_barriers.c | |||
@@ -29,6 +29,18 @@ | |||
29 | #include "testbed_api.h" | 29 | #include "testbed_api.h" |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * Logging shorthand | ||
33 | */ | ||
34 | #define LOG(type, ...) \ | ||
35 | GNUNET_log_from (type, "testbed-api-barriers", __VA_ARGS__); | ||
36 | |||
37 | /** | ||
38 | * Debug logging shorthand | ||
39 | */ | ||
40 | #define LOG_DEBUG(...) \ | ||
41 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); | ||
42 | |||
43 | /** | ||
32 | * Handle for barrier | 44 | * Handle for barrier |
33 | */ | 45 | */ |
34 | struct GNUNET_TESTBED_Barrier | 46 | struct GNUNET_TESTBED_Barrier |
@@ -119,8 +131,13 @@ GNUNET_TESTBED_handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | |||
119 | msize = ntohs (msg->header.size); | 131 | msize = ntohs (msg->header.size); |
120 | name = msg->data; | 132 | name = msg->data; |
121 | name_len = ntohs (msg->name_len); | 133 | name_len = ntohs (msg->name_len); |
122 | if ( (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize) | 134 | LOG_DEBUG ("Received BARRIER_STATUS msg\n"); |
123 | || ('\0' != name[name_len]) ) | 135 | if (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize) |
136 | { | ||
137 | GNUNET_break_op (0); | ||
138 | return GNUNET_SYSERR; | ||
139 | } | ||
140 | if ('\0' != name[name_len]) | ||
124 | { | 141 | { |
125 | GNUNET_break_op (0); | 142 | GNUNET_break_op (0); |
126 | return GNUNET_SYSERR; | 143 | return GNUNET_SYSERR; |
@@ -143,11 +160,17 @@ GNUNET_TESTBED_handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | |||
143 | (void) memcpy (emsg, msg->data + name_len + 1, emsg_len); | 160 | (void) memcpy (emsg, msg->data + name_len + 1, emsg_len); |
144 | } | 161 | } |
145 | if (NULL == barrier_map) | 162 | if (NULL == barrier_map) |
163 | { | ||
164 | GNUNET_break_op (0); | ||
146 | goto cleanup; | 165 | goto cleanup; |
166 | } | ||
147 | GNUNET_CRYPTO_hash (name, name_len, &key); | 167 | GNUNET_CRYPTO_hash (name, name_len, &key); |
148 | barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key); | 168 | barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key); |
149 | if (NULL == barrier) | 169 | if (NULL == barrier) |
170 | { | ||
171 | GNUNET_break_op (0); | ||
150 | goto cleanup; | 172 | goto cleanup; |
173 | } | ||
151 | GNUNET_assert (NULL != barrier->cb); | 174 | GNUNET_assert (NULL != barrier->cb); |
152 | barrier->cb (barrier->cls, name, barrier, status, emsg); | 175 | barrier->cb (barrier->cls, name, barrier, status, emsg); |
153 | if (BARRIER_STATUS_INITIALISED == status) | 176 | if (BARRIER_STATUS_INITIALISED == status) |
@@ -200,6 +223,7 @@ GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller, | |||
200 | GNUNET_break (0); | 223 | GNUNET_break (0); |
201 | return NULL; | 224 | return NULL; |
202 | } | 225 | } |
226 | LOG_DEBUG ("Initialising barrier `%s'\n", name); | ||
203 | barrier = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Barrier)); | 227 | barrier = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Barrier)); |
204 | barrier->c = controller; | 228 | barrier->c = controller; |
205 | barrier->name = GNUNET_strdup (name); | 229 | barrier->name = GNUNET_strdup (name); |
@@ -340,6 +364,8 @@ receive_handler (void *cls, const struct GNUNET_MessageHeader *message) | |||
340 | case BARRIER_STATUS_CROSSED: | 364 | case BARRIER_STATUS_CROSSED: |
341 | h->cb (h->cls, h->name, GNUNET_OK); | 365 | h->cb (h->cls, h->name, GNUNET_OK); |
342 | goto destroy; | 366 | goto destroy; |
367 | default: | ||
368 | GNUNET_break_op (0); | ||
343 | } | 369 | } |
344 | 370 | ||
345 | fail: | 371 | fail: |
@@ -410,10 +436,15 @@ GNUNET_TESTBED_barrier_wait (const char *name, | |||
410 | GNUNET_assert (NULL != name); | 436 | GNUNET_assert (NULL != name); |
411 | cfg_filename = getenv (ENV_TESTBED_CONFIG); | 437 | cfg_filename = getenv (ENV_TESTBED_CONFIG); |
412 | if (NULL == cfg_filename) | 438 | if (NULL == cfg_filename) |
439 | { | ||
440 | LOG (GNUNET_ERROR_TYPE_ERROR, "Are you running under testbed?\n"); | ||
413 | return NULL; | 441 | return NULL; |
442 | } | ||
414 | cfg = GNUNET_CONFIGURATION_create (); | 443 | cfg = GNUNET_CONFIGURATION_create (); |
415 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_filename)); | 444 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_filename)) |
416 | { | 445 | { |
446 | LOG (GNUNET_ERROR_TYPE_ERROR, "Unable to load configuration from file `%s'\n", | ||
447 | cfg_filename); | ||
417 | GNUNET_CONFIGURATION_destroy (cfg); | 448 | GNUNET_CONFIGURATION_destroy (cfg); |
418 | return NULL; | 449 | return NULL; |
419 | } | 450 | } |
@@ -425,6 +456,7 @@ GNUNET_TESTBED_barrier_wait (const char *name, | |||
425 | h->cls = cls; | 456 | h->cls = cls; |
426 | if (NULL == h->conn) | 457 | if (NULL == h->conn) |
427 | { | 458 | { |
459 | LOG (GNUNET_ERROR_TYPE_ERROR, "Unable to connect to local testbed-barrier service\n"); | ||
428 | destroy_handle (h); | 460 | destroy_handle (h); |
429 | return NULL; | 461 | return NULL; |
430 | } | 462 | } |
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index b00e2825c..25054bf1d 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c | |||
@@ -1006,6 +1006,7 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1006 | 1006 | ||
1007 | if (status != GNUNET_OK) | 1007 | if (status != GNUNET_OK) |
1008 | { | 1008 | { |
1009 | rc->cproc = NULL; | ||
1009 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1010 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1010 | _("Controller crash detected. Shutting down.\n")); | 1011 | _("Controller crash detected. Shutting down.\n")); |
1011 | GNUNET_SCHEDULER_shutdown (); | 1012 | GNUNET_SCHEDULER_shutdown (); |
@@ -1360,4 +1361,18 @@ error_cleanup: | |||
1360 | } | 1361 | } |
1361 | 1362 | ||
1362 | 1363 | ||
1364 | /** | ||
1365 | * Obtain handle to the master controller from a testbed run. The handle | ||
1366 | * returned should not be disconnected. | ||
1367 | * | ||
1368 | * @param h the testbed run handle | ||
1369 | * @return handle to the master controller | ||
1370 | */ | ||
1371 | struct GNUNET_TESTBED_Controller * | ||
1372 | GNUNET_TESTBED_run_get_controller_handle (struct GNUNET_TESTBED_RunHandle *h) | ||
1373 | { | ||
1374 | return h->c; | ||
1375 | } | ||
1376 | |||
1377 | |||
1363 | /* end of testbed_api_testbed.c */ | 1378 | /* end of testbed_api_testbed.c */ |