From 43365f0c4f03ffa75b5018e3a7899fc338b40b29 Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Wed, 28 Apr 2010 13:59:11 +0000 Subject: minor testing changes --- src/testing/Makefile.am | 24 ++- src/testing/test_testing_data_remote.conf | 33 +++++ ...est_testing_data_topology_small_world_ring.conf | 2 +- src/testing/test_testing_group.c | 2 +- src/testing/test_testing_group_remote.c | 139 +++++++++++++++++ src/testing/test_testing_topology.c | 13 +- src/testing/testing_group.c | 165 +++++++++++---------- 7 files changed, 288 insertions(+), 90 deletions(-) create mode 100644 src/testing/test_testing_data_remote.conf create mode 100644 src/testing/test_testing_group_remote.c (limited to 'src/testing') diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 1041dd901..2cfa330b3 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -25,28 +25,29 @@ check_PROGRAMS = \ test_testing \ test_testing_connect \ test_testing_group \ - test_testing_topology_clique -# test_testing_group_remote + test_testing_topology_clique +# test_testing_group_remote \ # test_testing_topology_ring \ # test_testing_topology_2d_torus \ # test_testing_topology_small_world_ring \ # test_testing_topology_small_world_torus \ # test_testing_topology_erdos_renyi \ -# test_testing_topology_internat +# test_testing_topology_internat \ +# test_testing_topology_scale_free TESTS = \ test_testing \ test_testing_connect \ test_testing_group \ - test_testing_topology_clique -# test_testing_group_remote + test_testing_topology_clique +# test_testing_group_remote \ # test_testing_topology_ring \ # test_testing_topology_2d_torus \ # test_testing_topology_small_world_ring \ # test_testing_topology_small_world_torus \ # test_testing_topology_erdos_renyi \ -# test_testing_topology_internat -#$(check_PROGRAMS) +# test_testing_topology_internat \ +# test_testing_topology_scale_free test_testing_SOURCES = \ test_testing.c @@ -114,6 +115,12 @@ test_testing_topology_clique_LDADD = \ # $(top_builddir)/src/testing/libgnunettesting.la \ # $(top_builddir)/src/util/libgnunetutil.la +#test_testing_topology_scale_free_SOURCES = \ +# test_testing_topology.c +#test_testing_topology_scale_free_LDADD = \ +# $(top_builddir)/src/testing/libgnunettesting.la \ +# $(top_builddir)/src/util/libgnunetutil.la + EXTRA_DIST = \ test_testing_data.conf \ @@ -125,5 +132,6 @@ EXTRA_DIST = \ test_testing_data_topology_small_world_ring.conf \ test_testing_data_topology_small_world_torus.conf \ test_testing_data_topology_erdos_renyi.conf \ - test_testing_data_topology_internat.conf + test_testing_data_topology_internat.conf \ + test_testing_data_topology_scale_free.conf diff --git a/src/testing/test_testing_data_remote.conf b/src/testing/test_testing_data_remote.conf new file mode 100644 index 000000000..26de59a85 --- /dev/null +++ b/src/testing/test_testing_data_remote.conf @@ -0,0 +1,33 @@ +[PATHS] +SERVICEHOME = /tmp/test-gnunet-testing/ +DEFAULTCONFIG = test_testing_data.conf + +[resolver] +PORT = 2564 + +[transport] +PORT = 2565 +PLUGINS = tcp +#PREFIX = xterm -e xterm -T transport -e gdb -x cmd --args +#PREFIX = valgrind --tool=memcheck --log-file=logs%p + +[arm] +PORT = 2566 +DEFAULTSERVICES = peerinfo transport core + +[statistics] +PORT = 2567 + +[transport-tcp] +PORT = 2568 + +[peerinfo] +PORT = 2569 + +[core] +PORT = 2570 + +[testing] +CONTROL_HOST = 131.159.20.42 +HOSTS = 127.0.0.1 +WEAKRANDOM = YES diff --git a/src/testing/test_testing_data_topology_small_world_ring.conf b/src/testing/test_testing_data_topology_small_world_ring.conf index f97723ff2..3883f1bee 100644 --- a/src/testing/test_testing_data_topology_small_world_ring.conf +++ b/src/testing/test_testing_data_topology_small_world_ring.conf @@ -30,7 +30,7 @@ PORT = 2570 #DEBUG = YES [testing] -NUM_PEERS = 5 +NUM_PEERS = 25 WEAKRANDOM = YES TOPOLOGY = 2 F2F = YES diff --git a/src/testing/test_testing_group.c b/src/testing/test_testing_group.c index 61ef82449..d9d22dd02 100644 --- a/src/testing/test_testing_group.c +++ b/src/testing/test_testing_group.c @@ -24,7 +24,7 @@ #include "platform.h" #include "gnunet_testing_lib.h" -#define VERBOSE GNUNET_YES +#define VERBOSE GNUNET_NO #define NUM_PEERS 4 diff --git a/src/testing/test_testing_group_remote.c b/src/testing/test_testing_group_remote.c new file mode 100644 index 000000000..c1bd2c8a6 --- /dev/null +++ b/src/testing/test_testing_group_remote.c @@ -0,0 +1,139 @@ +/* + 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_remote.c + * @brief testcase for testing remote and local starting and connecting + * of hosts from the testing library. The test_testing_data_remote.conf + * file should be modified if this testcase is intended to be used. + */ +#include "platform.h" +#include "gnunet_testing_lib.h" + +#define VERBOSE GNUNET_YES + + +/** + * How long until we give up on connecting the peers? + */ +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) + +#define DEFAULT_NUM_PEERS 8; + +static int ok; + +static int peers_left; + +static struct GNUNET_TESTING_PeerGroup *pg; + +static struct GNUNET_SCHEDULER_Handle *sched; + +static unsigned long long num_peers; + +static char *hostnames; + + +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 + + if (GNUNET_SYSERR == + GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", + &num_peers)) + num_peers = DEFAULT_NUM_PEERS; + + GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hosts", + &hostnames); + + peers_left = num_peers; + pg = GNUNET_TESTING_daemons_start (sched, cfg, + peers_left, + &my_cb, NULL, NULL, NULL, hostnames); + GNUNET_assert (pg != NULL); +} + +static int +check () +{ + char *const argv[] = { "test-testing", + "-c", + "test_testing_data_remote.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 (); + /** + * Still need to remove the base testing directory here, + * because group starts will create subdirectories under this + * main dir. However, we no longer need to sleep, as the + * shutdown sequence won't return until everything is cleaned + * up. + */ + GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing"); + return ret; +} + +/* end of test_testing_group.c */ diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index 2006cc468..446cd4dfb 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c @@ -25,7 +25,7 @@ #include "gnunet_testing_lib.h" #include "gnunet_core_service.h" -#define VERBOSE GNUNET_YES +#define VERBOSE GNUNET_NO /** * How long until we fail the whole testcase? @@ -81,6 +81,8 @@ static int transmit_ready_failed; static int transmit_ready_called; +static enum GNUNET_TESTING_Topology topology; + #define MTYPE 12345 struct GNUNET_TestMessage @@ -518,7 +520,7 @@ create_topology () maybe this way is best so that the client can know both when peers are started, and when they are connected. */ - expected_connections = GNUNET_TESTING_create_topology (pg); + expected_connections = GNUNET_TESTING_create_topology (pg, topology); #if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n", expected_connections); @@ -575,6 +577,7 @@ run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + unsigned long long topology_num; sched = s; ok = 1; @@ -588,6 +591,12 @@ run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons based on config file %s\n", cfgfile); #endif + + if (GNUNET_YES == + GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "topology", + &topology_num)) + topology = topology_num; + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", &num_peers)) diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 43ebd5e25..e617bc113 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -27,7 +27,7 @@ #include "gnunet_arm_service.h" #include "gnunet_testing_lib.h" -#define VERBOSE_TESTING GNUNET_NO +#define VERBOSE_TESTING GNUNET_YES /** * Lowest port used for GNUnet testing. Should be high enough to not @@ -354,14 +354,28 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigne return added; } +/** + * Scale free network construction as described in: + * + * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999. + * + * Start with a network of "one" peer, then progressively add + * peers up to the total number. At each step, iterate over + * all possible peers and connect new peer based on number of + * existing connections of the target peer. + * + * @param pg the peer group we are dealing with + * + * @return the number of connections created + */ static int create_scale_free (struct GNUNET_TESTING_PeerGroup *pg) { - int total_connections; - int outer_count; - int i; - int previous_total_connections; + unsigned int total_connections; + unsigned int outer_count; + unsigned int i; + unsigned int previous_total_connections; double random; double probability; @@ -370,14 +384,19 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg) /* Add a connection between the first two nodes */ total_connections = add_connections(pg, 0, 1); - for (outer_count = 1; outer_count < pg->total - 1; outer_count++) + for (outer_count = 1; outer_count < pg->total; outer_count++) { previous_total_connections = total_connections; for (i = 0; i < outer_count; i++) { - probability = pg->peers[i].num_connections / previous_total_connections; + probability = pg->peers[i].num_connections / (double)previous_total_connections; random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL); +#if VERBOSE_TESTING + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Considering connecting peer %d to peer %d\n", + outer_count, i); +#endif if (random < probability) { #if VERBOSE_TESTING @@ -1099,109 +1118,99 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg) * the connection actually happened. * * @param pg the peer group struct representing the running peers + * @param topology which topology to connect the peers in * * @return the number of connections should be created by the topology, so the * caller knows how many to wait for (if it so chooses) * */ int -GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg) +GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, enum GNUNET_TESTING_Topology topology) { - unsigned long long topology_num; int ret; int num_connections; GNUNET_assert (pg->notify_connection != NULL); ret = GNUNET_OK; - if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_number (pg->cfg, "testing", "topology", - &topology_num)) + + switch (topology) { - switch (topology_num) - { - case GNUNET_TESTING_TOPOLOGY_CLIQUE: + case GNUNET_TESTING_TOPOLOGY_CLIQUE: #if VERBOSE_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating clique topology\n")); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Creating clique topology\n")); #endif - num_connections = create_clique (pg); - break; - case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: + num_connections = create_clique (pg); + break; + case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: #if VERBOSE_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating small world (ring) topology\n")); -#endif - num_connections = create_small_world_ring (pg); - break; - case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: -#if VERBOSE_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating small world (2d-torus) topology\n")); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Creating small world (ring) topology\n")); #endif - num_connections = create_small_world (pg); - break; - case GNUNET_TESTING_TOPOLOGY_RING: + num_connections = create_small_world_ring (pg); + break; + case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: #if VERBOSE_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating ring topology\n")); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Creating small world (2d-torus) topology\n")); #endif - num_connections = create_ring (pg); - break; - case GNUNET_TESTING_TOPOLOGY_2D_TORUS: + num_connections = create_small_world (pg); + break; + case GNUNET_TESTING_TOPOLOGY_RING: #if VERBOSE_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating 2d torus topology\n")); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Creating ring topology\n")); #endif - num_connections = create_2d_torus (pg); - break; - case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: + num_connections = create_ring (pg); + break; + case GNUNET_TESTING_TOPOLOGY_2D_TORUS: #if VERBOSE_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating Erdos-Renyi topology\n")); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Creating 2d torus topology\n")); #endif - num_connections = create_erdos_renyi (pg); - break; - case GNUNET_TESTING_TOPOLOGY_INTERNAT: + num_connections = create_2d_torus (pg); + break; + case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: #if VERBOSE_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating InterNAT topology\n")); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Creating Erdos-Renyi topology\n")); #endif - num_connections = create_nated_internet (pg); - break; - case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: + num_connections = create_erdos_renyi (pg); + break; + case GNUNET_TESTING_TOPOLOGY_INTERNAT: #if VERBOSE_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Creating Scale Free topology\n")); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Creating InterNAT topology\n")); #endif - num_connections = create_scale_free (pg); - break; - case GNUNET_TESTING_TOPOLOGY_NONE: - num_connections = 0; - break; - default: - num_connections = 0; - break; - } - if (num_connections < 1) - return GNUNET_SYSERR; - - if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "F2F")) - ret = create_and_copy_friend_files(pg); - if (ret == GNUNET_OK) - connect_topology(pg); - else - { + num_connections = create_nated_internet (pg); + break; + case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: #if VERBOSE_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Failed during friend file copying!\n")); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Creating Scale Free topology\n")); #endif - return GNUNET_SYSERR; - } + num_connections = create_scale_free (pg); + break; + case GNUNET_TESTING_TOPOLOGY_NONE: + num_connections = 0; + break; + default: + num_connections = 0; + break; } + if (num_connections < 1) + return GNUNET_SYSERR; + + if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "F2F")) + ret = create_and_copy_friend_files(pg); + if (ret == GNUNET_OK) + connect_topology(pg); else { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("No topology specified, was one intended?\n")); +#if VERBOSE_TESTING + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + _("Failed during friend file copying!\n")); +#endif return GNUNET_SYSERR; } -- cgit v1.2.3