callback for peergroup shutdown in testing, requisite testcase changes
authorNathan S. Evans <evans@in.tum.de>
Mon, 28 Jun 2010 12:21:40 +0000 (12:21 +0000)
committerNathan S. Evans <evans@in.tum.de>
Mon, 28 Jun 2010 12:21:40 +0000 (12:21 +0000)
src/testing/test_testing_connect.c
src/testing/test_testing_data_topology_clique.conf
src/testing/test_testing_data_topology_clique_minimum.conf
src/testing/test_testing_data_topology_clique_random.conf
src/testing/test_testing_group.c
src/testing/test_testing_group_remote.c
src/testing/test_testing_topology.c
src/testing/test_testing_topology_blacklist.c
src/testing/test_testing_topology_churn.c
src/testing/testing_group.c

index 8563014f2a3c91b0331e2aac81c33dd8e6ea9c22..28c6cddb028475fd7ed58c2b132fff2e2d36b9e7 100644 (file)
@@ -26,7 +26,6 @@
 
 #define VERBOSE GNUNET_NO
 
-
 /**
  * How long until we give up on connecting the peers?
  */
index 114364da2fc561873ae7d7baa2eb27c1737c58d9..a6cf1eb2e821a2c28a044084e33fd7d1e9a95784 100644 (file)
@@ -32,7 +32,7 @@ PORT = 2569
 #DEBUG = YES
 #PREFIX = xterm -e xterm -T peerinfo -e gdb --args
 #BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/peerinfo/.libs/gnunet-service-peerinfo
-#PREFIX = valgrind --tool=memcheck --log-file=peerinfo%p
+PREFIX = valgrind --tool=memcheck --log-file=peerinfo%p
 
 [core]
 PORT = 2570
index c8b056e9865c9d2cff3469c1aaf11dcbad321a09..e4a72862cc327f1f59152941d06ab1c9ff0673e9 100644 (file)
@@ -40,9 +40,9 @@ PORT = 2570
 #DEBUG = YES
 
 [testing]
-NUM_PEERS = 5
+NUM_PEERS = 20
 WEAKRANDOM = YES
 TOPOLOGY = CLIQUE
 CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM
-CONNECT_TOPOLOGY_OPTION_MODIFIER = 1.0
+CONNECT_TOPOLOGY_OPTION_MODIFIER = 2.0
 F2F = YES
index c79698ac15eb1567411276d6689cb75a44eba18b..f66baf439f87aeb227b82bffe276670b72403ffb 100644 (file)
@@ -40,9 +40,9 @@ PORT = 2570
 #DEBUG = YES
 
 [testing]
-NUM_PEERS = 5
+NUM_PEERS = 20
 WEAKRANDOM = YES
 TOPOLOGY = CLIQUE
 CONNECT_TOPOLOGY_OPTION = CONNECT_RANDOM_SUBSET
-CONNECT_TOPOLOGY_OPTION_MODIFIER = .5
+CONNECT_TOPOLOGY_OPTION_MODIFIER = .15
 F2F = YES
index 81d949e2a2d14d77c5bec1d61aa67a44ef7fb605..c0ceaa79937c5a938454f5212115dac87e400d30 100644 (file)
@@ -24,7 +24,7 @@
 #include "platform.h"
 #include "gnunet_testing_lib.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
 
 #define NUM_PEERS 4
 
@@ -43,6 +43,30 @@ static struct GNUNET_TESTING_PeerGroup *pg;
 
 static struct GNUNET_SCHEDULER_Handle *sched;
 
+/**
+ * Check whether peers successfully shut down.
+ */
+void shutdown_callback (void *cls,
+                        const char *emsg)
+{
+  if (emsg != NULL)
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Shutdown of peers failed!\n");
+#endif
+      if (ok == 0)
+        ok = 666;
+    }
+  else
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "All peers successfully shut down!\n");
+#endif
+    }
+}
+
 
 static void
 my_cb (void *cls,
@@ -59,7 +83,7 @@ my_cb (void *cls,
        {
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n");
          ok = 1;
-         GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+         GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
        }
       return;
     }
@@ -68,14 +92,14 @@ my_cb (void *cls,
   if (peers_left == 0)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started successfully, ending test!\n");
-      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
       ok = 0;
     }
   else if (failed_peers == peers_left)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n");
       ok = 1;
-      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
     }
 }
 
