gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated: rps: split tests and profil


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: rps: split tests and profiler, proper shutdown
Date: Wed, 06 Jun 2018 00:34:17 +0200

This is an automated email from the git hooks/post-receive script.

julius-buenger pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new d15b9286c rps: split tests and profiler, proper shutdown
d15b9286c is described below

commit d15b9286cbaa6f56299f9064d269d3a1aa1ddee4
Author: Julius Bünger <address@hidden>
AuthorDate: Wed Jun 6 00:33:56 2018 +0200

    rps: split tests and profiler, proper shutdown
---
 src/rps/Makefile.am                           |  16 +-
 src/rps/{test_rps.c => gnunet-rps-profiler.c} | 551 +++++++++-----------------
 src/rps/test_rps.c                            | 108 +++--
 src/rps/test_rps.conf                         |   2 +-
 4 files changed, 288 insertions(+), 389 deletions(-)

diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am
index b5f712268..aa354dff7 100644
--- a/src/rps/Makefile.am
+++ b/src/rps/Makefile.am
@@ -83,17 +83,17 @@ check_PROGRAMS = \
  test_rps_churn
 endif
 
+rps_test_src = \
+       test_rps.c \
+       rps-test_util.h rps-test_util.c \
+ gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c
+
 ld_rps_test_lib = \
        libgnunetrps.la \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(top_builddir)/src/testbed/libgnunettestbed.la \
   -lm
 
-rps_test_src = \
-       test_rps.c \
-       rps-test_util.h rps-test_util.c \
- gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c
-
 if ENABLE_TEST_RUN
 AM_TESTS_ENVIRONMENT=export 
GNUNET_PREFIX=$${GNUNET_PREFIX:address@hidden@};export 
PATH=$${GNUNET_PREFIX:address@hidden@}/bin:$$PATH;unset XDG_DATA_HOME;unset 
XDG_CONFIG_HOME;
 TESTS = $(check_PROGRAMS)
@@ -143,7 +143,11 @@ test_rps_churn_LDADD = $(ld_rps_test_lib)
 gnunet_rps_profiler_SOURCES = $(rps_test_src)
 gnunet_rps_profiler_LDADD = \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
-  $(ld_rps_test_lib)
+  libgnunetrps.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/testbed/libgnunettestbed.la \
+  -lm
+
 
 EXTRA_DIST = \
   test_rps.conf
diff --git a/src/rps/test_rps.c b/src/rps/gnunet-rps-profiler.c
similarity index 86%
copy from src/rps/test_rps.c
copy to src/rps/gnunet-rps-profiler.c
index bae28428f..1ad9deabb 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/gnunet-rps-profiler.c
@@ -25,6 +25,7 @@
  *        for one message from each peer.
  */
 #include "platform.h"
+//#include "rps_test_lib.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_testbed_service.h"
 
@@ -42,6 +43,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 +378,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 +568,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 +772,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 +815,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);
@@ -803,40 +858,6 @@ seed_peers (void *cls)
 
 
 /**
- * Seed peers.
- */
-static void
-seed_peers_big (void *cls)
-{
-  struct RPSPeer *peer = cls;
-  unsigned int seed_msg_size;
-  uint32_t num_peers_max;
-  unsigned int amount;
-  unsigned int i;
-
-  seed_msg_size = 8; /* sizeof (struct GNUNET_RPS_CS_SeedMessage) */
-  num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - seed_msg_size) /
-    sizeof (struct GNUNET_PeerIdentity);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-      "Peers that fit in one seed msg; %u\n",
-      num_peers_max);
-  amount = num_peers_max + (0.5 * num_peers_max);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-      "Seeding many (%u) peers:\n",
-      amount);
-  struct GNUNET_PeerIdentity ids_to_seed[amount];
-  for (i = 0; i < amount; i++)
-  {
-    ids_to_seed[i] = *peer->peer_id;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
-                i,
-                GNUNET_i2s (&ids_to_seed[i]));
-  }
-
-  GNUNET_RPS_seed_ids (peer->rps_handle, amount, ids_to_seed);
-}
-
-/**
  * Get the id of peer i.
  */
   void
@@ -847,7 +868,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 +922,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;
   }
