From d5128d1f3cbaf2e495ae1325b5c133cafca9437e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 31 Oct 2009 21:57:40 +0000 Subject: [PATCH] group test works --- BUGS | 4 +- TODO | 6 -- src/testing/Makefile.am | 15 +++- src/testing/test_testing_connect.c | 4 +- src/testing/test_testing_group.c | 119 +++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+), 11 deletions(-) create mode 100644 src/testing/test_testing_group.c diff --git a/BUGS b/BUGS index e764e3cd9..7bb7e0cf5 100644 --- a/BUGS +++ b/BUGS @@ -133,4 +133,6 @@ sane end-user should care about this codebase yet anyway. * HOSTLIST: - implement advertising of hostlist URL - implement learning of hostlist URLs - +* TESTING: + - consider changing API for peer-group termination to + call continuation when done diff --git a/TODO b/TODO index a15110632..d260a95c0 100644 --- a/TODO +++ b/TODO @@ -12,12 +12,6 @@ away), in order in which they will likely be done: * UPNP [Milan] Urgent items (before announcing ng.gnunet.org): -* TESTING (needed for DV, DHT, Topology) - - implement library for local testing - + consider changing API for peer-group termination to - call continuation when done - - implement testcases for library - + test group start * TEST: - topology (needs TESTING) - hostlist (maybe easier with TESTING?) diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index e62795a92..18144c514 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -22,9 +22,14 @@ libgnunettesting_la_LIBADD = $(XLIB) \ check_PROGRAMS = \ test_testing \ - test_testing_connect + test_testing_connect \ + test_testing_group -TESTS = $(check_PROGRAMS) +TESTS = \ + test_testing \ + test_testing_connect \ + test_testing_group +#$(check_PROGRAMS) test_testing_SOURCES = \ test_testing.c @@ -38,6 +43,12 @@ test_testing_connect_LDADD = \ $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la +test_testing_group_SOURCES = \ + test_testing_group.c +test_testing_group_LDADD = \ + $(top_builddir)/src/testing/libgnunettesting.la \ + $(top_builddir)/src/util/libgnunetutil.la + EXTRA_DIST = \ test_testing_data.conf \ test_testing_connect_peer1.conf \ diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c index b6a2d859a..431b63963 100644 --- a/src/testing/test_testing_connect.c +++ b/src/testing/test_testing_connect.c @@ -157,7 +157,7 @@ check () GNUNET_GETOPT_OPTION_END }; GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, - argv, "test-testing", "nohelp", + argv, "test-testing-connect", "nohelp", options, &run, &ok); return ok; } @@ -167,7 +167,7 @@ main (int argc, char *argv[]) { int ret; - GNUNET_log_setup ("test-testing", + GNUNET_log_setup ("test-testing-connect", #if VERBOSE "DEBUG", #else diff --git a/src/testing/test_testing_group.c b/src/testing/test_testing_group.c new file mode 100644 index 000000000..1d38ef5ec --- /dev/null +++ b/src/testing/test_testing_group.c @@ -0,0 +1,119 @@ +/* + 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 testing/test_testing_group.c + * @brief testcase for functions to connect two peers in testing.c + */ +#include "platform.h" +#include "gnunet_testing_lib.h" + +#define VERBOSE GNUNET_NO + + +/** + * How long until we give up on connecting the peers? + */ +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) + + +static int ok; + +static int peers_left; + +static struct GNUNET_TESTING_PeerGroup *pg; + +static struct GNUNET_SCHEDULER_Handle *sched; + + +static void my_cb(void *cls, + const struct GNUNET_PeerIdentity *id, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Daemon *d, + const char *emsg) +{ + GNUNET_assert (id != NULL); + peers_left--; + if (peers_left == 0) + { + GNUNET_TESTING_daemons_stop (pg); + ok = 0; + } +} + + +static void +run (void *cls, + struct GNUNET_SCHEDULER_Handle *s, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + sched = s; + ok = 1; +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting daemons.\n"); +#endif + peers_left = 4; + pg = GNUNET_TESTING_daemons_start (sched, cfg, + peers_left, + &my_cb, NULL, NULL); + GNUNET_assert (pg != NULL); +} + +static int +check () +{ + char *const argv[] = { "test-testing", + "-c", + "test_testing_data.conf", +#if VERBOSE + "-L", "DEBUG", +#endif + NULL + }; + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_OPTION_END + }; + GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, + argv, "test-testing-group", "nohelp", + options, &run, &ok); + return ok; +} + +int +main (int argc, char *argv[]) +{ + int ret; + + GNUNET_log_setup ("test-testing-group", +#if VERBOSE + "DEBUG", +#else + "WARNING", +#endif + NULL); + ret = check (); + sleep (1); + GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing"); + return ret; +} + +/* end of test_testing_group.c */ -- 2.25.1