diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-08-11 18:28:50 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-08-11 18:28:50 +0000 |
commit | c34cc2e767ce2e48787148694c810602f19f7d5e (patch) | |
tree | 0d92d664350148893b459455e5cf717d016fe16f /src/transport | |
parent | e46dcf44fb9a8d2ef95b291fe9a49d8c451e0848 (diff) | |
download | gnunet-c34cc2e767ce2e48787148694c810602f19f7d5e.tar.gz gnunet-c34cc2e767ce2e48787148694c810602f19f7d5e.zip |
transport testing testcase
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/Makefile.am | 7 | ||||
-rw-r--r-- | src/transport/test_transport_testing.c | 301 |
2 files changed, 59 insertions, 249 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 5d0e40439..5fe5aa32f 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -264,6 +264,7 @@ libgnunet_plugin_transport_https_la_CPPFLAGS = \ | |||
264 | 264 | ||
265 | 265 | ||
266 | check_PROGRAMS = \ | 266 | check_PROGRAMS = \ |
267 | test_transport_testing \ | ||
267 | test_transport_api_disconnect \ | 268 | test_transport_api_disconnect \ |
268 | $(TEST_TRANSPORT_ATS) \ | 269 | $(TEST_TRANSPORT_ATS) \ |
269 | $(ATS_TRANSPORT_BENCHMARKS) \ | 270 | $(ATS_TRANSPORT_BENCHMARKS) \ |
@@ -297,6 +298,7 @@ check_PROGRAMS = \ | |||
297 | 298 | ||
298 | if ENABLE_TEST_RUN | 299 | if ENABLE_TEST_RUN |
299 | TESTS = \ | 300 | TESTS = \ |
301 | test_transport_testing \ | ||
300 | test_transport_api_disconnect \ | 302 | test_transport_api_disconnect \ |
301 | $(TEST_TRANSPORT_ATS) \ | 303 | $(TEST_TRANSPORT_ATS) \ |
302 | $(ATS_TRANSPORT_BENCHMARKS) \ | 304 | $(ATS_TRANSPORT_BENCHMARKS) \ |
@@ -329,6 +331,11 @@ TESTS = \ | |||
329 | $(WLAN_UREL_TEST) | 331 | $(WLAN_UREL_TEST) |
330 | endif | 332 | endif |
331 | 333 | ||
334 | test_transport_testing_SOURCES = \ | ||
335 | test_transport_testing.c | ||
336 | test_transport_testing_LDADD = \ | ||
337 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
338 | $(top_builddir)/src/transport/libgnunettransporttesting.la | ||
332 | 339 | ||
333 | test_transport_api_disconnect_SOURCES = \ | 340 | test_transport_api_disconnect_SOURCES = \ |
334 | test_transport_api_disconnect.c | 341 | test_transport_api_disconnect.c |
diff --git a/src/transport/test_transport_testing.c b/src/transport/test_transport_testing.c index b2ac507d2..1a176c129 100644 --- a/src/transport/test_transport_testing.c +++ b/src/transport/test_transport_testing.c | |||
@@ -48,123 +48,7 @@ | |||
48 | */ | 48 | */ |
49 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 49 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
50 | 50 | ||
51 | /** | 51 | static struct PeerContext * p; |
52 | * How long until we give up on transmitting the message? | ||
53 | */ | ||
54 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | ||
55 | |||
56 | #define MTYPE 12345 | ||
57 | |||
58 | static struct PeerContext p1; | ||
59 | |||
60 | static struct PeerContext p2; | ||
61 | |||
62 | static int ok; | ||
63 | |||
64 | static int is_tcp; | ||
65 | |||
66 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
67 | |||
68 | static GNUNET_SCHEDULER_TaskIdentifier tct; | ||
69 | |||
70 | |||
71 | #if VERBOSE | ||
72 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | ||
73 | #else | ||
74 | #define OKPP do { ok++; } while (0) | ||
75 | #endif | ||
76 | |||
77 | |||
78 | |||
79 | static void | ||
80 | stop_arm (struct PeerContext *p) | ||
81 | { | ||
82 | #if START_ARM | ||
83 | if (NULL != p->arm_proc) | ||
84 | { | ||
85 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
86 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
87 | GNUNET_OS_process_wait (p->arm_proc); | ||
88 | GNUNET_OS_process_close (p->arm_proc); | ||
89 | p->arm_proc = NULL; | ||
90 | } | ||
91 | #endif | ||
92 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
93 | } | ||
94 | |||
95 | |||
96 | |||
97 | |||
98 | static void | ||
99 | exchange_hello_last (void *cls, | ||
100 | const struct GNUNET_MessageHeader *message) | ||
101 | { | ||
102 | struct PeerContext *me = cls; | ||
103 | |||
104 | GNUNET_assert (message != NULL); | ||
105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
106 | "Exchanging HELLO of size %d with peer (%s)!\n", | ||
107 | (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), | ||
108 | GNUNET_i2s (&me->id)); | ||
109 | GNUNET_assert (GNUNET_OK == | ||
110 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | ||
111 | message, &me->id)); | ||
112 | GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL); | ||
113 | } | ||
114 | |||
115 | |||
116 | static void | ||
117 | exchange_hello (void *cls, | ||
118 | const struct GNUNET_MessageHeader *message) | ||
119 | { | ||
120 | struct PeerContext *me = cls; | ||
121 | |||
122 | GNUNET_assert (message != NULL); | ||
123 | GNUNET_assert (GNUNET_OK == | ||
124 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | ||
125 | message, &me->id)); | ||
126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
127 | "Exchanging HELLO of size %d from peer %s!\n", | ||
128 | (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), | ||
129 | GNUNET_i2s (&me->id)); | ||
130 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); | ||
131 | } | ||
132 | |||
133 | |||
134 | static void | ||
135 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
136 | { | ||
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | ||
138 | GNUNET_break (0); | ||
139 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
140 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); | ||
141 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); | ||
142 | GNUNET_TRANSPORT_disconnect (p1.th); | ||
143 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
144 | if (GNUNET_SCHEDULER_NO_TASK != tct) | ||
145 | { | ||
146 | GNUNET_SCHEDULER_cancel (tct); | ||
147 | tct = GNUNET_SCHEDULER_NO_TASK; | ||
148 | } | ||
149 | ok = 1; | ||
150 | } | ||
151 | |||
152 | static void | ||
153 | end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
154 | { | ||
155 | ok = 60; | ||
156 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
157 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); | ||
158 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); | ||
159 | GNUNET_TRANSPORT_disconnect (p1.th); | ||
160 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
161 | if (GNUNET_SCHEDULER_NO_TASK != tct) | ||
162 | { | ||
163 | GNUNET_SCHEDULER_cancel (tct); | ||
164 | tct = GNUNET_SCHEDULER_NO_TASK; | ||
165 | } | ||
166 | ok = 0; | ||
167 | } | ||
168 | 52 | ||
169 | static void | 53 | static void |
170 | notify_connect (void *cls, | 54 | notify_connect (void *cls, |
@@ -172,88 +56,25 @@ notify_connect (void *cls, | |||
172 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 56 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
173 | uint32_t ats_count) | 57 | uint32_t ats_count) |
174 | { | 58 | { |
175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n", |
176 | "Peer `%4s' connected to us (%p)!\n", | 60 | GNUNET_i2s (peer)); |
177 | GNUNET_i2s (peer), | ||
178 | cls); | ||
179 | if (cls == &p1) | ||
180 | { | ||
181 | GNUNET_assert (ok >= 2); | ||
182 | OKPP; | ||
183 | OKPP; | ||
184 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
185 | GNUNET_SCHEDULER_cancel (die_task); | ||
186 | if (GNUNET_SCHEDULER_NO_TASK != tct) | ||
187 | GNUNET_SCHEDULER_cancel (tct); | ||
188 | tct = GNUNET_SCHEDULER_NO_TASK; | ||
189 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT, | ||
190 | &end_normally, NULL); | ||
191 | } | ||
192 | } | 61 | } |
193 | 62 | ||
194 | |||
195 | static void | 63 | static void |
196 | notify_disconnect (void *cls, | 64 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
197 | const struct GNUNET_PeerIdentity *peer) | ||
198 | { | 65 | { |
199 | if ( (ok != 60) && | 66 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n", |
200 | (GNUNET_SCHEDULER_NO_TASK != die_task) ) | 67 | GNUNET_i2s (peer)); |
201 | { | ||
202 | GNUNET_SCHEDULER_cancel (die_task); | ||
203 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
204 | } | ||
205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
206 | "Peer `%4s' disconnected (%p)!\n", | ||
207 | GNUNET_i2s (peer), cls); | ||
208 | } | 68 | } |
209 | 69 | ||
210 | |||
211 | static void | 70 | static void |
212 | setup_peer (struct PeerContext *p, | 71 | notify_receive (void *cls, |
213 | const char *cfgname) | 72 | const struct GNUNET_PeerIdentity *peer, |
214 | { | 73 | const struct GNUNET_MessageHeader *message, |
215 | p->cfg = GNUNET_CONFIGURATION_create (); | 74 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
216 | 75 | uint32_t ats_count) | |
217 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
218 | if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME")) | ||
219 | { | ||
220 | GNUNET_assert (GNUNET_OK == | ||
221 | GNUNET_CONFIGURATION_get_value_string (p->cfg, | ||
222 | "PATHS", "SERVICEHOME", | ||
223 | &p->servicehome)); | ||
224 | GNUNET_DISK_directory_remove (p->servicehome); | ||
225 | } | ||
226 | |||
227 | #if START_ARM | ||
228 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | ||
229 | "gnunet-service-arm", | ||
230 | #if VERBOSE_ARM | ||
231 | "-L", "DEBUG", | ||
232 | #endif | ||
233 | "-c", cfgname, NULL); | ||
234 | #endif | ||
235 | p->th = GNUNET_TRANSPORT_connect (p->cfg, | ||
236 | NULL, p, | ||
237 | NULL, | ||
238 | ¬ify_connect, ¬ify_disconnect); | ||
239 | GNUNET_assert (p->th != NULL); | ||
240 | } | ||
241 | |||
242 | |||
243 | static void | ||
244 | try_connect (void *cls, | ||
245 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
246 | { | 76 | { |
247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 77 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n"); |
248 | "Asking peers to connect...\n"); | ||
249 | /* FIXME: 'pX.id' may still be all-zeros here... */ | ||
250 | GNUNET_TRANSPORT_try_connect (p2.th, | ||
251 | &p1.id); | ||
252 | GNUNET_TRANSPORT_try_connect (p1.th, | ||
253 | &p2.id); | ||
254 | tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
255 | &try_connect, | ||
256 | NULL); | ||
257 | } | 78 | } |
258 | 79 | ||
259 | 80 | ||
@@ -262,68 +83,40 @@ run (void *cls, | |||
262 | char *const *args, | 83 | char *const *args, |
263 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 84 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
264 | { | 85 | { |
265 | GNUNET_assert (ok == 1); | 86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n"); |
266 | OKPP; | 87 | p = GNUNET_TRANSPORT_TESTING_start_peer("test_quota_compliance_tcp_peer1.conf"); |
267 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 88 | |
268 | &end_badly, NULL); | 89 | if (p != NULL) |
269 | if (is_tcp) | 90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer was successfully started\n"); |
270 | { | 91 | else |
271 | setup_peer (&p1, "test_transport_api_multiaddress_tcp_peer1.conf"); | 92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer was not started successfully\n"); |
272 | setup_peer (&p2, "test_transport_api_multiaddress_tcp_peer2.conf"); | 93 | GNUNET_assert (p != NULL); |
273 | } | 94 | |
274 | GNUNET_assert(p1.th != NULL); | 95 | |
275 | GNUNET_assert(p2.th != NULL); | 96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tConnecting to transport service\n"); |
276 | 97 | GNUNET_assert (p->th == NULL); | |
277 | GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); | 98 | p->th = GNUNET_TRANSPORT_connect(p->cfg, NULL, |
278 | GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); | 99 | NULL, |
279 | tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL); | 100 | ¬ify_receive, |
280 | } | 101 | ¬ify_connect, |
102 | ¬ify_disconnect); | ||
103 | GNUNET_assert (p->th != NULL); | ||
281 | 104 | ||
282 | static int | 105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tDisconnecting to transport service\n"); |
283 | check () | 106 | GNUNET_TRANSPORT_disconnect(p->th); |
284 | { | ||
285 | static char *const argv[] = { "test-transport-api", | ||
286 | "-c", | ||
287 | "test_transport_api_data.conf", | ||
288 | #if VERBOSE | ||
289 | "-L", "DEBUG", | ||
290 | #endif | ||
291 | NULL | ||
292 | }; | ||
293 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
294 | GNUNET_GETOPT_OPTION_END | ||
295 | }; | ||
296 | 107 | ||
297 | #if WRITECONFIG | 108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n"); |
298 | setTransportOptions("test_transport_api_data.conf"); | 109 | GNUNET_TRANSPORT_TESTING_stop_peer(p); |
299 | #endif | ||
300 | ok = 1; | ||
301 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | ||
302 | argv, "test-transport-api", "nohelp", | ||
303 | options, &run, &ok); | ||
304 | stop_arm (&p1); | ||
305 | stop_arm (&p2); | ||
306 | 110 | ||
307 | if (p1.servicehome != NULL) | 111 | GNUNET_free (p); |
308 | { | ||
309 | GNUNET_DISK_directory_remove (p1.servicehome); | ||
310 | GNUNET_free(p1.servicehome); | ||
311 | } | ||
312 | if (p2.servicehome != NULL) | ||
313 | { | ||
314 | GNUNET_DISK_directory_remove (p2.servicehome); | ||
315 | GNUNET_free(p2.servicehome); | ||
316 | } | ||
317 | return ok; | ||
318 | } | 112 | } |
319 | 113 | ||
320 | |||
321 | int | 114 | int |
322 | main (int argc, char *argv[]) | 115 | main (int argc, char *argv[]) |
323 | { | 116 | { |
324 | int ret; | 117 | int ret = 0; |
325 | 118 | ||
326 | GNUNET_log_setup ("test-transport-api", | 119 | GNUNET_log_setup ("test_transport_testing", |
327 | #if VERBOSE | 120 | #if VERBOSE |
328 | "DEBUG", | 121 | "DEBUG", |
329 | #else | 122 | #else |
@@ -331,12 +124,22 @@ main (int argc, char *argv[]) | |||
331 | #endif | 124 | #endif |
332 | NULL); | 125 | NULL); |
333 | 126 | ||
334 | if (strstr(argv[0], "tcp") != NULL) | 127 | char *const argv_1[] = { "test_transport_testing", |
335 | { | 128 | "-c", |
336 | is_tcp = GNUNET_YES; | 129 | "test_transport_api_data.conf", |
337 | } | 130 | #if VERBOSE |
131 | "-L", "DEBUG", | ||
132 | #endif | ||
133 | NULL | ||
134 | }; | ||
135 | |||
136 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
137 | GNUNET_GETOPT_OPTION_END | ||
138 | }; | ||
338 | 139 | ||
339 | ret = check (); | 140 | GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, |
141 | argv_1, "test_transport_testing", "nohelp", | ||
142 | options, &run, &ret); | ||
340 | 143 | ||
341 | return ret; | 144 | return ret; |
342 | } | 145 | } |