From 3df90c73c968bc0efd3027aa0e1811ef7902fe2a Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Thu, 20 Oct 2011 17:35:19 +0000 Subject: [PATCH] Added testcase for opposite peers in a small 2d grid --- src/dht/Makefile.am | 15 ++++++++-- src/dht/test_dht_2dtorus.c | 57 ++++++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index 2a62979e1..6a8ce280a 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am @@ -78,7 +78,8 @@ check_PROGRAMS = \ test_dht_twopeer_get_put \ test_dht_twopeer_path_tracking \ test_dht_multipeer \ - test_dht_2dtorus + test_dht_2dtorus \ + test_dht_2dtorus_far if ENABLE_TEST_RUN TESTS = test_dht_api $(check_SCRIPTS) \ @@ -87,7 +88,8 @@ TESTS = test_dht_api $(check_SCRIPTS) \ test_dht_twopeer_get_put \ test_dht_twopeer_path_tracking \ test_dht_multipeer \ - test_dht_2dtorus + test_dht_2dtorus \ + test_dht_2dtorus_far endif test_dht_api_SOURCES = \ @@ -148,6 +150,15 @@ test_dht_2dtorus_LDADD = \ test_dht_2dtorus_DEPENDENCIES = \ libgnunetdht.la +test_dht_2dtorus_far_SOURCES = \ + test_dht_2dtorus.c +test_dht_2dtorus_far_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/testing/libgnunettesting.la \ + $(top_builddir)/src/dht/libgnunetdht.la +test_dht_2dtorus_far_DEPENDENCIES = \ + libgnunetdht.la + EXTRA_DIST = \ $(check_SCRIPTS) \ diff --git a/src/dht/test_dht_2dtorus.c b/src/dht/test_dht_2dtorus.c index d5acbbcb3..7c6c61a81 100644 --- a/src/dht/test_dht_2dtorus.c +++ b/src/dht/test_dht_2dtorus.c @@ -41,6 +41,8 @@ static int ok; +static int far; + /** * Be verbose */ @@ -204,15 +206,38 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_TESTING_Daemon *d; struct GNUNET_TESTING_Daemon *o; + struct GNUNET_TESTING_Daemon *aux; + const char *id_aux; + const char *id_origin = "FC74"; + const char *id_near = "9P6V"; + const char *id_far = "KPST"; + unsigned int i; - d = GNUNET_TESTING_daemon_get (pg, 2); - o = GNUNET_TESTING_daemon_get (pg, 0); + d = o = NULL; + for (i = 0; i < num_peers; i++) + { + aux = GNUNET_TESTING_daemon_get (pg, i); + id_aux = GNUNET_i2s (&aux->id); + if (strcmp (id_aux, id_origin) == 0) + o = aux; + if (far == GNUNET_YES && strcmp (id_aux, id_far) == 0) + d = aux; + if (far == GNUNET_NO && strcmp (id_aux, id_near) == 0) + d = aux; + } + if (NULL == o || NULL == d) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "test: Peers not found (hostkey file changed?)\n"); + GNUNET_SCHEDULER_cancel (disconnect_task); + disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); + } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: looking for [2] %s\n", + "test: looking for %s\n", GNUNET_h2s_full (&d->id.hashPubKey)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "test: from [0] %s\n", + "test: from %s\n", GNUNET_h2s_full (&o->id.hashPubKey)); get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ @@ -353,23 +378,12 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, struct GNUNET_TESTING_Daemon *first_daemon, struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) { -// GNUNET_PEER_Id f; -// GNUNET_PEER_Id s; if (emsg == NULL) { total_connections++; - /*f = */GNUNET_PEER_intern(first); - /*s = */GNUNET_PEER_intern(second); -// GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: New connection!\n"); -// GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, -// "test: %s (%u)\n", -// GNUNET_h2s(&first->hashPubKey), -// f); -// GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, -// "test: %s (%u)\n", -// GNUNET_h2s(&second->hashPubKey), -// s); + GNUNET_PEER_intern(first); + GNUNET_PEER_intern(second); } else { @@ -508,6 +522,15 @@ main (int xargc, char *xargv[]) #endif NULL }; + + if (strstr (xargv[0], "2dtorus_far") != NULL) + { + far = GNUNET_YES; + } + else + { + far = GNUNET_NO; + } GNUNET_PROGRAM_run (sizeof(argv)/sizeof(char*) - 1, argv, "test_dht_2dtorus", gettext_noop ("Test dht in a small 2D torus."), options, -- 2.25.1