index 6b7fabb3109aa236f931788813b9b2b9619b9b96..562e858e5fccddcaa038cda7691ec2c9cefce935 100644 (file)
@@ -50,6 +50,30 @@ static unsigned long long num_peers;
 
 static char *hostnames;
 
+/**
+ * Check whether peers successfully shut down.
+ */
+void shutdown_callback (void *cls,
+                        const char *emsg)
+{
+  if (emsg != NULL)
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Shutdown of peers failed!\n");
+#endif
+      if (ok == 0)
+        ok = 666;
+    }
+  else
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "All peers successfully shut down!\n");
+#endif
+    }
+}
+
 
 static void
 my_cb (void *cls,
@@ -65,13 +89,13 @@ my_cb (void *cls,
   peers_left--;
   if (peers_left == 0)
     {
-      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
       ok = 0;
     }
   else if (peers_failed == peers_left)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n");
-      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
     }
 }
 
index d7bb836e9e58429d1f28c574b8750e257715f07e..ba9084e31ec87e5cc6ecf66f5861e51f5927bbe6 100644 (file)
@@ -25,7 +25,7 @@
 #include "gnunet_testing_lib.h"
 #include "gnunet_core_service.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
 
 /**
  * How long until we fail the whole testcase?
@@ -137,6 +137,30 @@ struct TestMessageContext
 
 static struct TestMessageContext *test_messages;
 
+/**
+ * Check whether peers successfully shut down.
+ */
+void shutdown_callback (void *cls,
+                        const char *emsg)
+{
+  if (emsg != NULL)
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Shutdown of peers failed!\n");
+#endif
+      if (ok == 0)
+        ok = 666;
+    }
+  else
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "All peers successfully shut down!\n");
+#endif
+    }
+}
+
 static void
 finish_testing ()
 {
@@ -179,11 +203,8 @@ finish_testing ()
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "Calling daemons_stop\n");
 #endif
-  GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
-#if VERBOSE
-          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      "daemons_stop finished\n");
-#endif
+  GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+
   if (dotOutFile != NULL)
     {
       fprintf(dotOutFile, "}");
@@ -282,7 +303,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
 
   if (pg != NULL)
     {
-      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
       ok = 7331;                /* Opposite of leet */
     }
   else
@@ -295,8 +316,6 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
     }
 }
 
-
-
 static size_t
 transmit_ready (void *cls, size_t size, void *buf)
 {
index 9788fa87cb1aff567d29df11be81254c88e8f8e1..b68386cd74d70d0441c0de188591180f8b8d13b8 100644 (file)
@@ -96,6 +96,31 @@ struct GNUNET_TestMessage
   uint32_t uid;
 };
 
+
+/**
+ * Check whether peers successfully shut down.
+ */
+void shutdown_callback (void *cls,
+                        const char *emsg)
+{
+  if (emsg != NULL)
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Shutdown of peers failed!\n");
+#endif
+      if (ok == 0)
+        ok = 666;
+    }
+  else
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "All peers successfully shut down!\n");
+#endif
+    }
+}
+
 static void
 finish_testing ()
 {
@@ -110,7 +135,7 @@ finish_testing ()
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "Calling daemons_stop\n");
 #endif
-  GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+  GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
 #if VERBOSE
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "daemons_stop finished\n");
@@ -133,7 +158,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
 
   if (pg != NULL)
     {
-      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
       ok = 7331;                /* Opposite of leet */
     }
   else
index 0d894378ffa5def951ec0ca9e463f893afbcaeeb..ba493e295cca61457451227b47bab40dd5af660c 100644 (file)
@@ -74,6 +74,30 @@ struct GNUNET_TestMessage
   uint32_t uid;
 };
 
+/**
+ * Check whether peers successfully shut down.
+ */
+void shutdown_callback (void *cls,
+                        const char *emsg)
+{
+  if (emsg != NULL)
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Shutdown of peers failed!\n");
+#endif
+      if (ok == 0)
+        ok = 666;
+    }
+  else
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "All peers successfully shut down!\n");
+#endif
+    }
+}
+
 static void
 finish_testing ()
 {
@@ -91,7 +115,7 @@ finish_testing ()
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "Calling daemons_stop\n");
 #endif
-  GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+  GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
 #if VERBOSE
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "daemons_stop finished\n");
@@ -109,7 +133,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
 
   if (pg != NULL)
     {
-      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
       ok = 7331;                /* Opposite of leet */
     }
   else
