clean up in transport tests
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 16 Jun 2011 12:35:26 +0000 (12:35 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 16 Jun 2011 12:35:26 +0000 (12:35 +0000)
src/transport/test_transport_api.c
src/transport/test_transport_api_reliability.c
src/transport/test_transport_api_unreliability.c
src/transport/transport-testing.h [new file with mode: 0644]

index 8b057d51309cfbe1c48153eaa67995ec7eeefb29..853ce9aa5c5b14c89c3334f772f108b2f1ae7a62 100644 (file)
@@ -35,6 +35,7 @@
 #include "gnunet_scheduler_lib.h"
 #include "gnunet_transport_service.h"
 #include "transport.h"
+#include "transport-testing.h"
 
 #define VERBOSE GNUNET_NO
 
 
 #define MTYPE 12345
 
-struct PeerContext
-{
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-  struct GNUNET_TRANSPORT_Handle *th;
-  struct GNUNET_PeerIdentity id;
-#if START_ARM
-  struct GNUNET_OS_Process *arm_proc;
-#endif
-};
-
 static struct PeerContext p1;
 
 static struct PeerContext p2;
@@ -276,6 +267,12 @@ setup_peer (struct PeerContext *p,
            const char *cfgname)
 {
   p->cfg = GNUNET_CONFIGURATION_create ();
+
+  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+  if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
+      GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome);
+  GNUNET_DISK_directory_remove (p->servicehome);
+
 #if START_ARM
   p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
                                         "gnunet-service-arm",
@@ -284,7 +281,10 @@ setup_peer (struct PeerContext *p,
 #endif
                                         "-c", cfgname, NULL);
 #endif
-  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+
+
+  if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
+      GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome);
 
   if (is_https)
     {
@@ -514,6 +514,14 @@ check ()
       GNUNET_free(cert_file_p1);
       GNUNET_free(cert_file_p2);
     }
+
+  if ((p1.servicehome != NULL) && (p2.servicehome != NULL))
+  {
+    GNUNET_DISK_directory_remove (p1.servicehome);
+    GNUNET_DISK_directory_remove (p2.servicehome);
+    GNUNET_free(p1.servicehome);
+    GNUNET_free(p2.servicehome);
+  }
   return ok;
 }
 
@@ -668,7 +676,8 @@ main (int argc, char *argv[])
                       "`%s' not properly installed, cannot run NAT test!\n",
                      "gnunet-nat-server");
           return 0;
-        }
+        }      GNUNET_free(p1.servicehome);
+        GNUNET_free(p2.servicehome);
     }
   else if (strstr(argv[0], "udp") != NULL)
     {
@@ -696,16 +705,6 @@ main (int argc, char *argv[])
     }
 
   ret = check ();
-  if (is_multi_protocol)
-  {
-         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-multi-peer-1/");
-         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-multi-peer-2/");
-  }
-  else
-  {
-         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
-         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
-  }
 
   return ret;
 }
index 45642486c3a7160e885e6d4f7dc127df4d6eccf5..4db329ad61e2f4b804d5f0d8b89ce5196565ad31 100644 (file)
@@ -36,6 +36,7 @@
 #include "gnunet_transport_service.h"
 #include "gauger.h"
 #include "transport.h"
+#include "transport-testing.h"
 
 #define VERBOSE GNUNET_NO
 
 
 #define MTYPE 12345
 
-struct PeerContext
-{
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-  struct GNUNET_TRANSPORT_Handle *th;
-  struct GNUNET_PeerIdentity id;
-#if START_ARM
-  struct GNUNET_OS_Process *arm_proc;
-#endif
-};
-
 static struct PeerContext p1;
 
 static struct PeerContext p2;
@@ -438,6 +429,11 @@ static void
 setup_peer (struct PeerContext *p, const char *cfgname)
 {
   p->cfg = GNUNET_CONFIGURATION_create ();
+  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+  if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
+      GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome);
+  GNUNET_DISK_directory_remove (p->servicehome);
+
 #if START_ARM
   p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
                                        "gnunet-service-arm",
@@ -447,7 +443,6 @@ setup_peer (struct PeerContext *p, const char *cfgname)
 #endif
                                         "-c", cfgname, NULL);
 #endif
-  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
 
   if (is_https)
     {
@@ -462,11 +457,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
          if (0 == stat (key_file_p1, &sbuf ))
            {
              if (0 == remove(key_file_p1))
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                            "Successfully removed existing private key file `%s'\n",
                            key_file_p1);
              else
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                            "Failed to remove private key file `%s'\n",
                            key_file_p1);
            }
@@ -477,11 +472,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
          if (0 == stat (cert_file_p1, &sbuf ))
            {
              if (0 == remove(cert_file_p1))
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                            "Successfully removed existing certificate file `%s'\n",
                            cert_file_p1);
              else
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                            "Failed to remove existing certificate file `%s'\n",
                            cert_file_p1);
            }
@@ -496,11 +491,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
          if (0 == stat (key_file_p2, &sbuf ))
            {
              if (0 == remove(key_file_p2))
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                            "Successfully removed existing private key file `%s'\n",
                            key_file_p2);
              else
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                            "Failed to remove private key file `%s'\n",
                            key_file_p2);
            }
@@ -511,11 +506,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
          if (0 == stat (cert_file_p2, &sbuf ))
            {
              if (0 == remove(cert_file_p2))
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                            "Successfully removed existing certificate file `%s'\n",
                            cert_file_p2);
              else
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                            "Failed to remove existing certificate file `%s'\n",
                            cert_file_p2);
            }
