-pi can be slower than this (see build 1241)
[oweals/gnunet.git] / src / experimentation / test_experimentation_clique_run.c
index bc325c5c9e760a3c131d897756f2543b061651d2..875e7501dc3da4e9e37bd13190bc5e75e7df4312 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include "platform.h"
-#include "gnunet_common.h"
+#include "gnunet_util_lib.h"
 #include "gnunet_testbed_service.h"
 
 
@@ -91,11 +91,12 @@ struct ExperimentationPeer
   unsigned int inactive_nodes;
   unsigned int issuer;
   unsigned int experiments_active;
-  unsigned int experiments_running;
+  unsigned int experiments_outbound_running;
+  unsigned int experiments_inbound_running;
 };
 
 
-struct ExperimentationPeer ph[NUM_PEERS];
+struct ExperimentationPeer bp_slaves[NUM_PEERS];
 
 /**
  * Shutdown nicely
@@ -111,9 +112,9 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   for (peer = 0; peer < NUM_PEERS; peer++)
   {
-       if (NULL != ph[peer].stat_op)
-               GNUNET_TESTBED_operation_done (ph[peer].stat_op);
-       ph[peer].stat_op = NULL;
+       if (NULL != bp_slaves[peer].stat_op)
+               GNUNET_TESTBED_operation_done (bp_slaves[peer].stat_op);
+       bp_slaves[peer].stat_op = NULL;
   }
 
   if (NULL != op)
@@ -162,21 +163,31 @@ controller_event_cb (void *cls,
 static void
 check_end ()
 {
-
-       static int last_experiments_value = 0;
+       static int last_in_experiments_value = 0;
+       static int last_out_experiments_value = 0;
   unsigned int peer;
-  unsigned int t_running_experiments = 0;
+  unsigned int t_running_outbound_experiments = 0;
+  unsigned int t_running_inbound_experiments = 0;
 
        for (peer = 0; peer < NUM_PEERS; peer++)
        {
-               t_running_experiments += ph[peer].experiments_running;
+               t_running_outbound_experiments += bp_slaves[peer].experiments_outbound_running;
+               t_running_inbound_experiments += bp_slaves[peer].experiments_inbound_running;
+
        }
 
-       if (last_experiments_value < t_running_experiments)
+       //fprintf (stderr, "%u %u \n", t_running_outbound_experiments, t_running_inbound_experiments);
+       if (last_in_experiments_value < t_running_inbound_experiments)
                fprintf (stderr, ".");
-       last_experiments_value = t_running_experiments;
+       last_in_experiments_value = t_running_inbound_experiments;
+       if (last_out_experiments_value < t_running_outbound_experiments)
+               fprintf (stderr, ".");
+       last_out_experiments_value = t_running_outbound_experiments;
+
 
-       if (t_running_experiments == (NUM_PEERS * NUM_EXPERIMENTS))
+
+       if ((t_running_inbound_experiments == (NUM_PEERS * NUM_EXPERIMENTS)) &&
+                       (t_running_outbound_experiments == (NUM_PEERS * NUM_EXPERIMENTS)))
        {
                        fprintf (stderr, "\n");
                        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "All %u peers are running experiments\n", NUM_PEERS);
@@ -207,11 +218,17 @@ stat_iterator (void *cls, const char *subsystem, const char *name,
                        peer->experiments_active = value;
        }
 
-       if (0 == strcmp (name, "# experiments running"))
+       if (0 == strcmp (name, "# experiments outbound running"))
        {
-                       peer->experiments_running = value;
+                       peer->experiments_outbound_running = value;
        }
 
+       if (0 == strcmp (name, "# experiments inbound running"))
+       {
+                       peer->experiments_inbound_running = value;
+       }
+
+
        check_end ();
 
        return GNUNET_OK;
@@ -244,7 +261,10 @@ stat_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
                 (peer->sh, "experimentation", "# experiments active",
                  stat_iterator, peer));
   GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
-                (peer->sh, "experimentation", "# experiments running",
+                (peer->sh, "experimentation", "# experiments outbound running",
+                 stat_iterator, peer));
+  GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
+                (peer->sh, "experimentation", "# experiments inbound running",
                  stat_iterator, peer));
 }
 
@@ -283,7 +303,10 @@ stat_disconnect_adapter (void *cls, void *op_result)
                 (peer->sh, "experimentation", "# experiments active",
                  stat_iterator, peer));
   GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
-                (peer->sh, "experimentation", "# experiments running",
+                (peer->sh, "experimentation", "# experiments outbound running",
+                 stat_iterator, peer));
+  GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
+                (peer->sh, "experimentation", "# experiments inbound running",
                  stat_iterator, peer));
   GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
   peer->sh = NULL;
@@ -295,6 +318,7 @@ stat_disconnect_adapter (void *cls, void *op_result)
  * Signature of a main function for a testcase.
  *
  * @param cls closure
+ * @param h the run handle
  * @param num_peers number of peers in 'peers'
  * @param peers_ handle to peers run in the testbed
  * @param links_succeeded the number of overlay link connection attempts that
@@ -303,7 +327,9 @@ stat_disconnect_adapter (void *cls, void *op_result)
  *          failed
  */
 static void
-test_master (void *cls, unsigned int num_peers,
+test_master (void *cls,
+             struct GNUNET_TESTBED_RunHandle *h,
+             unsigned int num_peers,
              struct GNUNET_TESTBED_Peer **peers_,
              unsigned int links_succeeded,
              unsigned int links_failed)
@@ -317,12 +343,12 @@ test_master (void *cls, unsigned int num_peers,
   {
     GNUNET_assert (NULL != peers_[peer]);
     /* Connect to peer's statistic service */
-    ph[peer].stat_op = GNUNET_TESTBED_service_connect (NULL,
+    bp_slaves[peer].stat_op = GNUNET_TESTBED_service_connect (NULL,
                                                                                                                                peers_[peer], "statistics",
-                                                                                                                               &stat_comp_cb, &ph[peer],
+                                                                                                                               &stat_comp_cb, &bp_slaves[peer],
                                     &stat_connect_adapter,
                                     &stat_disconnect_adapter,
-                                    &ph[peer]);
+                                    &bp_slaves[peer]);
 
   }
   peers = peers_;