aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-12-20 21:55:01 +0000
committerChristian Grothoff <christian@grothoff.org>2010-12-20 21:55:01 +0000
commitac9dfe2326a4d1a2c601a77589bc84e1da4a0250 (patch)
tree7ec1707ce3aff0e84f33a4d708f5b8f745d0deda /src
parentb020f296645f1a207eb2decbdd2366007e6eb2dd (diff)
downloadgnunet-ac9dfe2326a4d1a2c601a77589bc84e1da4a0250.tar.gz
gnunet-ac9dfe2326a4d1a2c601a77589bc84e1da4a0250.zip
reconnect via testing testcase
Diffstat (limited to 'src')
-rw-r--r--src/testing/Makefile.am40
-rw-r--r--src/testing/test_testing_reconnect.c234
2 files changed, 257 insertions, 17 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index bd4495035..8084a9779 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -20,12 +20,11 @@ libgnunettesting_la_LIBADD = $(XLIB) \
20 $(top_builddir)/src/transport/libgnunettransport.la \ 20 $(top_builddir)/src/transport/libgnunettransport.la \
21 -lm \ 21 -lm \
22 $(top_builddir)/src/util/libgnunetutil.la 22 $(top_builddir)/src/util/libgnunetutil.la
23
24#noinst_PROGRAMS = ${check_PROGRAMS}
25 23
26check_PROGRAMS = \ 24check_PROGRAMS = \
27 test_testing \ 25 test_testing \
28 test_testing_connect \ 26 test_testing_connect \
27 test_testing_reconnect \
29 test_testing_group \ 28 test_testing_group \
30 test_testing_topology_stability \ 29 test_testing_topology_stability \
31 test_testing_topology_clique \ 30 test_testing_topology_clique \
@@ -49,6 +48,7 @@ if !DISABLE_TEST_RUN
49TESTS = \ 48TESTS = \
50 test_testing \ 49 test_testing \
51 test_testing_connect \ 50 test_testing_connect \
51 test_testing_reconnect \
52 test_testing_group \ 52 test_testing_group \
53 test_testing_topology_clique 53 test_testing_topology_clique
54# test_testing_topology_stability \ 54# test_testing_topology_stability \
@@ -80,36 +80,42 @@ test_testing_connect_LDADD = \
80 $(top_builddir)/src/testing/libgnunettesting.la \ 80 $(top_builddir)/src/testing/libgnunettesting.la \
81 $(top_builddir)/src/util/libgnunetutil.la 81 $(top_builddir)/src/util/libgnunetutil.la
82 82
83test_testing_reconnect_SOURCES = \
84 test_testing_reconnect.c
85test_testing_reconnect_LDADD = \
86 $(top_builddir)/src/testing/libgnunettesting.la \
87 $(top_builddir)/src/util/libgnunetutil.la
88
83test_testing_group_SOURCES = \ 89test_testing_group_SOURCES = \
84 test_testing_group.c 90 test_testing_group.c
85test_testing_group_LDADD = \ 91test_testing_group_LDADD = \
86 $(top_builddir)/src/testing/libgnunettesting.la \ 92 $(top_builddir)/src/testing/libgnunettesting.la \
87 $(top_builddir)/src/util/libgnunetutil.la 93 $(top_builddir)/src/util/libgnunetutil.la
88 94
89test_testing_topology_clique_SOURCES = \ 95test_testing_topology_clique_SOURCES = \
90 test_testing_topology.c 96 test_testing_topology.c
91test_testing_topology_clique_LDADD = \ 97test_testing_topology_clique_LDADD = \
92 $(top_builddir)/src/testing/libgnunettesting.la \ 98 $(top_builddir)/src/testing/libgnunettesting.la \
93 $(top_builddir)/src/util/libgnunetutil.la 99 $(top_builddir)/src/util/libgnunetutil.la
94 100
95test_testing_topology_stability_SOURCES = \ 101test_testing_topology_stability_SOURCES = \
96 test_testing_topology.c 102 test_testing_topology.c
97test_testing_topology_stability_LDADD = \ 103test_testing_topology_stability_LDADD = \
98 $(top_builddir)/src/testing/libgnunettesting.la \ 104 $(top_builddir)/src/testing/libgnunettesting.la \
99 $(top_builddir)/src/util/libgnunetutil.la 105 $(top_builddir)/src/util/libgnunetutil.la
100 106
101test_testing_topology_blacklist_SOURCES = \ 107test_testing_topology_blacklist_SOURCES = \
102 test_testing_topology_blacklist.c 108 test_testing_topology_blacklist.c
103test_testing_topology_blacklist_LDADD = \ 109test_testing_topology_blacklist_LDADD = \
104 $(top_builddir)/src/testing/libgnunettesting.la \ 110 $(top_builddir)/src/testing/libgnunettesting.la \
105 $(top_builddir)/src/util/libgnunetutil.la 111 $(top_builddir)/src/util/libgnunetutil.la
106 112
107test_testing_topology_churn_SOURCES = \ 113test_testing_topology_churn_SOURCES = \
108 test_testing_topology_churn.c 114 test_testing_topology_churn.c
109test_testing_topology_churn_LDADD = \ 115test_testing_topology_churn_LDADD = \
110 $(top_builddir)/src/testing/libgnunettesting.la \ 116 $(top_builddir)/src/testing/libgnunettesting.la \
111 $(top_builddir)/src/util/libgnunetutil.la 117 $(top_builddir)/src/util/libgnunetutil.la
112 118
113test_testing_topology_clique_random_SOURCES = \ 119test_testing_topology_clique_random_SOURCES = \
114 test_testing_topology.c 120 test_testing_topology.c
115test_testing_topology_clique_random_LDADD = \ 121test_testing_topology_clique_random_LDADD = \
@@ -121,7 +127,7 @@ test_testing_topology_clique_minimum_SOURCES = \
121test_testing_topology_clique_minimum_LDADD = \ 127test_testing_topology_clique_minimum_LDADD = \
122 $(top_builddir)/src/testing/libgnunettesting.la \ 128 $(top_builddir)/src/testing/libgnunettesting.la \
123 $(top_builddir)/src/util/libgnunetutil.la 129 $(top_builddir)/src/util/libgnunetutil.la
124 130
125test_testing_topology_clique_dfs_SOURCES = \ 131test_testing_topology_clique_dfs_SOURCES = \
126 test_testing_topology.c 132 test_testing_topology.c
127test_testing_topology_clique_dfs_LDADD = \ 133test_testing_topology_clique_dfs_LDADD = \
@@ -133,7 +139,7 @@ test_testing_topology_line_SOURCES = \
133test_testing_topology_line_LDADD = \ 139test_testing_topology_line_LDADD = \
134 $(top_builddir)/src/testing/libgnunettesting.la \ 140 $(top_builddir)/src/testing/libgnunettesting.la \
135 $(top_builddir)/src/util/libgnunetutil.la 141 $(top_builddir)/src/util/libgnunetutil.la
136 142
137 143
138test_testing_group_remote_SOURCES = \ 144test_testing_group_remote_SOURCES = \
139 test_testing_group_remote.c 145 test_testing_group_remote.c
@@ -146,25 +152,25 @@ test_testing_topology_ring_SOURCES = \
146test_testing_topology_ring_LDADD = \ 152test_testing_topology_ring_LDADD = \
147 $(top_builddir)/src/testing/libgnunettesting.la \ 153 $(top_builddir)/src/testing/libgnunettesting.la \
148 $(top_builddir)/src/util/libgnunetutil.la 154 $(top_builddir)/src/util/libgnunetutil.la
149 155
150test_testing_topology_2d_torus_SOURCES = \ 156test_testing_topology_2d_torus_SOURCES = \
151 test_testing_topology.c 157 test_testing_topology.c
152test_testing_topology_2d_torus_LDADD = \ 158test_testing_topology_2d_torus_LDADD = \
153 $(top_builddir)/src/testing/libgnunettesting.la \ 159 $(top_builddir)/src/testing/libgnunettesting.la \
154 $(top_builddir)/src/util/libgnunetutil.la 160 $(top_builddir)/src/util/libgnunetutil.la
155 161
156test_testing_topology_small_world_ring_SOURCES = \ 162test_testing_topology_small_world_ring_SOURCES = \
157 test_testing_topology.c 163 test_testing_topology.c
158test_testing_topology_small_world_ring_LDADD = \ 164test_testing_topology_small_world_ring_LDADD = \
159 $(top_builddir)/src/testing/libgnunettesting.la \ 165 $(top_builddir)/src/testing/libgnunettesting.la \
160 $(top_builddir)/src/util/libgnunetutil.la 166 $(top_builddir)/src/util/libgnunetutil.la
161 167
162test_testing_topology_small_world_torus_SOURCES = \ 168test_testing_topology_small_world_torus_SOURCES = \
163 test_testing_topology.c 169 test_testing_topology.c
164test_testing_topology_small_world_torus_LDADD = \ 170test_testing_topology_small_world_torus_LDADD = \
165 $(top_builddir)/src/testing/libgnunettesting.la \ 171 $(top_builddir)/src/testing/libgnunettesting.la \
166 $(top_builddir)/src/util/libgnunetutil.la 172 $(top_builddir)/src/util/libgnunetutil.la
167 173
168test_testing_topology_internat_SOURCES = \ 174test_testing_topology_internat_SOURCES = \
169 test_testing_topology.c 175 test_testing_topology.c
170test_testing_topology_internat_LDADD = \ 176test_testing_topology_internat_LDADD = \
@@ -176,7 +182,7 @@ test_testing_topology_erdos_renyi_SOURCES = \
176test_testing_topology_erdos_renyi_LDADD = \ 182test_testing_topology_erdos_renyi_LDADD = \
177 $(top_builddir)/src/testing/libgnunettesting.la \ 183 $(top_builddir)/src/testing/libgnunettesting.la \
178 $(top_builddir)/src/util/libgnunetutil.la 184 $(top_builddir)/src/util/libgnunetutil.la
179 185
180test_testing_topology_scale_free_SOURCES = \ 186test_testing_topology_scale_free_SOURCES = \
181 test_testing_topology.c 187 test_testing_topology.c
182test_testing_topology_scale_free_LDADD = \ 188test_testing_topology_scale_free_LDADD = \
@@ -188,8 +194,8 @@ test_testing_topology_none_SOURCES = \
188test_testing_topology_none_LDADD = \ 194test_testing_topology_none_LDADD = \
189 $(top_builddir)/src/testing/libgnunettesting.la \ 195 $(top_builddir)/src/testing/libgnunettesting.la \
190 $(top_builddir)/src/util/libgnunetutil.la 196 $(top_builddir)/src/util/libgnunetutil.la
191 197
192 198
193EXTRA_DIST = \ 199EXTRA_DIST = \
194 test_testing_data.conf \ 200 test_testing_data.conf \
195 test_testing_connect_peer1.conf \ 201 test_testing_connect_peer1.conf \
@@ -208,4 +214,4 @@ EXTRA_DIST = \
208 test_testing_data_topology_blacklist.conf \ 214 test_testing_data_topology_blacklist.conf \
209 test_testing_data_topology_churn.conf \ 215 test_testing_data_topology_churn.conf \
210 test_testing_data_topology_none.conf 216 test_testing_data_topology_none.conf
211 217
diff --git a/src/testing/test_testing_reconnect.c b/src/testing/test_testing_reconnect.c
new file mode 100644
index 000000000..87a442408
--- /dev/null
+++ b/src/testing/test_testing_reconnect.c
@@ -0,0 +1,234 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors)
4
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file testing/test_testing_reconnect.c
22 * @brief testcase for functions to connect two peers in testing.c
23 */
24#include "platform.h"
25#include "gnunet_testing_lib.h"
26
27#define VERBOSE GNUNET_NO
28
29/**
30 * How long until we give up on connecting the peers?
31 */
32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
33
34#define CONNECT_ATTEMPTS 3
35
36static int ok;
37
38static struct GNUNET_TESTING_Daemon *d1;
39
40static struct GNUNET_TESTING_Daemon *d2;
41
42static struct GNUNET_CONFIGURATION_Handle *c1;
43
44static struct GNUNET_CONFIGURATION_Handle *c2;
45
46/**
47 * How many start-connect-stop iterations should we do?
48 */
49#define NUM_PHASES 2
50
51static int phase;
52
53/**
54 * Run the next phase of starting daemons, connecting them and
55 * stopping them again.
56 */
57static void
58run_phase ();
59
60static void
61end2_cb (void *cls, const char *emsg)
62{
63
64 if (emsg != NULL)
65 {
66 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending with error: %s\n", emsg);
67 ok = 1;
68 }
69 else
70 {
71 if (phase < NUM_PHASES)
72 {
73 fprintf (stderr, ".");
74 run_phase();
75 return;
76 }
77 fprintf (stderr, ".\n");
78#if VERBOSE
79 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
80 "Both daemons terminated, will now exit.\n");
81#endif
82 ok = 0;
83 }
84}
85
86static void
87end1_cb (void *cls, const char *emsg)
88{
89 if (emsg != NULL)
90 {
91 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping daemon 1 gave: %s\n",
92 emsg);
93 ok = 1;
94 }
95 else
96 {
97 ok = 0;
98 }
99
100 GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL,
101 (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO,
102 GNUNET_NO);
103 d2 = NULL;
104}
105
106static void
107finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
108{
109 GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &end1_cb, NULL,
110 (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO,
111 GNUNET_NO);
112 d1 = NULL;
113}
114
115
116static void
117my_connect_complete (void *cls,
118 const struct GNUNET_PeerIdentity *first,
119 const struct GNUNET_PeerIdentity *second,
120 unsigned int distance,
121 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
122 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
123 struct GNUNET_TESTING_Daemon *first_daemon,
124 struct GNUNET_TESTING_Daemon *second_daemon,
125 const char *emsg)
126{
127#if VERBOSE
128 fprintf (stderr, "Peer %s ", GNUNET_i2s (first));
129 fprintf (stderr, "connected to %s\n", GNUNET_i2s (second));
130#endif
131 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
132}
133
134
135
136
137static void
138my_cb2 (void *cls,
139 const struct GNUNET_PeerIdentity *id,
140 const struct GNUNET_CONFIGURATION_Handle *cfg,
141 struct GNUNET_TESTING_Daemon *d, const char *emsg)
142{
143 GNUNET_assert (id != NULL);
144#if VERBOSE
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
146 "Daemon `%s' started.\n", GNUNET_i2s (id));
147#endif
148 GNUNET_TESTING_daemons_connect (d1, d2,
149 TIMEOUT, CONNECT_ATTEMPTS,
150 &my_connect_complete, NULL);
151}
152
153
154static void
155my_cb1 (void *cls,
156 const struct GNUNET_PeerIdentity *id,
157 const struct GNUNET_CONFIGURATION_Handle *cfg,
158 struct GNUNET_TESTING_Daemon *d, const char *emsg)
159{
160 GNUNET_assert (id != NULL);
161#if VERBOSE
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 "Daemon `%s' started.\n", GNUNET_i2s (id));
164#endif
165 d2 =
166 GNUNET_TESTING_daemon_start (c2, TIMEOUT, NULL, NULL, 0, NULL, NULL,
167 &my_cb2, NULL);
168 GNUNET_assert (d2 != NULL);
169}
170
171
172static void
173run (void *cls,
174 char *const *args,
175 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
176{
177 ok = 1;
178#if VERBOSE
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n");
180#endif
181 c1 = GNUNET_CONFIGURATION_create ();
182 GNUNET_CONFIGURATION_parse (c1, "test_testing_connect_peer1.conf");
183 c2 = GNUNET_CONFIGURATION_create ();
184 GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf");
185 run_phase ();
186}
187
188static void
189run_phase ()
190{
191 phase++;
192 d1 =
193 GNUNET_TESTING_daemon_start (c1, TIMEOUT, NULL, NULL, 0, NULL, NULL,
194 &my_cb1, NULL);
195 GNUNET_assert (d1 != NULL);
196}
197
198static int
199check ()
200{
201 char *const argv[] = { "test-testing-reconnect",
202 "-c",
203 "test_testing_data.conf",
204#if VERBOSE
205 "-L", "DEBUG",
206#endif
207 NULL
208 };
209 struct GNUNET_GETOPT_CommandLineOption options[] = {
210 GNUNET_GETOPT_OPTION_END
211 };
212 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
213 argv, "test-testing-reconnect", "nohelp",
214 options, &run, &ok);
215 return ok;
216}
217
218int
219main (int argc, char *argv[])
220{
221 int ret;
222
223 GNUNET_log_setup ("test-testing-reconnect",
224#if VERBOSE
225 "DEBUG",
226#else
227 "WARNING",
228#endif
229 NULL);
230 ret = check ();
231 return ret;
232}
233
234/* end of test_testing_reconnect.c */