From 1a956f969b0166ee609a88d37ace19486bd6bcee Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Wed, 18 Jul 2012 13:03:17 +0000 Subject: [PATCH] fix; modified testcase for test_testbed_api; valigrind suppression for zlib --- src/include/gnunet_testbed_service.h | 9 +++--- src/testbed/Makefile.am | 1 + src/testbed/test_testbed_api.c | 44 ++++++++++++++++++++-------- src/testbed/testbed_api.c | 34 ++++++++++++++++----- src/testbed/valgrind-zlib.supp | 7 +++++ 5 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 src/testbed/valgrind-zlib.supp diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h index 8888d781e..d6c4354fe 100644 --- a/src/include/gnunet_testbed_service.h +++ b/src/include/gnunet_testbed_service.h @@ -429,10 +429,11 @@ typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls, * configuration (port numbers, unix domain sockets and service home * values are changed as per TESTING library on the remote host) * @param cb function called when the controller is successfully started or - * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be - * called if cb is called with GNUNET_SYSERR as status. Will never be - * called in the same task as 'GNUNET_TESTBED_controller_start' - * (synchronous errors will be signalled by returning NULL) + * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be + * called if cb is called with GNUNET_SYSERR as status. Will never be + * called in the same task as 'GNUNET_TESTBED_controller_start' + * (synchronous errors will be signalled by returning NULL). This + * parameter cannot be NULL. * @param cls closure for above callbacks * @return the controller process handle, NULL on errors */ diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 86d04ebde..707040a75 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am @@ -71,6 +71,7 @@ check_PROGRAMS = \ if ENABLE_TEST_RUN TESTS = \ + test_testbed_api \ test_testbed_api_hosts \ test_gnunet_testbed_helper endif diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c index 9bdae1fb0..6378fd9cc 100644 --- a/src/testbed/test_testbed_api.c +++ b/src/testbed/test_testbed_api.c @@ -171,23 +171,21 @@ registration_comp (void *cls, const char *emsg) /** - * Main run function. + * Callback to signal successfull startup of the controller process * - * @param cls NULL - * @param args arguments passed to GNUNET_PROGRAM_run - * @param cfgfile the path to configuration file - * @param cfg the configuration file handle + * @param cls the closure from GNUNET_TESTBED_controller_start() + * @param cfg the configuration with which the controller has been started; + * NULL if status is not GNUNET_OK + * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, + * GNUNET_TESTBED_controller_stop() shouldn't be called in this case */ -static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +static void +status_cb (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, int status) { uint64_t event_mask; - host = GNUNET_TESTBED_host_create (NULL, NULL, 0); - GNUNET_assert (NULL != host); - cfg = GNUNET_CONFIGURATION_dup (config); - cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, NULL, NULL); + GNUNET_assert (GNUNET_OK == status); event_mask = 0; event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); @@ -201,7 +199,27 @@ run (void *cls, char *const *args, const char *cfgfile, reg_handle = GNUNET_TESTBED_register_host (controller, neighbour, ®istration_comp, neighbour); - GNUNET_assert (NULL != reg_handle); + GNUNET_assert (NULL != reg_handle); +} + + + +/** + * Main run function. + * + * @param cls NULL + * @param args arguments passed to GNUNET_PROGRAM_run + * @param cfgfile the path to configuration file + * @param cfg the configuration file handle + */ +static void +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) +{ + host = GNUNET_TESTBED_host_create (NULL, NULL, 0); + GNUNET_assert (NULL != host); + cfg = GNUNET_CONFIGURATION_dup (config); + cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb, NULL); abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5), &do_abort, NULL); } diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 5af8d71c6..6cdcabdd6 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -444,11 +444,17 @@ struct GNUNET_TESTBED_ControllerProc * The closure for the above callback */ void *cls; + /** * The send handle for the helper */ struct GNUNET_HELPER_SendHandle *shandle; + /** + * The message corresponding to send handle + */ + struct GNUNET_MessageHeader *msg; + /** * The port number for ssh; used for helpers starting ssh */ @@ -484,6 +490,7 @@ static int helper_mst (void *cls, void *client, { struct GNUNET_TESTBED_ControllerProc *cp = cls; const struct GNUNET_TESTBED_HelperReply *msg; + const char *hostname; char *config; uLongf config_size; uLongf xconfig_size; @@ -503,10 +510,13 @@ static int helper_mst (void *cls, void *client, cp->cfg = GNUNET_CONFIGURATION_create (); GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->cfg, config, config_size, GNUNET_NO)); + GNUNET_free (config); + if ((NULL == cp->host) || + (NULL == (hostname = GNUNET_TESTBED_host_get_hostname_ (cp->host)))) + hostname = "localhost"; /* Change the hostname so that we can connect to it */ GNUNET_CONFIGURATION_set_value_string (cp->cfg, "testbed", "hostname", - (NULL == cp->host) ? "localhost" : - GNUNET_TESTBED_host_get_hostname_ (cp->host)); + hostname); cp->cb (cp->cls, cp->cfg, GNUNET_OK); return GNUNET_OK; } @@ -523,7 +533,11 @@ static int helper_mst (void *cls, void *client, static void clear_msg (void *cls, int result) { - GNUNET_free (cls); + struct GNUNET_TESTBED_ControllerProc *cp = cls; + + GNUNET_assert (NULL != cp->shandle); + cp->shandle = NULL; + GNUNET_free (cp->msg); } @@ -561,10 +575,11 @@ helper_exp_cb (void *cls) * configuration (port numbers, unix domain sockets and service home * values are changed as per TESTING library on the remote host) * @param cb function called when the controller is successfully started or - * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be - * called if cb is called with GNUNET_SYSERR as status. Will never be - * called in the same task as 'GNUNET_TESTBED_controller_start' - * (synchronous errors will be signalled by returning NULL) + * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be + * called if cb is called with GNUNET_SYSERR as status. Will never be + * called in the same task as 'GNUNET_TESTBED_controller_start' + * (synchronous errors will be signalled by returning NULL). This + * parameter cannot be NULL. * @param cls closure for above callbacks * @return the controller process handle, NULL on errors */ @@ -625,8 +640,9 @@ GNUNET_TESTBED_controller_start (const char *controller_ip, cp->cb = cb; cp->cls = cls; msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_ip, cfg); + cp->msg = &msg->header; cp->shandle = GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, - &clear_msg, msg); + &clear_msg, cp); if (NULL == cp->shandle) { GNUNET_free (msg); @@ -650,6 +666,8 @@ GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cp) if (NULL != cp->shandle) GNUNET_HELPER_send_cancel (cp->shandle); GNUNET_HELPER_stop (cp->helper); + if (NULL != cp->cfg) + GNUNET_CONFIGURATION_destroy (cp->cfg); GNUNET_free_non_null (cp->port); GNUNET_free_non_null (cp->dst); GNUNET_free (cp); diff --git a/src/testbed/valgrind-zlib.supp b/src/testbed/valgrind-zlib.supp new file mode 100644 index 000000000..683eb377a --- /dev/null +++ b/src/testbed/valgrind-zlib.supp @@ -0,0 +1,7 @@ +{ + + Memcheck:Cond + fun:inflateReset2 + obj:* + obj:* +} \ No newline at end of file -- 2.25.1