group test works
authorChristian Grothoff <christian@grothoff.org>
Sat, 31 Oct 2009 21:57:40 +0000 (21:57 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 31 Oct 2009 21:57:40 +0000 (21:57 +0000)
BUGS
TODO
src/testing/Makefile.am
src/testing/test_testing_connect.c
src/testing/test_testing_group.c [new file with mode: 0644]

diff --git a/BUGS b/BUGS
index e764e3cd99b22ca1f70e0cf57f53513e6a86a679..7bb7e0cf5433b42c14e9aa37f0221e75bcee99db 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -133,4 +133,6 @@ sane end-user should care about this codebase yet anyway.
 * HOSTLIST:
   - implement advertising of hostlist URL
   - implement learning of hostlist URLs
-
+* TESTING:
+  - consider changing API for peer-group termination to 
+    call continuation when done
diff --git a/TODO b/TODO
index a15110632ad8d39fb7391cb65e53a162f0ce980b..d260a95c0e20045c0ec62375afa3520871e17c06 100644 (file)
--- a/TODO
+++ b/TODO
@@ -12,12 +12,6 @@ away), in order in which they will likely be done:
 * UPNP [Milan]
 
 Urgent items (before announcing ng.gnunet.org):
-* TESTING (needed for DV, DHT, Topology)
-  - implement library for local testing
-    + consider changing API for peer-group termination to 
-      call continuation when done
-  - implement testcases for library
-    + test group start
 * TEST:
   - topology (needs TESTING)
   - hostlist (maybe easier with TESTING?)
index e62795a92f9c9f0e189f8d469430d6ff689cea66..18144c514325a399266611442fe950d44dcd4428 100644 (file)
@@ -22,9 +22,14 @@ libgnunettesting_la_LIBADD = $(XLIB) \
 
 check_PROGRAMS = \
  test_testing \
- test_testing_connect
+ test_testing_connect \
+ test_testing_group
 
-TESTS = $(check_PROGRAMS)
+TESTS = \
+ test_testing \
+ test_testing_connect \
+ test_testing_group
+#$(check_PROGRAMS)
 
 test_testing_SOURCES = \
  test_testing.c
@@ -38,6 +43,12 @@ test_testing_connect_LDADD = \
  $(top_builddir)/src/testing/libgnunettesting.la \
  $(top_builddir)/src/util/libgnunetutil.la  
 
+test_testing_group_SOURCES = \
+ test_testing_group.c
+test_testing_group_LDADD = \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/util/libgnunetutil.la  
+
 EXTRA_DIST = \
  test_testing_data.conf \
  test_testing_connect_peer1.conf \
index b6a2d859a7e03cd80c6224d976386c9e965361b6..431b63963fd2f3a00a2826ab2dc794d5f73de2d4 100644 (file)
@@ -157,7 +157,7 @@ check ()
     GNUNET_GETOPT_OPTION_END
   };
   GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
-                      argv, "test-testing", "nohelp",
+                      argv, "test-testing-connect", "nohelp",
                       options, &run, &ok);
   return ok;
 }
@@ -167,7 +167,7 @@ main (int argc, char *argv[])
 {
   int ret;
 
-  GNUNET_log_setup ("test-testing",
+  GNUNET_log_setup ("test-testing-connect",
 #if VERBOSE
                     "DEBUG",
 #else
diff --git a/src/testing/test_testing_group.c b/src/testing/test_testing_group.c
new file mode 100644 (file)
index 0000000..1d38ef5
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+     This file is part of GNUnet.
+     (C) 2009 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file testing/test_testing_group.c
+ * @brief testcase for functions to connect two peers in testing.c
+ */
+#include "platform.h"
+#include "gnunet_testing_lib.h"
+
+#define VERBOSE GNUNET_NO
+
+
+/**
+ * How long until we give up on connecting the peers?
+ */
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+
+
+static int ok;
+
+static int peers_left;
+
+static struct GNUNET_TESTING_PeerGroup *pg;
+
+static struct GNUNET_SCHEDULER_Handle *sched;
+
+
+static void my_cb(void *cls,
+                  const struct GNUNET_PeerIdentity *id,
+                  const struct GNUNET_CONFIGURATION_Handle *cfg,
+                  struct GNUNET_TESTING_Daemon *d,
+                  const char *emsg)
+{
+  GNUNET_assert (id != NULL);
+  peers_left--;
+  if (peers_left == 0)
+    {
+      GNUNET_TESTING_daemons_stop (pg);
+      ok = 0;
+    }
+}
+
+
+static void
+run (void *cls,
+     struct GNUNET_SCHEDULER_Handle *s,
+     char *const *args,
+     const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  sched = s;
+  ok = 1;
+#if VERBOSE
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Starting daemons.\n");
+#endif
+  peers_left = 4;
+  pg = GNUNET_TESTING_daemons_start (sched, cfg, 
+                                    peers_left,
+                                    &my_cb, NULL, NULL);
+  GNUNET_assert (pg != NULL);
+}
+
+static int
+check ()
+{
+  char *const argv[] = { "test-testing",
+    "-c",
+    "test_testing_data.conf",
+#if VERBOSE
+    "-L", "DEBUG",
+#endif
+    NULL
+  };
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+  GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+                      argv, "test-testing-group", "nohelp",
+                      options, &run, &ok);
+  return ok;
+}
+
+int
+main (int argc, char *argv[])
+{
+  int ret;
+
+  GNUNET_log_setup ("test-testing-group",
+#if VERBOSE
+                    "DEBUG",
+#else
+                    "WARNING",
+#endif
+                    NULL);
+  ret = check ();
+  sleep (1);
+  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
+  return ret;
+}
+
+/* end of test_testing_group.c */