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/testbed_api_test.c | |
parent | 2234e06e79ad0eb9106a6b7b75e79a040fe841b6 (diff) | |
download | gnunet-9ec9052c1cee478ab24f66a466774d6f63ace858.tar.gz gnunet-9ec9052c1cee478ab24f66a466774d6f63ace858.zip |
controller callback added in GNUNET_TESTBED_test_run
Diffstat (limited to 'src/testbed/testbed_api_test.c')
-rw-r--r-- | src/testbed/testbed_api_test.c | 41 |
1 files changed, 38 insertions, 3 deletions
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); |