diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-11-02 10:19:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-11-02 10:19:00 +0000 |
commit | c6ef80f13164795b0b53bc7c4c7cae2452cf861e (patch) | |
tree | 9205d3cf10cc02c359b229e291375ca483f93090 /src/dht/test_dht_monitor.c | |
parent | 2100eaeefbccd6cb2b6f952320092542f82a2051 (diff) | |
download | gnunet-c6ef80f13164795b0b53bc7c4c7cae2452cf861e.tar.gz gnunet-c6ef80f13164795b0b53bc7c4c7cae2452cf861e.zip |
-major DHT test cleanup
Diffstat (limited to 'src/dht/test_dht_monitor.c')
-rw-r--r-- | src/dht/test_dht_monitor.c | 235 |
1 files changed, 25 insertions, 210 deletions
diff --git a/src/dht/test_dht_monitor.c b/src/dht/test_dht_monitor.c index f6474a37e..e8be7e49c 100644 --- a/src/dht/test_dht_monitor.c +++ b/src/dht/test_dht_monitor.c | |||
@@ -426,71 +426,38 @@ monitor_res_cb (void *cls, | |||
426 | 426 | ||
427 | 427 | ||
428 | /** | 428 | /** |
429 | * peergroup_ready: start test when all peers are connected | 429 | * Main function of the test. |
430 | * | 430 | * |
431 | * @param cls closure | 431 | * @param cls closure (NULL) |
432 | * @param emsg error message | 432 | * @param ctx argument to give to GNUNET_DHT_TEST_cleanup on test end |
433 | * @param num_peers number of peers that are running | ||
434 | * @param peers array of peers | ||
435 | * @param dhts handle to each of the DHTs of the peers | ||
433 | */ | 436 | */ |
434 | static void | 437 | static void |
435 | peergroup_ready (void *cls, const char *emsg) | 438 | run (void *cls, |
439 | struct GNUNET_DHT_TEST_Context *ctx, | ||
440 | unsigned int num_peers, | ||
441 | struct GNUNET_TESTBED_Peer **peers, | ||
442 | struct GNUNET_DHT_Handle **dhts) | ||
436 | { | 443 | { |
437 | struct GNUNET_TESTING_Daemon *d; | ||
438 | char *buf; | ||
439 | int buf_len; | ||
440 | unsigned int i; | 444 | unsigned int i; |
441 | 445 | ||
442 | if (emsg != NULL) | 446 | GNUNET_assert (NUM_PEERS == num_peers); |
443 | { | 447 | my_peers = peers; |
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
445 | "test: Peergroup callback called with error, aborting test!\n"); | ||
446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n", | ||
447 | emsg); | ||
448 | ok++; | ||
449 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
450 | return; | ||
451 | } | ||
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
453 | "test: Peer Group started successfully with %u connections\n", | ||
454 | total_connections); | ||
455 | if (data_file != NULL) | ||
456 | { | ||
457 | buf = NULL; | ||
458 | buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections); | ||
459 | if (buf_len > 0) | ||
460 | GNUNET_DISK_file_write (data_file, buf, buf_len); | ||
461 | GNUNET_free (buf); | ||
462 | } | ||
463 | peers_running = GNUNET_TESTING_daemons_running (pg); | ||
464 | |||
465 | GNUNET_assert (peers_running == num_peers); | ||
466 | hs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_Handle *)); | ||
467 | mhs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_MonitorHandle *)); | 448 | mhs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_MonitorHandle *)); |
468 | d_far = o = NULL; | ||
469 | o = GNUNET_TESTING_daemon_get (pg, 0); | ||
470 | d_far = GNUNET_TESTING_daemon_get (pg, 4); | ||
471 | |||
472 | for (i = 0; i < num_peers; i++) | 449 | for (i = 0; i < num_peers; i++) |
473 | { | 450 | { |
474 | d = GNUNET_TESTING_daemon_get (pg, i); | 451 | d = GNUNET_TESTING_daemon_get (pg, i); |
475 | hs[i] = GNUNET_DHT_connect (d->cfg, 32); | 452 | hs[i] = GNUNET_DHT_connect (d->cfg, 32); |
476 | mhs[i] = GNUNET_DHT_monitor_start(hs[i], | 453 | mhs[i] = GNUNET_DHT_monitor_start (hs[i], |
477 | GNUNET_BLOCK_TYPE_ANY, | 454 | GNUNET_BLOCK_TYPE_ANY, |
478 | NULL, | 455 | NULL, |
479 | &monitor_get_cb, | 456 | &monitor_get_cb, |
480 | &monitor_res_cb, | 457 | &monitor_res_cb, |
481 | &monitor_put_cb, | 458 | &monitor_put_cb, |
482 | (void *)(long)i); | 459 | (void *)(long)i); |
483 | } | 460 | } |
484 | |||
485 | if ((NULL == o) || (NULL == d_far)) | ||
486 | { | ||
487 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
488 | "test: Error getting daemons from pg\n"); | ||
489 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
490 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); | ||
491 | return; | ||
492 | } | ||
493 | monitor_counter = 0; | ||
494 | put_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 461 | put_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
495 | (GNUNET_TIME_UNIT_SECONDS, 3), | 462 | (GNUNET_TIME_UNIT_SECONDS, 3), |
496 | &put_id, NULL); | 463 | &put_id, NULL); |
@@ -500,173 +467,21 @@ peergroup_ready (void *cls, const char *emsg) | |||
500 | NULL); | 467 | NULL); |
501 | disconnect_task = | 468 | disconnect_task = |
502 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); | 469 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); |
503 | |||
504 | } | ||
505 | |||
506 | |||
507 | /** | ||
508 | * Function that will be called whenever two daemons are connected by | ||
509 | * the testing library. | ||
510 | * | ||
511 | * @param cls closure | ||
512 | * @param first peer id for first daemon | ||
513 | * @param second peer id for the second daemon | ||
514 | * @param distance distance between the connected peers | ||
515 | * @param first_cfg config for the first daemon | ||
516 | * @param second_cfg config for the second daemon | ||
517 | * @param first_daemon handle for the first daemon | ||
518 | * @param second_daemon handle for the second daemon | ||
519 | * @param emsg error message (NULL on success) | ||
520 | */ | ||
521 | static void | ||
522 | connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, | ||
523 | const struct GNUNET_PeerIdentity *second, uint32_t distance, | ||
524 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, | ||
525 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, | ||
526 | struct GNUNET_TESTING_Daemon *first_daemon, | ||
527 | struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) | ||
528 | { | ||
529 | |||
530 | if (emsg == NULL) | ||
531 | { | ||
532 | total_connections++; | ||
533 | GNUNET_PEER_intern (first); | ||
534 | GNUNET_PEER_intern (second); | ||
535 | } | ||
536 | else | ||
537 | { | ||
538 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
539 | "test: Problem with new connection (%s)\n", emsg); | ||
540 | } | ||
541 | } | 470 | } |
542 | 471 | ||
543 | 472 | ||
544 | /** | 473 | /** |
545 | * run: load configuration options and schedule test to run (start peergroup) | ||
546 | * @param cls closure | ||
547 | * @param args argv | ||
548 | * @param cfgfile configuration file name (can be NULL) | ||
549 | * @param cfg configuration handle | ||
550 | */ | ||
551 | static void | ||
552 | run (void *cls, char *const *args, const char *cfgfile, | ||
553 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
554 | { | ||
555 | char *temp_str; | ||
556 | struct GNUNET_TESTING_Host *hosts; | ||
557 | char *data_filename; | ||
558 | |||
559 | ok = 1; | ||
560 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
561 | |||
562 | GNUNET_log_setup ("test_dht_monitor", | ||
563 | "WARNING", | ||
564 | NULL); | ||
565 | |||
566 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Starting daemons.\n"); | ||
567 | GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing_old", | ||
568 | "use_progressbars", "YES"); | ||
569 | if (GNUNET_OK != | ||
570 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing_old", | ||
571 | "num_peers", &num_peers)) | ||
572 | { | ||
573 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
574 | "Option TESTING:NUM_PEERS is required!\n"); | ||
575 | return; | ||
576 | } | ||
577 | |||
578 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing_old", | ||
579 | "topology_output_file", | ||
580 | &topology_file)) | ||
581 | { | ||
582 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
583 | "Option test_dht_monitor:topology_output_file is required!\n"); | ||
584 | return; | ||
585 | } | ||
586 | |||
587 | if (GNUNET_OK == | ||
588 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_dht_topo", | ||
589 | "data_output_file", | ||
590 | &data_filename)) | ||
591 | { | ||
592 | data_file = | ||
593 | GNUNET_DISK_file_open (data_filename, | ||
594 | GNUNET_DISK_OPEN_READWRITE | | ||
595 | GNUNET_DISK_OPEN_CREATE, | ||
596 | GNUNET_DISK_PERM_USER_READ | | ||
597 | GNUNET_DISK_PERM_USER_WRITE); | ||
598 | if (data_file == NULL) | ||
599 | { | ||
600 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", | ||
601 | data_filename); | ||
602 | GNUNET_free (data_filename); | ||
603 | } | ||
604 | } | ||
605 | |||
606 | if (GNUNET_YES == | ||
607 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_dht_topo", | ||
608 | "output_file", &temp_str)) | ||
609 | { | ||
610 | output_file = | ||
611 | GNUNET_DISK_file_open (temp_str, | ||
612 | GNUNET_DISK_OPEN_READWRITE | | ||
613 | GNUNET_DISK_OPEN_CREATE, | ||
614 | GNUNET_DISK_PERM_USER_READ | | ||
615 | GNUNET_DISK_PERM_USER_WRITE); | ||
616 | if (output_file == NULL) | ||
617 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", | ||
618 | temp_str); | ||
619 | } | ||
620 | GNUNET_free_non_null (temp_str); | ||
621 | |||
622 | hosts = GNUNET_TESTING_hosts_load (testing_cfg); | ||
623 | |||
624 | pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT, | ||
625 | &connect_cb, &peergroup_ready, NULL, | ||
626 | hosts); | ||
627 | GNUNET_assert (pg != NULL); | ||
628 | shutdown_handle = | ||
629 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
630 | &shutdown_task, NULL); | ||
631 | } | ||
632 | |||
633 | |||
634 | /** | ||
635 | * test_dht_monitor command line options | ||
636 | */ | ||
637 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
638 | {'V', "verbose", NULL, | ||
639 | gettext_noop ("be verbose (print progress information)"), | ||
640 | 0, &GNUNET_GETOPT_set_one, &verbose}, | ||
641 | GNUNET_GETOPT_OPTION_END | ||
642 | }; | ||
643 | |||
644 | |||
645 | /** | ||
646 | * Main: start test | 474 | * Main: start test |
647 | */ | 475 | */ |
648 | int | 476 | int |
649 | main (int xargc, char *xargv[]) | 477 | main (int xargc, char *xargv[]) |
650 | { | 478 | { |
651 | char *const argv[] = { "test-dht-monitor", | 479 | GNUNET_DHT_TEST_run ("test-dht-monitor", |
652 | "-c", | 480 | "test_dht_monitor.conf", |
653 | "test_dht_line.conf", | 481 | NUM_PEERS, |
654 | NULL | 482 | &run, NULL); |
655 | }; | ||
656 | |||
657 | in_test = GNUNET_NO; | ||
658 | GNUNET_PROGRAM_run (sizeof (argv) / sizeof (char *) - 1, argv, | ||
659 | "test_dht_monitor", | ||
660 | gettext_noop ("Test dht monitoring in a line."), | ||
661 | options, &run, NULL); | ||
662 | #if REMOVE_DIR | ||
663 | GNUNET_DISK_directory_remove ("/tmp/test_dht_monitor"); | ||
664 | #endif | ||
665 | if (0 != ok) | ||
666 | { | ||
667 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: FAILED!\n"); | ||
668 | } | ||
669 | return ok; | 483 | return ok; |
670 | } | 484 | } |
671 | 485 | ||
486 | |||
672 | /* end of test_dht_monitor.c */ | 487 | /* end of test_dht_monitor.c */ |