aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/test_testbed_api.c')
-rw-r--r--src/testbed/test_testbed_api.c354
1 files changed, 178 insertions, 176 deletions
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c
index 37dc362ea..ad71aa35e 100644
--- a/src/testbed/test_testbed_api.c
+++ b/src/testbed/test_testbed_api.c
@@ -34,13 +34,13 @@
34 * Generic logging shortcut 34 * Generic logging shortcut
35 */ 35 */
36#define LOG(kind, ...) \ 36#define LOG(kind, ...) \
37 GNUNET_log(kind, __VA_ARGS__) 37 GNUNET_log (kind, __VA_ARGS__)
38 38
39/** 39/**
40 * Relative time seconds shorthand 40 * Relative time seconds shorthand
41 */ 41 */
42#define TIME_REL_SECS(sec) \ 42#define TIME_REL_SECS(sec) \
43 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) 43 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
44 44
45/** 45/**
46 * Our localhost 46 * Our localhost
@@ -101,7 +101,8 @@ static int result;
101/** 101/**
102 * Enumeration of sub testcases 102 * Enumeration of sub testcases
103 */ 103 */
104enum Test { 104enum Test
105{
105 /** 106 /**
106 * Test cases which are not covered by the below ones 107 * Test cases which are not covered by the below ones
107 */ 108 */
@@ -135,23 +136,23 @@ static enum Test sub_test;
135 * @param tc the task context 136 * @param tc the task context
136 */ 137 */
137static void 138static void
138do_shutdown(void *cls) 139do_shutdown (void *cls)
139{ 140{
140 LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n"); 141 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n");
141 if (NULL != abort_task) 142 if (NULL != abort_task)
142 GNUNET_SCHEDULER_cancel(abort_task); 143 GNUNET_SCHEDULER_cancel (abort_task);
143 if (NULL != reg_handle) 144 if (NULL != reg_handle)
144 GNUNET_TESTBED_cancel_registration(reg_handle); 145 GNUNET_TESTBED_cancel_registration (reg_handle);
145 if (NULL != controller) 146 if (NULL != controller)
146 GNUNET_TESTBED_controller_disconnect(controller); 147 GNUNET_TESTBED_controller_disconnect (controller);
147 if (NULL != cfg) 148 if (NULL != cfg)
148 GNUNET_CONFIGURATION_destroy(cfg); 149 GNUNET_CONFIGURATION_destroy (cfg);
149 if (NULL != cp) 150 if (NULL != cp)
150 GNUNET_TESTBED_controller_stop(cp); 151 GNUNET_TESTBED_controller_stop (cp);
151 if (NULL != neighbour) 152 if (NULL != neighbour)
152 GNUNET_TESTBED_host_destroy(neighbour); 153 GNUNET_TESTBED_host_destroy (neighbour);
153 if (NULL != host) 154 if (NULL != host)
154 GNUNET_TESTBED_host_destroy(host); 155 GNUNET_TESTBED_host_destroy (host);
155} 156}
156 157
157 158
@@ -159,15 +160,15 @@ do_shutdown(void *cls)
159 * shortcut to exit during failure 160 * shortcut to exit during failure
160 */ 161 */
161#define FAIL_TEST(cond, ret) do { \ 162#define FAIL_TEST(cond, ret) do { \
162 if (!(cond)) { \ 163 if (! (cond)) { \
163 GNUNET_break(0); \ 164 GNUNET_break (0); \
164 if (NULL != abort_task) \ 165 if (NULL != abort_task) \
165 GNUNET_SCHEDULER_cancel (abort_task); \ 166 GNUNET_SCHEDULER_cancel (abort_task); \
166 abort_task = NULL; \ 167 abort_task = NULL; \
167 GNUNET_SCHEDULER_add_now(do_shutdown, NULL); \ 168 GNUNET_SCHEDULER_add_now (do_shutdown, NULL); \
168 ret; \ 169 ret; \
169 } \ 170 } \
170 } while (0) 171} while (0)
171 172
172 173
173/** 174/**
@@ -177,11 +178,11 @@ do_shutdown(void *cls)
177 * @param tc the task context 178 * @param tc the task context
178 */ 179 */
179static void 180static void
180do_abort(void *cls) 181do_abort (void *cls)
181{ 182{
182 LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); 183 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
183 abort_task = NULL; 184 abort_task = NULL;
184 do_shutdown(cls); 185 do_shutdown (cls);
185} 186}
186 187
187 188
@@ -196,13 +197,13 @@ do_abort(void *cls)
196 * @return service handle to return in 'op_result', NULL on error 197 * @return service handle to return in 'op_result', NULL on error
197 */ 198 */
198static void * 199static void *
199arm_connect_adapter(void *cls, 200arm_connect_adapter (void *cls,
200 const struct GNUNET_CONFIGURATION_Handle *cfg) 201 const struct GNUNET_CONFIGURATION_Handle *cfg)
201{ 202{
202 FAIL_TEST(NULL == cls, return NULL); 203 FAIL_TEST (NULL == cls, return NULL);
203 FAIL_TEST(OTHER == sub_test, return NULL); 204 FAIL_TEST (OTHER == sub_test, return NULL);
204 sub_test = PEER_SERVICE_CONNECT; 205 sub_test = PEER_SERVICE_CONNECT;
205 arm_handle = GNUNET_ARM_connect(cfg, NULL, NULL); 206 arm_handle = GNUNET_ARM_connect (cfg, NULL, NULL);
206 return arm_handle; 207 return arm_handle;
207} 208}
208 209
@@ -215,17 +216,17 @@ arm_connect_adapter(void *cls,
215 * @param op_result service handle returned from the connect adapter 216 * @param op_result service handle returned from the connect adapter
216 */ 217 */
217static void 218static void
218arm_disconnect_adapter(void *cls, 219arm_disconnect_adapter (void *cls,
219 void *op_result) 220 void *op_result)
220{ 221{
221 FAIL_TEST(NULL != op_result, return ); 222 FAIL_TEST (NULL != op_result, return );
222 FAIL_TEST(op_result == arm_handle, return ); 223 FAIL_TEST (op_result == arm_handle, return );
223 GNUNET_ARM_disconnect(arm_handle); 224 GNUNET_ARM_disconnect (arm_handle);
224 arm_handle = NULL; 225 arm_handle = NULL;
225 FAIL_TEST(PEER_SERVICE_CONNECT == sub_test, return ); 226 FAIL_TEST (PEER_SERVICE_CONNECT == sub_test, return );
226 FAIL_TEST(NULL != operation, return ); 227 FAIL_TEST (NULL != operation, return );
227 operation = GNUNET_TESTBED_peer_stop(NULL, peer, NULL, NULL); 228 operation = GNUNET_TESTBED_peer_stop (NULL, peer, NULL, NULL);
228 FAIL_TEST(NULL != operation, return ); 229 FAIL_TEST (NULL != operation, return );
229} 230}
230 231
231 232
@@ -239,25 +240,25 @@ arm_disconnect_adapter(void *cls,
239 * operation has executed successfully. 240 * operation has executed successfully.
240 */ 241 */
241static void 242static void
242service_connect_comp_cb(void *cls, 243service_connect_comp_cb (void *cls,
243 struct GNUNET_TESTBED_Operation *op, 244 struct GNUNET_TESTBED_Operation *op,
244 void *ca_result, 245 void *ca_result,
245 const char *emsg) 246 const char *emsg)
246{ 247{
247 switch (sub_test) 248 switch (sub_test)
248 { 249 {
249 case PEER_SERVICE_CONNECT: 250 case PEER_SERVICE_CONNECT:
250 FAIL_TEST(operation == op, return ); 251 FAIL_TEST (operation == op, return );
251 FAIL_TEST(NULL == emsg, return ); 252 FAIL_TEST (NULL == emsg, return );
252 FAIL_TEST(NULL == cls, return ); 253 FAIL_TEST (NULL == cls, return );
253 FAIL_TEST(ca_result == arm_handle, return ); 254 FAIL_TEST (ca_result == arm_handle, return );
254 GNUNET_TESTBED_operation_done(operation); /* This results in call to 255 GNUNET_TESTBED_operation_done (operation); /* This results in call to
255 * disconnect adapter */ 256 * disconnect adapter */
256 break; 257 break;
257 258
258 default: 259 default:
259 FAIL_TEST(0, return ); 260 FAIL_TEST (0, return );
260 } 261 }
261} 262}
262 263
263 264
@@ -272,28 +273,28 @@ service_connect_comp_cb(void *cls,
272 * operation is successfull 273 * operation is successfull
273 */ 274 */
274static void 275static void
275peerinfo_cb(void *cb_cls, 276peerinfo_cb (void *cb_cls,
276 struct GNUNET_TESTBED_Operation *op, 277 struct GNUNET_TESTBED_Operation *op,
277 const struct GNUNET_TESTBED_PeerInformation *pinfo, 278 const struct GNUNET_TESTBED_PeerInformation *pinfo,
278 const char *emsg) 279 const char *emsg)
279{ 280{
280 switch (sub_test) 281 switch (sub_test)
281 { 282 {
282 case PEER_GETCONFIG: 283 case PEER_GETCONFIG:
283 FAIL_TEST(NULL != pinfo, return ); 284 FAIL_TEST (NULL != pinfo, return );
284 FAIL_TEST(NULL == emsg, return ); 285 FAIL_TEST (NULL == emsg, return );
285 FAIL_TEST(NULL == cb_cls, return ); 286 FAIL_TEST (NULL == cb_cls, return );
286 FAIL_TEST(operation == op, return ); 287 FAIL_TEST (operation == op, return );
287 FAIL_TEST(GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit, return ); 288 FAIL_TEST (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit, return );
288 FAIL_TEST(NULL != pinfo->result.cfg, return ); 289 FAIL_TEST (NULL != pinfo->result.cfg, return );
289 sub_test = PEER_DESTROY; 290 sub_test = PEER_DESTROY;
290 GNUNET_TESTBED_operation_done(operation); 291 GNUNET_TESTBED_operation_done (operation);
291 operation = GNUNET_TESTBED_peer_destroy(peer); 292 operation = GNUNET_TESTBED_peer_destroy (peer);
292 break; 293 break;
293 294
294 default: 295 default:
295 FAIL_TEST(0, return ); 296 FAIL_TEST (0, return );
296 } 297 }
297} 298}
298 299
299 300
@@ -305,65 +306,66 @@ peerinfo_cb(void *cb_cls,
305 * @param event information about the event 306 * @param event information about the event
306 */ 307 */
307static void 308static void
308controller_cb(void *cls, 309controller_cb (void *cls,
309 const struct GNUNET_TESTBED_EventInformation *event) 310 const struct GNUNET_TESTBED_EventInformation *event)
310{ 311{
311 switch (event->type) 312 switch (event->type)
313 {
314 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
315 switch (sub_test)
312 { 316 {
313 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 317 case PEER_DESTROY:
314 switch (sub_test) 318 FAIL_TEST (event->op == operation, return );
315 { 319 FAIL_TEST (NULL == event->op_cls, return );
316 case PEER_DESTROY: 320 FAIL_TEST (NULL == event->details.operation_finished.emsg, return );
317 FAIL_TEST(event->op == operation, return ); 321 FAIL_TEST (NULL == event->details.operation_finished.generic, return );
318 FAIL_TEST(NULL == event->op_cls, return ); 322 GNUNET_TESTBED_operation_done (operation);
319 FAIL_TEST(NULL == event->details.operation_finished.emsg, return ); 323 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
320 FAIL_TEST(NULL == event->details.operation_finished.generic, return );
321 GNUNET_TESTBED_operation_done(operation);
322 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
323 break;
324
325 case PEER_SERVICE_CONNECT:
326 FAIL_TEST(event->op == operation, return );
327 FAIL_TEST(NULL == event->op_cls, return );
328 FAIL_TEST(NULL == event->details.operation_finished.emsg, return );
329 FAIL_TEST(NULL != arm_handle, return );
330 FAIL_TEST(event->details.operation_finished.generic == arm_handle, return );
331 break;
332
333 default:
334 FAIL_TEST(0, return );
335 break;
336 }
337 break; 324 break;
338 325
339 case GNUNET_TESTBED_ET_PEER_START: 326 case PEER_SERVICE_CONNECT:
340 FAIL_TEST(event->details.peer_start.host == host, return ); 327 FAIL_TEST (event->op == operation, return );
341 FAIL_TEST(event->details.peer_start.peer == peer, return ); 328 FAIL_TEST (NULL == event->op_cls, return );
342 FAIL_TEST(OTHER == sub_test, return ); 329 FAIL_TEST (NULL == event->details.operation_finished.emsg, return );
343 GNUNET_TESTBED_operation_done(operation); 330 FAIL_TEST (NULL != arm_handle, return );
344 operation = 331 FAIL_TEST (event->details.operation_finished.generic == arm_handle,
345 GNUNET_TESTBED_service_connect(NULL, peer, "dht", 332 return );
346 &service_connect_comp_cb, NULL,
347 &arm_connect_adapter,
348 &arm_disconnect_adapter, NULL);
349 FAIL_TEST(NULL != operation, return );
350 break;
351
352 case GNUNET_TESTBED_ET_PEER_STOP:
353 FAIL_TEST(event->details.peer_stop.peer == peer, return );
354 FAIL_TEST(PEER_SERVICE_CONNECT == sub_test, return );
355 result = GNUNET_YES;
356 sub_test = PEER_GETCONFIG;
357 GNUNET_TESTBED_operation_done(operation);
358 operation =
359 GNUNET_TESTBED_peer_get_information(peer,
360 GNUNET_TESTBED_PIT_CONFIGURATION,
361 &peerinfo_cb, NULL);
362 break; 333 break;
363 334
364 default: 335 default:
365 FAIL_TEST(0, return ); /* We should never reach this state */ 336 FAIL_TEST (0, return );
337 break;
366 } 338 }
339 break;
340
341 case GNUNET_TESTBED_ET_PEER_START:
342 FAIL_TEST (event->details.peer_start.host == host, return );
343 FAIL_TEST (event->details.peer_start.peer == peer, return );
344 FAIL_TEST (OTHER == sub_test, return );
345 GNUNET_TESTBED_operation_done (operation);
346 operation =
347 GNUNET_TESTBED_service_connect (NULL, peer, "dht",
348 &service_connect_comp_cb, NULL,
349 &arm_connect_adapter,
350 &arm_disconnect_adapter, NULL);
351 FAIL_TEST (NULL != operation, return );
352 break;
353
354 case GNUNET_TESTBED_ET_PEER_STOP:
355 FAIL_TEST (event->details.peer_stop.peer == peer, return );
356 FAIL_TEST (PEER_SERVICE_CONNECT == sub_test, return );
357 result = GNUNET_YES;
358 sub_test = PEER_GETCONFIG;
359 GNUNET_TESTBED_operation_done (operation);
360 operation =
361 GNUNET_TESTBED_peer_get_information (peer,
362 GNUNET_TESTBED_PIT_CONFIGURATION,
363 &peerinfo_cb, NULL);
364 break;
365
366 default:
367 FAIL_TEST (0, return ); /* We should never reach this state */
368 }
367} 369}
368 370
369 371
@@ -377,22 +379,22 @@ controller_cb(void *cls,
377 * @param emsg NULL if peer is not NULL; else MAY contain the error description 379 * @param emsg NULL if peer is not NULL; else MAY contain the error description
378 */ 380 */
379static void 381static void
380peer_create_cb(void *cls, 382peer_create_cb (void *cls,
381 struct GNUNET_TESTBED_Peer *peer, 383 struct GNUNET_TESTBED_Peer *peer,
382 const char *emsg) 384 const char *emsg)
383{ 385{
384 struct GNUNET_TESTBED_Peer **peer_ptr; 386 struct GNUNET_TESTBED_Peer **peer_ptr;
385 387
386 peer_ptr = cls; 388 peer_ptr = cls;
387 FAIL_TEST(NULL != peer, return ); 389 FAIL_TEST (NULL != peer, return );
388 FAIL_TEST(NULL != peer_ptr, return ); 390 FAIL_TEST (NULL != peer_ptr, return );
389 *peer_ptr = peer; 391 *peer_ptr = peer;
390 GNUNET_TESTBED_operation_done(operation); 392 GNUNET_TESTBED_operation_done (operation);
391 operation = GNUNET_TESTBED_peer_start(NULL, 393 operation = GNUNET_TESTBED_peer_start (NULL,
392 peer, 394 peer,
393 NULL, 395 NULL,
394 NULL); 396 NULL);
395 FAIL_TEST(NULL != operation, return ); 397 FAIL_TEST (NULL != operation, return );
396} 398}
397 399
398 400
@@ -403,18 +405,18 @@ peer_create_cb(void *cls,
403 * @param emsg the error message; NULL if host registration is successful 405 * @param emsg the error message; NULL if host registration is successful
404 */ 406 */
405static void 407static void
406registration_comp(void *cls, 408registration_comp (void *cls,
407 const char *emsg) 409 const char *emsg)
408{ 410{
409 FAIL_TEST(cls == neighbour, return ); 411 FAIL_TEST (cls == neighbour, return );
410 reg_handle = NULL; 412 reg_handle = NULL;
411 operation = 413 operation =
412 GNUNET_TESTBED_peer_create(controller, 414 GNUNET_TESTBED_peer_create (controller,
413 host, 415 host,
414 cfg, 416 cfg,
415 &peer_create_cb, 417 &peer_create_cb,
416 &peer); 418 &peer);
417 FAIL_TEST(NULL != operation, return ); 419 FAIL_TEST (NULL != operation, return );
418} 420}
419 421
420 422
@@ -428,33 +430,33 @@ registration_comp(void *cls,
428 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 430 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
429 */ 431 */
430static void 432static void
431status_cb(void *cls, 433status_cb (void *cls,
432 const struct GNUNET_CONFIGURATION_Handle *cfg_, 434 const struct GNUNET_CONFIGURATION_Handle *cfg_,
433 int status) 435 int status)
434{ 436{
435 uint64_t event_mask; 437 uint64_t event_mask;
436 438
437 if (GNUNET_OK != status) 439 if (GNUNET_OK != status)
438 { 440 {
439 cp = NULL; 441 cp = NULL;
440 FAIL_TEST(0, return ); 442 FAIL_TEST (0, return );
441 return; 443 return;
442 } 444 }
443 event_mask = 0; 445 event_mask = 0;
444 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); 446 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
445 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); 447 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
446 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); 448 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
447 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); 449 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
448 controller = 450 controller =
449 GNUNET_TESTBED_controller_connect(host, event_mask, &controller_cb, 451 GNUNET_TESTBED_controller_connect (host, event_mask, &controller_cb,
450 NULL); 452 NULL);
451 FAIL_TEST(NULL != controller, return ); 453 FAIL_TEST (NULL != controller, return );
452 neighbour = GNUNET_TESTBED_host_create("localhost", NULL, cfg, 0); 454 neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, cfg, 0);
453 FAIL_TEST(NULL != neighbour, return ); 455 FAIL_TEST (NULL != neighbour, return );
454 reg_handle = 456 reg_handle =
455 GNUNET_TESTBED_register_host(controller, neighbour, &registration_comp, 457 GNUNET_TESTBED_register_host (controller, neighbour, &registration_comp,
456 neighbour); 458 neighbour);
457 FAIL_TEST(NULL != reg_handle, return ); 459 FAIL_TEST (NULL != reg_handle, return );
458} 460}
459 461
460 462
@@ -468,22 +470,22 @@ status_cb(void *cls,
468 * @param cfg the configuration file handle 470 * @param cfg the configuration file handle
469 */ 471 */
470static void 472static void
471run(void *cls, 473run (void *cls,
472 char *const *args, 474 char *const *args,
473 const char *cfgfile, 475 const char *cfgfile,
474 const struct GNUNET_CONFIGURATION_Handle *config) 476 const struct GNUNET_CONFIGURATION_Handle *config)
475{ 477{
476 cfg = GNUNET_CONFIGURATION_dup(config); 478 cfg = GNUNET_CONFIGURATION_dup (config);
477 host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); 479 host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
478 FAIL_TEST(NULL != host, return ); 480 FAIL_TEST (NULL != host, return );
479 cp = GNUNET_TESTBED_controller_start("127.0.0.1", host, 481 cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host,
480 &status_cb, 482 &status_cb,
481 NULL); 483 NULL);
482 abort_task = 484 abort_task =
483 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 485 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
484 (GNUNET_TIME_UNIT_MINUTES, 5), 486 (GNUNET_TIME_UNIT_MINUTES, 5),
485 &do_abort, 487 &do_abort,
486 NULL); 488 NULL);
487} 489}
488 490
489 491
@@ -491,7 +493,7 @@ run(void *cls,
491 * Main function 493 * Main function
492 */ 494 */
493int 495int
494main(int argc, char **argv) 496main (int argc, char **argv)
495{ 497{
496 int ret; 498 int ret;
497 499
@@ -504,8 +506,8 @@ main(int argc, char **argv)
504 506
505 result = GNUNET_SYSERR; 507 result = GNUNET_SYSERR;
506 ret = 508 ret =
507 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, 509 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
508 "test_testbed_api", "nohelp", options, &run, NULL); 510 "test_testbed_api", "nohelp", options, &run, NULL);
509 if ((GNUNET_OK != ret) || (GNUNET_OK != result)) 511 if ((GNUNET_OK != ret) || (GNUNET_OK != result))
510 return 1; 512 return 1;
511 return 0; 513 return 0;