From 33cbde487152c775a38628ae7b12e8f5e8040a52 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Thu, 16 Jun 2011 12:35:26 +0000 Subject: [PATCH] clean up in transport tests --- src/transport/test_transport_api.c | 43 +++++---- .../test_transport_api_reliability.c | 42 ++++----- .../test_transport_api_unreliability.c | 88 ++++--------------- src/transport/transport-testing.h | 37 ++++++++ 4 files changed, 94 insertions(+), 116 deletions(-) create mode 100644 src/transport/transport-testing.h diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 8b057d513..853ce9aa5 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c @@ -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 @@ -54,16 +55,6 @@ #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; } diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 45642486c..4db329ad6 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c @@ -36,6 +36,7 @@ #include "gnunet_transport_service.h" #include "gauger.h" #include "transport.h" +#include "transport-testing.h" #define VERBOSE GNUNET_NO @@ -57,16 +58,6 @@ #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; } diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c index fadb49f5d..2101def80 100644 --- a/src/transport/test_transport_api_unreliability.c +++ b/src/transport/test_transport_api_unreliability.c @@ -37,6 +37,7 @@ #include "gnunet_transport_service.h" #include "gauger.h" #include "transport.h" +#include "transport-testing.h" #define VERBOSE GNUNET_NO @@ -60,16 +61,6 @@ #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 index 000000000..db90354f4 --- /dev/null +++ b/src/transport/transport-testing.h @@ -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 */ -- 2.25.1