aboutsummaryrefslogtreecommitdiff
path: root/src/topology
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-09 13:39:10 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-09 13:39:10 +0000
commit4b3fd192b37405f857a8a5f8ab814ea4b9f1f94e (patch)
tree6662f62b737837030be9fc9924ff49a2c52954f0 /src/topology
parent9d732bb204de9177aad6ae70c910cbf2615d81a3 (diff)
downloadgnunet-4b3fd192b37405f857a8a5f8ab814ea4b9f1f94e.tar.gz
gnunet-4b3fd192b37405f857a8a5f8ab814ea4b9f1f94e.zip
migrating topology test to new testbed API
Diffstat (limited to 'src/topology')
-rw-r--r--src/topology/Makefile.am2
-rw-r--r--src/topology/test_gnunet_daemon_topology.c167
2 files changed, 31 insertions, 138 deletions
diff --git a/src/topology/Makefile.am b/src/topology/Makefile.am
index 4234625d6..91c21da12 100644
--- a/src/topology/Makefile.am
+++ b/src/topology/Makefile.am
@@ -36,7 +36,7 @@ endif
36test_gnunet_daemon_topology_SOURCES = \ 36test_gnunet_daemon_topology_SOURCES = \
37 test_gnunet_daemon_topology.c 37 test_gnunet_daemon_topology.c
38test_gnunet_daemon_topology_LDADD = \ 38test_gnunet_daemon_topology_LDADD = \
39 $(top_builddir)/src/testing_old/libgnunettesting_old.la \ 39 $(top_builddir)/src/testbed/libgnunettestbed.la \
40 $(top_builddir)/src/util/libgnunetutil.la 40 $(top_builddir)/src/util/libgnunetutil.la
41 41
42EXTRA_DIST = \ 42EXTRA_DIST = \
diff --git a/src/topology/test_gnunet_daemon_topology.c b/src/topology/test_gnunet_daemon_topology.c
index 35225e4da..e94123fe8 100644
--- a/src/topology/test_gnunet_daemon_topology.c
+++ b/src/topology/test_gnunet_daemon_topology.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors) 3 (C) 2009, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -22,183 +22,76 @@
22 * @brief testcase for topology maintenance code 22 * @brief testcase for topology maintenance code
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_testing_lib.h" 25#include "gnunet_testbed_service.h"
26 26
27 27
28#define NUM_PEERS 2 28#define NUM_PEERS 8
29 29
30/** 30/**
31 * How long until we give up on connecting the peers? 31 * How long until we give up on connecting the peers?
32 */ 32 */
33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600) 33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
34 34
35#define CONNECT_ATTEMPTS 3
36
37 35
38static int ok; 36static int ok;
39 37
40static int peers_left; 38static unsigned int connect_left;
41
42static int connect_left;
43
44static struct GNUNET_TESTING_PeerGroup *pg;
45
46static struct GNUNET_TESTING_Daemon *first;
47
48static struct GNUNET_TESTING_Daemon *last;
49
50/**
51 * Active connection attempt.
52 */
53struct GNUNET_TESTING_ConnectContext *cc[NUM_PEERS];
54 39
55/** 40static struct GNUNET_TESTBED_Peer *daemons[NUM_PEERS];
56 * Check whether peers successfully shut down.
57 */
58static void
59shutdown_callback (void *cls, const char *emsg)
60{
61 if (emsg != NULL)
62 {
63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
64 if (ok == 0)
65 ok = 666;
66 }
67 else
68 {
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n");
70 }
71}
72 41
73 42
74static void 43static void
75clean_up_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 44notify_connect_complete (void *cls,
45 struct GNUNET_TESTBED_Operation *op,
46 const char *emsg)
76{ 47{
77 unsigned int i; 48 unsigned int i;
78 49
79 for (i = 0; i < NUM_PEERS; i++)
80 {
81 if (NULL != cc[i])
82 {
83 GNUNET_TESTING_daemons_connect_cancel (cc[i]);
84 cc[i] = NULL;
85 }
86 }
87 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
88 ok = 0;
89}
90
91
92static void
93notify_connect_complete (void *cls, const struct GNUNET_PeerIdentity *first,
94 const struct GNUNET_PeerIdentity *second,
95 unsigned int distance,
96 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
97 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
98 struct GNUNET_TESTING_Daemon *first_daemon,
99 struct GNUNET_TESTING_Daemon *second_daemon,
100 const char *emsg)
101{
102 struct GNUNET_TESTING_ConnectContext **cc = cls;
103 unsigned int i;
104
105 *cc = NULL;
106 if (NULL != emsg) 50 if (NULL != emsg)
107 { 51 {
108 FPRINTF (stderr, "Failed to connect two peers: %s\n", emsg); 52 FPRINTF (stderr, "Failed to connect two peers: %s\n", emsg);
109 for (i = 0; i < NUM_PEERS; i++) 53 GNUNET_SCHEDULER_shutdown ();
110 if (NULL != cc[i]) 54 ok = 1;
111 {
112 GNUNET_TESTING_daemons_connect_cancel (cc[i]);
113 cc[i] = NULL;
114 }
115 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
116 GNUNET_assert (0);
117 return; 55 return;
118 } 56 }
119 connect_left--; 57 connect_left--;
120 if (connect_left == 0) 58 if (0 == connect_left)
121 { 59 {
122 /* FIXME: check that topology adds a few more links 60 /* FIXME: check that topology adds a few more links
123 * in addition to those that were seeded */ 61 * in addition to those that were seeded */
124 GNUNET_SCHEDULER_add_now (&clean_up_task, NULL); 62 GNUNET_SCHEDULER_shutdown ();
125 } 63 }
126} 64}
127 65
128 66
129static void 67static void
130my_cb (void *cls, const struct GNUNET_PeerIdentity *id, 68do_connect (void *cls,
131 const struct GNUNET_CONFIGURATION_Handle *cfg, 69 unsigned int num_peers,
132 struct GNUNET_TESTING_Daemon *d, const char *emsg) 70 struct GNUNET_TESTBED_Peer **peers)
133{ 71{
134 GNUNET_assert (id != NULL); 72 unsigned int i;
135 peers_left--;
136 if (first == NULL)
137 {
138 connect_left = NUM_PEERS;
139 first = d;
140 last = d;
141 return;
142 }
143 cc[peers_left] =
144 GNUNET_TESTING_daemons_connect (last, d, TIMEOUT, CONNECT_ATTEMPTS,
145 GNUNET_YES, &notify_connect_complete,
146 &cc[peers_left]);
147 if (peers_left == 0)
148 {
149 /* close circle */
150 cc[NUM_PEERS - 1] =
151 GNUNET_TESTING_daemons_connect (d, first, TIMEOUT, CONNECT_ATTEMPTS,
152 GNUNET_YES, &notify_connect_complete,
153 &cc[NUM_PEERS - 1]);
154 }
155}
156
157
158static void
159run (void *cls, char *const *args, const char *cfgfile,
160 const struct GNUNET_CONFIGURATION_Handle *cfg)
161{
162 ok = 1;
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
164 peers_left = NUM_PEERS;
165 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, peers_left, peers_left,
166 TIMEOUT, NULL, NULL, &my_cb, NULL, NULL,
167 NULL, NULL);
168 GNUNET_assert (pg != NULL);
169}
170
171 73
172static int 74 GNUNET_assert (NUM_PEERS == num_peers);
173check () 75 for (i=0;i<num_peers-1;i++)
174{ 76 {
175 char *const argv[] = { 77 connect_left++;
176 "test-gnunet-daemon-topology", 78 GNUNET_TESTBED_overlay_connect (NULL,
177 "-c", 79 &notify_connect_complete, NULL,
178 "test_gnunet_daemon_topology_data.conf", 80 peers[i], peers[i+1]);
179 NULL 81 }
180 };
181 struct GNUNET_GETOPT_CommandLineOption options[] = {
182 GNUNET_GETOPT_OPTION_END
183 };
184 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
185 "test-gnunet-daemon-topology", "nohelp", options, &run,
186 &ok);
187 return ok;
188} 82}
189 83
190 84
191int 85int
192main (int argc, char *argv[]) 86main (int argc, char *argv[])
193{ 87{
194 int ret; 88 GNUNET_TESTBED_test_run ("test-gnunet-daemon-topology",
195 89 "test_gnunet_daemon_topology_data.conf",
196 GNUNET_log_setup ("test-gnunet-daemon-topology", 90 NUM_PEERS,
197 "WARNING", 91 0, NULL, NULL,
198 NULL); 92 &do_connect, NULL);
199 ret = check ();
200 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-topology"); 93 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-topology");
201 return ret; 94 return ok;
202} 95}
203 96
204/* end of test_gnunet_daemon_topology.c */ 97/* end of test_gnunet_daemon_topology.c */