@@ -798,6 +793,8 @@ check ()
     GNUNET_free(key_file_p2);
     GNUNET_free(cert_file_p1);
     GNUNET_free(cert_file_p2);
+    GNUNET_free(p1.servicehome);
+    GNUNET_free(p2.servicehome);
   }
 
   return ok;
@@ -812,9 +809,6 @@ main (int argc, char *argv[])
   return GNUNET_SYSERR;
 #endif
 
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
-
   if (strstr(argv[0], "tcp_nat") != NULL)
     {
       is_tcp_nat = GNUNET_YES;
@@ -857,8 +851,8 @@ main (int argc, char *argv[])
 #endif
                     NULL);
   ret = check ();
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
+  GNUNET_DISK_directory_remove (p1.servicehome);
+  GNUNET_DISK_directory_remove (p2.servicehome);
   return ret;
 }
 
index fadb49f5d9a85a420ad277a58233f839aba68b46..2101def806907ba098503054e2f3d570ca7e4e5b 100644 (file)
@@ -37,6 +37,7 @@
 #include "gnunet_transport_service.h"
 #include "gauger.h"
 #include "transport.h"
+#include "transport-testing.h"
 
 #define VERBOSE GNUNET_NO
 
 
 #define MTYPE 12345
 
-struct PeerContext
-{
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-  struct GNUNET_TRANSPORT_Handle *th;
-  struct GNUNET_PeerIdentity id;
-#if START_ARM
-  struct GNUNET_OS_Process *arm_proc;
-#endif
-};
-
 static struct PeerContext p1;
 
 static struct PeerContext p2;
@@ -533,6 +524,13 @@ static void
 setup_peer (struct PeerContext *p, const char *cfgname)
 {
   p->cfg = GNUNET_CONFIGURATION_create ();
+
+  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+  if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
+      GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome);
+  GNUNET_DISK_directory_remove (p->servicehome);
+
+
 #if START_ARM
   p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
                                        "gnunet-service-arm",
@@ -542,64 +540,6 @@ setup_peer (struct PeerContext *p, const char *cfgname)
 #endif
                                         "-c", cfgname, NULL);
 #endif
-  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
-
-  if (is_https)
-  {
-         struct stat sbuf;
-         if (p==&p1)
-         {
-                 if (GNUNET_CONFIGURATION_have_value (p->cfg,
-                                                                                          "transport-https", "KEY_FILE"))
-                               GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p1);
-                 if (key_file_p1 == NULL)
-                         GNUNET_asprintf(&key_file_p1,"https_p1.key");
-                 if (0 == stat (key_file_p1, &sbuf ))
-                 {
-                         if (0 == remove(key_file_p1))
-                             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing private key file `%s'\n",key_file_p1);
-                         else
-                                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove private key file `%s'\n",key_file_p1);
-                 }
-                 if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
-                         GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p1);
-                 if (cert_file_p1 == NULL)
-                         GNUNET_asprintf(&cert_file_p1,"https_p1.cert");
-                 if (0 == stat (cert_file_p1, &sbuf ))
-                 {
-                         if (0 == remove(cert_file_p1))
-                             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing certificate file `%s'\n",cert_file_p1);
-                         else
-                                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove existing certificate file `%s'\n",cert_file_p1);
-                 }
-         }
-         else if (p==&p2)
-         {
-                 if (GNUNET_CONFIGURATION_have_value (p->cfg,
-                                                                                          "transport-https", "KEY_FILE"))
-                               GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p2);
-                 if (key_file_p2 == NULL)
-                         GNUNET_asprintf(&key_file_p2,"https_p2.key");
-                 if (0 == stat (key_file_p2, &sbuf ))
-                 {
-                         if (0 == remove(key_file_p2))
-                             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing private key file `%s'\n",key_file_p2);
-                         else
-                                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove private key file `%s'\n",key_file_p2);
-                 }
-                 if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
-                         GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p2);
-                 if (cert_file_p2 == NULL)
-                         GNUNET_asprintf(&cert_file_p2,"https_p2.cert");
-                 if (0 == stat (cert_file_p2, &sbuf ))
-                 {
-                         if (0 == remove(cert_file_p2))
-                             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing certificate file `%s'\n",cert_file_p2);
-                         else
-                                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove existing certificate file `%s'\n",cert_file_p2);
-                 }
-         }
-  }
 
   p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
                                     p,
@@ -864,6 +804,15 @@ check ()
     GNUNET_free(cert_file_p2);
   }
 
+  if ((p1.servicehome != NULL) && (p2.servicehome != NULL))
+  {
+    GNUNET_DISK_directory_remove (p1.servicehome);
+    GNUNET_DISK_directory_remove (p2.servicehome);
+    GNUNET_free(p1.servicehome);
+    GNUNET_free(p2.servicehome);
+  }
+  return ok;
+
   return ok;
 }
 
@@ -921,8 +870,7 @@ main (int argc, char *argv[])
 #endif
                     NULL);
   ret = check ();
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
+
   GNUNET_free_non_null(test_name);
   return ret;
 }
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
new file mode 100644 (file)
index 0000000..db90354
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+     This file is part of GNUnet.
+     (C) 2006, 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 transport_testing.h
+ * @brief testing lib for transport service
+ *
+ * @author Matthias Wachs
+ */
+
+struct PeerContext
+{
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+  struct GNUNET_TRANSPORT_Handle *th;
+  struct GNUNET_PeerIdentity id;
+  struct GNUNET_OS_Process *arm_proc;
+  char * servicehome;
+};
+
+/* end of transport_testing.h */