From 2f73cafe6ad49fbed8aa3c0991fd3512f5fe3971 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 10 Jun 2012 13:25:53 +0000 Subject: [PATCH] -more testcase cleanup --- src/namestore/Makefile.am | 14 ++++ src/namestore/test_namestore_api.c | 72 ++++------------ src/namestore/test_namestore_api_put.c | 111 +++++++++---------------- src/transport/Makefile.am | 16 ++-- src/transport/test_plugin_transport.c | 13 +-- 5 files changed, 80 insertions(+), 146 deletions(-) diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index fce9838c6..aea857d74 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am @@ -112,29 +112,34 @@ test_namestore_api_sign_verify_SOURCES = \ test_namestore_api_sign_verify.c test_namestore_api_sign_verify_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la test_namestore_api_SOURCES = \ test_namestore_api.c test_namestore_api_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la test_namestore_api_put_SOURCES = \ test_namestore_api_put.c test_namestore_api_put_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la test_namestore_api_lookup_SOURCES = \ test_namestore_api_lookup.c test_namestore_api_lookup_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la test_namestore_api_lookup_specific_type_SOURCES = \ test_namestore_api_lookup_specific_type.c test_namestore_api_lookup_specific_type_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la @@ -142,12 +147,14 @@ test_namestore_api_lookup_specific_type_LDADD = \ test_namestore_api_create_SOURCES = \ test_namestore_api_create.c test_namestore_api_create_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la test_namestore_api_create_update_SOURCES = \ test_namestore_api_create_update.c test_namestore_api_create_update_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la @@ -155,42 +162,49 @@ test_namestore_api_create_update_LDADD = \ test_namestore_api_remove_SOURCES = \ test_namestore_api_remove.c test_namestore_api_remove_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la test_namestore_api_remove_not_existing_record_SOURCES = \ test_namestore_api_remove_not_existing_record.c test_namestore_api_remove_not_existing_record_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la test_namestore_api_zone_to_name_SOURCES = \ test_namestore_api_zone_to_name.c test_namestore_api_zone_to_name_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la test_namestore_api_zone_iteration_SOURCES = \ test_namestore_api_zone_iteration.c test_namestore_api_zone_iteration_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la test_namestore_api_zone_iteration_specific_zone_SOURCES = \ test_namestore_api_zone_iteration_specific_zone.c test_namestore_api_zone_iteration_specific_zone_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la test_namestore_api_zone_iteration_stop_SOURCES = \ test_namestore_api_zone_iteration_stop.c test_namestore_api_zone_iteration_stop_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la test_namestore_record_serialization_SOURCES = \ test_namestore_record_serialization.c test_namestore_record_serialization_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/namestore/libgnunetnamestore.la diff --git a/src/namestore/test_namestore_api.c b/src/namestore/test_namestore_api.c index 565c27909..55601390a 100644 --- a/src/namestore/test_namestore_api.c +++ b/src/namestore/test_namestore_api.c @@ -24,6 +24,7 @@ #include "platform.h" #include "gnunet_common.h" #include "gnunet_namestore_service.h" +#include "gnunet_testing_lib-new.h" #define TEST_RECORD_TYPE 1234 #define TEST_RECORD_DATALEN 123 @@ -31,13 +32,11 @@ #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) -static struct GNUNET_NAMESTORE_Handle * nsh; +static struct GNUNET_NAMESTORE_Handle *nsh; static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; -static struct GNUNET_OS_Process *arm; - -static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; +static struct GNUNET_CRYPTO_RsaPrivateKey *privkey; static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; @@ -46,29 +45,6 @@ static struct GNUNET_CRYPTO_ShortHashCode zone; static int res; -static void -start_arm (const char *cfgname) -{ - arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", - "gnunet-service-arm", "-c", cfgname, - NULL); -} - - -static void -stop_arm () -{ - if (NULL != arm) - { - if (0 != GNUNET_OS_process_kill (arm, SIGTERM)) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - GNUNET_OS_process_wait (arm); - GNUNET_OS_process_destroy (arm); - arm = NULL; - } -} - - /** * Re-establish the connection to the service. * @@ -85,10 +61,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (privkey != NULL) GNUNET_CRYPTO_rsa_key_free (privkey); privkey = NULL; - - if (NULL != arm) - stop_arm(); - + GNUNET_SCHEDULER_shutdown (); res = 1; } @@ -107,13 +80,10 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) privkey = NULL; if (nsh != NULL) + { GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); - nsh = NULL; - - - if (NULL != arm) - stop_arm(); - + nsh = NULL; + } res = 0; } @@ -138,7 +108,7 @@ name_lookup_proc (void *cls, static void put_cont (void *cls, int32_t success, const char *emsg) { - char * name = cls; + const char *name = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); @@ -166,7 +136,7 @@ delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_CRYPTO_RsaSignature signature; @@ -191,13 +161,11 @@ run (void *cls, char *const *args, const char *cfgfile, rd.data_size = TEST_RECORD_DATALEN; rd.data = GNUNET_malloc(TEST_RECORD_DATALEN); memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); - start_arm (cfgfile); - GNUNET_assert (arm != NULL); nsh = GNUNET_NAMESTORE_connect (cfg); GNUNET_break (NULL != nsh); GNUNET_NAMESTORE_record_put (nsh, &pubkey, name, - GNUNET_TIME_UNIT_FOREVER_ABS, - 1, &rd, &signature, put_cont, name); + GNUNET_TIME_UNIT_FOREVER_ABS, + 1, &rd, &signature, &put_cont, (void*) name); GNUNET_free ((void *)rd.data); } @@ -205,18 +173,14 @@ run (void *cls, char *const *args, const char *cfgfile, int main (int argc, char *argv[]) { - static char *const argv[] = { "test-namestore-api", - "-c", - "test_namestore_api.conf", - NULL - }; - static struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - res = 1; - GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-namestore-api", - "nohelp", options, &run, &res); + if (0 != + GNUNET_TESTING_service_run ("test-namestore-api", + "namestore", + "test_namestore_api.conf", + &run, + NULL)) + return 1; return res; } diff --git a/src/namestore/test_namestore_api_put.c b/src/namestore/test_namestore_api_put.c index 7409ff5d5..438c49243 100644 --- a/src/namestore/test_namestore_api_put.c +++ b/src/namestore/test_namestore_api_put.c @@ -24,21 +24,26 @@ #include "platform.h" #include "gnunet_common.h" #include "gnunet_namestore_service.h" +#include "gnunet_testing_lib-new.h" #include "namestore.h" #define RECORDS 5 + #define TEST_RECORD_TYPE 1234 + #define TEST_RECORD_DATALEN 123 + #define TEST_RECORD_DATA 'a' #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) + static struct GNUNET_NAMESTORE_Handle * nsh; static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; -static struct GNUNET_OS_Process *arm; static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; + static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; static struct GNUNET_NAMESTORE_RecordData *s_rd; @@ -46,27 +51,6 @@ static struct GNUNET_NAMESTORE_RecordData *s_rd; static int res; -static void -start_arm (const char *cfgname) -{ - arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", - "gnunet-service-arm", "-c", cfgname, - NULL); -} - -static void -stop_arm () -{ - if (NULL != arm) - { - if (0 != GNUNET_OS_process_kill (arm, SIGTERM)) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - GNUNET_OS_process_wait (arm); - GNUNET_OS_process_destroy (arm); - arm = NULL; - } -} - /** * Re-establish the connection to the service. * @@ -81,11 +65,11 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) nsh = NULL; if (privkey != NULL) + { GNUNET_CRYPTO_rsa_key_free (privkey); - privkey = NULL; - - if (NULL != arm) - stop_arm(); + privkey = NULL; + } + GNUNET_SCHEDULER_shutdown (); res = 1; } @@ -100,47 +84,48 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } if (privkey != NULL) + { GNUNET_CRYPTO_rsa_key_free (privkey); - privkey = NULL; - + privkey = NULL; + } if (nsh != NULL) + { GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); - nsh = NULL; - - if (NULL != arm) - stop_arm(); + nsh = NULL; + } } static void put_cont (void *cls, int32_t success, const char *emsg) { - char * name = cls; + const char * name = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Name store added record for `%s': %s\n", + name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); if (success == GNUNET_OK) res = 0; else res = 1; - - GNUNET_SCHEDULER_add_now(&end, NULL); + GNUNET_SCHEDULER_add_now (&end, NULL); } static struct GNUNET_NAMESTORE_RecordData * create_record (int count) { - int c; + unsigned int c; struct GNUNET_NAMESTORE_RecordData * rd; - rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData)); + rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData)); for (c = 0; c < RECORDS; c++) { - rd[c].expiration = GNUNET_TIME_absolute_get(); - rd[c].record_type = TEST_RECORD_TYPE; - rd[c].data_size = TEST_RECORD_DATALEN; - rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); - memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); + rd[c].expiration = GNUNET_TIME_absolute_get(); + rd[c].record_type = TEST_RECORD_TYPE; + rd[c].data_size = TEST_RECORD_DATALEN; + rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); + memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); } return rd; } @@ -165,70 +150,52 @@ delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_CRYPTO_RsaSignature *signature; const char * s_name = "dummy.dummy.gnunet"; int c; + char *hostkey_file; delete_existing_db(cfg); endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); - /* load privat key */ - char *hostkey_file; GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey = GNUNET_CRYPTO_rsa_key_create_from_file(hostkey_file); - GNUNET_free (hostkey_file); - GNUNET_assert (privkey != NULL); + GNUNET_free (hostkey_file); /* get public key */ GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); - - start_arm (cfgfile); - GNUNET_assert (arm != NULL); - nsh = GNUNET_NAMESTORE_connect (cfg); GNUNET_break (NULL != nsh); - /* create record */ s_rd = create_record (RECORDS); - signature = GNUNET_NAMESTORE_create_signature(privkey, s_rd[0].expiration, s_name, s_rd, RECORDS); - GNUNET_break (s_rd != NULL); GNUNET_break (s_name != NULL); - GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name, - GNUNET_TIME_UNIT_FOREVER_ABS, - RECORDS, s_rd, signature, put_cont, s_name); - + GNUNET_TIME_UNIT_FOREVER_ABS, + RECORDS, s_rd, signature, &put_cont, (void*) s_name); GNUNET_free (signature); - for (c = 0; c < RECORDS; c++) GNUNET_free_non_null((void *) s_rd[c].data); GNUNET_free (s_rd); - } int main (int argc, char *argv[]) { - static char *const argv[] = { "test-namestore-api", - "-c", - "test_namestore_api.conf", - NULL - }; - static struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - res = 1; - GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-namestore-api", - "nohelp", options, &run, &res); + if (0 != GNUNET_TESTING_service_run ("test-namestore-api-put", + "namestore", + "test_namestore_api.conf", + &run, + NULL)) + return 1; return res; } diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 8a318b961..6334de1ae 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -389,7 +389,7 @@ test_transport_api_tcp_LDADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la - + test_transport_api_bidirectional_connect_SOURCES = \ test_transport_api_bidirectional_connect.c test_transport_api_bidirectional_connect_LDADD = \ @@ -415,7 +415,7 @@ test_transport_api_restart_2peers_LDADD = \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la - + test_transport_api_limited_sockets_tcp_SOURCES = \ test_transport_api_limited_sockets.c test_transport_api_limited_sockets_tcp_LDADD = \ @@ -463,7 +463,7 @@ test_transport_api_timeout_http_LDADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la - + test_transport_api_timeout_https_SOURCES = \ test_transport_api_timeout.c test_transport_api_timeout_https_LDADD = \ @@ -471,7 +471,7 @@ test_transport_api_timeout_https_LDADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la - + test_transport_api_reliability_tcp_nat_SOURCES = \ test_transport_api_reliability.c test_transport_api_reliability_tcp_nat_LDADD = \ @@ -495,7 +495,7 @@ test_transport_api_unreliability_wlan_LDADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la - + test_transport_api_udp_SOURCES = \ test_transport_api.c test_transport_api_udp_LDADD = \ @@ -503,7 +503,7 @@ test_transport_api_udp_LDADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la - + test_transport_api_timeout_udp_SOURCES = \ test_transport_api_timeout.c test_transport_api_timeout_udp_LDADD = \ @@ -535,8 +535,8 @@ test_transport_api_http_LDADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la - - test_transport_api_http_nat_SOURCES = \ + +test_transport_api_http_nat_SOURCES = \ test_transport_api.c test_transport_api_http_nat_LDADD = \ $(top_builddir)/src/transport/libgnunettransport.la \ diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index f101f14e1..55dfb40a1 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c @@ -34,8 +34,6 @@ #include "gnunet_transport_plugin.h" #include "transport.h" -#define VERBOSE GNUNET_NO - /** * How long until we give up on transmitting the message? */ @@ -253,20 +251,11 @@ main (int argc, char *const *argv) "test_plugin_transport", "-c", "test_plugin_transport_data.conf", - "-L", -#if VERBOSE - "DEBUG", -#else - "WARNING", -#endif + "-L", "WARNING", NULL }; GNUNET_log_setup ("test-plugin-transport", -#if VERBOSE - "DEBUG", -#else "WARNING", -#endif NULL); ok = 1; /* set to fail */ ret = -- 2.25.1