From 7798dcc6f7959f3936359654f2f6bef3790c8d80 Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Wed, 18 Jul 2012 08:35:38 +0000 Subject: [PATCH] fixed test_gnunet_testbed_helper --- src/testbed/Makefile.am | 2 +- src/testbed/gnunet-testbed-helper.c | 3 +- src/testbed/test_gnunet_testbed_helper.c | 70 ++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 45a083f79..87fd57587 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am @@ -72,7 +72,7 @@ check_PROGRAMS = \ if ENABLE_TEST_RUN TESTS = \ test_testbed_api_hosts \ - #test_gnunet_testbed_helper + test_gnunet_testbed_helper endif test_testbed_api_hosts_SOURCES = \ diff --git a/src/testbed/gnunet-testbed-helper.c b/src/testbed/gnunet-testbed-helper.c index 23dfeddc2..9327518a6 100644 --- a/src/testbed/gnunet-testbed-helper.c +++ b/src/testbed/gnunet-testbed-helper.c @@ -152,7 +152,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (NULL != stdin_fd) (void) GNUNET_DISK_file_close (stdin_fd); if (NULL != stdout_fd) - (void) GNUNET_DISK_file_close (stdin_fd); + (void) GNUNET_DISK_file_close (stdout_fd); GNUNET_SERVER_mst_destroy (tokenizer); tokenizer = NULL; if (NULL != testbed) @@ -420,6 +420,7 @@ int main (int argc, char **argv) }; ret = GNUNET_OK; + //sleep (60); if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-helper", "Helper for starting gnunet-service-testbed", diff --git a/src/testbed/test_gnunet_testbed_helper.c b/src/testbed/test_gnunet_testbed_helper.c index 26baf82a7..78f6ee69d 100644 --- a/src/testbed/test_gnunet_testbed_helper.c +++ b/src/testbed/test_gnunet_testbed_helper.c @@ -27,6 +27,7 @@ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_testbed_service.h" +#include #include "testbed_api.h" #include "testbed_helper.h" @@ -69,6 +70,11 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; */ static struct GNUNET_CONFIGURATION_Handle *cfg; +/** + * Global testing status + */ +static int result; + /** * Shutdown nicely @@ -97,9 +103,11 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) static void do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) { - LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); abort_task = GNUNET_SCHEDULER_NO_TASK; - GNUNET_HELPER_send_cancel (shandle); + LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); + result = GNUNET_SYSERR; + if (NULL != shandle) + GNUNET_HELPER_send_cancel (shandle); if (GNUNET_SCHEDULER_NO_TASK == shutdown_task) shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); } @@ -119,10 +127,59 @@ cont_cb (void *cls, int result) shandle = NULL; LOG (GNUNET_ERROR_TYPE_DEBUG, "Message sent\n"); GNUNET_assert (GNUNET_OK == result); +} + + +/** + * Functions with this signature are called whenever a + * complete message is received by the tokenizer. + * + * Do not call GNUNET_SERVER_mst_destroy in callback + * + * @param cls closure + * @param client identification of the client + * @param message the actual message + * + * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing + */ +static int +mst_cb (void *cls, void *client, const struct GNUNET_MessageHeader *message) +{ + const struct GNUNET_TESTBED_HelperReply *msg; + char *config; + uLongf config_size; + uLongf xconfig_size; + + msg = (const struct GNUNET_TESTBED_HelperReply *) message; + GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) + < ntohs (msg->header.size)); + GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY + == ntohs (msg->header.type)); + config_size = (uLongf) ntohs (msg->config_size); + xconfig_size = (uLongf) (ntohs (msg->header.size) + - sizeof (struct GNUNET_TESTBED_HelperReply)); + config = GNUNET_malloc (config_size); + GNUNET_assert (Z_OK == uncompress ((Bytef *) config, &config_size, + (const Bytef *) &msg[1], xconfig_size)); if (GNUNET_SCHEDULER_NO_TASK == shutdown_task) shutdown_task = GNUNET_SCHEDULER_add_delayed - (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), + (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &do_shutdown, NULL); + return GNUNET_OK; +} + + +/** + * Callback that will be called when the helper process dies. This is not called + * when the helper process is stoped using GNUNET_HELPER_stop() + * + * @param cls the closure from GNUNET_HELPER_start() + */ +static void +exp_cb (void *cls) +{ + helper = NULL; + result = GNUNET_SYSERR; } @@ -146,7 +203,7 @@ run (void *cls, char *const *args, const char *cfgfile, helper = GNUNET_HELPER_start ("gnunet-testbed-helper", binary_argv, - NULL, NULL, NULL); + &mst_cb, &exp_cb, NULL); GNUNET_assert (NULL != helper); cfg = GNUNET_CONFIGURATION_dup (cfg2); msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_name, cfg); @@ -171,13 +228,14 @@ int main (int argc, char **argv) struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; - + + result = GNUNET_OK; if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test_gnunet_testbed_helper", "Testcase for testing gnunet-testbed-helper.c", options, &run, NULL)) return 1; - return 0; + return (GNUNET_OK == result) ? 0 : 1; } /* end of test_gnunet_testbed_helper.c */ -- 2.25.1