@@ -1035,6 +1056,8 @@ rps_disconnect_adapter (void *cls,
 {
   struct RPSPeer *peer = cls;
   struct GNUNET_RPS_Handle *h = op_result;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnect_adapter()\n");
   GNUNET_assert (NULL != peer);
   GNUNET_RPS_disconnect (h);
   peer->rps_handle = NULL;
@@ -1045,27 +1068,6 @@ rps_disconnect_adapter (void *cls,
  * Definition of tests
 ***********************************************************************/
 
-// TODO check whether tests can be stopped earlier
-static int
-default_eval_cb (void)
-{
-  return evaluate ();
-}
-
-static int
-no_eval (void)
-{
-  return 0;
-}
-
-/**
- * Initialise given RPSPeer
- */
-static void default_init_peer (struct RPSPeer *rps_peer)
-{
-  rps_peer->num_ids_to_request = 1;
-}
-
 /**
  * Callback to call on receipt of a reply
  *
@@ -1105,10 +1107,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 +1124,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);
@@ -1176,22 +1178,6 @@ cancel_request (struct PendingReply *pending_rep)
   GNUNET_free (pending_rep);
 }
 
-/**
- * Cancel a request.
- */
-static void
-cancel_request_cb (void *cls)
-{
-  struct RPSPeer *rps_peer = cls;
-  struct PendingReply *pending_rep;
-
-  if (GNUNET_YES == in_shutdown)
-    return;
-  pending_rep = rps_peer->pending_rep_head;
-  GNUNET_assert (1 <= rps_peer->num_pending_reps);
-  cancel_request (pending_rep);
-}
-
 
 /**
  * Schedule requests for peer @a rps_peer that have neither been scheduled, nor
@@ -1290,7 +1276,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;
   }
@@ -1310,114 +1296,6 @@ mal_cb (struct RPSPeer *rps_peer)
   #endif /* ENABLE_MALICIOUS */
 }
 
-
-/***********************************
- * SINGLE_REQUEST
-***********************************/
-static void
-single_req_cb (struct RPSPeer *rps_peer)
-{
-  if (GNUNET_YES == in_shutdown)
-  {
-    return;
-  }
-
-  schedule_missing_requests (rps_peer);
-}
-
-/***********************************
- * DELAYED_REQUESTS
-***********************************/
-static void
-delay_req_cb (struct RPSPeer *rps_peer)
-{
-  if (GNUNET_YES == in_shutdown)
-  {
-    return;
-  }
-
-  schedule_missing_requests (rps_peer);
-}
-
-/***********************************
- * SEED
-***********************************/
-static void
-seed_cb (struct RPSPeer *rps_peer)
-{
-  if (GNUNET_YES == in_shutdown)
-  {
-    return;
-  }
-
-  GNUNET_SCHEDULER_add_delayed (
-      GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
-      seed_peers, rps_peer);
-}
-
-/***********************************
- * SEED_BIG
-***********************************/
-static void
-seed_big_cb (struct RPSPeer *rps_peer)
-{
-  if (GNUNET_YES == in_shutdown)
-  {
-    return;
-  }
-
-  // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers
-  GNUNET_SCHEDULER_add_delayed (
-      GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
-      seed_peers_big, rps_peer);
-}
-
-/***********************************
- * SINGLE_PEER_SEED
-***********************************/
-static void
-single_peer_seed_cb (struct RPSPeer *rps_peer)
-{
-  // TODO
-}
-
-/***********************************
- * SEED_REQUEST
-***********************************/
-static void
-seed_req_cb (struct RPSPeer *rps_peer)
-{
-  if (GNUNET_YES == in_shutdown)
-  {
-    return;
-  }
-
-  GNUNET_SCHEDULER_add_delayed (
-      GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
-      seed_peers, rps_peer);
-  schedule_missing_requests (rps_peer);
-}
-
-//TODO start big mal
-
-/***********************************
- * REQUEST_CANCEL
-***********************************/
-static void
-req_cancel_cb (struct RPSPeer *rps_peer)
-{
-  if (GNUNET_YES == in_shutdown)
-  {
-    return;
-  }
-
-  schedule_missing_requests (rps_peer);
-  GNUNET_SCHEDULER_add_delayed (
-      GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
-                                     (cur_test_run.request_interval + 1)),
-      cancel_request_cb, rps_peer);
-}
-
 /***********************************
  * CHURN
 ***********************************/
@@ -1439,7 +1317,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 +1358,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 +1493,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;
   }
