aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fs/gnunet-fs-profiler.c14
-rw-r--r--src/include/gnunet_testbed_service.h24
-rw-r--r--src/testbed/test_testbed_api_testbed_run.c11
-rw-r--r--src/testbed/testbed_api_test.c58
-rw-r--r--src/testbed/testbed_api_testbed.c30
5 files changed, 49 insertions, 88 deletions
diff --git a/src/fs/gnunet-fs-profiler.c b/src/fs/gnunet-fs-profiler.c
index 4d4d34051..7a0b7e804 100644
--- a/src/fs/gnunet-fs-profiler.c
+++ b/src/fs/gnunet-fs-profiler.c
@@ -124,14 +124,14 @@ terminate_task (void *cls,
124 124
125 125
126/** 126/**
127 * The testbed has been started, now begin the experiment. 127 * Signature of a main function for a testcase.
128 * 128 *
129 * @param cls configuration handle 129 * @param cls closure
130 * @param tc scheduler context 130 * @param num_peers number of peers in 'peers'
131 */ 131 * @param peers handle to peers run in the testbed
132 */
132static void 133static void
133master_task (void *cls, 134test_master (void *cls, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers)
134 const struct GNUNET_SCHEDULER_TaskContext *tc)
135{ 135{
136 // const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 136 // const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
137 // FIXME: enable clients to signal 'completion' before timeout; 137 // FIXME: enable clients to signal 'completion' before timeout;
@@ -163,7 +163,7 @@ run (void *cls, char *const *args, const char *cfgfile,
163 cfg, 163 cfg,
164 num_peers, 164 num_peers,
165 0, NULL, NULL, 165 0, NULL, NULL,
166 &master_task, (void *) cfg); 166 &test_master, (void *) cfg);
167} 167}
168 168
169 169
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h
index c128f29d2..ab304d4e9 100644
--- a/src/include/gnunet_testbed_service.h
+++ b/src/include/gnunet_testbed_service.h
@@ -1363,6 +1363,18 @@ GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1363 1363
1364 1364
1365/** 1365/**
1366 * Signature of a main function for a testcase.
1367 *
1368 * @param cls closure
1369 * @param num_peers number of peers in 'peers'
1370 * @param peers handle to peers run in the testbed
1371 */
1372typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1373 unsigned int num_peers,
1374 struct GNUNET_TESTBED_Peer **peers);
1375
1376
1377/**
1366 * Convenience method for running a testbed with 1378 * Convenience method for running a testbed with
1367 * a single call. Underlay and overlay topology 1379 * a single call. Underlay and overlay topology
1368 * are configured using the "UNDERLAY" and "OVERLAY" 1380 * are configured using the "UNDERLAY" and "OVERLAY"
@@ -1387,8 +1399,8 @@ GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1387 * set in the event_mask as this is the only way get access to the 1399 * set in the event_mask as this is the only way get access to the
1388 * handle of each peer 1400 * handle of each peer
1389 * @param cc_cls closure for cc 1401 * @param cc_cls closure for cc
1390 * @param master task to run once the testbed is ready 1402 * @param test_master this callback will be called once the test is ready
1391 * @param master_cls closure for 'task'. 1403 * @param test_master_cls closure for 'test_master'.
1392 */ 1404 */
1393void 1405void
1394GNUNET_TESTBED_run (const char *host_filename, 1406GNUNET_TESTBED_run (const char *host_filename,
@@ -1397,8 +1409,8 @@ GNUNET_TESTBED_run (const char *host_filename,
1397 uint64_t event_mask, 1409 uint64_t event_mask,
1398 GNUNET_TESTBED_ControllerCallback cc, 1410 GNUNET_TESTBED_ControllerCallback cc,
1399 void *cc_cls, 1411 void *cc_cls,
1400 GNUNET_SCHEDULER_Task master, 1412 GNUNET_TESTBED_TestMaster test_master,
1401 void *master_cls); 1413 void *test_master_cls);
1402 1414
1403 1415
1404/** 1416/**
@@ -1442,8 +1454,8 @@ typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1442 * set in the event_mask as this is the only way get access to the 1454 * set in the event_mask as this is the only way get access to the
1443 * handle of each peer 1455 * handle of each peer
1444 * @param cc_cls closure for cc 1456 * @param cc_cls closure for cc
1445 * @param test_master task to run once the test is ready 1457 * @param test_master this callback will be called once the test is ready
1446 * @param test_master_cls closure for 'task'. 1458 * @param test_master_cls closure for 'test_master'.
1447 * @param GNUNET_SYSERR on error, GNUNET_OK on success 1459 * @param GNUNET_SYSERR on error, GNUNET_OK on success
1448 */ 1460 */
1449int 1461int
diff --git a/src/testbed/test_testbed_api_testbed_run.c b/src/testbed/test_testbed_api_testbed_run.c
index 349dc4923..d41e33772 100644
--- a/src/testbed/test_testbed_api_testbed_run.c
+++ b/src/testbed/test_testbed_api_testbed_run.c
@@ -90,13 +90,14 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
90 90
91 91
92/** 92/**
93 * Task to be executed when peers are ready 93 * Signature of a main function for a testcase.
94 * 94 *
95 * @param cls NULL 95 * @param cls closure
96 * @param tc the task context 96 * @param num_peers number of peers in 'peers'
97 * @param peers handle to peers run in the testbed
97 */ 98 */
98static void 99static void
99master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 100test_master (void *cls, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers_)
100{ 101{
101 result = GNUNET_OK; 102 result = GNUNET_OK;
102 GNUNET_assert (NULL != peers[0]); 103 GNUNET_assert (NULL != peers[0]);
@@ -153,7 +154,7 @@ run (void *cls, char *const *args, const char *cfgfile,
153 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); 154 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
154 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); 155 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
155 GNUNET_TESTBED_run (NULL, config, NUM_PEERS, event_mask, &controller_event_cb, 156 GNUNET_TESTBED_run (NULL, config, NUM_PEERS, event_mask, &controller_event_cb,
156 NULL, &master_task, NULL); 157 NULL, &test_master, NULL);
157 abort_task = 158 abort_task =
158 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 159 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
159 (GNUNET_TIME_UNIT_SECONDS, 300), &do_abort, 160 (GNUNET_TIME_UNIT_SECONDS, 300), &do_abort,
diff --git a/src/testbed/testbed_api_test.c b/src/testbed/testbed_api_test.c
index 0fa55fa36..9ac8cf4ea 100644
--- a/src/testbed/testbed_api_test.c
+++ b/src/testbed/testbed_api_test.c
@@ -62,59 +62,10 @@ struct TestRunContext
62 * Number of peers to start 62 * Number of peers to start
63 */ 63 */
64 unsigned int num_peers; 64 unsigned int num_peers;
65
66 /**
67 * counter for loading peers
68 */
69 unsigned int peer_cnt;
70
71 /**
72 * Followed by peers list
73 */
74 struct GNUNET_TESTBED_Peer *peers[0];
75}; 65};
76 66
77 67
78/** 68/**
79 * Controller event callback
80 *
81 * @param cls NULL
82 * @param event the controller event
83 */
84static void
85controller_event_cb (void *cls,
86 const struct GNUNET_TESTBED_EventInformation *event)
87{
88 struct TestRunContext *rc = cls;
89
90 if ((NULL != rc->cc) && (0 != (rc->event_mask & (1LL << event->type))))
91 rc->cc (rc->cc_cls, event);
92 if (rc->peer_cnt == rc->num_peers)
93 return;
94 GNUNET_assert (GNUNET_TESTBED_ET_PEER_START == event->type);
95 GNUNET_assert (NULL == rc->peers[rc->peer_cnt]);
96 GNUNET_assert (NULL != event->details.peer_start.peer);
97 rc->peers[rc->peer_cnt++] = event->details.peer_start.peer;
98}
99
100
101/**
102 * Task to be executed when peers are ready
103 *
104 * @param cls NULL
105 * @param tc the task context
106 */
107static void
108master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
109{
110 struct TestRunContext *rc = cls;
111
112 GNUNET_assert (rc->peer_cnt == rc->num_peers);
113 rc->test_master (rc->test_master_cls, rc->num_peers, rc->peers);
114}
115
116
117/**
118 * Main run function. 69 * Main run function.
119 * 70 *
120 * @param cls NULL 71 * @param cls NULL
@@ -127,12 +78,9 @@ run (void *cls, char *const *args, const char *cfgfile,
127 const struct GNUNET_CONFIGURATION_Handle *config) 78 const struct GNUNET_CONFIGURATION_Handle *config)
128{ 79{
129 struct TestRunContext *rc = cls; 80 struct TestRunContext *rc = cls;
130 uint64_t event_mask; 81
131 82 GNUNET_TESTBED_run (NULL, config, rc->num_peers, rc->event_mask,
132 event_mask = rc->event_mask; 83 rc->cc, rc->cc_cls, rc->test_master, rc->test_master_cls);
133 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
134 GNUNET_TESTBED_run (NULL, config, rc->num_peers, event_mask,
135 &controller_event_cb, rc, &master_task, rc);
136} 84}
137 85
138 86
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c
index 3617f9a3d..a6beb6aff 100644
--- a/src/testbed/testbed_api_testbed.c
+++ b/src/testbed/testbed_api_testbed.c
@@ -163,14 +163,14 @@ struct RunContext
163 void *cc_cls; 163 void *cc_cls;
164 164
165 /** 165 /**
166 * Master task to call when testbed initialization is done 166 * TestMaster callback to call when testbed initialization is done
167 */ 167 */
168 GNUNET_SCHEDULER_Task master; 168 GNUNET_TESTBED_TestMaster test_master;
169 169
170 /** 170 /**
171 * The closure for the master task 171 * The closure for the TestMaster callback
172 */ 172 */
173 void *master_cls; 173 void *test_master_cls;
174 174
175 /** 175 /**
176 * The head element of DLL operations 176 * The head element of DLL operations
@@ -493,9 +493,8 @@ call_master (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
493 GNUNET_TESTBED_operation_done (rc->topology_operation); 493 GNUNET_TESTBED_operation_done (rc->topology_operation);
494 rc->topology_operation = NULL; 494 rc->topology_operation = NULL;
495 } 495 }
496 if (NULL != rc->master) 496 if (NULL != rc->test_master)
497 GNUNET_SCHEDULER_add_continuation (rc->master, rc->master_cls, 497 rc->test_master (rc->test_master_cls, rc->num_peers, rc->peers);
498 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
499} 498}
500 499
501 500
@@ -645,7 +644,7 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
645 } 644 }
646 645
647call_cc: 646call_cc:
648 if ((0 != (rc->event_mask && (1LL << event->type))) && (NULL != rc->cc)) 647 if ((0 != (rc->event_mask & (1LL << event->type))) && (NULL != rc->cc))
649 rc->cc (rc->cc_cls, event); 648 rc->cc (rc->cc_cls, event);
650 if (GNUNET_TESTBED_ET_PEER_START != event->type) 649 if (GNUNET_TESTBED_ET_PEER_START != event->type)
651 return; 650 return;
@@ -809,6 +808,7 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
809 event_mask = rc->event_mask; 808 event_mask = rc->event_mask;
810 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); 809 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
811 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 810 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
811 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
812 if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE) 812 if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE)
813 event_mask |= GNUNET_TESTBED_ET_CONNECT; 813 event_mask |= GNUNET_TESTBED_ET_CONNECT;
814 rc->c = 814 rc->c =
@@ -909,15 +909,16 @@ host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, int status
909 * set in the event_mask as this is the only way get access to the 909 * set in the event_mask as this is the only way get access to the
910 * handle of each peer 910 * handle of each peer
911 * @param cc_cls closure for cc 911 * @param cc_cls closure for cc
912 * @param master task to run once the testbed is ready 912 * @param test_master this callback will be called once the test is ready
913 * @param master_cls 913 * @param test_master_cls closure for 'test_master'.
914 */ 914 */
915void 915void
916GNUNET_TESTBED_run (const char *host_filename, 916GNUNET_TESTBED_run (const char *host_filename,
917 const struct GNUNET_CONFIGURATION_Handle *cfg, 917 const struct GNUNET_CONFIGURATION_Handle *cfg,
918 unsigned int num_peers, uint64_t event_mask, 918 unsigned int num_peers, uint64_t event_mask,
919 GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, 919 GNUNET_TESTBED_ControllerCallback cc, void *cc_cls,
920 GNUNET_SCHEDULER_Task master, void *master_cls) 920 GNUNET_TESTBED_TestMaster test_master,
921 void *test_master_cls)
921{ 922{
922 struct RunContext *rc; 923 struct RunContext *rc;
923 char *topology; 924 char *topology;
@@ -945,11 +946,10 @@ GNUNET_TESTBED_run (const char *host_filename,
945 rc->cfg = GNUNET_CONFIGURATION_dup (cfg); 946 rc->cfg = GNUNET_CONFIGURATION_dup (cfg);
946 rc->num_peers = num_peers; 947 rc->num_peers = num_peers;
947 rc->event_mask = event_mask; 948 rc->event_mask = event_mask;
948 rc->event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
949 rc->cc = cc; 949 rc->cc = cc;
950 rc->cc_cls = cc_cls; 950 rc->cc_cls = cc_cls;
951 rc->master = master; 951 rc->test_master = test_master;
952 rc->master_cls = master_cls; 952 rc->test_master_cls = test_master_cls;
953 rc->state = RC_INIT; 953 rc->state = RC_INIT;
954 rc->topology = GNUNET_TESTBED_TOPOLOGY_NONE; 954 rc->topology = GNUNET_TESTBED_TOPOLOGY_NONE;
955 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (rc->cfg, "testbed", 955 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (rc->cfg, "testbed",