summaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/test_testbed_api_test.c')
-rw-r--r--src/testbed/test_testbed_api_test.c146
1 files changed, 73 insertions, 73 deletions
diff --git a/src/testbed/test_testbed_api_test.c b/src/testbed/test_testbed_api_test.c
index 3f8f536e7..f0d8d1d25 100644
--- a/src/testbed/test_testbed_api_test.c
+++ b/src/testbed/test_testbed_api_test.c
@@ -33,7 +33,7 @@
33 * Generic logging shortcut 33 * Generic logging shortcut
34 */ 34 */
35#define LOG(kind, ...) \ 35#define LOG(kind, ...) \
36 GNUNET_log(kind, __VA_ARGS__) 36 GNUNET_log (kind, __VA_ARGS__)
37 37
38/** 38/**
39 * Number of peers we want to start 39 * Number of peers we want to start
@@ -53,12 +53,12 @@ static struct GNUNET_TESTBED_Operation *op;
53/** 53/**
54 * Abort task identifier 54 * Abort task identifier
55 */ 55 */
56static struct GNUNET_SCHEDULER_Task * abort_task; 56static struct GNUNET_SCHEDULER_Task *abort_task;
57 57
58/** 58/**
59 * shutdown task identifier 59 * shutdown task identifier
60 */ 60 */
61static struct GNUNET_SCHEDULER_Task * shutdown_task; 61static struct GNUNET_SCHEDULER_Task *shutdown_task;
62 62
63/** 63/**
64 * Testing result 64 * Testing result
@@ -72,30 +72,30 @@ static int result;
72 * @param cls NULL 72 * @param cls NULL
73 */ 73 */
74static void 74static void
75do_shutdown(void *cls) 75do_shutdown (void *cls)
76{ 76{
77 shutdown_task = NULL; 77 shutdown_task = NULL;
78 if (NULL != abort_task) 78 if (NULL != abort_task)
79 GNUNET_SCHEDULER_cancel(abort_task); 79 GNUNET_SCHEDULER_cancel (abort_task);
80 if (NULL != op) 80 if (NULL != op)
81 GNUNET_TESTBED_operation_done(op); 81 GNUNET_TESTBED_operation_done (op);
82 GNUNET_SCHEDULER_shutdown(); 82 GNUNET_SCHEDULER_shutdown ();
83} 83}
84 84
85/** 85/**
86 * shortcut to exit during failure 86 * shortcut to exit during failure
87 */ 87 */
88#define FAIL_TEST(cond) do { \ 88#define FAIL_TEST(cond) do { \
89 if (!(cond)) { \ 89 if (! (cond)) { \
90 GNUNET_break(0); \ 90 GNUNET_break (0); \
91 if (NULL != abort_task) \ 91 if (NULL != abort_task) \
92 GNUNET_SCHEDULER_cancel (abort_task); \ 92 GNUNET_SCHEDULER_cancel (abort_task); \
93 abort_task = NULL; \ 93 abort_task = NULL; \
94 if (NULL == shutdown_task) \ 94 if (NULL == shutdown_task) \
95 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); \ 95 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); \
96 return; \ 96 return; \
97 } \ 97 } \
98 } while (0) 98} while (0)
99 99
100 100
101/** 101/**
@@ -104,13 +104,13 @@ do_shutdown(void *cls)
104 * @param cls NULL 104 * @param cls NULL
105 */ 105 */
106static void 106static void
107do_abort(void *cls) 107do_abort (void *cls)
108{ 108{
109 LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); 109 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
110 abort_task = NULL; 110 abort_task = NULL;
111 if (NULL != shutdown_task) 111 if (NULL != shutdown_task)
112 GNUNET_SCHEDULER_cancel(shutdown_task); 112 GNUNET_SCHEDULER_cancel (shutdown_task);
113 do_shutdown(cls); 113 do_shutdown (cls);
114} 114}
115 115
116 116
@@ -124,19 +124,19 @@ do_abort(void *cls)
124 * operation is successfull 124 * operation is successfull
125 */ 125 */
126static void 126static void
127peerinfo_cb(void *cb_cls, struct GNUNET_TESTBED_Operation *op_, 127peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
128 const struct GNUNET_TESTBED_PeerInformation *pinfo, 128 const struct GNUNET_TESTBED_PeerInformation *pinfo,
129 const char *emsg) 129 const char *emsg)
130{ 130{
131 FAIL_TEST(op == op_); 131 FAIL_TEST (op == op_);
132 FAIL_TEST(NULL == cb_cls); 132 FAIL_TEST (NULL == cb_cls);
133 FAIL_TEST(NULL == emsg); 133 FAIL_TEST (NULL == emsg);
134 FAIL_TEST(GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit); 134 FAIL_TEST (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit);
135 FAIL_TEST(NULL != pinfo->result.id); 135 FAIL_TEST (NULL != pinfo->result.id);
136 GNUNET_TESTBED_operation_done(op); 136 GNUNET_TESTBED_operation_done (op);
137 op = NULL; 137 op = NULL;
138 result = GNUNET_OK; 138 result = GNUNET_OK;
139 shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 139 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
140} 140}
141 141
142 142
@@ -149,19 +149,19 @@ peerinfo_cb(void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
149 * operation has executed successfully. 149 * operation has executed successfully.
150 */ 150 */
151static void 151static void
152op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) 152op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg)
153{ 153{
154 FAIL_TEST(NULL == cls); 154 FAIL_TEST (NULL == cls);
155 FAIL_TEST(op == op_); 155 FAIL_TEST (op == op_);
156 if (NULL != emsg) 156 if (NULL != emsg)
157 { 157 {
158 LOG(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); 158 LOG (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
159 FAIL_TEST(0); 159 FAIL_TEST (0);
160 } 160 }
161 GNUNET_TESTBED_operation_done(op); 161 GNUNET_TESTBED_operation_done (op);
162 op = GNUNET_TESTBED_peer_get_information(peers[0], 162 op = GNUNET_TESTBED_peer_get_information (peers[0],
163 GNUNET_TESTBED_PIT_IDENTITY, 163 GNUNET_TESTBED_PIT_IDENTITY,
164 &peerinfo_cb, NULL); 164 &peerinfo_cb, NULL);
165} 165}
166 166
167 167
@@ -172,19 +172,19 @@ op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg)
172 * @param event the controller event 172 * @param event the controller event
173 */ 173 */
174static void 174static void
175controller_event_cb(void *cls, 175controller_event_cb (void *cls,
176 const struct GNUNET_TESTBED_EventInformation *event) 176 const struct GNUNET_TESTBED_EventInformation *event)
177{ 177{
178 switch (event->type) 178 switch (event->type)
179 { 179 {
180 case GNUNET_TESTBED_ET_CONNECT: 180 case GNUNET_TESTBED_ET_CONNECT:
181 FAIL_TEST(event->details.peer_connect.peer1 == peers[0]); 181 FAIL_TEST (event->details.peer_connect.peer1 == peers[0]);
182 FAIL_TEST(event->details.peer_connect.peer2 == peers[1]); 182 FAIL_TEST (event->details.peer_connect.peer2 == peers[1]);
183 break; 183 break;
184 184
185 default: 185 default:
186 FAIL_TEST(0); 186 FAIL_TEST (0);
187 } 187 }
188} 188}
189 189
190 190
@@ -201,27 +201,27 @@ controller_event_cb(void *cls,
201 * failed 201 * failed
202 */ 202 */
203static void 203static void
204test_master(void *cls, 204test_master (void *cls,
205 struct GNUNET_TESTBED_RunHandle *h, 205 struct GNUNET_TESTBED_RunHandle *h,
206 unsigned int num_peers, 206 unsigned int num_peers,
207 struct GNUNET_TESTBED_Peer **peers_, 207 struct GNUNET_TESTBED_Peer **peers_,
208 unsigned int links_succeeded, 208 unsigned int links_succeeded,
209 unsigned int links_failed) 209 unsigned int links_failed)
210{ 210{
211 unsigned int peer; 211 unsigned int peer;
212 212
213 FAIL_TEST(NULL == cls); 213 FAIL_TEST (NULL == cls);
214 FAIL_TEST(NUM_PEERS == num_peers); 214 FAIL_TEST (NUM_PEERS == num_peers);
215 FAIL_TEST(NULL != peers_); 215 FAIL_TEST (NULL != peers_);
216 for (peer = 0; peer < num_peers; peer++) 216 for (peer = 0; peer < num_peers; peer++)
217 FAIL_TEST(NULL != peers_[peer]); 217 FAIL_TEST (NULL != peers_[peer]);
218 peers = peers_; 218 peers = peers_;
219 op = GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peers[0], 219 op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0],
220 peers[1]); 220 peers[1]);
221 abort_task = 221 abort_task =
222 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 222 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
223 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, 223 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
224 NULL); 224 NULL);
225} 225}
226 226
227 227
@@ -229,7 +229,7 @@ test_master(void *cls,
229 * Main function 229 * Main function
230 */ 230 */
231int 231int
232main(int argc, char **argv) 232main (int argc, char **argv)
233{ 233{
234 uint64_t event_mask; 234 uint64_t event_mask;
235 235
@@ -237,10 +237,10 @@ main(int argc, char **argv)
237 event_mask = 0; 237 event_mask = 0;
238 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); 238 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
239 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 239 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
240 (void)GNUNET_TESTBED_test_run("test_testbed_api_test", 240 (void) GNUNET_TESTBED_test_run ("test_testbed_api_test",
241 "test_testbed_api.conf", NUM_PEERS, 241 "test_testbed_api.conf", NUM_PEERS,
242 event_mask, &controller_event_cb, NULL, 242 event_mask, &controller_event_cb, NULL,
243 &test_master, NULL); 243 &test_master, NULL);
244 if (GNUNET_OK != result) 244 if (GNUNET_OK != result)
245 return 1; 245 return 1;
246 return 0; 246 return 0;