From: Safey A.Halim Date: Fri, 15 Jan 2010 15:24:30 +0000 (+0000) Subject: Test case for arm exponential backoff (Incomplete) X-Git-Tag: initial-import-from-subversion-38251~22963 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a257f028184102b04995c6774f065200919a3dff;p=oweals%2Fgnunet.git Test case for arm exponential backoff (Incomplete) --- diff --git a/src/arm/Makefile.am b/src/arm/Makefile.am index 4bfda1756..36161e8a0 100644 --- a/src/arm/Makefile.am +++ b/src/arm/Makefile.am @@ -23,7 +23,8 @@ libgnunetarm_la_LDFLAGS = \ bin_PROGRAMS = \ gnunet-arm \ - gnunet-service-arm + gnunet-service-arm \ + mockup-service gnunet_arm_SOURCES = \ gnunet-arm.c @@ -39,13 +40,20 @@ gnunet_service_arm_LDADD = \ $(GN_LIBINTL) -check_PROGRAMS = \ - test_arm_api +mockup_service_SOURCES = \ + mockup-service.c + mockup_service_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la + +check_PROGRAMS = \ + test_arm_api \ + test_exponential_backoff + check_SCRIPTS = \ test_gnunet_arm.sh -TESTS = $(check_PROGRAMS) $(check_SCRIPTS) +TESTS = test_arm_api $(check_SCRIPTS) test_arm_api_SOURCES = \ test_arm_api.c @@ -53,6 +61,12 @@ test_arm_api_LDADD = \ $(top_builddir)/src/arm/libgnunetarm.la \ $(top_builddir)/src/util/libgnunetutil.la - +test_exponential_backoff_SOURCES = \ + test_exponential_backoff.c +test_exponential_backoff_LDADD = \ + $(top_builddir)/src/arm/libgnunetarm.la \ + $(top_builddir)/src/util/libgnunetutil.la + + EXTRA_DIST = \ test_arm_api_data.conf diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c new file mode 100644 index 000000000..026138fab --- /dev/null +++ b/src/arm/mockup-service.c @@ -0,0 +1,54 @@ +/* + This file is part of GNUnet. + (C) 2007, 2008, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include +#include "platform.h" +#include "gnunet_disk_lib.h" +#include "gnunet_getopt_lib.h" +#include "gnunet_protocols.h" +#include "gnunet_service_lib.h" +#include "gnunet_statistics_service.h" +#include "gnunet_strings_lib.h" +#include "gnunet_time_lib.h" + + +static void +run (void *cls, + struct GNUNET_SCHEDULER_Handle *sched, + struct GNUNET_SERVER_Handle *server, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + /* Does nothing */ + int x = 0; +} + + +int main(int argc, char *const *argv) +{ + int ret; + + ret = (GNUNET_OK == + GNUNET_SERVICE_run (argc, + argv, + "do-nothing", GNUNET_SERVICE_OPTION_NONE, + &run, NULL)) ? 0 : 1; + + return ret; +} \ No newline at end of file diff --git a/src/arm/test_arm_api_data.conf b/src/arm/test_arm_api_data.conf index cbfb30534..92f7efb45 100644 --- a/src/arm/test_arm_api_data.conf +++ b/src/arm/test_arm_api_data.conf @@ -9,3 +9,14 @@ DEFAULTSERVICES = [resolver] #DEBUG = YES + +[do-nothing] +#DEBUG = YES +PORT = 2223 +HOSTNAME = localhost +HOME = $SERVICEHOME +CONFIG = $DEFAULTCONFIG +BINARY = mockup-service +ACCEPT_FROM = 127.0.0.1; +ACCEPT_FROM6 = ::1; +ALLOW_SHUTDOWN = YES diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c new file mode 100644 index 000000000..bbd0f2000 --- /dev/null +++ b/src/arm/test_exponential_backoff.c @@ -0,0 +1,229 @@ +/* + This file is part of GNUnet. + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file arm/test_exponential_backoff.c + * @brief testcase for gnunet-service-arm.c + */ +#include "platform.h" +#include "gnunet_arm_service.h" +#include "gnunet_client_lib.h" +#include "gnunet_configuration_lib.h" +#include "gnunet_program_lib.h" + +#define START_ARM GNUNET_YES +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) + +static struct GNUNET_SCHEDULER_Handle *sched; +static const struct GNUNET_CONFIGURATION_Handle *cfg; +static struct GNUNET_ARM_Handle *arm; +static int ok = 1; +static int kill_ok = GNUNET_OK; +static FILE *killLogFilePtr; +static char *killLogFileName; + +static void +arm_notify_stop (void *cls, int success) +{ + GNUNET_assert (success == GNUNET_NO); +#if START_ARM + GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, NULL, NULL); +#endif +} + + +static void +do_nothing_notify_stop (void *cls, int success) +{ + GNUNET_assert (success == GNUNET_NO); +} + + +static void +do_nothing_notify (void *cls, int success) +{ + GNUNET_assert (success == GNUNET_YES); + ok = 1; +} + + +static void +arm_notify (void *cls, int success) +{ + GNUNET_assert (success == GNUNET_YES); + GNUNET_ARM_start_service (arm, "do-nothing", TIMEOUT, &do_nothing_notify, NULL); +} + + +static void +kill_task (void *cbData, + const struct GNUNET_SCHEDULER_TaskContext *tc); +static void +do_nothing_restarted_notify_task (void *unused, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + static char a; + static int trialCount = 0; + + trialCount++; + if (trialCount >= 11) { + if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) + fprintf(killLogFilePtr, "Reason is shutdown!\n"); + else if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) + fprintf(killLogFilePtr, "%d.Reason is timeout!\n", trialCount); + else if ((tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE) != 0) + fprintf(killLogFilePtr, "%d.Service is running!\n", trialCount); + } + + GNUNET_SCHEDULER_add_now (sched, &kill_task, &a); // checks if this was too fast +} + + +static void +kill_task (void *cbData, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + int* reason; + struct GNUNET_CLIENT_Connection * doNothingConnection = NULL; + static struct GNUNET_TIME_Absolute startedWaitingAt; + struct GNUNET_TIME_Relative waitedFor; + static int trialCount = 0; + + reason = cbData; + if (NULL != reason) { + waitedFor = GNUNET_TIME_absolute_get_duration(startedWaitingAt); + trialCount++; + if (trialCount >= 11) + fprintf(killLogFilePtr, "Trial no.%d, Started waiting at:%lld. Waited for: %lld\n", trialCount, startedWaitingAt.value, waitedFor.value); + } + + /* Connect to the doNothing task */ + doNothingConnection = GNUNET_CLIENT_connect (sched, "do-nothing", cfg); + if (NULL == doNothingConnection) + fprintf(killLogFilePtr, "Unable to connect to do-nothing process!\n"); + else if (trialCount == 20) { + GNUNET_ARM_stop_service (arm, "do-nothing", TIMEOUT, &arm_notify_stop, NULL); + return; + } + + /* Use the created connection to kill the doNothingTask */ + GNUNET_CLIENT_service_shutdown(doNothingConnection); + sleep(0.005); + startedWaitingAt = GNUNET_TIME_absolute_get(); + /* + * There is something wrong here! + * TIMEOUT value is set to 10 seconds (a drastically large value) + * debugging is showing that the reason for which + * do_nothing_restarted_notify_task is called is "always" + * TIMEOUT which means that the "do-nothing" service is not running + * however the overall execution time doesn't exceed 2 seconds + * which means there is something tricky about the TIMOUT passed + * to function GNUNET_CLIENT_service_test() + */ + GNUNET_CLIENT_service_test(sched, "do-nothing", cfg, TIMEOUT, &do_nothing_restarted_notify_task, NULL); +} + +static void +task (void *cls, + struct GNUNET_SCHEDULER_Handle *s, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) +{ + cfg = c; + sched = s; + + arm = GNUNET_ARM_connect (cfg, sched, NULL); +#if START_ARM + GNUNET_ARM_start_service (arm, "arm", TIMEOUT, &arm_notify, NULL); +#else + arm_do_nothing (NULL, GNUNET_YES); +#endif + GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL); +} + +static int +check () +{ + char *const argv[] = { + "test-arm-api", + "-c", "test_arm_api_data.conf", +#if VERBOSE + "-L", "DEBUG", +#endif + NULL + }; + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_OPTION_END + }; + + /* Running ARM and running the do_nothing task */ + GNUNET_assert (GNUNET_OK == + GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, + argv, + "test-exponential-backoff", + "nohelp", options, &task, NULL)); + + + return ok; +} + +static int +init() +{ + killLogFileName = GNUNET_DISK_mktemp("exponential-backoff-waiting.log"); + if (NULL == (killLogFilePtr = FOPEN(killLogFileName, "w"))) { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", killLogFileName); + GNUNET_free (killLogFileName); + return GNUNET_SYSERR; + } + + return GNUNET_OK; +} + + +static void +houseKeep() +{ + GNUNET_assert (0 == fclose (killLogFilePtr)); + GNUNET_free(killLogFileName); +} + + +int +main (int argc, char *argv[]) +{ + int ret; + + + GNUNET_log_setup ("test-exponential-backoff", +#if VERBOSE + "DEBUG", +#else + "WARNING", +#endif + NULL); + + init(); + ret = check (); + houseKeep(); + return ret; +} + +/* end of test_exponential_backoff.c */