From: Christian Grothoff Date: Fri, 15 Jun 2012 08:38:53 +0000 (+0000) Subject: -simplifying tests with new testing lib X-Git-Tag: initial-import-from-subversion-38251~13051 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=36ca9fcc68935edd109481d30f9e6e15a825c282;p=oweals%2Fgnunet.git -simplifying tests with new testing lib --- diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index 224c0fd0c..efe126a2c 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am @@ -327,36 +327,42 @@ test_fs_namespace_list_updateable_LDADD = \ test_fs_publish_SOURCES = \ test_fs_publish.c test_fs_publish_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/fs/libgnunetfs.la \ $(top_builddir)/src/util/libgnunetutil.la test_fs_publish_persistence_SOURCES = \ test_fs_publish_persistence.c test_fs_publish_persistence_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/fs/libgnunetfs.la \ $(top_builddir)/src/util/libgnunetutil.la test_fs_search_SOURCES = \ test_fs_search.c test_fs_search_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/fs/libgnunetfs.la \ $(top_builddir)/src/util/libgnunetutil.la test_fs_search_probes_SOURCES = \ test_fs_search_probes.c test_fs_search_probes_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/fs/libgnunetfs.la \ $(top_builddir)/src/util/libgnunetutil.la test_fs_search_persistence_SOURCES = \ test_fs_search_persistence.c test_fs_search_persistence_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/fs/libgnunetfs.la \ $(top_builddir)/src/util/libgnunetutil.la test_fs_start_stop_SOURCES = \ test_fs_start_stop.c test_fs_start_stop_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/fs/libgnunetfs.la \ $(top_builddir)/src/util/libgnunetutil.la diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c index 1560f4ea3..47a604c1d 100644 --- a/src/fs/test_fs_publish.c +++ b/src/fs/test_fs_publish.c @@ -17,23 +17,17 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - /** * @file fs/test_fs_publish.c * @brief simple testcase for publish operation (indexing, listing * indexed, directory structure) * @author Christian Grothoff */ - #include "platform.h" #include "gnunet_util_lib.h" -#include "gnunet_arm_service.h" +#include "gnunet_testing_lib-new.h" #include "gnunet_fs_service.h" -#define VERBOSE GNUNET_NO - -#define START_ARM GNUNET_YES - /** * File-size we use for testing. */ @@ -49,15 +43,6 @@ */ #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) -struct PeerContext -{ - struct GNUNET_CONFIGURATION_Handle *cfg; -#if START_ARM - struct GNUNET_OS_Process *arm_proc; -#endif -}; - -static struct PeerContext p1; static struct GNUNET_TIME_Absolute start; @@ -71,6 +56,7 @@ static char *fn2; static int err; + static void abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -107,14 +93,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) case GNUNET_FS_STATUS_PUBLISH_PROGRESS: ret = event->value.publish.cctx; GNUNET_assert (publish == event->value.publish.pc); -#if VERBOSE - printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); -#endif + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long) event->value.publish.completed, + (unsigned long long) event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long) event->value.publish.specifics. + progress.offset); break; case GNUNET_FS_STATUS_PUBLISH_ERROR: ret = event->value.publish.cctx; @@ -168,44 +153,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) 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", -#if VERBOSE - "-L", "DEBUG", -#endif - "-c", cfgname, NULL); -#endif - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); -} - - -static void -stop_arm (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); -} - - -static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { const char *keywords[] = { @@ -221,7 +169,6 @@ run (void *cls, char *const *args, const char *cfgfile, size_t i; struct GNUNET_FS_BlockOptions bo; - setup_peer (&p1, "test_fs_publish_data.conf"); fs = GNUNET_FS_start (cfg, "test-fs-publish", &progress_cb, NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); GNUNET_assert (NULL != fs); @@ -283,40 +230,10 @@ run (void *cls, char *const *args, const char *cfgfile, int main (int argc, char *argv[]) { - char *const argvx[] = { - "test-fs-publish", - "-c", - "test_fs_publish_data.conf", -#if VERBOSE - "-L", "DEBUG", -#endif - NULL - }; - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - - GNUNET_log_setup ("test_fs_publish", -#if VERBOSE - "DEBUG", -#else - "WARNING", -#endif - NULL); - GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, - "test-fs-publish", "nohelp", options, &run, NULL); - stop_arm (&p1); - GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/"); - if (fn1 != NULL) - { - GNUNET_DISK_directory_remove (fn1); - GNUNET_free (fn1); - } - if (fn2 != NULL) - { - GNUNET_DISK_directory_remove (fn2); - GNUNET_free (fn2); - } + if (0 != GNUNET_TESTING_peer_run ("test-fs-publish", + "test_fs_publish_data.conf", + &run, NULL)) + return 1; return err; } diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c index 7d3bc32ae..cbe859531 100644 --- a/src/fs/test_fs_publish_persistence.c +++ b/src/fs/test_fs_publish_persistence.c @@ -17,21 +17,16 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - /** * @file fs/test_fs_publish_persistence.c * @brief simple testcase for persistence of simple publish operation * @author Christian Grothoff */ - #include "platform.h" #include "gnunet_util_lib.h" -#include "gnunet_arm_service.h" +#include "gnunet_testing_lib-new.h" #include "gnunet_fs_service.h" -#define VERBOSE GNUNET_NO - -#define START_ARM GNUNET_YES /** * File-size we use for testing. @@ -48,15 +43,6 @@ */ #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) -struct PeerContext -{ - struct GNUNET_CONFIGURATION_Handle *cfg; -#if START_ARM - struct GNUNET_OS_Process *arm_proc; -#endif -}; - -static struct PeerContext p1; static struct GNUNET_TIME_Absolute start; @@ -76,6 +62,7 @@ static int err; static GNUNET_SCHEDULER_TaskIdentifier rtask; + static void abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -231,44 +218,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) 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", -#if VERBOSE - "-L", "DEBUG", -#endif - "-c", cfgname, NULL); -#endif - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); -} - - -static void -stop_arm (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); -} - - -static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c) { const char *keywords[] = { @@ -285,7 +235,6 @@ run (void *cls, char *const *args, const char *cfgfile, struct GNUNET_FS_BlockOptions bo; cfg = c; - setup_peer (&p1, "test_fs_publish_data.conf"); fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", &progress_cb, NULL, GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); GNUNET_assert (NULL != fs); @@ -344,40 +293,10 @@ run (void *cls, char *const *args, const char *cfgfile, int main (int argc, char *argv[]) { - char *const argvx[] = { - "test-fs-publish-persistence", - "-c", - "test_fs_publish_data.conf", -#if VERBOSE - "-L", "DEBUG", -#endif - NULL - }; - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - - GNUNET_log_setup ("test_fs_publish_persistence", -#if VERBOSE - "DEBUG", -#else - "WARNING", -#endif - NULL); - GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, - "test-fs-publish", "nohelp", options, &run, NULL); - stop_arm (&p1); - GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/"); - if (fn1 != NULL) - { - GNUNET_DISK_directory_remove (fn1); - GNUNET_free (fn1); - } - if (fn2 != NULL) - { - GNUNET_DISK_directory_remove (fn2); - GNUNET_free (fn2); - } + if (0 != GNUNET_TESTING_peer_run ("test-fs-publish-persistence", + "test_fs_publish_data.conf", + &run, NULL)) + return 1; return err; } diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c index 04c5897ac..1ae84a8d0 100644 --- a/src/fs/test_fs_search.c +++ b/src/fs/test_fs_search.c @@ -17,21 +17,16 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - /** * @file fs/test_fs_search.c * @brief simple testcase for simple publish + search operation * @author Christian Grothoff */ - #include "platform.h" #include "gnunet_util_lib.h" -#include "gnunet_arm_service.h" +#include "gnunet_testing_lib-new.h" #include "gnunet_fs_service.h" -#define VERBOSE GNUNET_NO - -#define START_ARM GNUNET_YES /** * File-size we use for testing. @@ -48,16 +43,6 @@ */ #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) -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; static struct GNUNET_TIME_Absolute start; @@ -96,14 +81,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) switch (event->status) { case GNUNET_FS_STATUS_PUBLISH_PROGRESS: -#if VERBOSE - printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); -#endif + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long) event->value.publish.completed, + (unsigned long long) event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long) event->value.publish.specifics. + progress.offset); break; case GNUNET_FS_STATUS_PUBLISH_COMPLETED: kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); @@ -115,9 +99,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) GNUNET_assert (search != NULL); break; case GNUNET_FS_STATUS_SEARCH_RESULT: -#if VERBOSE - printf ("Search complete.\n"); -#endif + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Search complete.\n"); GNUNET_SCHEDULER_add_continuation (&abort_search_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); break; @@ -169,41 +152,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) 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 (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); -} - - -static void -stop_arm (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); -} - - -static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { const char *keywords[] = { @@ -217,7 +166,6 @@ run (void *cls, char *const *args, const char *cfgfile, struct GNUNET_FS_FileInformation *fi; size_t i; - setup_peer (&p1, "test_fs_search_data.conf"); fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); GNUNET_assert (NULL != fs); @@ -247,23 +195,10 @@ run (void *cls, char *const *args, const char *cfgfile, int main (int argc, char *argv[]) { - char *const argvx[] = { - "test-fs-search", - "-c", - "test_fs_search_data.conf", - NULL - }; - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - - GNUNET_log_setup ("test_fs_search", - "WARNING", - NULL); - GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, - "test-fs-search", "nohelp", options, &run, NULL); - stop_arm (&p1); - GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/"); + if (0 != GNUNET_TESTING_peer_run ("test-fs-search", + "test_fs_search_data.conf", + &run, NULL)) + return 1; return 0; } diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c index d18b50eb5..cedf4b8a5 100644 --- a/src/fs/test_fs_search_persistence.c +++ b/src/fs/test_fs_search_persistence.c @@ -17,21 +17,16 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - /** * @file fs/test_fs_search_persistence.c * @brief simple testcase for persistence of search operation * @author Christian Grothoff */ - #include "platform.h" #include "gnunet_util_lib.h" -#include "gnunet_arm_service.h" +#include "gnunet_testing_lib-new.h" #include "gnunet_fs_service.h" -#define VERBOSE GNUNET_NO - -#define START_ARM GNUNET_YES /** * File-size we use for testing. @@ -48,16 +43,6 @@ */ #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) -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; static struct GNUNET_TIME_Absolute start; @@ -69,6 +54,7 @@ static struct GNUNET_FS_PublishContext *publish; static const struct GNUNET_CONFIGURATION_Handle *cfg; + static void abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -99,8 +85,6 @@ restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } - - /** * Consider scheduling the restart-task. * Only runs the restart task once per event @@ -135,14 +119,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) switch (event->status) { case GNUNET_FS_STATUS_PUBLISH_PROGRESS: -#if VERBOSE - printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", - (unsigned long long) event->value.publish.completed, - (unsigned long long) event->value.publish.size, - event->value.publish.specifics.progress.depth, - (unsigned long long) event->value.publish.specifics. - progress.offset); -#endif + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Publish is progressing (%llu/%llu at level %u off %llu)...\n", + (unsigned long long) event->value.publish.completed, + (unsigned long long) event->value.publish.size, + event->value.publish.specifics.progress.depth, + (unsigned long long) event->value.publish.specifics. + progress.offset); break; case GNUNET_FS_STATUS_PUBLISH_COMPLETED: kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); @@ -163,9 +146,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) case GNUNET_FS_STATUS_SEARCH_RESULT: /* FIXME: consider_restart (event->status); cannot be tested with * search result since we exit here after the first one... */ -#if VERBOSE - printf ("Search complete.\n"); -#endif + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Search complete.\n"); GNUNET_SCHEDULER_add_continuation (&abort_search_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); break; @@ -231,44 +213,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) 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", -#if VERBOSE - "-L", "DEBUG", -#endif - "-c", cfgname, NULL); -#endif - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); -} - - -static void -stop_arm (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); -} - - -static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c) { const char *keywords[] = { @@ -283,7 +228,6 @@ run (void *cls, char *const *args, const char *cfgfile, struct GNUNET_FS_BlockOptions bo; cfg = c; - setup_peer (&p1, "test_fs_search_data.conf"); fs = GNUNET_FS_start (cfg, "test-fs-search-persistence", &progress_cb, NULL, GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); GNUNET_assert (NULL != fs); @@ -313,32 +257,10 @@ run (void *cls, char *const *args, const char *cfgfile, int main (int argc, char *argv[]) { - char *const argvx[] = { - "test-fs-search-persistence", - "-c", - "test_fs_search_data.conf", -#if VERBOSE - "-L", "DEBUG", -#endif - NULL - }; - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - - GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/"); - GNUNET_log_setup ("test_fs_search_persistence", -#if VERBOSE - "DEBUG", -#else - "WARNING", -#endif - NULL); - GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, - "test-fs-search-persistence", "nohelp", options, &run, - NULL); - stop_arm (&p1); - GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/"); + if (0 != GNUNET_TESTING_peer_run ("test-fs-search-persistence", + "test_fs_search_data.conf", + &run, NULL)) + return 1; return 0; } diff --git a/src/fs/test_fs_search_probes.c b/src/fs/test_fs_search_probes.c index b81659899..be710a79c 100644 --- a/src/fs/test_fs_search_probes.c +++ b/src/fs/test_fs_search_probes.c @@ -25,10 +25,9 @@ */ #include "platform.h" #include "gnunet_util_lib.h" -#include "gnunet_arm_service.h" +#include "gnunet_testing_lib-new.h" #include "gnunet_fs_service.h" -#define START_ARM GNUNET_YES /** * File-size we use for testing. @@ -45,16 +44,6 @@ */ #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) -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; static struct GNUNET_TIME_Absolute start; @@ -166,41 +155,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) 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 (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); -} - - -static void -stop_arm (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); -} - - -static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { const char *keywords[] = { @@ -214,7 +169,6 @@ run (void *cls, char *const *args, const char *cfgfile, struct GNUNET_FS_FileInformation *fi; size_t i; - setup_peer (&p1, "test_fs_search_data.conf"); fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, GNUNET_FS_FLAGS_DO_PROBES, GNUNET_FS_OPTIONS_END); @@ -245,23 +199,10 @@ run (void *cls, char *const *args, const char *cfgfile, int main (int argc, char *argv[]) { - char *const argvx[] = { - "test-fs-search-probes", - "-c", - "test_fs_search_data.conf", - NULL - }; - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - - GNUNET_log_setup ("test_fs_search_probes", - "WARNING", - NULL); - GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, - "test-fs-search", "nohelp", options, &run, NULL); - stop_arm (&p1); - GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/"); + if (0 != GNUNET_TESTING_peer_run ("test-fs-search-probes", + "test_fs_search_data.conf", + &run, NULL)) + return 1; return 0; } diff --git a/src/fs/test_fs_start_stop.c b/src/fs/test_fs_start_stop.c index 6bd698a43..f3dff69f6 100644 --- a/src/fs/test_fs_start_stop.c +++ b/src/fs/test_fs_start_stop.c @@ -17,7 +17,6 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - /** * @file fs/test_fs_start_stop.c * @brief testcase for fs.c (start-stop only) @@ -26,23 +25,9 @@ #include "platform.h" #include "gnunet_util_lib.h" -#include "gnunet_arm_service.h" +#include "gnunet_testing_lib-new.h" #include "gnunet_fs_service.h" -#define VERBOSE GNUNET_NO - -#define START_ARM GNUNET_YES - -static struct PeerContext p1; - -struct PeerContext -{ - struct GNUNET_CONFIGURATION_Handle *cfg; -#if START_ARM - struct GNUNET_OS_Process *arm_proc; -#endif -}; - static void * progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) @@ -52,49 +37,11 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) 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", -#if VERBOSE - "-L", "DEBUG", -#endif - "-c", cfgname, NULL); -#endif - GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); -} - - -static void -stop_arm (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); -} - - -static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_FS_Handle *fs; - setup_peer (&p1, "test_fs_data.conf"); fs = GNUNET_FS_start (cfg, "test-fs-start-stop", &progress_cb, NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); GNUNET_assert (NULL != fs); @@ -105,30 +52,10 @@ run (void *cls, char *const *args, const char *cfgfile, int main (int argc, char *argv[]) { - char *const argvx[] = { - "test-fs-start-stop", - "-c", - "test_fs_data.conf", -#if VERBOSE - "-L", "DEBUG", -#endif - NULL - }; - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - - GNUNET_log_setup ("test_fs_start_stop", -#if VERBOSE - "DEBUG", -#else - "WARNING", -#endif - NULL); - GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, - "test-fs-start-stop", "nohelp", options, &run, NULL); - stop_arm (&p1); - GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs/"); + if (0 != GNUNET_TESTING_peer_run ("test-fs-start-stop", + "test_fs_data.conf", + &run, NULL)) + return 1; return 0; } diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c index b7a58ec0f..9d6c4abe0 100644 --- a/src/fs/test_fs_uri.c +++ b/src/fs/test_fs_uri.c @@ -17,19 +17,16 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - /** * @file fs/test_fs_uri.c * @brief Test for fs_uri.c * @author Christian Grothoff */ - #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_fs_service.h" #include "fs_api.h" -#define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; } static int testKeyword () @@ -41,26 +38,26 @@ testKeyword () if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/++", &emsg))) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } GNUNET_free (emsg); ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/foo+bar", &emsg); if (ret == NULL) { GNUNET_free (emsg); - ABORT (); + GNUNET_assert (0); } if (!GNUNET_FS_uri_test_ksk (ret)) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } if ((2 != ret->data.ksk.keywordCount) || (0 != strcmp (" foo", ret->data.ksk.keywords[0])) || (0 != strcmp (" bar", ret->data.ksk.keywords[1]))) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } uri = GNUNET_FS_uri_to_string (ret); @@ -68,13 +65,14 @@ testKeyword () { GNUNET_free (uri); GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } GNUNET_free (uri); GNUNET_FS_uri_destroy (ret); return 0; } + static int testLocation () { @@ -157,6 +155,7 @@ testLocation () return 0; } + static int testNamespace (int i) { @@ -170,7 +169,7 @@ testNamespace (int i) &emsg))) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } GNUNET_free (emsg); if (NULL != @@ -179,13 +178,13 @@ testNamespace (int i) ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3V/test", &emsg))) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } GNUNET_free (emsg); if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/test", &emsg))) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } GNUNET_free (emsg); ret = @@ -195,17 +194,17 @@ testNamespace (int i) if (ret == NULL) { GNUNET_free (emsg); - ABORT (); + GNUNET_assert (0); } if (GNUNET_FS_uri_test_ksk (ret)) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } if (!GNUNET_FS_uri_test_sks (ret)) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } uri = GNUNET_FS_uri_to_string (ret); @@ -215,7 +214,7 @@ testNamespace (int i) { GNUNET_FS_uri_destroy (ret); GNUNET_free (uri); - ABORT (); + GNUNET_assert (0); } GNUNET_free (uri); GNUNET_FS_uri_destroy (ret); @@ -236,7 +235,7 @@ testFile (int i) &emsg))) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } GNUNET_free (emsg); if (NULL != @@ -246,7 +245,7 @@ testFile (int i) &emsg))) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } GNUNET_free (emsg); if (NULL != @@ -256,7 +255,7 @@ testFile (int i) &emsg))) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } GNUNET_free (emsg); ret = @@ -266,22 +265,22 @@ testFile (int i) if (ret == NULL) { GNUNET_free (emsg); - ABORT (); + GNUNET_assert (0); } if (GNUNET_FS_uri_test_ksk (ret)) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } if (GNUNET_FS_uri_test_sks (ret)) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } if (GNUNET_ntohll (ret->data.chk.file_length) != 42) { GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } uri = GNUNET_FS_uri_to_string (ret); @@ -291,13 +290,14 @@ testFile (int i) { GNUNET_free (uri); GNUNET_FS_uri_destroy (ret); - ABORT (); + GNUNET_assert (0); } GNUNET_free (uri); GNUNET_FS_uri_destroy (ret); return 0; } + int main (int argc, char *argv[]) { @@ -305,11 +305,7 @@ main (int argc, char *argv[]) int i; GNUNET_log_setup ("test_fs_uri", -#if VERBOSE - "DEBUG", -#else "WARNING", -#endif NULL); GNUNET_CRYPTO_random_disable_entropy_gathering (); failureCount += testKeyword ();