aboutsummaryrefslogtreecommitdiff
path: root/src/rps/test_rps.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r--src/rps/test_rps.c108
1 files changed, 84 insertions, 24 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index bae28428f6..39aeacfebc 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -42,6 +42,12 @@ static uint32_t num_peers;
/**
* How long do we run the test?
+ * In seconds.
+ */
+static uint32_t timeout_s;
+
+/**
+ * How long do we run the test?
*/
//#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
static struct GNUNET_TIME_Relative timeout;
@@ -371,6 +377,11 @@ static int ok;
/**
* Identifier for the churn task that runs periodically
*/
+static struct GNUNET_SCHEDULER_Task *post_test_task;
+
+/**
+ * Identifier for the churn task that runs periodically
+ */
static struct GNUNET_SCHEDULER_Task *shutdown_task;
/**
@@ -556,6 +567,11 @@ struct SingleTestRun
} cur_test_run;
/**
+ * Did we finish the test?
+ */
+static int post_test;
+
+/**
* Are we shutting down?
*/
static int in_shutdown;
@@ -755,6 +771,41 @@ shutdown_op (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Shutdown task scheduled, going down.\n");
in_shutdown = GNUNET_YES;
+ if (NULL != post_test_task)
+ {
+ GNUNET_SCHEDULER_cancel (post_test_task);
+ }
+ if (NULL != churn_task)
+ {
+ GNUNET_SCHEDULER_cancel (churn_task);
+ churn_task = NULL;
+ }
+ for (i = 0; i < num_peers; i++)
+ {
+ if (NULL != rps_peers[i].rps_handle)
+ {
+ GNUNET_RPS_disconnect (rps_peers[i].rps_handle);
+ }
+ if (NULL != rps_peers[i].op)
+ {
+ GNUNET_TESTBED_operation_done (rps_peers[i].op);
+ }
+ }
+}
+
+
+/**
+ * Task run on timeout to collect statistics and potentially shut down.
+ */
+static void
+post_test_op (void *cls)
+{
+ unsigned int i;
+
+ post_test_task = NULL;
+ post_test = GNUNET_YES;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Post test task scheduled, going down.\n");
if (NULL != churn_task)
{
GNUNET_SCHEDULER_cancel (churn_task);
@@ -763,7 +814,10 @@ shutdown_op (void *cls)
for (i = 0; i < num_peers; i++)
{
if (NULL != rps_peers[i].op)
+ {
GNUNET_TESTBED_operation_done (rps_peers[i].op);
+ rps_peers[i].op = NULL;
+ }
if (NULL != cur_test_run.post_test)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i);
@@ -847,7 +901,7 @@ info_cb (void *cb_cls,
{
struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -901,7 +955,7 @@ rps_connect_complete_cb (void *cls,
struct RPSPeer *rps_peer = cls;
struct GNUNET_RPS_Handle *rps = ca_result;
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -1105,10 +1159,10 @@ default_reply_handle (void *cls,
if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n");
- GNUNET_assert (NULL != shutdown_task);
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL);
- GNUNET_assert (NULL!= shutdown_task);
+ GNUNET_assert (NULL != post_test_task);
+ GNUNET_SCHEDULER_cancel (post_test_task);
+ post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL);
+ GNUNET_assert (NULL!= post_test_task);
}
}
@@ -1122,7 +1176,7 @@ request_peers (void *cls)
struct RPSPeer *rps_peer;
struct PendingReply *pending_rep;
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
return;
rps_peer = pending_req->rps_peer;
GNUNET_assert (1 <= rps_peer->num_pending_reqs);
@@ -1185,7 +1239,7 @@ cancel_request_cb (void *cls)
struct RPSPeer *rps_peer = cls;
struct PendingReply *pending_rep;
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
return;
pending_rep = rps_peer->pending_rep_head;
GNUNET_assert (1 <= rps_peer->num_pending_reps);
@@ -1290,7 +1344,7 @@ mal_cb (struct RPSPeer *rps_peer)
{
uint32_t num_mal_peers;
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -1317,7 +1371,7 @@ mal_cb (struct RPSPeer *rps_peer)
static void
single_req_cb (struct RPSPeer *rps_peer)
{
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -1331,7 +1385,7 @@ single_req_cb (struct RPSPeer *rps_peer)
static void
delay_req_cb (struct RPSPeer *rps_peer)
{
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -1345,7 +1399,7 @@ delay_req_cb (struct RPSPeer *rps_peer)
static void
seed_cb (struct RPSPeer *rps_peer)
{
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -1361,7 +1415,7 @@ seed_cb (struct RPSPeer *rps_peer)
static void
seed_big_cb (struct RPSPeer *rps_peer)
{
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -1387,7 +1441,7 @@ single_peer_seed_cb (struct RPSPeer *rps_peer)
static void
seed_req_cb (struct RPSPeer *rps_peer)
{
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -1406,7 +1460,7 @@ seed_req_cb (struct RPSPeer *rps_peer)
static void
req_cancel_cb (struct RPSPeer *rps_peer)
{
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -1439,7 +1493,7 @@ churn (void *cls);
static void
churn_test_cb (struct RPSPeer *rps_peer)
{
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -1480,7 +1534,7 @@ churn_cb (void *cls,
// FIXME
struct OpListEntry *entry = cls;
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -1615,7 +1669,7 @@ churn (void *cls)
double portion_go_online;
double portion_go_offline;
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -1731,7 +1785,7 @@ profiler_reply_handle (void *cls,
static void
profiler_cb (struct RPSPeer *rps_peer)
{
- if (GNUNET_YES == in_shutdown)
+ if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
{
return;
}
@@ -2644,7 +2698,12 @@ run (void *cls,
if (NULL != churn_task)
GNUNET_SCHEDULER_cancel (churn_task);
+ post_test_task = GNUNET_SCHEDULER_add_delayed (timeout, &post_test_op, NULL);
+ timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ (timeout_s * 1.2) + 0.1 * num_peers);
shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL);
+
}
@@ -2673,7 +2732,7 @@ main (int argc, char *argv[])
cur_test_run.stat_collect_flags = 0;
cur_test_run.have_collect_view = NO_COLLECT_VIEW;
churn_task = NULL;
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
+ timeout_s = 30;
if (strstr (argv[0], "malicious") != NULL)
{
@@ -2725,7 +2784,7 @@ main (int argc, char *argv[])
cur_test_run.main_test = seed_big_cb;
cur_test_run.eval_cb = no_eval;
cur_test_run.have_churn = HAVE_NO_CHURN;
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
+ timeout_s = 10;
}
else if (strstr (argv[0], "_single_peer_seed") != NULL)
@@ -2761,7 +2820,7 @@ main (int argc, char *argv[])
cur_test_run.main_test = req_cancel_cb;
cur_test_run.eval_cb = no_eval;
cur_test_run.have_churn = HAVE_NO_CHURN;
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
+ timeout_s = 10;
}
else if (strstr (argv[0], "_churn") != NULL)
@@ -2775,7 +2834,7 @@ main (int argc, char *argv[])
cur_test_run.eval_cb = default_eval_cb;
cur_test_run.have_churn = HAVE_NO_CHURN;
cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
+ timeout_s = 10;
}
else if (strstr (argv[0], "profiler") != NULL)
@@ -2814,12 +2873,13 @@ main (int argc, char *argv[])
STAT_TYPE_RECV_PULL_REQ |
STAT_TYPE_RECV_PULL_REP;
cur_test_run.have_collect_view = COLLECT_VIEW;
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300);
+ timeout_s = 150;
/* 'Clean' directory */
(void) GNUNET_DISK_directory_remove ("/tmp/rps/");
GNUNET_DISK_directory_create ("/tmp/rps/");
}
+ timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s);
rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);