[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11364 - gnunet/src/testing
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11364 - gnunet/src/testing |
Date: |
Wed, 12 May 2010 17:48:52 +0200 |
Author: nevans
Date: 2010-05-12 17:48:52 +0200 (Wed, 12 May 2010)
New Revision: 11364
Added:
gnunet/src/testing/test_testing_data_topology_churn.conf
gnunet/src/testing/test_testing_topology_churn.c
Modified:
gnunet/src/testing/testing.c
gnunet/src/testing/testing_group.c
Log:
churn fixes and testcase
Added: gnunet/src/testing/test_testing_data_topology_churn.conf
===================================================================
--- gnunet/src/testing/test_testing_data_topology_churn.conf
(rev 0)
+++ gnunet/src/testing/test_testing_data_topology_churn.conf 2010-05-12
15:48:52 UTC (rev 11364)
@@ -0,0 +1,44 @@
+[PATHS]
+SERVICEHOME = /tmp/test-gnunet-testing/
+DEFAULTCONFIG = test_testing_data_topology_churn.conf
+
+[resolver]
+PORT = 2564
+
+[transport]
+PORT = 2565
+PLUGINS = tcp
+#PREFIX = xterm -e xterm -T transport -e gdb --args
+#BINARY =
/home/mrwiggles/documents/research/gnunet/gnunet-ng/src/transport/.libs/gnunet-service-transport
+#PREFIX = valgrind --tool=memcheck --log-file=logs%p
+#DEBUG = YES
+
+[arm]
+PORT = 2566
+DEFAULTSERVICES = peerinfo transport core
+
+[statistics]
+PORT = 2567
+
+[transport-tcp]
+PORT = 2568
+
+[transport-udp]
+PORT = 2568
+
+[peerinfo]
+PORT = 2569
+#DEBUG = YES
+#PREFIX = xterm -e xterm -T peerinfo -e gdb --args
+#BINARY =
/home/mrwiggles/documents/research/gnunet/gnunet-ng/src/peerinfo/.libs/gnunet-service-peerinfo
+#PREFIX = valgrind --tool=memcheck --log-file=peerinfo%p
+
+[core]
+PORT = 2570
+#PREFIX = xterm -e xterm -T CORE -e gdb --args
+#PREFIX = valgrind --tool=memcheck --log-file=logs%p
+#DEBUG = YES
+
+[testing]
+NUM_PEERS = 12
+WEAKRANDOM = YES
Added: gnunet/src/testing/test_testing_topology_churn.c
===================================================================
--- gnunet/src/testing/test_testing_topology_churn.c
(rev 0)
+++ gnunet/src/testing/test_testing_topology_churn.c 2010-05-12 15:48:52 UTC
(rev 11364)
@@ -0,0 +1,322 @@
+/*
+ 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_topology_churn.c
+ * @brief base testcase for testing simple churn functionality
+ */
+#include "platform.h"
+#include "gnunet_testing_lib.h"
+#include "gnunet_core_service.h"
+
+#define VERBOSE GNUNET_YES
+
+/**
+ * How long until we fail the whole testcase?
+ */
+#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
600)
+
+/**
+ * How long until we give up on starting the peers? (Must be longer than the
connect timeout!)
+ */
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
+
+#define DEFAULT_NUM_PEERS 4
+
+static int ok;
+
+static unsigned long long num_peers;
+
+static unsigned int expected_connections;
+
+static unsigned int expected_failed_connections;
+
+static unsigned long long peers_left;
+
+static struct GNUNET_TESTING_PeerGroup *pg;
+
+static struct GNUNET_SCHEDULER_Handle *sched;
+
+const struct GNUNET_CONFIGURATION_Handle *main_cfg;
+
+GNUNET_SCHEDULER_TaskIdentifier die_task;
+
+static char *test_directory;
+
+#define MTYPE 12345
+
+struct GNUNET_TestMessage
+{
+ /**
+ * Header of the message
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Unique identifier for this message.
+ */
+ uint32_t uid;
+};
+
+static void
+finish_testing ()
+{
+ GNUNET_assert (pg != NULL);
+
+ if (die_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel(sched, die_task);
+
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Called finish testing, stopping daemons.\n");
+#endif
+
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Calling daemons_stop\n");
+#endif
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "daemons_stop finished\n");
+#endif
+
+ ok = 0;
+}
+
+static void
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+{
+ char *msg = cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "End badly was called (%s)... stopping daemons.\n", msg);
+
+ if (pg != NULL)
+ {
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+ ok = 7331; /* Opposite of leet */
+ }
+ else
+ ok = 401; /* Never got peers started */
+
+}
+
+struct ChurnTestContext
+{
+ GNUNET_SCHEDULER_Task next_task;
+
+};
+
+static struct ChurnTestContext churn_ctx;
+
+/**
+ * Churn callback, report on success or failure of churn operation.
+ *
+ * @param cls closure
+ * @param emsg NULL on success
+ */
+void churn_callback(void *cls,
+ const char *emsg)
+{
+ if (emsg == NULL)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Successfully churned peers!\n",
emsg);
+ GNUNET_SCHEDULER_add_now(sched, churn_ctx.next_task, NULL);
+ }
+ else
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to churn peers with error
`%s'\n", emsg);
+ GNUNET_SCHEDULER_cancel(sched, die_task);
+ die_task = GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL);
+ }
+}
+
+
+static void
+churn_peers_both()
+{
+ churn_ctx.next_task = &finish_testing;
+ GNUNET_TESTING_daemons_churn(pg, 1, 1, TIMEOUT, &churn_callback, NULL);
+}
+
+static void
+churn_peers_off_again()
+{
+ churn_ctx.next_task = &churn_peers_both;
+ GNUNET_TESTING_daemons_churn(pg, 2, 0, TIMEOUT, &churn_callback, NULL);
+}
+
+static void
+churn_peers_on()
+{
+ churn_ctx.next_task = &churn_peers_off_again;
+ GNUNET_TESTING_daemons_churn(pg, 0, 2, TIMEOUT, &churn_callback, NULL);
+}
+
+static void
+churn_peers_off()
+{
+ churn_ctx.next_task = &churn_peers_on;
+ GNUNET_TESTING_daemons_churn(pg, 2, 0, TIMEOUT, &churn_callback, NULL);
+}
+
+static void
+peers_started_callback (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
+{
+ if (emsg != NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error:
`%s'\n",
+ emsg);
+ return;
+ }
+ GNUNET_assert (id != NULL);
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
+ (num_peers - peers_left) + 1, num_peers);
+#endif
+ peers_left--;
+ if (peers_left == 0)
+ {
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now testing churn!\n",
+ num_peers);
+#endif
+ GNUNET_SCHEDULER_cancel (sched, die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (sched,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, 5),
+ &end_badly, "from
peers_started_callback");
+ churn_peers_off ();
+ 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 based on config file %s\n", cfgfile);
+#endif
+
+ if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths",
"servicehome", &test_directory))
+ {
+ ok = 404;
+ return;
+ }
+
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
+ &num_peers))
+ num_peers = DEFAULT_NUM_PEERS;
+
+ main_cfg = cfg;
+
+ peers_left = num_peers;
+
+ /* For this specific test we only really want a CLIQUE topology as the
+ * overlay allowed topology, and a RING topology as the underlying connection
+ * allowed topology. So we will expect only num_peers * 2 connections to
+ * work, and (num_peers * (num_peers - 1)) - (num_peers * 2) to fail.
+ */
+ expected_connections = num_peers * (num_peers - 1);
+ expected_failed_connections = expected_connections - (num_peers * 2);
+
+
+ /* Set up a task to end testing if peer start fails */
+ die_task = GNUNET_SCHEDULER_add_delayed (sched,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, 5),
+ &end_badly, "didn't start all
daemons in reasonable amount of time!!!");
+
+ pg = GNUNET_TESTING_daemons_start (sched, cfg,
+ peers_left, TIMEOUT, NULL, NULL,
&peers_started_callback, NULL,
+ NULL, NULL, NULL);
+
+}
+
+static int
+check ()
+{
+ int ret;
+ char *const argv[] = {"test-testing-topology-churn",
+ "-c",
+ "test_testing_data_topology_churn.conf",
+#if VERBOSE
+ "-L", "DEBUG",
+#endif
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+ argv, "test-testing-topology-churn", "nohelp",
+ options, &run, &ok);
+ if (ret != GNUNET_OK)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-testing-topology-churn':
Failed with error code %d\n", ret);
+ }
+
+ return ok;
+}
+
+int
+main (int argc, char *argv[])
+{
+ int ret;
+
+ GNUNET_log_setup ("test_testing_topology_churn",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+ ret = check ();
+
+ /**
+ * Need to remove base directory, subdirectories taken care
+ * of by the testing framework.
+ */
+ if (test_directory != NULL)
+ {
+ if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing
directory %s\n", test_directory);
+ }
+ }
+
+ return ret;
+}
+
+/* end of test_testing_topology_churn.c */
Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c 2010-05-12 15:21:56 UTC (rev 11363)
+++ gnunet/src/testing/testing.c 2010-05-12 15:48:52 UTC (rev 11364)
@@ -38,7 +38,7 @@
#include "gnunet_hello_lib.h"
#define DEBUG_TESTING GNUNET_NO
-#define DEBUG_TESTING_RECONNECT GNUNET_YES
+#define DEBUG_TESTING_RECONNECT GNUNET_NO
/**
* How long do we wait after starting gnunet-service-arm
@@ -544,6 +544,7 @@
return;
}
/* wait some more */
+ fprintf(stderr, "scheduling in shutdown_start\n");
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
GNUNET_CONSTANTS_EXEC_WAIT,
@@ -589,11 +590,15 @@
}
GNUNET_free_non_null(d->hello);
+ d->hello = NULL;
GNUNET_free_non_null (d->shortname);
+ d->shortname = NULL;
if (NULL != d->dead_cb)
d->dead_cb (d->dead_cb_cls, NULL);
- GNUNET_free (d);
+ if (d->churn == GNUNET_NO)
+ GNUNET_free (d);
+
break;
case SP_CONFIG_UPDATE:
/* confirm copying complete */
@@ -969,6 +974,7 @@
if (allow_restart == GNUNET_YES)
d->churn = GNUNET_YES;
+
if (d->th != NULL)
{
GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d);
@@ -1014,10 +1020,10 @@
GNUNET_free_non_null(del_arg);
d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout);
+ fprintf(stderr, "scheduling shutdown fsm phase\n");
d->task
- = GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm, d);
+ = GNUNET_SCHEDULER_add_now (d->sched,
+ &start_fsm, d);
}
@@ -1407,7 +1413,7 @@
return;
}
#if DEBUG_TESTING_RECONNECT
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "re-attempting connect of peer %s to
peer %s\n",
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "re-attempting connect of peer %s to
peer %s\n",
ctx->d1->shortname, ctx->d2->shortname);
#endif
Modified: gnunet/src/testing/testing_group.c
===================================================================
--- gnunet/src/testing/testing_group.c 2010-05-12 15:21:56 UTC (rev 11363)
+++ gnunet/src/testing/testing_group.c 2010-05-12 15:48:52 UTC (rev 11364)
@@ -29,6 +29,8 @@
#define VERBOSE_TESTING GNUNET_NO
+#define DEBUG_CHURN GNUNET_NO
+
/**
* Lowest port used for GNUnet testing. Should be high enough to not
* conflict with other applications running on the hosts but be low
@@ -2712,12 +2714,17 @@
churn_ctx->num_to_stop--;
}
+#if DEBUG_CHURN
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopped peer, %d left.\n",
churn_ctx->num_to_stop);
+#endif
total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) +
(churn_ctx->num_to_start - churn_ctx->num_failed_start);
if (total_left == 0)
{
if ((churn_ctx->num_failed_stop > 0) || (churn_ctx->num_failed_start > 0))
- GNUNET_asprintf(&error_message, "Churn didn't complete successfully, %u
peers failed to start %u peers failed to be stopped!",
churn_ctx->num_failed_start, churn_ctx->num_failed_stop);
+ {
+ GNUNET_asprintf(&error_message, "Churn didn't complete successfully,
%u peers failed to start %u peers failed to be stopped!",
churn_ctx->num_failed_start, churn_ctx->num_failed_stop);
+ }
churn_ctx->cb(churn_ctx->cb_cls, error_message);
GNUNET_free_non_null(error_message);
GNUNET_free(churn_ctx);
@@ -2757,6 +2764,10 @@
churn_ctx->num_to_start--;
}
+#if DEBUG_CHURN
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Started peer, %d left.\n",
churn_ctx->num_to_start);
+#endif
+
total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) +
(churn_ctx->num_to_start - churn_ctx->num_failed_start);
if (total_left == 0)
@@ -2810,6 +2821,12 @@
running = 0;
stopped = 0;
+ if ((von == 0) && (voff == 0)) /* No peers at all? */
+ {
+ cb(cb_cls, NULL);
+ return;
+ }
+
for (i = 0; i < pg->total; i++)
{
if (pg->peers[i].daemon->running == GNUNET_YES)
@@ -2839,9 +2856,15 @@
churn_ctx = GNUNET_malloc(sizeof(struct ChurnContext));
running_arr = GNUNET_malloc(running * sizeof(unsigned int));
stopped_arr = GNUNET_malloc(stopped * sizeof(unsigned int));
- running_permute = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK,
running);
- stopped_permute = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK,
stopped);
+ running_permute = NULL;
+ stopped_permute = NULL;
+
+ if (running > 0)
+ running_permute = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK,
running);
+ if (stopped > 0)
+ stopped_permute = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK,
stopped);
+
running = 0;
stopped = 0;
@@ -2866,13 +2889,24 @@
for (i = 0; i < voff; i++)
{
+#if DEBUG_CHURN
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n",
running_permute[i]);
+#endif
GNUNET_TESTING_daemon_stop(pg->peers[running_arr[running_permute[i]]].daemon,
timeout, &churn_stop_callback, churn_ctx, GNUNET_NO, GNUNET_YES);
}
for (i = 0; i < von; i++)
{
+#if DEBUG_CHURN
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n",
stopped_permute[i]);
+#endif
GNUNET_TESTING_daemon_start_stopped(pg->peers[stopped_arr[stopped_permute[i]]].daemon,
timeout, &churn_start_callback, churn_ctx);
}
+
+ GNUNET_free(running_arr);
+ GNUNET_free(stopped_arr);
+ GNUNET_free_non_null(running_permute);
+ GNUNET_free_non_null(stopped_permute);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11364 - gnunet/src/testing,
gnunet <=