-use testing lib
authorChristian Grothoff <christian@grothoff.org>
Fri, 15 Jun 2012 11:18:29 +0000 (11:18 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 15 Jun 2012 11:18:29 +0000 (11:18 +0000)
src/vpn/Makefile.am
src/vpn/test_gnunet_vpn.c

index 2af34f8e16c2a7a29ae4f2b531a3a51c453465c4..0f252990eb8c1af36cc7a0ccf64fdbf097634824 100644 (file)
@@ -85,26 +85,26 @@ test_gnunet_vpn_4_over_SOURCES = \
  test_gnunet_vpn.c
 test_gnunet_vpn_4_over_LDADD = -lmicrohttpd @LIBCURL@ \
  $(top_builddir)/src/vpn/libgnunetvpn.la \
- $(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
  $(top_builddir)/src/util/libgnunetutil.la 
 
 test_gnunet_vpn_6_over_SOURCES = \
  test_gnunet_vpn.c
 test_gnunet_vpn_6_over_LDADD = -lmicrohttpd @LIBCURL@ \
  $(top_builddir)/src/vpn/libgnunetvpn.la \
- $(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
  $(top_builddir)/src/util/libgnunetutil.la 
 
 test_gnunet_vpn_4_to_6_SOURCES = \
  test_gnunet_vpn.c
 test_gnunet_vpn_4_to_6_LDADD = -lmicrohttpd @LIBCURL@ \
  $(top_builddir)/src/vpn/libgnunetvpn.la \
- $(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
  $(top_builddir)/src/util/libgnunetutil.la 
 
 test_gnunet_vpn_6_to_4_SOURCES = \
  test_gnunet_vpn.c
 test_gnunet_vpn_6_to_4_LDADD = -lmicrohttpd @LIBCURL@ \
  $(top_builddir)/src/vpn/libgnunetvpn.la \
- $(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
  $(top_builddir)/src/util/libgnunetutil.la 
index 4c941bd9294488e10c41c186cbb59280ba170215..78bea39a72c7412e2a70cc9914e4c1268d1841a4 100644 (file)
 #include <curl/curl.h>
 #include <microhttpd.h>
 #include "gnunet_vpn_service.h"
-#include "gnunet_arm_service.h"
+#include "gnunet_testing_lib-new.h"
 
 #define PORT 48080
 
-#define START_ARM GNUNET_YES
-
-#define VERBOSE GNUNET_NO
-
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
 
-struct PeerContext
-{
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-  struct GNUNET_PeerIdentity id;
-#if START_ARM
-  struct GNUNET_OS_Process *arm_proc;
-#endif
-};
-
-static struct PeerContext p1;
 
 /**
  * Return value for 'main'.
@@ -96,7 +82,6 @@ struct CBC
 static struct CBC cbc;
 
 
-
 static size_t
 copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx)
 {
@@ -388,7 +373,7 @@ mhd_main ()
 
 
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct in_addr v4;
@@ -435,41 +420,6 @@ run (void *cls, char *const *args, const char *cfgfile,
 }
 
 
-static void
-setup_peer (struct PeerContext *p, const char *cfgname)
-{
-  p->cfg = GNUNET_CONFIGURATION_create ();
-#if START_ARM
-  p->arm_proc =
-      GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
-                               "gnunet-service-arm",
-                               "-c", cfgname, NULL);
-#endif
-  GNUNET_assert (NULL != p->arm_proc);
-  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
-}
-
-
-static void
-stop_peer (struct PeerContext *p)
-{
-#if START_ARM
-  if (NULL != p->arm_proc)
-  {
-    if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
-      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-    if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
-      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
-                GNUNET_OS_process_get_pid (p->arm_proc));
-    GNUNET_OS_process_destroy (p->arm_proc);
-    p->arm_proc = NULL;
-  }
-#endif
-  GNUNET_CONFIGURATION_destroy (p->cfg);
-}
-
-
 /**
  * Test if the given AF is supported by this system.
  * 
@@ -494,21 +444,11 @@ test_af (int af)
 }
 
 
-
 int
 main (int argc, char *const *argv)
 {
   const char *type;
   const char *bin;
-  char *const argvx[] = {
-    "test_gnunet_vpn",
-    "-c",
-    "test_gnunet_vpn.conf",
-    NULL
-  };
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
   
   if (0 != ACCESS ("/dev/net/tun", R_OK))
   {
@@ -577,20 +517,15 @@ main (int argc, char *const *argv)
             "Required address families not supported by this system, skipping test.\n");
     return 0;
   }
-
-
   if (0 != curl_global_init (CURL_GLOBAL_WIN32))
   {
     fprintf (stderr, "failed to initialize curl\n");
     return 2;
   }
-  setup_peer (&p1, "test_gnunet_vpn.conf");
-  GNUNET_log_setup ("test_gnunet_vpn",
-                    "WARNING",
-                    NULL);
-  GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
-                      "test_gnunet_vpn", "nohelp", options, &run, NULL);
-  stop_peer (&p1);
+  if (0 != GNUNET_TESTING_peer_run ("test-gnunet-vpn",
+                                   "test_gnunet_vpn.conf",
+                                   &run, NULL))
+    return 1;
   GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn");
   return global_ret;
 }