diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-03 10:45:57 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-03 10:45:57 +0000 |
commit | 9ec9052c1cee478ab24f66a466774d6f63ace858 (patch) | |
tree | 78b7d2c1348c6e5658e994d03678ed3dc0b6f54d /src/testbed | |
parent | 2234e06e79ad0eb9106a6b7b75e79a040fe841b6 (diff) | |
download | gnunet-9ec9052c1cee478ab24f66a466774d6f63ace858.tar.gz gnunet-9ec9052c1cee478ab24f66a466774d6f63ace858.zip |
controller callback added in GNUNET_TESTBED_test_run
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/test_testbed_api_test.c | 65 | ||||
-rw-r--r-- | src/testbed/testbed_api_test.c | 41 | ||||
-rw-r--r-- | src/testbed/testbed_api_testbed.c | 5 |
3 files changed, 100 insertions, 11 deletions
diff --git a/src/testbed/test_testbed_api_test.c b/src/testbed/test_testbed_api_test.c index 83d18ce0c..43a5628ad 100644 --- a/src/testbed/test_testbed_api_test.c +++ b/src/testbed/test_testbed_api_test.c | |||
@@ -34,6 +34,16 @@ | |||
34 | #define NUM_PEERS 25 | 34 | #define NUM_PEERS 25 |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Array of peers | ||
38 | */ | ||
39 | static struct GNUNET_TESTBED_Peer **peers; | ||
40 | |||
41 | /** | ||
42 | * Operation handle | ||
43 | */ | ||
44 | static struct GNUNET_TESTBED_Operation *op; | ||
45 | |||
46 | /** | ||
37 | * Testing result | 47 | * Testing result |
38 | */ | 48 | */ |
39 | static int result; | 49 | static int result; |
@@ -53,6 +63,42 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
53 | 63 | ||
54 | 64 | ||
55 | /** | 65 | /** |
66 | * Controller event callback | ||
67 | * | ||
68 | * @param cls NULL | ||
69 | * @param event the controller event | ||
70 | */ | ||
71 | static void | ||
72 | controller_event_cb (void *cls, | ||
73 | const struct GNUNET_TESTBED_EventInformation *event) | ||
74 | { | ||
75 | switch (event->type) | ||
76 | { | ||
77 | case GNUNET_TESTBED_ET_CONNECT: | ||
78 | GNUNET_assert (event->details.peer_connect.peer1 == peers[0]); | ||
79 | GNUNET_assert (event->details.peer_connect.peer2 == peers[1]); | ||
80 | GNUNET_TESTBED_operation_done (op); | ||
81 | op = GNUNET_TESTBED_peer_get_information (peers[0], | ||
82 | GNUNET_TESTBED_PIT_IDENTITY); | ||
83 | break; | ||
84 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
85 | GNUNET_assert (event->details.operation_finished.operation == op); | ||
86 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | ||
87 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | ||
88 | GNUNET_assert (GNUNET_TESTBED_PIT_IDENTITY == | ||
89 | event->details.operation_finished.pit); | ||
90 | GNUNET_assert (NULL != event->details.operation_finished.op_result.pid); | ||
91 | GNUNET_TESTBED_operation_done (op); | ||
92 | result = GNUNET_OK; | ||
93 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
94 | break; | ||
95 | default: | ||
96 | GNUNET_assert (0); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | |||
101 | /** | ||
56 | * Signature of a main function for a testcase. | 102 | * Signature of a main function for a testcase. |
57 | * | 103 | * |
58 | * @param cls closure | 104 | * @param cls closure |
@@ -61,18 +107,17 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
61 | */ | 107 | */ |
62 | static void | 108 | static void |
63 | test_master (void *cls, unsigned int num_peers, | 109 | test_master (void *cls, unsigned int num_peers, |
64 | struct GNUNET_TESTBED_Peer **peers) | 110 | struct GNUNET_TESTBED_Peer **peers_) |
65 | { | 111 | { |
66 | unsigned int peer; | 112 | unsigned int peer; |
67 | 113 | ||
68 | GNUNET_assert (NULL == cls); | 114 | GNUNET_assert (NULL == cls); |
69 | GNUNET_assert (NUM_PEERS == num_peers); | 115 | GNUNET_assert (NUM_PEERS == num_peers); |
70 | GNUNET_assert (NULL != peers); | 116 | GNUNET_assert (NULL != peers_); |
71 | for (peer = 0; peer < num_peers; peer++) | 117 | for (peer = 0; peer < num_peers; peer++) |
72 | GNUNET_assert (NULL != peers[peer]); | 118 | GNUNET_assert (NULL != peers_[peer]); |
73 | result = GNUNET_OK; | 119 | peers = peers_; |
74 | /* Artificial delay for shutdown */ | 120 | op = GNUNET_TESTBED_overlay_connect (NULL, peers[0], peers[1]); |
75 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, NULL); | ||
76 | } | 121 | } |
77 | 122 | ||
78 | 123 | ||
@@ -82,9 +127,15 @@ test_master (void *cls, unsigned int num_peers, | |||
82 | int | 127 | int |
83 | main (int argc, char **argv) | 128 | main (int argc, char **argv) |
84 | { | 129 | { |
130 | uint64_t event_mask; | ||
131 | |||
85 | result = GNUNET_SYSERR; | 132 | result = GNUNET_SYSERR; |
133 | event_mask = 0; | ||
134 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | ||
135 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
86 | GNUNET_TESTBED_test_run ("test_testbed_api_test", "test_testbed_api.conf", | 136 | GNUNET_TESTBED_test_run ("test_testbed_api_test", "test_testbed_api.conf", |
87 | NUM_PEERS, &test_master, NULL); | 137 | NUM_PEERS, event_mask, &controller_event_cb, NULL, |
138 | &test_master, NULL); | ||
88 | if (GNUNET_OK != result) | 139 | if (GNUNET_OK != result) |
89 | return 1; | 140 | return 1; |
90 | return 0; | 141 | return 0; |
diff --git a/src/testbed/testbed_api_test.c b/src/testbed/testbed_api_test.c index c040e1c79..0a15b3db9 100644 --- a/src/testbed/testbed_api_test.c +++ b/src/testbed/testbed_api_test.c | |||
@@ -44,6 +44,21 @@ struct TestRunContext | |||
44 | void *test_master_cls; | 44 | void *test_master_cls; |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * The controller event callback | ||
48 | */ | ||
49 | GNUNET_TESTBED_ControllerCallback cc; | ||
50 | |||
51 | /** | ||
52 | * Closure for the above callback | ||
53 | */ | ||
54 | void *cc_cls; | ||
55 | |||
56 | /** | ||
57 | * event mask for the controller callback | ||
58 | */ | ||
59 | uint64_t event_mask; | ||
60 | |||
61 | /** | ||
47 | * Number of peers to start | 62 | * Number of peers to start |
48 | */ | 63 | */ |
49 | unsigned int num_peers; | 64 | unsigned int num_peers; |
@@ -72,6 +87,8 @@ controller_event_cb (void *cls, | |||
72 | { | 87 | { |
73 | struct TestRunContext *rc = cls; | 88 | struct TestRunContext *rc = cls; |
74 | 89 | ||
90 | if ((NULL != rc->cc) && (0 != (rc->event_mask & (1LL << event->type)))) | ||
91 | rc->cc (rc->cc_cls, event); | ||
75 | if (rc->peer_cnt == rc->num_peers) | 92 | if (rc->peer_cnt == rc->num_peers) |
76 | return; | 93 | return; |
77 | GNUNET_assert (GNUNET_TESTBED_ET_PEER_START == event->type); | 94 | GNUNET_assert (GNUNET_TESTBED_ET_PEER_START == event->type); |
@@ -110,9 +127,12 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
110 | const struct GNUNET_CONFIGURATION_Handle *config) | 127 | const struct GNUNET_CONFIGURATION_Handle *config) |
111 | { | 128 | { |
112 | struct TestRunContext *rc = cls; | 129 | struct TestRunContext *rc = cls; |
113 | 130 | uint64_t event_mask; | |
114 | GNUNET_TESTBED_run (NULL, config, rc->num_peers, 0, &controller_event_cb, rc, | 131 | |
115 | &master_task, rc); | 132 | event_mask = rc->event_mask; |
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); | ||
116 | } | 136 | } |
117 | 137 | ||
118 | 138 | ||
@@ -136,12 +156,24 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
136 | * @param cfg_filename configuration filename to use | 156 | * @param cfg_filename configuration filename to use |
137 | * (for testbed, controller and peers) | 157 | * (for testbed, controller and peers) |
138 | * @param num_peers number of peers to start | 158 | * @param num_peers number of peers to start |
159 | * @param event_mask bit mask with set of events to call 'cc' for; | ||
160 | * or-ed values of "1LL" shifted by the | ||
161 | * respective 'enum GNUNET_TESTBED_EventType' | ||
162 | * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...") | ||
163 | * @param cc controller callback to invoke on events; This callback is called | ||
164 | * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't | ||
165 | * set in the event_mask as this is the only way get access to the | ||
166 | * handle of each peer | ||
167 | * @param cc_cls closure for cc | ||
139 | * @param test_master task to run once the test is ready | 168 | * @param test_master task to run once the test is ready |
140 | * @param test_master_cls closure for 'task'. | 169 | * @param test_master_cls closure for 'task'. |
141 | */ | 170 | */ |
142 | void | 171 | void |
143 | GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename, | 172 | GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename, |
144 | unsigned int num_peers, | 173 | unsigned int num_peers, |
174 | uint64_t event_mask, | ||
175 | GNUNET_TESTBED_ControllerCallback cc, | ||
176 | void *cc_cls, | ||
145 | GNUNET_TESTBED_TestMaster test_master, | 177 | GNUNET_TESTBED_TestMaster test_master, |
146 | void *test_master_cls) | 178 | void *test_master_cls) |
147 | { | 179 | { |
@@ -165,6 +197,9 @@ GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename, | |||
165 | rc->test_master = test_master; | 197 | rc->test_master = test_master; |
166 | rc->test_master_cls = test_master_cls; | 198 | rc->test_master_cls = test_master_cls; |
167 | rc->num_peers = num_peers; | 199 | rc->num_peers = num_peers; |
200 | rc->event_mask = event_mask; | ||
201 | rc->cc = cc; | ||
202 | rc->cc_cls = cc_cls; | ||
168 | (void) GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 203 | (void) GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, |
169 | testname, "nohelp", options, &run, rc); | 204 | testname, "nohelp", options, &run, rc); |
170 | GNUNET_free (rc); | 205 | GNUNET_free (rc); |
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index 6e6145aaa..76aec1d97 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c | |||
@@ -470,7 +470,10 @@ shutdown_run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
470 | * or-ed values of "1LL" shifted by the | 470 | * or-ed values of "1LL" shifted by the |
471 | * respective 'enum GNUNET_TESTBED_EventType' | 471 | * respective 'enum GNUNET_TESTBED_EventType' |
472 | * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...") | 472 | * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...") |
473 | * @param cc controller callback to invoke on events | 473 | * @param cc controller callback to invoke on events; This callback is called |
474 | * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't | ||
475 | * set in the event_mask as this is the only way get access to the | ||
476 | * handle of each peer | ||
474 | * @param cc_cls closure for cc | 477 | * @param cc_cls closure for cc |
475 | * @param master task to run once the testbed is ready | 478 | * @param master task to run once the testbed is ready |
476 | */ | 479 | */ |