@@ -1679,7 +1557,13 @@ churn (void *cls)
 static void profiler_init_peer (struct RPSPeer *rps_peer)
 {
   if (num_peers - 1 == rps_peer->index)
+  {
     rps_peer->num_ids_to_request = cur_test_run.num_requests;
+  } else {
+    rps_peer->num_ids_to_request = 0;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n",
+              rps_peer->num_ids_to_request);
 }
 
 
@@ -1699,12 +1583,15 @@ profiler_reply_handle (void *cls,
   struct RPSPeer *rcv_rps_peer;
   char *file_name;
   char *file_name_dh;
+  char *file_name_dhr;
   unsigned int i;
   struct PendingReply *pending_rep = (struct PendingReply *) cls;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n");
   rps_peer = pending_rep->rps_peer;
   file_name = "/tmp/rps/received_ids";
   file_name_dh = "/tmp/rps/diehard_input";
+  file_name_dhr = "/tmp/rps/diehard_input_raw";
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "[%s] got %" PRIu64 " peers:\n",
               GNUNET_i2s (rps_peer->peer_id),
@@ -1723,6 +1610,9 @@ profiler_reply_handle (void *cls,
     tofile (file_name_dh,
              "%" PRIu32 "\n",
              (uint32_t) rcv_rps_peer->index);
+    to_file_raw (file_name_dhr,
+                 &rcv_rps_peer->index,
+                 sizeof (uint32_t));
   }
   default_reply_handle (cls, n, recv_peers);
 }
@@ -1731,7 +1621,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;
   }
@@ -2565,7 +2455,7 @@ void post_profiler (struct RPSPeer *rps_peer)
  *          failed
  */
 static void
