summaryrefslogtreecommitdiff
path: root/src/rps/test_rps.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-08-02 14:48:32 +0000
committerJulius Bünger <buenger@mytum.de>2015-08-02 14:48:32 +0000
commitad63b02064fb479339eb6cadff25923cebd730ff (patch)
tree39d00bf0803edf32eab59db25b7abaaf69df5412 /src/rps/test_rps.c
parent0003886059ee5fc76b17e268efd289b0503cd185 (diff)
downloadgnunet-ad63b02064fb479339eb6cadff25923cebd730ff.tar.gz
gnunet-ad63b02064fb479339eb6cadff25923cebd730ff.zip
-improved testing
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r--src/rps/test_rps.c69
1 files changed, 39 insertions, 30 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index 4a4a9ee1a..3d3853d64 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -267,6 +267,11 @@ static int ok;
267 */ 267 */
268static struct GNUNET_SCHEDULER_Task *churn_task; 268static struct GNUNET_SCHEDULER_Task *churn_task;
269 269
270/**
271 * Identifier for the churn task that runs periodically
272 */
273static struct GNUNET_SCHEDULER_Task *shutdown_task;
274
270 275
271/** 276/**
272 * Called to initialise the given RPSPeer 277 * Called to initialise the given RPSPeer
@@ -453,25 +458,23 @@ ids_to_file (char *file_name,
453 * Test the success of a single test 458 * Test the success of a single test
454 */ 459 */
455static int 460static int
456evaluate (struct RPSPeer *loc_rps_peers, 461evaluate (void)
457 unsigned int num_loc_rps_peers,
458 unsigned int expected_recv)
459{ 462{
460 unsigned int i; 463 unsigned int i;
461 int tmp_ok; 464 int tmp_ok;
462 465
463 tmp_ok = (1 == loc_rps_peers[0].num_rec_ids); 466 tmp_ok = 1;
464 467
465 for (i = 0 ; i < num_loc_rps_peers ; i++) 468 for (i = 0; i < num_peers; i++)
466 { 469 {
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "%u. peer [%s] received %u of %u expected peer_ids: %i\n", 471 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
469 i, 472 i,
470 GNUNET_i2s (loc_rps_peers[i].peer_id), 473 GNUNET_i2s (rps_peers[i].peer_id),
471 loc_rps_peers[i].num_rec_ids, 474 rps_peers[i].num_rec_ids,
472 expected_recv, 475 rps_peers[i].num_ids_to_request,
473 (1 == loc_rps_peers[i].num_rec_ids)); 476 (rps_peers[i].num_ids_to_request == rps_peers[i].num_rec_ids));
474 tmp_ok &= (1 == loc_rps_peers[i].num_rec_ids); 477 tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_rec_ids);
475 } 478 }
476 return tmp_ok? 0 : 1; 479 return tmp_ok? 0 : 1;
477} 480}
@@ -495,7 +498,7 @@ make_oplist_entry ()
495 * Task run on timeout to shut everything down. 498 * Task run on timeout to shut everything down.
496 */ 499 */
497static void 500static void
498shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 501shutdown_op (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
499{ 502{
500 unsigned int i; 503 unsigned int i;
501 504
@@ -650,7 +653,7 @@ rps_connect_adapter (void *cls,
650 */ 653 */
651static void 654static void
652rps_disconnect_adapter (void *cls, 655rps_disconnect_adapter (void *cls,
653 void *op_result) 656 void *op_result)
654{ 657{
655 struct GNUNET_RPS_Handle *h = op_result; 658 struct GNUNET_RPS_Handle *h = op_result;
656 GNUNET_RPS_disconnect (h); 659 GNUNET_RPS_disconnect (h);
@@ -665,7 +668,7 @@ rps_disconnect_adapter (void *cls,
665static int 668static int
666default_eval_cb (void) 669default_eval_cb (void)
667{ 670{
668 return evaluate (rps_peers, num_peers, 1); 671 return evaluate ();
669} 672}
670 673
671static int 674static int
@@ -708,7 +711,7 @@ default_reply_handle (void *cls,
708 GNUNET_i2s (rps_peer->peer_id), 711 GNUNET_i2s (rps_peer->peer_id),
709 n); 712 n);
710 713
711 for (i = 0 ; i < n ; i++) 714 for (i = 0; i < n; i++)
712 { 715 {
713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
714 "%u: %s\n", 717 "%u: %s\n",
@@ -717,6 +720,12 @@ default_reply_handle (void *cls,
717 720
718 GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); 721 GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]);
719 } 722 }
723
724 if (0 == evaluate ())
725 {
726 GNUNET_SCHEDULER_cancel (shutdown_task);
727 shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL);
728 }
720} 729}
721 730
722/** 731/**
@@ -843,6 +852,16 @@ cancel_pending_req_rep (struct RPSPeer *rps_peer)
843/*********************************** 852/***********************************
844 * MALICIOUS 853 * MALICIOUS
845***********************************/ 854***********************************/
855
856/**
857 * Initialise only non-mal RPSPeers
858 */
859static void mal_init_peer (struct RPSPeer *rps_peer)
860{
861 if (rps_peer->index >= round (portion * num_peers))
862 rps_peer->num_ids_to_request = 1;
863}
864
846static void 865static void
847mal_pre (void *cls, struct GNUNET_RPS_Handle *h) 866mal_pre (void *cls, struct GNUNET_RPS_Handle *h)
848{ 867{
@@ -888,17 +907,6 @@ mal_cb (struct RPSPeer *rps_peer)
888 #endif /* ENABLE_MALICIOUS */ 907 #endif /* ENABLE_MALICIOUS */
889} 908}
890 909
891static int
892mal_eval (void)
893{
894 unsigned int num_mal_peers;
895
896 num_mal_peers = round (num_peers * portion);
897 return evaluate (&rps_peers[num_mal_peers],
898 num_peers - (num_mal_peers),
899 1);
900}
901
902 910
903/*********************************** 911/***********************************
904 * SINGLE_REQUEST 912 * SINGLE_REQUEST
@@ -1270,7 +1278,7 @@ profiler_eval (void)
1270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); 1278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
1271 } 1279 }
1272 1280
1273 return 0; 1281 return evaluate ();
1274} 1282}
1275 1283
1276 1284
@@ -1331,7 +1339,7 @@ run (void *cls,
1331 1339
1332 if (NULL != churn_task) 1340 if (NULL != churn_task)
1333 GNUNET_SCHEDULER_cancel (churn_task); 1341 GNUNET_SCHEDULER_cancel (churn_task);
1334 GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL); 1342 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
1335} 1343}
1336 1344
1337 1345
@@ -1360,7 +1368,7 @@ main (int argc, char *argv[])
1360 { 1368 {
1361 cur_test_run.pre_test = mal_pre; 1369 cur_test_run.pre_test = mal_pre;
1362 cur_test_run.main_test = mal_cb; 1370 cur_test_run.main_test = mal_cb;
1363 cur_test_run.eval_cb = mal_eval; 1371 cur_test_run.init_peer = mal_init_peer;
1364 1372
1365 if (strstr (argv[0], "_1") != NULL) 1373 if (strstr (argv[0], "_1") != NULL)
1366 { 1374 {
@@ -1432,6 +1440,7 @@ main (int argc, char *argv[])
1432 num_peers = 1; 1440 num_peers = 1;
1433 cur_test_run.main_test = req_cancel_cb; 1441 cur_test_run.main_test = req_cancel_cb;
1434 cur_test_run.eval_cb = no_eval; 1442 cur_test_run.eval_cb = no_eval;
1443 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1435 } 1444 }
1436 1445
1437 else if (strstr (argv[0], "profiler") != NULL) 1446 else if (strstr (argv[0], "profiler") != NULL)