diff options
author | Julius Bünger <buenger@mytum.de> | 2018-06-06 00:33:56 +0200 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2018-06-06 00:34:36 +0200 |
commit | d15b9286cbaa6f56299f9064d269d3a1aa1ddee4 (patch) | |
tree | d9798b5d8495cdd4b92c58a1015a8f83bbe827d1 /src/rps/test_rps.c | |
parent | 6ab858be606ee40db66e349c165a6862a79c65a4 (diff) | |
download | gnunet-d15b9286cbaa6f56299f9064d269d3a1aa1ddee4.tar.gz gnunet-d15b9286cbaa6f56299f9064d269d3a1aa1ddee4.zip |
rps: split tests and profiler, proper shutdown
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r-- | src/rps/test_rps.c | 108 |
1 files changed, 84 insertions, 24 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index bae28428f..39aeacfeb 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -42,6 +42,12 @@ static uint32_t num_peers; | |||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * How long do we run the test? | 44 | * How long do we run the test? |
45 | * In seconds. | ||
46 | */ | ||
47 | static uint32_t timeout_s; | ||
48 | |||
49 | /** | ||
50 | * How long do we run the test? | ||
45 | */ | 51 | */ |
46 | //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 52 | //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
47 | static struct GNUNET_TIME_Relative timeout; | 53 | static struct GNUNET_TIME_Relative timeout; |
@@ -371,6 +377,11 @@ static int ok; | |||
371 | /** | 377 | /** |
372 | * Identifier for the churn task that runs periodically | 378 | * Identifier for the churn task that runs periodically |
373 | */ | 379 | */ |
380 | static struct GNUNET_SCHEDULER_Task *post_test_task; | ||
381 | |||
382 | /** | ||
383 | * Identifier for the churn task that runs periodically | ||
384 | */ | ||
374 | static struct GNUNET_SCHEDULER_Task *shutdown_task; | 385 | static struct GNUNET_SCHEDULER_Task *shutdown_task; |
375 | 386 | ||
376 | /** | 387 | /** |
@@ -556,6 +567,11 @@ struct SingleTestRun | |||
556 | } cur_test_run; | 567 | } cur_test_run; |
557 | 568 | ||
558 | /** | 569 | /** |
570 | * Did we finish the test? | ||
571 | */ | ||
572 | static int post_test; | ||
573 | |||
574 | /** | ||
559 | * Are we shutting down? | 575 | * Are we shutting down? |
560 | */ | 576 | */ |
561 | static int in_shutdown; | 577 | static int in_shutdown; |
@@ -755,6 +771,41 @@ shutdown_op (void *cls) | |||
755 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 771 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
756 | "Shutdown task scheduled, going down.\n"); | 772 | "Shutdown task scheduled, going down.\n"); |
757 | in_shutdown = GNUNET_YES; | 773 | in_shutdown = GNUNET_YES; |
774 | if (NULL != post_test_task) | ||
775 | { | ||
776 | GNUNET_SCHEDULER_cancel (post_test_task); | ||
777 | } | ||
778 | if (NULL != churn_task) | ||
779 | { | ||
780 | GNUNET_SCHEDULER_cancel (churn_task); | ||
781 | churn_task = NULL; | ||
782 | } | ||
783 | for (i = 0; i < num_peers; i++) | ||
784 | { | ||
785 | if (NULL != rps_peers[i].rps_handle) | ||
786 | { | ||
787 | GNUNET_RPS_disconnect (rps_peers[i].rps_handle); | ||
788 | } | ||
789 | if (NULL != rps_peers[i].op) | ||
790 | { | ||
791 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | ||
792 | } | ||
793 | } | ||
794 | } | ||
795 | |||
796 | |||
797 | /** | ||
798 | * Task run on timeout to collect statistics and potentially shut down. | ||
799 | */ | ||
800 | static void | ||
801 | post_test_op (void *cls) | ||
802 | { | ||
803 | unsigned int i; | ||
804 | |||
805 | post_test_task = NULL; | ||
806 | post_test = GNUNET_YES; | ||
807 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
808 | "Post test task scheduled, going down.\n"); | ||
758 | if (NULL != churn_task) | 809 | if (NULL != churn_task) |
759 | { | 810 | { |
760 | GNUNET_SCHEDULER_cancel (churn_task); | 811 | GNUNET_SCHEDULER_cancel (churn_task); |
@@ -763,7 +814,10 @@ shutdown_op (void *cls) | |||
763 | for (i = 0; i < num_peers; i++) | 814 | for (i = 0; i < num_peers; i++) |
764 | { | 815 | { |
765 | if (NULL != rps_peers[i].op) | 816 | if (NULL != rps_peers[i].op) |
817 | { | ||
766 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | 818 | GNUNET_TESTBED_operation_done (rps_peers[i].op); |
819 | rps_peers[i].op = NULL; | ||
820 | } | ||
767 | if (NULL != cur_test_run.post_test) | 821 | if (NULL != cur_test_run.post_test) |
768 | { | 822 | { |
769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); | 823 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); |
@@ -847,7 +901,7 @@ info_cb (void *cb_cls, | |||
847 | { | 901 | { |
848 | struct OpListEntry *entry = (struct OpListEntry *) cb_cls; | 902 | struct OpListEntry *entry = (struct OpListEntry *) cb_cls; |
849 | 903 | ||
850 | if (GNUNET_YES == in_shutdown) | 904 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
851 | { | 905 | { |
852 | return; | 906 | return; |
853 | } | 907 | } |
@@ -901,7 +955,7 @@ rps_connect_complete_cb (void *cls, | |||
901 | struct RPSPeer *rps_peer = cls; | 955 | struct RPSPeer *rps_peer = cls; |
902 | struct GNUNET_RPS_Handle *rps = ca_result; | 956 | struct GNUNET_RPS_Handle *rps = ca_result; |
903 | 957 | ||
904 | if (GNUNET_YES == in_shutdown) | 958 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
905 | { | 959 | { |
906 | return; | 960 | return; |
907 | } | 961 | } |
@@ -1105,10 +1159,10 @@ default_reply_handle (void *cls, | |||
1105 | if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) | 1159 | if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) |
1106 | { | 1160 | { |
1107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); | 1161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); |
1108 | GNUNET_assert (NULL != shutdown_task); | 1162 | GNUNET_assert (NULL != post_test_task); |
1109 | GNUNET_SCHEDULER_cancel (shutdown_task); | 1163 | GNUNET_SCHEDULER_cancel (post_test_task); |
1110 | shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL); | 1164 | post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); |
1111 | GNUNET_assert (NULL!= shutdown_task); | 1165 | GNUNET_assert (NULL!= post_test_task); |
1112 | } | 1166 | } |
1113 | } | 1167 | } |
1114 | 1168 | ||
@@ -1122,7 +1176,7 @@ request_peers (void *cls) | |||
1122 | struct RPSPeer *rps_peer; | 1176 | struct RPSPeer *rps_peer; |
1123 | struct PendingReply *pending_rep; | 1177 | struct PendingReply *pending_rep; |
1124 | 1178 | ||
1125 | if (GNUNET_YES == in_shutdown) | 1179 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1126 | return; | 1180 | return; |
1127 | rps_peer = pending_req->rps_peer; | 1181 | rps_peer = pending_req->rps_peer; |
1128 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); | 1182 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); |
@@ -1185,7 +1239,7 @@ cancel_request_cb (void *cls) | |||
1185 | struct RPSPeer *rps_peer = cls; | 1239 | struct RPSPeer *rps_peer = cls; |
1186 | struct PendingReply *pending_rep; | 1240 | struct PendingReply *pending_rep; |
1187 | 1241 | ||
1188 | if (GNUNET_YES == in_shutdown) | 1242 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1189 | return; | 1243 | return; |
1190 | pending_rep = rps_peer->pending_rep_head; | 1244 | pending_rep = rps_peer->pending_rep_head; |
1191 | GNUNET_assert (1 <= rps_peer->num_pending_reps); | 1245 | GNUNET_assert (1 <= rps_peer->num_pending_reps); |
@@ -1290,7 +1344,7 @@ mal_cb (struct RPSPeer *rps_peer) | |||
1290 | { | 1344 | { |
1291 | uint32_t num_mal_peers; | 1345 | uint32_t num_mal_peers; |
1292 | 1346 | ||
1293 | if (GNUNET_YES == in_shutdown) | 1347 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1294 | { | 1348 | { |
1295 | return; | 1349 | return; |
1296 | } | 1350 | } |
@@ -1317,7 +1371,7 @@ mal_cb (struct RPSPeer *rps_peer) | |||
1317 | static void | 1371 | static void |
1318 | single_req_cb (struct RPSPeer *rps_peer) | 1372 | single_req_cb (struct RPSPeer *rps_peer) |
1319 | { | 1373 | { |
1320 | if (GNUNET_YES == in_shutdown) | 1374 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1321 | { | 1375 | { |
1322 | return; | 1376 | return; |
1323 | } | 1377 | } |
@@ -1331,7 +1385,7 @@ single_req_cb (struct RPSPeer *rps_peer) | |||
1331 | static void | 1385 | static void |
1332 | delay_req_cb (struct RPSPeer *rps_peer) | 1386 | delay_req_cb (struct RPSPeer *rps_peer) |
1333 | { | 1387 | { |
1334 | if (GNUNET_YES == in_shutdown) | 1388 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1335 | { | 1389 | { |
1336 | return; | 1390 | return; |
1337 | } | 1391 | } |
@@ -1345,7 +1399,7 @@ delay_req_cb (struct RPSPeer *rps_peer) | |||
1345 | static void | 1399 | static void |
1346 | seed_cb (struct RPSPeer *rps_peer) | 1400 | seed_cb (struct RPSPeer *rps_peer) |
1347 | { | 1401 | { |
1348 | if (GNUNET_YES == in_shutdown) | 1402 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1349 | { | 1403 | { |
1350 | return; | 1404 | return; |
1351 | } | 1405 | } |
@@ -1361,7 +1415,7 @@ seed_cb (struct RPSPeer *rps_peer) | |||
1361 | static void | 1415 | static void |
1362 | seed_big_cb (struct RPSPeer *rps_peer) | 1416 | seed_big_cb (struct RPSPeer *rps_peer) |
1363 | { | 1417 | { |
1364 | if (GNUNET_YES == in_shutdown) | 1418 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1365 | { | 1419 | { |
1366 | return; | 1420 | return; |
1367 | } | 1421 | } |
@@ -1387,7 +1441,7 @@ single_peer_seed_cb (struct RPSPeer *rps_peer) | |||
1387 | static void | 1441 | static void |
1388 | seed_req_cb (struct RPSPeer *rps_peer) | 1442 | seed_req_cb (struct RPSPeer *rps_peer) |
1389 | { | 1443 | { |
1390 | if (GNUNET_YES == in_shutdown) | 1444 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1391 | { | 1445 | { |
1392 | return; | 1446 | return; |
1393 | } | 1447 | } |
@@ -1406,7 +1460,7 @@ seed_req_cb (struct RPSPeer *rps_peer) | |||
1406 | static void | 1460 | static void |
1407 | req_cancel_cb (struct RPSPeer *rps_peer) | 1461 | req_cancel_cb (struct RPSPeer *rps_peer) |
1408 | { | 1462 | { |
1409 | if (GNUNET_YES == in_shutdown) | 1463 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1410 | { | 1464 | { |
1411 | return; | 1465 | return; |
1412 | } | 1466 | } |
@@ -1439,7 +1493,7 @@ churn (void *cls); | |||
1439 | static void | 1493 | static void |
1440 | churn_test_cb (struct RPSPeer *rps_peer) | 1494 | churn_test_cb (struct RPSPeer *rps_peer) |
1441 | { | 1495 | { |
1442 | if (GNUNET_YES == in_shutdown) | 1496 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1443 | { | 1497 | { |
1444 | return; | 1498 | return; |
1445 | } | 1499 | } |
@@ -1480,7 +1534,7 @@ churn_cb (void *cls, | |||
1480 | // FIXME | 1534 | // FIXME |
1481 | struct OpListEntry *entry = cls; | 1535 | struct OpListEntry *entry = cls; |
1482 | 1536 | ||
1483 | if (GNUNET_YES == in_shutdown) | 1537 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1484 | { | 1538 | { |
1485 | return; | 1539 | return; |
1486 | } | 1540 | } |
@@ -1615,7 +1669,7 @@ churn (void *cls) | |||
1615 | double portion_go_online; | 1669 | double portion_go_online; |
1616 | double portion_go_offline; | 1670 | double portion_go_offline; |
1617 | 1671 | ||
1618 | if (GNUNET_YES == in_shutdown) | 1672 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1619 | { | 1673 | { |
1620 | return; | 1674 | return; |
1621 | } | 1675 | } |
@@ -1731,7 +1785,7 @@ profiler_reply_handle (void *cls, | |||
1731 | static void | 1785 | static void |
1732 | profiler_cb (struct RPSPeer *rps_peer) | 1786 | profiler_cb (struct RPSPeer *rps_peer) |
1733 | { | 1787 | { |
1734 | if (GNUNET_YES == in_shutdown) | 1788 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1735 | { | 1789 | { |
1736 | return; | 1790 | return; |
1737 | } | 1791 | } |
@@ -2644,7 +2698,12 @@ run (void *cls, | |||
2644 | 2698 | ||
2645 | if (NULL != churn_task) | 2699 | if (NULL != churn_task) |
2646 | GNUNET_SCHEDULER_cancel (churn_task); | 2700 | GNUNET_SCHEDULER_cancel (churn_task); |
2701 | post_test_task = GNUNET_SCHEDULER_add_delayed (timeout, &post_test_op, NULL); | ||
2702 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
2703 | (timeout_s * 1.2) + 0.1 * num_peers); | ||
2647 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); | 2704 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); |
2705 | shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); | ||
2706 | |||
2648 | } | 2707 | } |
2649 | 2708 | ||
2650 | 2709 | ||
@@ -2673,7 +2732,7 @@ main (int argc, char *argv[]) | |||
2673 | cur_test_run.stat_collect_flags = 0; | 2732 | cur_test_run.stat_collect_flags = 0; |
2674 | cur_test_run.have_collect_view = NO_COLLECT_VIEW; | 2733 | cur_test_run.have_collect_view = NO_COLLECT_VIEW; |
2675 | churn_task = NULL; | 2734 | churn_task = NULL; |
2676 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); | 2735 | timeout_s = 30; |
2677 | 2736 | ||
2678 | if (strstr (argv[0], "malicious") != NULL) | 2737 | if (strstr (argv[0], "malicious") != NULL) |
2679 | { | 2738 | { |
@@ -2725,7 +2784,7 @@ main (int argc, char *argv[]) | |||
2725 | cur_test_run.main_test = seed_big_cb; | 2784 | cur_test_run.main_test = seed_big_cb; |
2726 | cur_test_run.eval_cb = no_eval; | 2785 | cur_test_run.eval_cb = no_eval; |
2727 | cur_test_run.have_churn = HAVE_NO_CHURN; | 2786 | cur_test_run.have_churn = HAVE_NO_CHURN; |
2728 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); | 2787 | timeout_s = 10; |
2729 | } | 2788 | } |
2730 | 2789 | ||
2731 | else if (strstr (argv[0], "_single_peer_seed") != NULL) | 2790 | else if (strstr (argv[0], "_single_peer_seed") != NULL) |
@@ -2761,7 +2820,7 @@ main (int argc, char *argv[]) | |||
2761 | cur_test_run.main_test = req_cancel_cb; | 2820 | cur_test_run.main_test = req_cancel_cb; |
2762 | cur_test_run.eval_cb = no_eval; | 2821 | cur_test_run.eval_cb = no_eval; |
2763 | cur_test_run.have_churn = HAVE_NO_CHURN; | 2822 | cur_test_run.have_churn = HAVE_NO_CHURN; |
2764 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); | 2823 | timeout_s = 10; |
2765 | } | 2824 | } |
2766 | 2825 | ||
2767 | else if (strstr (argv[0], "_churn") != NULL) | 2826 | else if (strstr (argv[0], "_churn") != NULL) |
@@ -2775,7 +2834,7 @@ main (int argc, char *argv[]) | |||
2775 | cur_test_run.eval_cb = default_eval_cb; | 2834 | cur_test_run.eval_cb = default_eval_cb; |
2776 | cur_test_run.have_churn = HAVE_NO_CHURN; | 2835 | cur_test_run.have_churn = HAVE_NO_CHURN; |
2777 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; | 2836 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; |
2778 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); | 2837 | timeout_s = 10; |
2779 | } | 2838 | } |
2780 | 2839 | ||
2781 | else if (strstr (argv[0], "profiler") != NULL) | 2840 | else if (strstr (argv[0], "profiler") != NULL) |
@@ -2814,12 +2873,13 @@ main (int argc, char *argv[]) | |||
2814 | STAT_TYPE_RECV_PULL_REQ | | 2873 | STAT_TYPE_RECV_PULL_REQ | |
2815 | STAT_TYPE_RECV_PULL_REP; | 2874 | STAT_TYPE_RECV_PULL_REP; |
2816 | cur_test_run.have_collect_view = COLLECT_VIEW; | 2875 | cur_test_run.have_collect_view = COLLECT_VIEW; |
2817 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300); | 2876 | timeout_s = 150; |
2818 | 2877 | ||
2819 | /* 'Clean' directory */ | 2878 | /* 'Clean' directory */ |
2820 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); | 2879 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); |
2821 | GNUNET_DISK_directory_create ("/tmp/rps/"); | 2880 | GNUNET_DISK_directory_create ("/tmp/rps/"); |
2822 | } | 2881 | } |
2882 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s); | ||
2823 | 2883 | ||
2824 | rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); | 2884 | rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); |
2825 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); | 2885 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); |