-run (void *cls,
+test_run (void *cls,
      struct GNUNET_TESTBED_RunHandle *h,
      unsigned int n_peers,
      struct GNUNET_TESTBED_Peer **peers,
@@ -2576,6 +2466,7 @@ run (void *cls,
   struct OpListEntry *entry;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n");
+  printf ("test 1\n");
 
   /* Check whether we timed out */
   if (n_peers != num_peers ||
@@ -2593,10 +2484,12 @@ run (void *cls,
 
 
   /* Initialize peers */
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n");
   testbed_peers = peers;
   num_peers_online = 0;
   for (i = 0; i < num_peers; i++)
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i);
     entry = make_oplist_entry ();
     entry->index = i;
     rps_peers[i].index = i;
@@ -2644,7 +2537,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);
+
 }
 
 
@@ -2655,171 +2553,57 @@ run (void *cls,
  * @param argv unused
  * @return 0 on success
  */
-int
-main (int argc, char *argv[])
+static void
+run (void *cls,
+    char *const *args,
+    const char *cfgfile,
+    const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  int ret_value;
+  //int ret_value;
 
   /* Defaults for tests */
-  num_peers = 5;
-  cur_test_run.name = "test-rps-default";
-  cur_test_run.init_peer = default_init_peer;
-  cur_test_run.pre_test = NULL;
-  cur_test_run.reply_handle = default_reply_handle;
-  cur_test_run.eval_cb = default_eval_cb;
-  cur_test_run.post_test = NULL;
-  cur_test_run.have_churn = HAVE_CHURN;
-  cur_test_run.have_collect_statistics = NO_COLLECT_STATISTICS;
-  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);
-
-  if (strstr (argv[0], "malicious") != NULL)
-  {
-    cur_test_run.pre_test = mal_pre;
-    cur_test_run.main_test = mal_cb;
-    cur_test_run.init_peer = mal_init_peer;
 
-    if (strstr (argv[0], "_1") != NULL)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
-      cur_test_run.name = "test-rps-malicious_1";
-      mal_type = 1;
-    }
-    else if (strstr (argv[0], "_2") != NULL)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
-      cur_test_run.name = "test-rps-malicious_2";
-      mal_type = 2;
-    }
-    else if (strstr (argv[0], "_3") != NULL)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n");
-      cur_test_run.name = "test-rps-malicious_3";
-      mal_type = 3;
-    }
-  }
-
-  else if (strstr (argv[0], "_single_req") != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
-    cur_test_run.name = "test-rps-single-req";
-    cur_test_run.main_test = single_req_cb;
-    cur_test_run.have_churn = HAVE_NO_CHURN;
-  }
-
-  else if (strstr (argv[0], "_delayed_reqs") != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
-    cur_test_run.name = "test-rps-delayed-reqs";
-    cur_test_run.main_test = delay_req_cb;
-    cur_test_run.have_churn = HAVE_NO_CHURN;
-  }
-
-  else if (strstr (argv[0], "_seed_big") != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > 
GNUNET_MAX_MESSAGE_SIZE)\n");
-    num_peers = 1;
-    cur_test_run.name = "test-rps-seed-big";
-    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);
-  }
-
-  else if (strstr (argv[0], "_single_peer_seed") != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a 
single peer\n");
-    cur_test_run.name = "test-rps-single-peer-seed";
-    cur_test_run.main_test = single_peer_seed_cb;
-    cur_test_run.have_churn = HAVE_NO_CHURN;
-  }
-
-  else if (strstr (argv[0], "_seed_request") != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on 
multiple peers\n");
-    cur_test_run.name = "test-rps-seed-request";
-    cur_test_run.main_test = seed_req_cb;
-    cur_test_run.have_churn = HAVE_NO_CHURN;
-  }
-
-  else if (strstr (argv[0], "_seed") != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
-    cur_test_run.name = "test-rps-seed";
-    cur_test_run.main_test = seed_cb;
-    cur_test_run.eval_cb = no_eval;
-    cur_test_run.have_churn = HAVE_NO_CHURN;
-  }
-
-  else if (strstr (argv[0], "_req_cancel") != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
-    cur_test_run.name = "test-rps-req-cancel";
-    num_peers = 1;
-    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);
-  }
-
-  else if (strstr (argv[0], "_churn") != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test churn\n");
-    cur_test_run.name = "test-rps-churn";
-    num_peers = 5;
-    cur_test_run.init_peer = default_init_peer;
-    cur_test_run.main_test = churn_test_cb;
-    cur_test_run.reply_handle = default_reply_handle;
-    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);
-  }
-
-  else if (strstr (argv[0], "profiler") != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
-    cur_test_run.name = "test-rps-profiler";
-    num_peers = 100;
-    mal_type = 3;
-    cur_test_run.init_peer = profiler_init_peer;
-    //cur_test_run.pre_test = mal_pre;
-    cur_test_run.pre_test = pre_profiler;
-    cur_test_run.main_test = profiler_cb;
-    cur_test_run.reply_handle = profiler_reply_handle;
-    cur_test_run.eval_cb = profiler_eval;
-    cur_test_run.post_test = post_profiler;
-    cur_test_run.request_interval = 2;
-    cur_test_run.num_requests = 5;
-    //cur_test_run.have_churn = HAVE_CHURN;
-    cur_test_run.have_churn = HAVE_NO_CHURN;
-    cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
-    cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
-    cur_test_run.stat_collect_flags = STAT_TYPE_ROUNDS |
-                                      STAT_TYPE_BLOCKS |
-                                      STAT_TYPE_BLOCKS_MANY_PUSH |
-                                      STAT_TYPE_BLOCKS_NO_PUSH |
-                                      STAT_TYPE_BLOCKS_NO_PULL |
-                                      STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL |
-                                      STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL |
-                                      STAT_TYPE_ISSUED_PUSH_SEND |
-                                      STAT_TYPE_ISSUED_PULL_REQ |
-                                      STAT_TYPE_ISSUED_PULL_REP |
-                                      STAT_TYPE_SENT_PUSH_SEND |
-                                      STAT_TYPE_SENT_PULL_REQ |
-                                      STAT_TYPE_SENT_PULL_REP |
-                                      STAT_TYPE_RECV_PUSH_SEND |
-                                      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);
-
-    /* 'Clean' directory */
-    (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
-    GNUNET_DISK_directory_create ("/tmp/rps/");
-  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
+  cur_test_run.name = "test-rps-profiler";
+  num_peers = 10;
+  mal_type = 3;
+  cur_test_run.init_peer = profiler_init_peer;
+  //cur_test_run.pre_test = mal_pre;
+  cur_test_run.pre_test = pre_profiler;
+  cur_test_run.main_test = profiler_cb;
+  cur_test_run.reply_handle = profiler_reply_handle;
+  cur_test_run.eval_cb = profiler_eval;
+  cur_test_run.post_test = post_profiler;
+  cur_test_run.request_interval = 2;
+  cur_test_run.num_requests = 5;
+  //cur_test_run.have_churn = HAVE_CHURN;
+  cur_test_run.have_churn = HAVE_NO_CHURN;
+  cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
+  cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
+  cur_test_run.stat_collect_flags = STAT_TYPE_ROUNDS |
+                                    STAT_TYPE_BLOCKS |
+                                    STAT_TYPE_BLOCKS_MANY_PUSH |
+                                    STAT_TYPE_BLOCKS_NO_PUSH |
+                                    STAT_TYPE_BLOCKS_NO_PULL |
+                                    STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL |
+                                    STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL |
+                                    STAT_TYPE_ISSUED_PUSH_SEND |
+                                    STAT_TYPE_ISSUED_PULL_REQ |
+                                    STAT_TYPE_ISSUED_PULL_REP |
+                                    STAT_TYPE_SENT_PUSH_SEND |
+                                    STAT_TYPE_SENT_PULL_REQ |
+                                    STAT_TYPE_SENT_PULL_REP |
+                                    STAT_TYPE_RECV_PUSH_SEND |
+                                    STAT_TYPE_RECV_PULL_REQ |
+                                    STAT_TYPE_RECV_PULL_REP;
+  cur_test_run.have_collect_view = COLLECT_VIEW;
+  timeout_s = 300;
+
+  /* '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);
@@ -2833,13 +2617,63 @@ main (int argc, char *argv[])
                                                  with the malicious portion */
 
   ok = 1;
-  ret_value = GNUNET_TESTBED_test_run (cur_test_run.name,
-                                       "test_rps.conf",
-                                       num_peers,
-                                       0, NULL, NULL,
-                                       &run, NULL);
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              "_test_run returned.\n");
+              "before _run()\n");
+  //ret_value = GNUNET_TESTBED_test_run (cur_test_run.name,
+  //                                     "test_rps.conf",
+  //                                     num_peers,
+  //                                     0, NULL, NULL,
+  //                                     &test_run, NULL);
+  GNUNET_TESTBED_run (NULL,
+                      cfg,
+                      num_peers,
+                      0, /* event mask */
+                      NULL,
+                      NULL,
+                      &test_run,
+                      NULL);
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "after _run()\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "gnunet-rps-profiler returned.\n");
+}
+
+/**
+ * Entry point for the testcase, sets up the testbed.
+ *
+ * @param argc unused
+ * @param argv unused
+ * @return 0 on success
+ */
+int
+main (int argc, char *argv[])
+{
+  int ret_value;
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_option_uint ('n',
+                               "peers",
+                               "COUNT",
+                               gettext_noop ("number of peers to start"),
+                               &num_peers),
+    GNUNET_GETOPT_OPTION_END
+  };
+
+  //if (GNUNET_OK !=
+  //    GNUNET_STRINGS_get_utf8_args (argc, argv,
+  //                                  &argc, &argv))
+  //  return 2;
+  ret_value = 0;
+  if (GNUNET_OK !=
+      GNUNET_PROGRAM_run (argc,
+                          argv,
+                          "gnunet-rps-profiler",
+                          gettext_noop ("Measure quality and performance of 
the RPS service."),
+                          options,
+                          &run,
+                          NULL))
+  {
+    ret_value = 1;
+  }
   if (GNUNET_OK != ret_value)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -2856,6 +2690,7 @@ main (int argc, char *argv[])
   GNUNET_free (rps_peers);
   GNUNET_free (rps_peer_ids);
   GNUNET_CONTAINER_multipeermap_destroy (peer_map);
+  printf ("test -1\n");
   return ret_value;
 }
 
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;
 
 /**
  * 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);
diff --git a/src/rps/test_rps.conf b/src/rps/test_rps.conf
index cf6b3150c..e4ed111e2 100644
--- a/src/rps/test_rps.conf
+++ b/src/rps/test_rps.conf
@@ -33,7 +33,7 @@ OVERLAY_TOPOLOGY = CLIQUE
 
 # OVERLAY_RANDOM_LINKS = 25
 
-# SETUP_TIMEOUT = 2 m
+SETUP_TIMEOUT = 2 m
 
 [nse]
 WORKBITS = 0

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]