diff options
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r-- | src/rps/test_rps.c | 126 |
1 files changed, 92 insertions, 34 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index bae28428f..3ef1e6611 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2012 GNUnet e.V. | 3 | Copyright (C) 2009, 2012 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file rps/test_rps.c | 19 | * @file rps/test_rps.c |
@@ -42,6 +40,12 @@ static uint32_t num_peers; | |||
42 | 40 | ||
43 | /** | 41 | /** |
44 | * How long do we run the test? | 42 | * How long do we run the test? |
43 | * In seconds. | ||
44 | */ | ||
45 | static uint32_t timeout_s; | ||
46 | |||
47 | /** | ||
48 | * How long do we run the test? | ||
45 | */ | 49 | */ |
46 | //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 50 | //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
47 | static struct GNUNET_TIME_Relative timeout; | 51 | static struct GNUNET_TIME_Relative timeout; |
@@ -371,6 +375,11 @@ static int ok; | |||
371 | /** | 375 | /** |
372 | * Identifier for the churn task that runs periodically | 376 | * Identifier for the churn task that runs periodically |
373 | */ | 377 | */ |
378 | static struct GNUNET_SCHEDULER_Task *post_test_task; | ||
379 | |||
380 | /** | ||
381 | * Identifier for the churn task that runs periodically | ||
382 | */ | ||
374 | static struct GNUNET_SCHEDULER_Task *shutdown_task; | 383 | static struct GNUNET_SCHEDULER_Task *shutdown_task; |
375 | 384 | ||
376 | /** | 385 | /** |
@@ -556,6 +565,11 @@ struct SingleTestRun | |||
556 | } cur_test_run; | 565 | } cur_test_run; |
557 | 566 | ||
558 | /** | 567 | /** |
568 | * Did we finish the test? | ||
569 | */ | ||
570 | static int post_test; | ||
571 | |||
572 | /** | ||
559 | * Are we shutting down? | 573 | * Are we shutting down? |
560 | */ | 574 | */ |
561 | static int in_shutdown; | 575 | static int in_shutdown; |
@@ -755,6 +769,10 @@ shutdown_op (void *cls) | |||
755 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 769 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
756 | "Shutdown task scheduled, going down.\n"); | 770 | "Shutdown task scheduled, going down.\n"); |
757 | in_shutdown = GNUNET_YES; | 771 | in_shutdown = GNUNET_YES; |
772 | if (NULL != post_test_task) | ||
773 | { | ||
774 | GNUNET_SCHEDULER_cancel (post_test_task); | ||
775 | } | ||
758 | if (NULL != churn_task) | 776 | if (NULL != churn_task) |
759 | { | 777 | { |
760 | GNUNET_SCHEDULER_cancel (churn_task); | 778 | GNUNET_SCHEDULER_cancel (churn_task); |
@@ -762,8 +780,42 @@ shutdown_op (void *cls) | |||
762 | } | 780 | } |
763 | for (i = 0; i < num_peers; i++) | 781 | for (i = 0; i < num_peers; i++) |
764 | { | 782 | { |
783 | if (NULL != rps_peers[i].rps_handle) | ||
784 | { | ||
785 | GNUNET_RPS_disconnect (rps_peers[i].rps_handle); | ||
786 | } | ||
765 | if (NULL != rps_peers[i].op) | 787 | if (NULL != rps_peers[i].op) |
788 | { | ||
766 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | 789 | GNUNET_TESTBED_operation_done (rps_peers[i].op); |
790 | } | ||
791 | } | ||
792 | } | ||
793 | |||
794 | |||
795 | /** | ||
796 | * Task run on timeout to collect statistics and potentially shut down. | ||
797 | */ | ||
798 | static void | ||
799 | post_test_op (void *cls) | ||
800 | { | ||
801 | unsigned int i; | ||
802 | |||
803 | post_test_task = NULL; | ||
804 | post_test = GNUNET_YES; | ||
805 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
806 | "Post test task scheduled, going down.\n"); | ||
807 | if (NULL != churn_task) | ||
808 | { | ||
809 | GNUNET_SCHEDULER_cancel (churn_task); | ||
810 | churn_task = NULL; | ||
811 | } | ||
812 | for (i = 0; i < num_peers; i++) | ||
813 | { | ||
814 | if (NULL != rps_peers[i].op) | ||
815 | { | ||
816 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | ||
817 | rps_peers[i].op = NULL; | ||
818 | } | ||
767 | if (NULL != cur_test_run.post_test) | 819 | if (NULL != cur_test_run.post_test) |
768 | { | 820 | { |
769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); | 821 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); |
@@ -847,7 +899,7 @@ info_cb (void *cb_cls, | |||
847 | { | 899 | { |
848 | struct OpListEntry *entry = (struct OpListEntry *) cb_cls; | 900 | struct OpListEntry *entry = (struct OpListEntry *) cb_cls; |
849 | 901 | ||
850 | if (GNUNET_YES == in_shutdown) | 902 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
851 | { | 903 | { |
852 | return; | 904 | return; |
853 | } | 905 | } |
@@ -901,7 +953,7 @@ rps_connect_complete_cb (void *cls, | |||
901 | struct RPSPeer *rps_peer = cls; | 953 | struct RPSPeer *rps_peer = cls; |
902 | struct GNUNET_RPS_Handle *rps = ca_result; | 954 | struct GNUNET_RPS_Handle *rps = ca_result; |
903 | 955 | ||
904 | if (GNUNET_YES == in_shutdown) | 956 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
905 | { | 957 | { |
906 | return; | 958 | return; |
907 | } | 959 | } |
@@ -1105,10 +1157,10 @@ default_reply_handle (void *cls, | |||
1105 | if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) | 1157 | if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) |
1106 | { | 1158 | { |
1107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); | 1159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); |
1108 | GNUNET_assert (NULL != shutdown_task); | 1160 | GNUNET_assert (NULL != post_test_task); |
1109 | GNUNET_SCHEDULER_cancel (shutdown_task); | 1161 | GNUNET_SCHEDULER_cancel (post_test_task); |
1110 | shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL); | 1162 | post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); |
1111 | GNUNET_assert (NULL!= shutdown_task); | 1163 | GNUNET_assert (NULL!= post_test_task); |
1112 | } | 1164 | } |
1113 | } | 1165 | } |
1114 | 1166 | ||
@@ -1122,7 +1174,7 @@ request_peers (void *cls) | |||
1122 | struct RPSPeer *rps_peer; | 1174 | struct RPSPeer *rps_peer; |
1123 | struct PendingReply *pending_rep; | 1175 | struct PendingReply *pending_rep; |
1124 | 1176 | ||
1125 | if (GNUNET_YES == in_shutdown) | 1177 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1126 | return; | 1178 | return; |
1127 | rps_peer = pending_req->rps_peer; | 1179 | rps_peer = pending_req->rps_peer; |
1128 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); | 1180 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); |
@@ -1185,7 +1237,7 @@ cancel_request_cb (void *cls) | |||
1185 | struct RPSPeer *rps_peer = cls; | 1237 | struct RPSPeer *rps_peer = cls; |
1186 | struct PendingReply *pending_rep; | 1238 | struct PendingReply *pending_rep; |
1187 | 1239 | ||
1188 | if (GNUNET_YES == in_shutdown) | 1240 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1189 | return; | 1241 | return; |
1190 | pending_rep = rps_peer->pending_rep_head; | 1242 | pending_rep = rps_peer->pending_rep_head; |
1191 | GNUNET_assert (1 <= rps_peer->num_pending_reps); | 1243 | GNUNET_assert (1 <= rps_peer->num_pending_reps); |
@@ -1290,7 +1342,7 @@ mal_cb (struct RPSPeer *rps_peer) | |||
1290 | { | 1342 | { |
1291 | uint32_t num_mal_peers; | 1343 | uint32_t num_mal_peers; |
1292 | 1344 | ||
1293 | if (GNUNET_YES == in_shutdown) | 1345 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1294 | { | 1346 | { |
1295 | return; | 1347 | return; |
1296 | } | 1348 | } |
@@ -1317,7 +1369,7 @@ mal_cb (struct RPSPeer *rps_peer) | |||
1317 | static void | 1369 | static void |
1318 | single_req_cb (struct RPSPeer *rps_peer) | 1370 | single_req_cb (struct RPSPeer *rps_peer) |
1319 | { | 1371 | { |
1320 | if (GNUNET_YES == in_shutdown) | 1372 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1321 | { | 1373 | { |
1322 | return; | 1374 | return; |
1323 | } | 1375 | } |
@@ -1331,7 +1383,7 @@ single_req_cb (struct RPSPeer *rps_peer) | |||
1331 | static void | 1383 | static void |
1332 | delay_req_cb (struct RPSPeer *rps_peer) | 1384 | delay_req_cb (struct RPSPeer *rps_peer) |
1333 | { | 1385 | { |
1334 | if (GNUNET_YES == in_shutdown) | 1386 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1335 | { | 1387 | { |
1336 | return; | 1388 | return; |
1337 | } | 1389 | } |
@@ -1345,7 +1397,7 @@ delay_req_cb (struct RPSPeer *rps_peer) | |||
1345 | static void | 1397 | static void |
1346 | seed_cb (struct RPSPeer *rps_peer) | 1398 | seed_cb (struct RPSPeer *rps_peer) |
1347 | { | 1399 | { |
1348 | if (GNUNET_YES == in_shutdown) | 1400 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1349 | { | 1401 | { |
1350 | return; | 1402 | return; |
1351 | } | 1403 | } |
@@ -1361,7 +1413,7 @@ seed_cb (struct RPSPeer *rps_peer) | |||
1361 | static void | 1413 | static void |
1362 | seed_big_cb (struct RPSPeer *rps_peer) | 1414 | seed_big_cb (struct RPSPeer *rps_peer) |
1363 | { | 1415 | { |
1364 | if (GNUNET_YES == in_shutdown) | 1416 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1365 | { | 1417 | { |
1366 | return; | 1418 | return; |
1367 | } | 1419 | } |
@@ -1387,7 +1439,7 @@ single_peer_seed_cb (struct RPSPeer *rps_peer) | |||
1387 | static void | 1439 | static void |
1388 | seed_req_cb (struct RPSPeer *rps_peer) | 1440 | seed_req_cb (struct RPSPeer *rps_peer) |
1389 | { | 1441 | { |
1390 | if (GNUNET_YES == in_shutdown) | 1442 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1391 | { | 1443 | { |
1392 | return; | 1444 | return; |
1393 | } | 1445 | } |
@@ -1406,7 +1458,7 @@ seed_req_cb (struct RPSPeer *rps_peer) | |||
1406 | static void | 1458 | static void |
1407 | req_cancel_cb (struct RPSPeer *rps_peer) | 1459 | req_cancel_cb (struct RPSPeer *rps_peer) |
1408 | { | 1460 | { |
1409 | if (GNUNET_YES == in_shutdown) | 1461 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1410 | { | 1462 | { |
1411 | return; | 1463 | return; |
1412 | } | 1464 | } |
@@ -1439,7 +1491,7 @@ churn (void *cls); | |||
1439 | static void | 1491 | static void |
1440 | churn_test_cb (struct RPSPeer *rps_peer) | 1492 | churn_test_cb (struct RPSPeer *rps_peer) |
1441 | { | 1493 | { |
1442 | if (GNUNET_YES == in_shutdown) | 1494 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1443 | { | 1495 | { |
1444 | return; | 1496 | return; |
1445 | } | 1497 | } |
@@ -1480,7 +1532,7 @@ churn_cb (void *cls, | |||
1480 | // FIXME | 1532 | // FIXME |
1481 | struct OpListEntry *entry = cls; | 1533 | struct OpListEntry *entry = cls; |
1482 | 1534 | ||
1483 | if (GNUNET_YES == in_shutdown) | 1535 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1484 | { | 1536 | { |
1485 | return; | 1537 | return; |
1486 | } | 1538 | } |
@@ -1615,7 +1667,7 @@ churn (void *cls) | |||
1615 | double portion_go_online; | 1667 | double portion_go_online; |
1616 | double portion_go_offline; | 1668 | double portion_go_offline; |
1617 | 1669 | ||
1618 | if (GNUNET_YES == in_shutdown) | 1670 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1619 | { | 1671 | { |
1620 | return; | 1672 | return; |
1621 | } | 1673 | } |
@@ -1731,7 +1783,7 @@ profiler_reply_handle (void *cls, | |||
1731 | static void | 1783 | static void |
1732 | profiler_cb (struct RPSPeer *rps_peer) | 1784 | profiler_cb (struct RPSPeer *rps_peer) |
1733 | { | 1785 | { |
1734 | if (GNUNET_YES == in_shutdown) | 1786 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1735 | { | 1787 | { |
1736 | return; | 1788 | return; |
1737 | } | 1789 | } |
@@ -2644,7 +2696,12 @@ run (void *cls, | |||
2644 | 2696 | ||
2645 | if (NULL != churn_task) | 2697 | if (NULL != churn_task) |
2646 | GNUNET_SCHEDULER_cancel (churn_task); | 2698 | GNUNET_SCHEDULER_cancel (churn_task); |
2699 | post_test_task = GNUNET_SCHEDULER_add_delayed (timeout, &post_test_op, NULL); | ||
2700 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
2701 | (timeout_s * 1.2) + 0.1 * num_peers); | ||
2647 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); | 2702 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); |
2703 | shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); | ||
2704 | |||
2648 | } | 2705 | } |
2649 | 2706 | ||
2650 | 2707 | ||
@@ -2673,7 +2730,7 @@ main (int argc, char *argv[]) | |||
2673 | cur_test_run.stat_collect_flags = 0; | 2730 | cur_test_run.stat_collect_flags = 0; |
2674 | cur_test_run.have_collect_view = NO_COLLECT_VIEW; | 2731 | cur_test_run.have_collect_view = NO_COLLECT_VIEW; |
2675 | churn_task = NULL; | 2732 | churn_task = NULL; |
2676 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); | 2733 | timeout_s = 30; |
2677 | 2734 | ||
2678 | if (strstr (argv[0], "malicious") != NULL) | 2735 | if (strstr (argv[0], "malicious") != NULL) |
2679 | { | 2736 | { |
@@ -2725,7 +2782,7 @@ main (int argc, char *argv[]) | |||
2725 | cur_test_run.main_test = seed_big_cb; | 2782 | cur_test_run.main_test = seed_big_cb; |
2726 | cur_test_run.eval_cb = no_eval; | 2783 | cur_test_run.eval_cb = no_eval; |
2727 | cur_test_run.have_churn = HAVE_NO_CHURN; | 2784 | cur_test_run.have_churn = HAVE_NO_CHURN; |
2728 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); | 2785 | timeout_s = 10; |
2729 | } | 2786 | } |
2730 | 2787 | ||
2731 | else if (strstr (argv[0], "_single_peer_seed") != NULL) | 2788 | else if (strstr (argv[0], "_single_peer_seed") != NULL) |
@@ -2761,7 +2818,7 @@ main (int argc, char *argv[]) | |||
2761 | cur_test_run.main_test = req_cancel_cb; | 2818 | cur_test_run.main_test = req_cancel_cb; |
2762 | cur_test_run.eval_cb = no_eval; | 2819 | cur_test_run.eval_cb = no_eval; |
2763 | cur_test_run.have_churn = HAVE_NO_CHURN; | 2820 | cur_test_run.have_churn = HAVE_NO_CHURN; |
2764 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); | 2821 | timeout_s = 10; |
2765 | } | 2822 | } |
2766 | 2823 | ||
2767 | else if (strstr (argv[0], "_churn") != NULL) | 2824 | else if (strstr (argv[0], "_churn") != NULL) |
@@ -2775,7 +2832,7 @@ main (int argc, char *argv[]) | |||
2775 | cur_test_run.eval_cb = default_eval_cb; | 2832 | cur_test_run.eval_cb = default_eval_cb; |
2776 | cur_test_run.have_churn = HAVE_NO_CHURN; | 2833 | cur_test_run.have_churn = HAVE_NO_CHURN; |
2777 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; | 2834 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; |
2778 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); | 2835 | timeout_s = 10; |
2779 | } | 2836 | } |
2780 | 2837 | ||
2781 | else if (strstr (argv[0], "profiler") != NULL) | 2838 | else if (strstr (argv[0], "profiler") != NULL) |
@@ -2814,12 +2871,13 @@ main (int argc, char *argv[]) | |||
2814 | STAT_TYPE_RECV_PULL_REQ | | 2871 | STAT_TYPE_RECV_PULL_REQ | |
2815 | STAT_TYPE_RECV_PULL_REP; | 2872 | STAT_TYPE_RECV_PULL_REP; |
2816 | cur_test_run.have_collect_view = COLLECT_VIEW; | 2873 | cur_test_run.have_collect_view = COLLECT_VIEW; |
2817 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300); | 2874 | timeout_s = 150; |
2818 | 2875 | ||
2819 | /* 'Clean' directory */ | 2876 | /* 'Clean' directory */ |
2820 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); | 2877 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); |
2821 | GNUNET_DISK_directory_create ("/tmp/rps/"); | 2878 | GNUNET_DISK_directory_create ("/tmp/rps/"); |
2822 | } | 2879 | } |
2880 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s); | ||
2823 | 2881 | ||
2824 | rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); | 2882 | rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); |
2825 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); | 2883 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); |