index de624f25fa92781fa9aca4799f57942a621d603a..8316573054c42e5b49557d1827faf4c4d847212f 100644 (file)
 /**
  * @file testing/testing_group.c
  * @brief convenience API for writing testcases for GNUnet
+ * @author Nathan Evans
  * @author Christian Grothoff
  *
- * FIXME: have connection processor functions take a cls argument
- *        which specifies where to write the connection information
- *        instead of assuming it's certain peergroup places. (maybe?)
- * FIXME: create static struct which contains the TOPOLOGY enum, the
- *        associated string, and the function used to create it.
- *        Then replace the create_X calls with topology_struct[i][2]
- *        or something. (Store function pointers instead of using
- *        switch statements)
  */
 #include "platform.h"
 #include "gnunet_arm_service.h"
@@ -55,7 +48,7 @@
  * conflict with the port range for "local" ports (client apps; see
  * /proc/sys/net/ipv4/ip_local_port_range on Linux for example).
  */
-#define HIGH_PORT 32000
+#define HIGH_PORT 56000
 
 #define MAX_OUTSTANDING_CONNECTIONS 50
 
@@ -137,6 +130,36 @@ struct RestartContext
 
 };
 
+
+struct ShutdownContext
+{
+  /**
+   * Total peers to wait for
+   */
+  int total_peers;
+
+  /**
+   * Number of peers successfully shut down
+   */
+  int peers_down;
+
+  /**
+   * Number of peers failed to shut down
+   */
+  int peers_failed;
+
+  /**
+   * Callback to call when all peers either
+   * shutdown or failed to shutdown
+   */
+  GNUNET_TESTING_NotifyCompletion cb;
+
+  /**
+   * Closure for cb
+   */
+  void *cb_cls;
+};
+
 struct CreateTopologyContext
 {
 
@@ -3346,26 +3369,74 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
 }
 
 
+/**
+ * Callback for shutting down peers in a peer group.
+ *
+ * @param cls closure (struct ShutdownContext)
+ * @param emsg NULL on success
+ */
+void internal_shutdown_callback (void *cls,
+                        const char *emsg)
+{
+  struct ShutdownContext *shutdown_ctx = cls;
+
+  if (emsg == NULL)
+    {
+      shutdown_ctx->peers_down++;
+    }
+  else
+    {
+      shutdown_ctx->peers_failed++;
+    }
+
+  if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down + shutdown_ctx->peers_failed == shutdown_ctx->total_peers))
+    {
+      if (shutdown_ctx->peers_failed > 0)
+        shutdown_ctx->cb(shutdown_ctx->cb_cls, "Not all peers successfully shut down!");
+      else
+        shutdown_ctx->cb(shutdown_ctx->cb_cls, NULL);
+      GNUNET_free(shutdown_ctx);
+    }
+}
+
 /**
  * Shutdown all peers started in the given group.
  *
  * @param pg handle to the peer group
  * @param timeout how long to wait for shutdown
+ * @param cb callback to notify upon success or failure
+ * @param cb_cls closure for cb
  */
 void
 GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, 
-                            struct GNUNET_TIME_Relative timeout)
+                            struct GNUNET_TIME_Relative timeout,
+                            GNUNET_TESTING_NotifyCompletion cb,
+                             void *cb_cls)
 {
   unsigned int off;
+  struct ShutdownContext *shutdown_ctx;
+  GNUNET_TESTING_NotifyCompletion shutdown_cb;
+  void *shutdown_cb_cls;
 
-  for (off = 0; off < pg->total; off++)
+  GNUNET_assert(pg->total > 0);
+
+  shutdown_cb = NULL;
+  shutdown_ctx = NULL;
+
+  if (cb != NULL)
     {
-      /* FIXME: should we wait for our continuations to be called
-         here? This would require us to take a continuation as
-         well... */
+      shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext));
+      shutdown_ctx->cb = cb;
+      shutdown_ctx->cb_cls = cb_cls;
+      shutdown_ctx->total_peers = pg->total;
+      shutdown_cb = &internal_shutdown_callback;
+      shutdown_cb_cls = cb_cls;
+    }
 
+  for (off = 0; off < pg->total; off++)
+    {
       if (NULL != pg->peers[off].daemon)
-        GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, NULL, NULL, GNUNET_YES, GNUNET_NO);
+        GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, shutdown_cb, shutdown_ctx, GNUNET_YES, GNUNET_NO);
       if (NULL != pg->peers[off].cfg)
         GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg);
       if (pg->peers[off].allowed_peers != NULL)