summaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api_controllerlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/test_testbed_api_controllerlink.c')
-rw-r--r--src/testbed/test_testbed_api_controllerlink.c770
1 files changed, 399 insertions, 371 deletions
diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c
index 6c1a24f9c..ffcbebf00 100644
--- a/src/testbed/test_testbed_api_controllerlink.c
+++ b/src/testbed/test_testbed_api_controllerlink.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -45,19 +45,17 @@
45/** 45/**
46 * Generic logging shortcut 46 * Generic logging shortcut
47 */ 47 */
48#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 48#define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__)
49 49
50/** 50/**
51 * Debug logging shorthand 51 * Debug logging shorthand
52 */ 52 */
53#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 53#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
54 54
55/** 55/**
56 * Different stages in testing 56 * Different stages in testing
57 */ 57 */
58enum Stage 58enum Stage {
59{
60
61 /** 59 /**
62 * Initial stage 60 * Initial stage
63 */ 61 */
@@ -294,17 +292,17 @@ static enum Stage result;
294 */ 292 */
295#define FAIL_TEST(cond) \ 293#define FAIL_TEST(cond) \
296 do \ 294 do \
297 { \ 295 { \
298 if (! (cond)) \ 296 if (!(cond)) \
299 { \ 297 { \
300 GNUNET_break (0); \ 298 GNUNET_break(0); \
301 if (NULL != abort_task) \ 299 if (NULL != abort_task) \
302 GNUNET_SCHEDULER_cancel (abort_task); \ 300 GNUNET_SCHEDULER_cancel (abort_task); \
303 abort_task = NULL; \ 301 abort_task = NULL; \
304 GNUNET_SCHEDULER_shutdown (); \ 302 GNUNET_SCHEDULER_shutdown(); \
305 return; \ 303 return; \
306 } \ 304 } \
307 } while (0) 305 } while (0)
308 306
309 307
310/** 308/**
@@ -313,40 +311,40 @@ static enum Stage result;
313 * @param cls NULL 311 * @param cls NULL
314 */ 312 */
315static void 313static void
316do_shutdown (void *cls) 314do_shutdown(void *cls)
317{ 315{
318 if (NULL != abort_task) 316 if (NULL != abort_task)
319 GNUNET_SCHEDULER_cancel (abort_task); 317 GNUNET_SCHEDULER_cancel(abort_task);
320 if (NULL != delay_task_id) 318 if (NULL != delay_task_id)
321 { 319 {
322 GNUNET_SCHEDULER_cancel (delay_task_id); 320 GNUNET_SCHEDULER_cancel(delay_task_id);
323 delay_task_id = NULL; 321 delay_task_id = NULL;
324 } 322 }
325 if (NULL != hc_handle) 323 if (NULL != hc_handle)
326 GNUNET_TESTBED_is_host_habitable_cancel (hc_handle); 324 GNUNET_TESTBED_is_host_habitable_cancel(hc_handle);
327 if (NULL != op) 325 if (NULL != op)
328 { 326 {
329 GNUNET_TESTBED_operation_done (op); 327 GNUNET_TESTBED_operation_done(op);
330 op = NULL; 328 op = NULL;
331 } 329 }
332 if (NULL != mc) 330 if (NULL != mc)
333 GNUNET_TESTBED_controller_disconnect (mc); 331 GNUNET_TESTBED_controller_disconnect(mc);
334 if (NULL != cp) 332 if (NULL != cp)
335 GNUNET_TESTBED_controller_stop (cp); 333 GNUNET_TESTBED_controller_stop(cp);
336 if (NULL != slave3) 334 if (NULL != slave3)
337 GNUNET_TESTBED_host_destroy (slave3); 335 GNUNET_TESTBED_host_destroy(slave3);
338 if (NULL != slave2) 336 if (NULL != slave2)
339 GNUNET_TESTBED_host_destroy (slave2); 337 GNUNET_TESTBED_host_destroy(slave2);
340 if (NULL != slave) 338 if (NULL != slave)
341 GNUNET_TESTBED_host_destroy (slave); 339 GNUNET_TESTBED_host_destroy(slave);
342 if (NULL != host) 340 if (NULL != host)
343 GNUNET_TESTBED_host_destroy (host); 341 GNUNET_TESTBED_host_destroy(host);
344 if (NULL != cfg) 342 if (NULL != cfg)
345 GNUNET_CONFIGURATION_destroy (cfg); 343 GNUNET_CONFIGURATION_destroy(cfg);
346 if (NULL != cfg3) 344 if (NULL != cfg3)
347 GNUNET_CONFIGURATION_destroy (cfg3); 345 GNUNET_CONFIGURATION_destroy(cfg3);
348 if (NULL != rh) 346 if (NULL != rh)
349 GNUNET_TESTBED_cancel_registration (rh); 347 GNUNET_TESTBED_cancel_registration(rh);
350} 348}
351 349
352 350
@@ -356,11 +354,11 @@ do_shutdown (void *cls)
356 * @param cls NULL 354 * @param cls NULL
357 */ 355 */
358static void 356static void
359do_abort (void *cls) 357do_abort(void *cls)
360{ 358{
361 LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting in stage %d\n", result); 359 LOG(GNUNET_ERROR_TYPE_WARNING, "Aborting in stage %d\n", result);
362 abort_task = NULL; 360 abort_task = NULL;
363 GNUNET_SCHEDULER_shutdown (); 361 GNUNET_SCHEDULER_shutdown();
364} 362}
365 363
366 364
@@ -371,11 +369,11 @@ do_abort (void *cls)
371 * @return 369 * @return
372 */ 370 */
373static void 371static void
374do_abort_now (void *cls) 372do_abort_now(void *cls)
375{ 373{
376 if (NULL != abort_task) 374 if (NULL != abort_task)
377 GNUNET_SCHEDULER_cancel (abort_task); 375 GNUNET_SCHEDULER_cancel(abort_task);
378 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); 376 abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL);
379} 377}
380 378
381 379
@@ -386,7 +384,7 @@ do_abort_now (void *cls)
386 * @param emsg the error message; NULL if host registration is successful 384 * @param emsg the error message; NULL if host registration is successful
387 */ 385 */
388static void 386static void
389registration_cont (void *cls, const char *emsg); 387registration_cont(void *cls, const char *emsg);
390 388
391 389
392/** 390/**
@@ -396,26 +394,29 @@ registration_cont (void *cls, const char *emsg);
396 * @return 394 * @return
397 */ 395 */
398static void 396static void
399delay_task (void *cls) 397delay_task(void *cls)
400{ 398{
401 delay_task_id = NULL; 399 delay_task_id = NULL;
402 switch (result) 400 switch (result)
403 { 401 {
404 case SLAVE2_PEER_CREATE_SUCCESS: 402 case SLAVE2_PEER_CREATE_SUCCESS:
405 op = GNUNET_TESTBED_peer_stop (NULL, slave1_peer, NULL, NULL); 403 op = GNUNET_TESTBED_peer_stop(NULL, slave1_peer, NULL, NULL);
406 FAIL_TEST (NULL != op); 404 FAIL_TEST(NULL != op);
407 break; 405 break;
408 case MASTER_SLAVE2_PEERS_CONNECTED: 406
409 slave3 = GNUNET_TESTBED_host_create_with_id (3, "127.0.0.1", NULL, cfg, 0); 407 case MASTER_SLAVE2_PEERS_CONNECTED:
410 rh = GNUNET_TESTBED_register_host (mc, slave3, &registration_cont, NULL); 408 slave3 = GNUNET_TESTBED_host_create_with_id(3, "127.0.0.1", NULL, cfg, 0);
411 break; 409 rh = GNUNET_TESTBED_register_host(mc, slave3, &registration_cont, NULL);
412 case SLAVE2_SLAVE3_PEERS_CONNECTED: 410 break;
413 op = GNUNET_TESTBED_peer_stop (NULL, slave2_peer, NULL, NULL); 411
414 FAIL_TEST (NULL != op); 412 case SLAVE2_SLAVE3_PEERS_CONNECTED:
415 break; 413 op = GNUNET_TESTBED_peer_stop(NULL, slave2_peer, NULL, NULL);
416 default: 414 FAIL_TEST(NULL != op);
417 FAIL_TEST (0); 415 break;
418 } 416
417 default:
418 FAIL_TEST(0);
419 }
419} 420}
420 421
421 422
@@ -429,44 +430,48 @@ delay_task (void *cls)
429 * @param emsg NULL if peer is not NULL; else MAY contain the error description 430 * @param emsg NULL if peer is not NULL; else MAY contain the error description
430 */ 431 */
431static void 432static void
432peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) 433peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
433{ 434{
434 FAIL_TEST (NULL != peer); 435 FAIL_TEST(NULL != peer);
435 FAIL_TEST (NULL == emsg); 436 FAIL_TEST(NULL == emsg);
436 switch (result) 437 switch (result)
437 { 438 {
438 case MASTER_STARTED: 439 case MASTER_STARTED:
439 result = MASTER_PEER_CREATE_SUCCESS; 440 result = MASTER_PEER_CREATE_SUCCESS;
440 master_peer = peer; 441 master_peer = peer;
441 GNUNET_TESTBED_operation_done (op); 442 GNUNET_TESTBED_operation_done(op);
442 op = GNUNET_TESTBED_peer_start (NULL, master_peer, NULL, NULL); 443 op = GNUNET_TESTBED_peer_start(NULL, master_peer, NULL, NULL);
443 break; 444 break;
444 case SLAVE1_LINK_SUCCESS: 445
445 result = SLAVE1_PEER_CREATE_SUCCESS; 446 case SLAVE1_LINK_SUCCESS:
446 slave1_peer = peer; 447 result = SLAVE1_PEER_CREATE_SUCCESS;
447 GNUNET_TESTBED_operation_done (op); 448 slave1_peer = peer;
448 op = GNUNET_TESTBED_peer_start (NULL, slave1_peer, NULL, NULL); 449 GNUNET_TESTBED_operation_done(op);
449 break; 450 op = GNUNET_TESTBED_peer_start(NULL, slave1_peer, NULL, NULL);
450 case SLAVE2_LINK_SUCCESS: 451 break;
451 result = SLAVE2_PEER_CREATE_SUCCESS; 452
452 slave2_peer = peer; 453 case SLAVE2_LINK_SUCCESS:
453 GNUNET_TESTBED_operation_done (op); 454 result = SLAVE2_PEER_CREATE_SUCCESS;
454 op = NULL; 455 slave2_peer = peer;
455 delay_task_id = GNUNET_SCHEDULER_add_delayed ( 456 GNUNET_TESTBED_operation_done(op);
456 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), 457 op = NULL;
457 &delay_task, 458 delay_task_id = GNUNET_SCHEDULER_add_delayed(
458 NULL); 459 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1),
459 return; 460 &delay_task,
460 case SLAVE3_STARTED: 461 NULL);
461 result = SLAVE3_PEER_CREATE_SUCCESS; 462 return;
462 slave3_peer = peer; 463
463 GNUNET_TESTBED_operation_done (op); 464 case SLAVE3_STARTED:
464 op = GNUNET_TESTBED_peer_start (NULL, slave3_peer, NULL, NULL); 465 result = SLAVE3_PEER_CREATE_SUCCESS;
465 break; 466 slave3_peer = peer;
466 default: 467 GNUNET_TESTBED_operation_done(op);
467 FAIL_TEST (0); 468 op = GNUNET_TESTBED_peer_start(NULL, slave3_peer, NULL, NULL);
468 } 469 break;
469 FAIL_TEST (NULL != op); 470
471 default:
472 FAIL_TEST(0);
473 }
474 FAIL_TEST(NULL != op);
470} 475}
471 476
472 477
@@ -477,14 +482,14 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
477 * @param event the event information to check 482 * @param event the event information to check
478 */ 483 */
479static void 484static void
480check_operation_success (const struct GNUNET_TESTBED_EventInformation *event) 485check_operation_success(const struct GNUNET_TESTBED_EventInformation *event)
481{ 486{
482 FAIL_TEST (NULL != event); 487 FAIL_TEST(NULL != event);
483 FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); 488 FAIL_TEST(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
484 FAIL_TEST (event->op == op); 489 FAIL_TEST(event->op == op);
485 FAIL_TEST (NULL == event->op_cls); 490 FAIL_TEST(NULL == event->op_cls);
486 FAIL_TEST (NULL == event->details.operation_finished.emsg); 491 FAIL_TEST(NULL == event->details.operation_finished.emsg);
487 FAIL_TEST (NULL == event->details.operation_finished.generic); 492 FAIL_TEST(NULL == event->details.operation_finished.generic);
488} 493}
489 494
490 495
@@ -496,163 +501,180 @@ check_operation_success (const struct GNUNET_TESTBED_EventInformation *event)
496 * @param event information about the event 501 * @param event information about the event
497 */ 502 */
498static void 503static void
499controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) 504controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
500{ 505{
501 switch (result) 506 switch (result)
502 { 507 {
503 case SLAVE2_REGISTERED: 508 case SLAVE2_REGISTERED:
504 check_operation_success (event); 509 check_operation_success(event);
505 GNUNET_TESTBED_operation_done (op); 510 GNUNET_TESTBED_operation_done(op);
506 op = NULL; 511 op = NULL;
507 result = SLAVE1_LINK_SUCCESS; 512 result = SLAVE1_LINK_SUCCESS;
508 FAIL_TEST (NULL != slave2); 513 FAIL_TEST(NULL != slave2);
509 FAIL_TEST (NULL != slave); 514 FAIL_TEST(NULL != slave);
510 op = GNUNET_TESTBED_peer_create (mc, slave, cfg, peer_create_cb, NULL); 515 op = GNUNET_TESTBED_peer_create(mc, slave, cfg, peer_create_cb, NULL);
511 FAIL_TEST (NULL != op); 516 FAIL_TEST(NULL != op);
512 break; 517 break;
513 case SLAVE1_PEER_START_SUCCESS: 518
514 check_operation_success (event); 519 case SLAVE1_PEER_START_SUCCESS:
515 GNUNET_TESTBED_operation_done (op); 520 check_operation_success(event);
516 result = SLAVE2_LINK_SUCCESS; 521 GNUNET_TESTBED_operation_done(op);
517 op = GNUNET_TESTBED_peer_create (mc, slave2, cfg, peer_create_cb, NULL); 522 result = SLAVE2_LINK_SUCCESS;
518 FAIL_TEST (NULL != op); 523 op = GNUNET_TESTBED_peer_create(mc, slave2, cfg, peer_create_cb, NULL);
519 break; 524 FAIL_TEST(NULL != op);
520 case MASTER_PEER_CREATE_SUCCESS: 525 break;
521 FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); 526
522 FAIL_TEST (event->details.peer_start.host == host); 527 case MASTER_PEER_CREATE_SUCCESS:
523 FAIL_TEST (event->details.peer_start.peer == master_peer); 528 FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type);
524 GNUNET_TESTBED_operation_done (op); 529 FAIL_TEST(event->details.peer_start.host == host);
525 op = NULL; 530 FAIL_TEST(event->details.peer_start.peer == master_peer);
526 result = MASTER_PEER_START_SUCCESS; 531 GNUNET_TESTBED_operation_done(op);
527 slave = GNUNET_TESTBED_host_create_with_id (1, "127.0.0.1", NULL, cfg, 0); 532 op = NULL;
528 FAIL_TEST (NULL != slave); 533 result = MASTER_PEER_START_SUCCESS;
529 rh = GNUNET_TESTBED_register_host (mc, slave, &registration_cont, NULL); 534 slave = GNUNET_TESTBED_host_create_with_id(1, "127.0.0.1", NULL, cfg, 0);
530 FAIL_TEST (NULL != rh); 535 FAIL_TEST(NULL != slave);
531 break; 536 rh = GNUNET_TESTBED_register_host(mc, slave, &registration_cont, NULL);
532 case SLAVE1_PEER_CREATE_SUCCESS: 537 FAIL_TEST(NULL != rh);
533 FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); 538 break;
534 FAIL_TEST (event->details.peer_start.host == slave); 539
535 FAIL_TEST (event->details.peer_start.peer == slave1_peer); 540 case SLAVE1_PEER_CREATE_SUCCESS:
536 GNUNET_TESTBED_operation_done (op); 541 FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type);
537 result = SLAVE1_PEER_START_SUCCESS; 542 FAIL_TEST(event->details.peer_start.host == slave);
538 op = GNUNET_TESTBED_controller_link (NULL, mc, slave2, slave, GNUNET_YES); 543 FAIL_TEST(event->details.peer_start.peer == slave1_peer);
539 break; 544 GNUNET_TESTBED_operation_done(op);
540 case SLAVE2_PEER_CREATE_SUCCESS: 545 result = SLAVE1_PEER_START_SUCCESS;
541 FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type); 546 op = GNUNET_TESTBED_controller_link(NULL, mc, slave2, slave, GNUNET_YES);
542 FAIL_TEST (event->details.peer_stop.peer == slave1_peer); 547 break;
543 GNUNET_TESTBED_operation_done (op); 548
544 result = SLAVE1_PEER_STOP_SUCCESS; 549 case SLAVE2_PEER_CREATE_SUCCESS:
545 op = GNUNET_TESTBED_peer_start (NULL, slave2_peer, NULL, NULL); 550 FAIL_TEST(GNUNET_TESTBED_ET_PEER_STOP == event->type);
546 FAIL_TEST (NULL != op); 551 FAIL_TEST(event->details.peer_stop.peer == slave1_peer);
547 break; 552 GNUNET_TESTBED_operation_done(op);
548 case SLAVE3_PEER_CREATE_SUCCESS: 553 result = SLAVE1_PEER_STOP_SUCCESS;
549 FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); 554 op = GNUNET_TESTBED_peer_start(NULL, slave2_peer, NULL, NULL);
550 FAIL_TEST (event->details.peer_start.host == slave3); 555 FAIL_TEST(NULL != op);
551 FAIL_TEST (event->details.peer_start.peer == slave3_peer); 556 break;
552 GNUNET_TESTBED_operation_done (op); 557
553 result = SLAVE3_PEER_START_SUCCESS; 558 case SLAVE3_PEER_CREATE_SUCCESS:
554 sleep (1); 559 FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type);
555 LOG_DEBUG ("**************************************\n"); 560 FAIL_TEST(event->details.peer_start.host == slave3);
556 op = 561 FAIL_TEST(event->details.peer_start.peer == slave3_peer);
557 GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, slave2_peer, slave3_peer); 562 GNUNET_TESTBED_operation_done(op);
558 FAIL_TEST (NULL != op); 563 result = SLAVE3_PEER_START_SUCCESS;
559 break; 564 sleep(1);
560 case SLAVE3_PEER_START_SUCCESS: 565 LOG_DEBUG("**************************************\n");
561 FAIL_TEST (NULL != event); 566 op =
562 FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type); 567 GNUNET_TESTBED_overlay_connect(mc, NULL, NULL, slave2_peer, slave3_peer);
563 FAIL_TEST (event->details.peer_connect.peer1 == slave2_peer); 568 FAIL_TEST(NULL != op);
564 FAIL_TEST (event->details.peer_connect.peer2 == slave3_peer); 569 break;
565 result = SLAVE2_SLAVE3_PEERS_CONNECTED; 570
566 GNUNET_TESTBED_operation_done (op); 571 case SLAVE3_PEER_START_SUCCESS:
567 op = NULL; 572 FAIL_TEST(NULL != event);
568 delay_task_id = GNUNET_SCHEDULER_add_delayed ( 573 FAIL_TEST(GNUNET_TESTBED_ET_CONNECT == event->type);
569 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), 574 FAIL_TEST(event->details.peer_connect.peer1 == slave2_peer);
570 &delay_task, 575 FAIL_TEST(event->details.peer_connect.peer2 == slave3_peer);
571 NULL); 576 result = SLAVE2_SLAVE3_PEERS_CONNECTED;
572 break; 577 GNUNET_TESTBED_operation_done(op);
573 case SLAVE1_PEER_STOP_SUCCESS: 578 op = NULL;
574 FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); 579 delay_task_id = GNUNET_SCHEDULER_add_delayed(
575 FAIL_TEST (event->details.peer_start.host == slave2); 580 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1),
576 FAIL_TEST (event->details.peer_start.peer == slave2_peer); 581 &delay_task,
577 GNUNET_TESTBED_operation_done (op); 582 NULL);
578 result = SLAVE2_PEER_START_SUCCESS; 583 break;
579 op = 584
580 GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, master_peer, slave2_peer); 585 case SLAVE1_PEER_STOP_SUCCESS:
581 break; 586 FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type);
582 case SLAVE2_PEER_START_SUCCESS: 587 FAIL_TEST(event->details.peer_start.host == slave2);
583 FAIL_TEST (NULL != event); 588 FAIL_TEST(event->details.peer_start.peer == slave2_peer);
584 FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type); 589 GNUNET_TESTBED_operation_done(op);
585 FAIL_TEST (event->details.peer_connect.peer1 == master_peer); 590 result = SLAVE2_PEER_START_SUCCESS;
586 FAIL_TEST (event->details.peer_connect.peer2 == slave2_peer); 591 op =
587 result = MASTER_SLAVE2_PEERS_CONNECTED; 592 GNUNET_TESTBED_overlay_connect(mc, NULL, NULL, master_peer, slave2_peer);
588 GNUNET_TESTBED_operation_done (op); 593 break;
589 op = NULL; 594
590 delay_task_id = GNUNET_SCHEDULER_add_delayed ( 595 case SLAVE2_PEER_START_SUCCESS:
591 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), 596 FAIL_TEST(NULL != event);
592 &delay_task, 597 FAIL_TEST(GNUNET_TESTBED_ET_CONNECT == event->type);
593 NULL); 598 FAIL_TEST(event->details.peer_connect.peer1 == master_peer);
594 break; 599 FAIL_TEST(event->details.peer_connect.peer2 == slave2_peer);
595 case SLAVE2_SLAVE3_PEERS_CONNECTED: 600 result = MASTER_SLAVE2_PEERS_CONNECTED;
596 FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type); 601 GNUNET_TESTBED_operation_done(op);
597 FAIL_TEST (event->details.peer_stop.peer == slave2_peer); 602 op = NULL;
598 GNUNET_TESTBED_operation_done (op); 603 delay_task_id = GNUNET_SCHEDULER_add_delayed(
599 result = SLAVE2_PEER_STOP_SUCCESS; 604 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1),
600 op = GNUNET_TESTBED_peer_destroy (slave1_peer); 605 &delay_task,
601 FAIL_TEST (NULL != op); 606 NULL);
602 break; 607 break;
603 case SLAVE2_PEER_STOP_SUCCESS: 608
604 check_operation_success (event); 609 case SLAVE2_SLAVE3_PEERS_CONNECTED:
605 GNUNET_TESTBED_operation_done (op); 610 FAIL_TEST(GNUNET_TESTBED_ET_PEER_STOP == event->type);
606 result = SLAVE1_PEER_DESTROY_SUCCESS; 611 FAIL_TEST(event->details.peer_stop.peer == slave2_peer);
607 op = GNUNET_TESTBED_peer_destroy (slave2_peer); 612 GNUNET_TESTBED_operation_done(op);
608 FAIL_TEST (NULL != op); 613 result = SLAVE2_PEER_STOP_SUCCESS;
609 break; 614 op = GNUNET_TESTBED_peer_destroy(slave1_peer);
610 case SLAVE1_PEER_DESTROY_SUCCESS: 615 FAIL_TEST(NULL != op);
611 check_operation_success (event); 616 break;
612 GNUNET_TESTBED_operation_done (op); 617
613 op = NULL; 618 case SLAVE2_PEER_STOP_SUCCESS:
614 result = SLAVE2_PEER_DESTROY_SUCCESS; 619 check_operation_success(event);
615 op = GNUNET_TESTBED_get_slave_config (NULL, mc, slave3); 620 GNUNET_TESTBED_operation_done(op);
616 FAIL_TEST (NULL != op); 621 result = SLAVE1_PEER_DESTROY_SUCCESS;
617 break; 622 op = GNUNET_TESTBED_peer_destroy(slave2_peer);
618 case SLAVE2_PEER_DESTROY_SUCCESS: 623 FAIL_TEST(NULL != op);
619 FAIL_TEST (NULL != event); 624 break;
620 FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); 625
621 FAIL_TEST (event->op == op); 626 case SLAVE1_PEER_DESTROY_SUCCESS:
622 FAIL_TEST (NULL == event->op_cls); 627 check_operation_success(event);
623 FAIL_TEST (NULL == event->details.operation_finished.emsg); 628 GNUNET_TESTBED_operation_done(op);
624 cfg3 = GNUNET_CONFIGURATION_dup (event->details.operation_finished.generic); 629 op = NULL;
625 GNUNET_TESTBED_operation_done (op); 630 result = SLAVE2_PEER_DESTROY_SUCCESS;
626 result = SLAVE3_GET_CONFIG_SUCCESS; 631 op = GNUNET_TESTBED_get_slave_config(NULL, mc, slave3);
627 op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, slave, GNUNET_NO); 632 FAIL_TEST(NULL != op);
628 break; 633 break;
629 case SLAVE3_REGISTERED: 634
630 check_operation_success (event); 635 case SLAVE2_PEER_DESTROY_SUCCESS:
631 GNUNET_TESTBED_operation_done (op); 636 FAIL_TEST(NULL != event);
632 result = SLAVE3_STARTED; 637 FAIL_TEST(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
633 op = GNUNET_TESTBED_peer_create (mc, slave3, cfg, peer_create_cb, NULL); 638 FAIL_TEST(event->op == op);
634 FAIL_TEST (NULL != op); 639 FAIL_TEST(NULL == event->op_cls);
635 break; 640 FAIL_TEST(NULL == event->details.operation_finished.emsg);
636 case SLAVE3_GET_CONFIG_SUCCESS: 641 cfg3 = GNUNET_CONFIGURATION_dup(event->details.operation_finished.generic);
637 result = SLAVE3_LINK_SUCCESS; 642 GNUNET_TESTBED_operation_done(op);
638 GNUNET_TESTBED_operation_done (op); 643 result = SLAVE3_GET_CONFIG_SUCCESS;
639 op = GNUNET_TESTBED_peer_destroy (master_peer); 644 op = GNUNET_TESTBED_controller_link(NULL, mc, slave3, slave, GNUNET_NO);
640 break; 645 break;
641 case SLAVE3_LINK_SUCCESS: 646
642 check_operation_success (event); 647 case SLAVE3_REGISTERED:
643 result = MASTER_PEER_DESTROY_SUCCESS; 648 check_operation_success(event);
644 GNUNET_TESTBED_operation_done (op); 649 GNUNET_TESTBED_operation_done(op);
645 op = GNUNET_TESTBED_peer_destroy (slave3_peer); 650 result = SLAVE3_STARTED;
646 break; 651 op = GNUNET_TESTBED_peer_create(mc, slave3, cfg, peer_create_cb, NULL);
647 case MASTER_PEER_DESTROY_SUCCESS: 652 FAIL_TEST(NULL != op);
648 result = SUCCESS; 653 break;
649 GNUNET_TESTBED_operation_done (op); 654
650 op = NULL; 655 case SLAVE3_GET_CONFIG_SUCCESS:
651 GNUNET_SCHEDULER_shutdown (); 656 result = SLAVE3_LINK_SUCCESS;
652 break; 657 GNUNET_TESTBED_operation_done(op);
653 default: 658 op = GNUNET_TESTBED_peer_destroy(master_peer);
654 FAIL_TEST (0); 659 break;
655 } 660
661 case SLAVE3_LINK_SUCCESS:
662 check_operation_success(event);
663 result = MASTER_PEER_DESTROY_SUCCESS;
664 GNUNET_TESTBED_operation_done(op);
665 op = GNUNET_TESTBED_peer_destroy(slave3_peer);
666 break;
667
668 case MASTER_PEER_DESTROY_SUCCESS:
669 result = SUCCESS;
670 GNUNET_TESTBED_operation_done(op);
671 op = NULL;
672 GNUNET_SCHEDULER_shutdown();
673 break;
674
675 default:
676 FAIL_TEST(0);
677 }
656} 678}
657 679
658 680
@@ -663,40 +685,43 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
663 * @param emsg the error message; NULL if host registration is successful 685 * @param emsg the error message; NULL if host registration is successful
664 */ 686 */
665static void 687static void
666registration_cont (void *cls, const char *emsg) 688registration_cont(void *cls, const char *emsg)
667{ 689{
668 rh = NULL; 690 rh = NULL;
669 switch (result) 691 switch (result)
670 { 692 {
671 case MASTER_PEER_START_SUCCESS: 693 case MASTER_PEER_START_SUCCESS:
672 FAIL_TEST (NULL == emsg); 694 FAIL_TEST(NULL == emsg);
673 FAIL_TEST (NULL != mc); 695 FAIL_TEST(NULL != mc);
674 result = SLAVE1_REGISTERED; 696 result = SLAVE1_REGISTERED;
675 slave2 = GNUNET_TESTBED_host_create_with_id (2, "127.0.0.1", NULL, cfg, 0); 697 slave2 = GNUNET_TESTBED_host_create_with_id(2, "127.0.0.1", NULL, cfg, 0);
676 FAIL_TEST (NULL != slave2); 698 FAIL_TEST(NULL != slave2);
677 rh = GNUNET_TESTBED_register_host (mc, slave2, &registration_cont, NULL); 699 rh = GNUNET_TESTBED_register_host(mc, slave2, &registration_cont, NULL);
678 FAIL_TEST (NULL != rh); 700 FAIL_TEST(NULL != rh);
679 break; 701 break;
680 case SLAVE1_REGISTERED: 702
681 FAIL_TEST (NULL == emsg); 703 case SLAVE1_REGISTERED:
682 FAIL_TEST (NULL != mc); 704 FAIL_TEST(NULL == emsg);
683 result = SLAVE2_REGISTERED; 705 FAIL_TEST(NULL != mc);
684 FAIL_TEST (NULL != cfg); 706 result = SLAVE2_REGISTERED;
685 op = GNUNET_TESTBED_controller_link (NULL, mc, slave, NULL, GNUNET_YES); 707 FAIL_TEST(NULL != cfg);
686 FAIL_TEST (NULL != op); 708 op = GNUNET_TESTBED_controller_link(NULL, mc, slave, NULL, GNUNET_YES);
687 break; 709 FAIL_TEST(NULL != op);
688 case MASTER_SLAVE2_PEERS_CONNECTED: 710 break;
689 FAIL_TEST (NULL == emsg); 711
690 FAIL_TEST (NULL != mc); 712 case MASTER_SLAVE2_PEERS_CONNECTED:
691 FAIL_TEST (NULL == op); 713 FAIL_TEST(NULL == emsg);
692 result = SLAVE3_REGISTERED; 714 FAIL_TEST(NULL != mc);
693 op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, NULL, GNUNET_YES); 715 FAIL_TEST(NULL == op);
694 FAIL_TEST (NULL != op); 716 result = SLAVE3_REGISTERED;
695 break; 717 op = GNUNET_TESTBED_controller_link(NULL, mc, slave3, NULL, GNUNET_YES);
696 default: 718 FAIL_TEST(NULL != op);
697 GNUNET_break (0); 719 break;
698 do_abort_now (NULL); 720
699 } 721 default:
722 GNUNET_break(0);
723 do_abort_now(NULL);
724 }
700} 725}
701 726
702/** 727/**
@@ -709,33 +734,34 @@ registration_cont (void *cls, const char *emsg)
709 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 734 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
710 */ 735 */
711static void 736static void
712status_cb (void *cls, 737status_cb(void *cls,
713 const struct GNUNET_CONFIGURATION_Handle *config, 738 const struct GNUNET_CONFIGURATION_Handle *config,
714 int status) 739 int status)
715{ 740{
716 switch (result) 741 switch (result)
717 { 742 {
718 case INIT: 743 case INIT:
719 FAIL_TEST (GNUNET_OK == status); 744 FAIL_TEST(GNUNET_OK == status);
720 event_mask = 0; 745 event_mask = 0;
721 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); 746 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
722 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); 747 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
723 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); 748 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
724 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); 749 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
725 mc = GNUNET_TESTBED_controller_connect (host, 750 mc = GNUNET_TESTBED_controller_connect(host,
726 event_mask, 751 event_mask,
727 &controller_cb, 752 &controller_cb,
728 NULL); 753 NULL);
729 FAIL_TEST (NULL != mc); 754 FAIL_TEST(NULL != mc);
730 result = MASTER_STARTED; 755 result = MASTER_STARTED;
731 op = GNUNET_TESTBED_peer_create (mc, host, cfg, peer_create_cb, NULL); 756 op = GNUNET_TESTBED_peer_create(mc, host, cfg, peer_create_cb, NULL);
732 FAIL_TEST (NULL != op); 757 FAIL_TEST(NULL != op);
733 break; 758 break;
734 default: 759
735 GNUNET_break (0); 760 default:
736 cp = NULL; 761 GNUNET_break(0);
737 do_abort_now (NULL); 762 cp = NULL;
738 } 763 do_abort_now(NULL);
764 }
739} 765}
740 766
741 767
@@ -750,24 +776,24 @@ status_cb (void *cls,
750 * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not 776 * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not
751 */ 777 */
752static void 778static void
753host_habitable_cb (void *cls, 779host_habitable_cb(void *cls,
754 const struct GNUNET_TESTBED_Host *_host, 780 const struct GNUNET_TESTBED_Host *_host,
755 int status) 781 int status)
756{ 782{
757 hc_handle = NULL; 783 hc_handle = NULL;
758 if (GNUNET_NO == status) 784 if (GNUNET_NO == status)
759 { 785 {
760 (void) printf ("%s", 786 (void)printf("%s",
761 "Unable to run the test as this system is not configured " 787 "Unable to run the test as this system is not configured "
762 "to use password less SSH logins to localhost.\n" 788 "to use password less SSH logins to localhost.\n"
763 "Skipping test\n"); 789 "Skipping test\n");
764 GNUNET_SCHEDULER_cancel (abort_task); 790 GNUNET_SCHEDULER_cancel(abort_task);
765 abort_task = NULL; 791 abort_task = NULL;
766 GNUNET_SCHEDULER_shutdown (); 792 GNUNET_SCHEDULER_shutdown();
767 result = SKIP; 793 result = SKIP;
768 return; 794 return;
769 } 795 }
770 cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL); 796 cp = GNUNET_TESTBED_controller_start("127.0.0.1", host, status_cb, NULL);
771} 797}
772 798
773 799
@@ -780,35 +806,35 @@ host_habitable_cb (void *cls,
780 * @param cfg the configuration file handle 806 * @param cfg the configuration file handle
781 */ 807 */
782static void 808static void
783run (void *cls, 809run(void *cls,
784 char *const *args, 810 char *const *args,
785 const char *cfgfile, 811 const char *cfgfile,
786 const struct GNUNET_CONFIGURATION_Handle *config) 812 const struct GNUNET_CONFIGURATION_Handle *config)
787{ 813{
788 cfg = GNUNET_CONFIGURATION_dup (config); 814 cfg = GNUNET_CONFIGURATION_dup(config);
789 host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); 815 host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0);
790 FAIL_TEST (NULL != host); 816 FAIL_TEST(NULL != host);
791 if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable (host, 817 if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable(host,
792 config, 818 config,
793 &host_habitable_cb, 819 &host_habitable_cb,
794 NULL))) 820 NULL)))
795 { 821 {
796 GNUNET_TESTBED_host_destroy (host); 822 GNUNET_TESTBED_host_destroy(host);
797 GNUNET_CONFIGURATION_destroy (cfg); 823 GNUNET_CONFIGURATION_destroy(cfg);
798 cfg = NULL; 824 cfg = NULL;
799 host = NULL; 825 host = NULL;
800 (void) printf ("%s", 826 (void)printf("%s",
801 "Unable to run the test as this system is not configured " 827 "Unable to run the test as this system is not configured "
802 "to use password less SSH logins to localhost.\n" 828 "to use password less SSH logins to localhost.\n"
803 "Marking test as successful\n"); 829 "Marking test as successful\n");
804 result = SKIP; 830 result = SKIP;
805 return; 831 return;
806 } 832 }
807 abort_task = GNUNET_SCHEDULER_add_delayed ( 833 abort_task = GNUNET_SCHEDULER_add_delayed(
808 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5), 834 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5),
809 &do_abort, 835 &do_abort,
810 NULL); 836 NULL);
811 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 837 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
812} 838}
813 839
814 840
@@ -816,34 +842,36 @@ run (void *cls,
816 * Main function 842 * Main function
817 */ 843 */
818int 844int
819main (int argc, char **argv) 845main(int argc, char **argv)
820{ 846{
821 char *const argv2[] = {"test_testbed_api_controllerlink", 847 char *const argv2[] = { "test_testbed_api_controllerlink",
822 "-c", 848 "-c",
823 "test_testbed_api.conf", 849 "test_testbed_api.conf",
824 NULL}; 850 NULL };
825 struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; 851 struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END };
826 int ret; 852 int ret;
827 853
828 result = INIT; 854 result = INIT;
829 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, 855 ret = GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1,
830 argv2, 856 argv2,
831 "test_testbed_api_controllerlink", 857 "test_testbed_api_controllerlink",
832 "nohelp", 858 "nohelp",
833 options, 859 options,
834 &run, 860 &run,
835 NULL); 861 NULL);
836 if (GNUNET_OK != ret) 862 if (GNUNET_OK != ret)
837 return 1; 863 return 1;
838 switch (result) 864 switch (result)
839 { 865 {
840 case SUCCESS: 866 case SUCCESS:
841 return 0; 867 return 0;
842 case SKIP: 868
843 return 77; /* Mark test as skipped */ 869 case SKIP:
844 default: 870 return 77; /* Mark test as skipped */
845 return 1; 871
846 } 872 default:
873 return 1;
874 }
847} 875}
848 876
849/* end of test_testbed_api_controllerlink.c */ 877/* end of test_testbed_api_controllerlink.c */