From 8efaae301b29ec7cbdb921ac5e6b30ae2c143568 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 10 Jun 2012 11:38:46 +0000 Subject: [PATCH] -adding helper function to determine plugin names to testing --- src/include/gnunet_testing_lib-new.h | 21 +++++++++++++-- src/testing/testing.c | 40 +++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/include/gnunet_testing_lib-new.h b/src/include/gnunet_testing_lib-new.h index b88cd9e98..9bd6c3b25 100644 --- a/src/include/gnunet_testing_lib-new.h +++ b/src/include/gnunet_testing_lib-new.h @@ -73,7 +73,6 @@ GNUNET_TESTING_system_create (const char *tmppath, const char *controller); - /** * Free system resources. * @@ -225,6 +224,7 @@ typedef void (*GNUNET_TESTING_TestMain)(void *cls, * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'. * * @param tmppath path for storing temporary data for the test + * also used to setup the program name for logging * @param cfgfilename name of the configuration file to use; * use NULL to only run with defaults * @param tm main function of the testcase @@ -238,7 +238,6 @@ GNUNET_TESTING_peer_run (const char *tmppath, void *tm_cls); - /** * Start a single service (no ARM, except of course if the given * service name is 'arm') and run a test using the testing library. @@ -251,6 +250,7 @@ GNUNET_TESTING_peer_run (const char *tmppath, * and if that service doesn't itself depend on other services. * * @param tmppath path for storing temporary data for the test + * also used to setup the program name for logging * @param service_name name of the service to run * @param cfgfilename name of the configuration file to use; * use NULL to only run with defaults @@ -267,6 +267,23 @@ GNUNET_TESTING_service_run (const char *tmppath, +/** + * Sometimes we use the binary name to determine which specific + * test to run. In those cases, the string after the last "_" + * in 'argv[0]' specifies a string that determines the configuration + * file or plugin to use. + * + * This function returns the respective substring, taking care + * of issues such as binaries ending in '.exe' on W32. + * + * @param argv0 the name of the binary + * @return string between the last '_' and the '.exe' (or the end of the string), + * NULL if argv0 has no '_' + */ +char * +GNUNET_TESTING_get_testname_from_underscore (const char *argv0); + + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/testing/testing.c b/src/testing/testing.c index 68d1f1f39..39d7b717d 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -877,6 +877,7 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer) * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'. * * @param tmppath path for storing temporary data for the test + * also used to setup the program name for logging * @param cfgfilename name of the configuration file to use; * use NULL to only run with defaults * @param tm main function of the testcase @@ -943,7 +944,8 @@ service_run_main (void *cls, * This function is useful if the testcase is for a single service * and if that service doesn't itself depend on other services. * - * @param tmppath path for storing temporary data for the test + * @param tmppath path for storing temporary data for the test, + * also used to setup the program name for logging * @param service_name name of the service to run * @param cfgfilename name of the configuration file to use; * use NULL to only run with defaults @@ -963,6 +965,9 @@ GNUNET_TESTING_service_run (const char *tmppath, struct GNUNET_TESTING_Peer *peer; struct GNUNET_CONFIGURATION_Handle *cfg; + GNUNET_log_setup (tmppath, + "WARNING", + NULL); system = GNUNET_TESTING_system_create (tmppath, "127.0.0.1"); if (NULL == system) return 1; @@ -1010,4 +1015,37 @@ GNUNET_TESTING_service_run (const char *tmppath, } +/** + * Sometimes we use the binary name to determine which specific + * test to run. In those cases, the string after the last "_" + * in 'argv[0]' specifies a string that determines the configuration + * file or plugin to use. + * + * This function returns the respective substring, taking care + * of issues such as binaries ending in '.exe' on W32. + * + * @param argv0 the name of the binary + * @return string between the last '_' and the '.exe' (or the end of the string), + * NULL if argv0 has no '_' + */ +char * +GNUNET_TESTING_get_testname_from_underscore (const char *argv0) +{ + size_t slen = strlen (argv0) + 1; + char sbuf[slen]; + char *ret; + char *dot; + + memcpy (sbuf, argv0, slen); + ret = strrchr (sbuf, '_'); + if (NULL == ret) + return NULL; + ret++; /* skip underscore */ + dot = strchr (ret, '.'); + if (NULL != dot) + *dot = '\0'; + return GNUNET_strdup (ret); +} + + /* end of testing.c */ -- 2.25.1