From 823825f3995c0850c4bc748fa267c0a74d35dbb3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 10 Jun 2012 01:01:03 +0000 Subject: [PATCH] -minor fixes --- src/testing/test_testing_peerstartup.c | 36 ++-------------- src/testing/test_testing_portreservation.c | 2 + src/testing/test_testing_servicestartup.c | 50 +++------------------- src/testing/testing.c | 7 ++- 4 files changed, 18 insertions(+), 77 deletions(-) diff --git a/src/testing/test_testing_peerstartup.c b/src/testing/test_testing_peerstartup.c index 13853fe68..990486467 100644 --- a/src/testing/test_testing_peerstartup.c +++ b/src/testing/test_testing_peerstartup.c @@ -33,8 +33,6 @@ #define LOG(kind,...) \ GNUNET_log (kind, __VA_ARGS__) -#define TIME_REL_SEC(sec) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) /** * The testing context @@ -89,37 +87,11 @@ run (void *cls, char *const *args, const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *new_cfg; struct TestingContext *test_ctx; char *emsg; - char *_tmpdir; - char *tmpdir; -#ifdef MINGW - char *tmpdir_w; -#endif - struct GNUNET_PeerIdentity id; - _tmpdir = getenv ("TMP"); - if (NULL == _tmpdir) - _tmpdir = getenv ("TEMP"); - if (NULL == _tmpdir) - _tmpdir = getenv ("TMPDIR"); - if (NULL == _tmpdir) - _tmpdir = "/tmp"; - GNUNET_asprintf (&tmpdir, "%s/%s", _tmpdir, "test-gnunet-testing_new-XXXXXX"); -#ifdef MINGW - tmpdir_w = GNUNET_malloc (MAX_PATH + 1); - GNUNET_assert (ERROR_SUCCESS == plibc_conv_to_win_path (tmpdir, tmpdir_w)); - GNUNET_free (tmpdir); - tmpdir = tmpdir_w; - //GNUNET_assert (0 == _mktemp_s (tmpdir, strlen (tmpdir) + 1)); -#else - GNUNET_assert (mkdtemp (tmpdir) == tmpdir); -#endif - /* LOG (GNUNET_ERROR_TYPE_ERROR, */ - /* "Temporary directory: %s\n", tmpdir); */ - system = GNUNET_TESTING_system_create (tmpdir, + system = GNUNET_TESTING_system_create ("test-gnunet-testing", "127.0.0.1"); GNUNET_assert (NULL != system); - GNUNET_free (tmpdir); new_cfg = GNUNET_CONFIGURATION_dup (cfg); emsg = NULL; peer = GNUNET_TESTING_peer_configure (system, new_cfg, 0, &id, &emsg); @@ -130,9 +102,7 @@ run (void *cls, char *const *args, const char *cfgfile, test_ctx->system = system; test_ctx->peer = peer; test_ctx->cfg = new_cfg; - GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC (5), - &do_shutdown, test_ctx); - + GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); } @@ -150,3 +120,5 @@ int main (int argc, char *argv[]) return 1; return 0; } + +/* end of test_testing_peerstartup.c */ diff --git a/src/testing/test_testing_portreservation.c b/src/testing/test_testing_portreservation.c index 02d6e1686..f689f455a 100644 --- a/src/testing/test_testing_portreservation.c +++ b/src/testing/test_testing_portreservation.c @@ -89,3 +89,5 @@ int main (int argc, char *argv[]) } return 0; } + +/* end of test_testing_portreservation.c */ diff --git a/src/testing/test_testing_servicestartup.c b/src/testing/test_testing_servicestartup.c index 0d3c6ca13..236e84789 100644 --- a/src/testing/test_testing_servicestartup.c +++ b/src/testing/test_testing_servicestartup.c @@ -23,7 +23,6 @@ * @brief test case for testing service startup using new testing API * @author Sree Harsha Totakura */ - #include "platform.h" #include "gnunet_scheduler_lib.h" #include "gnunet_testing_lib-new.h" @@ -32,27 +31,12 @@ #define LOG(kind,...) \ GNUNET_log (kind, __VA_ARGS__) -#define TIME_REL_SEC(sec) \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) /** * Global test status */ static int test_success; -/** - * The shutdown task. Used to signal that testing is done and service has to be - * stopped - * - * @param cls NULL - */ -static void -shutdown_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - test_success = GNUNET_YES; - GNUNET_SCHEDULER_shutdown (); -} - /** * The testing callback function @@ -66,7 +50,8 @@ test_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) GNUNET_assert (NULL == cls); GNUNET_assert (NULL != cfg); LOG (GNUNET_ERROR_TYPE_DEBUG, "Service arm started successfully\n"); - GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC (3), &shutdown_task, NULL); + test_success = GNUNET_YES; + GNUNET_SCHEDULER_shutdown (); } @@ -75,37 +60,14 @@ test_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) */ int main (int argc, char *argv[]) { - char *_tmpdir; - char *tmpdir; -#ifdef MINGW - char *tmpdir_w; -#endif - - GNUNET_log_setup ("test_testing_new_servicestartup", "DEBUG", NULL); - _tmpdir = getenv ("TMP"); - if (NULL == _tmpdir) - _tmpdir = getenv ("TEMP"); - if (NULL == _tmpdir) - _tmpdir = getenv ("TMPDIR"); - if (NULL == _tmpdir) - _tmpdir = "/tmp"; - GNUNET_asprintf (&tmpdir, "%s/%s", _tmpdir, "test-gnunet-testing_new-XXXXXX"); -#ifdef MINGW - tmpdir_w = GNUNET_malloc (MAX_PATH + 1); - GNUNET_assert (ERROR_SUCCESS == plibc_conv_to_win_path (tmpdir, tmpdir_w)); - GNUNET_free (tmpdir); - tmpdir = tmpdir_w; - //GNUNET_assert (0 == _mktemp_s (tmpdir, strlen (tmpdir) + 1)); -#else - GNUNET_assert (mkdtemp (tmpdir) == tmpdir); -#endif - test_success = GNUNET_NO; - GNUNET_assert (0 == GNUNET_TESTING_service_run (tmpdir, + GNUNET_assert (0 == GNUNET_TESTING_service_run ("test-testing-servicestartup", "arm", "test_testing_defaults.conf", &test_run, NULL)); - GNUNET_free (tmpdir); return (GNUNET_YES == test_success) ? 0 : 1; } + +/* end of test_testing_servicestartup.c */ + diff --git a/src/testing/testing.c b/src/testing/testing.c index ac5edab34..949dd5357 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -245,7 +245,12 @@ GNUNET_TESTING_system_create (const char *tmppath, GNUNET_assert (NULL != tmppath); system = GNUNET_malloc (sizeof (struct GNUNET_TESTING_System)); - system->tmppath = GNUNET_strdup (tmppath); + system->tmppath = GNUNET_DISK_mkdtemp (tmppath); + if (NULL == system->tmppath) + { + GNUNET_free (system); + return NULL; + } if (NULL != controller) system->controller = GNUNET_strdup (controller); if (GNUNET_OK != hostkeys_load (system)) -- 2.25.1