diff options
-rw-r--r-- | src/transport/test_transport_address_switch.c | 677 | ||||
-rw-r--r-- | src/transport/test_transport_api_disconnect.c | 4 | ||||
-rw-r--r-- | src/transport/test_transport_testing_restart.c | 92 | ||||
-rw-r--r-- | src/transport/test_transport_testing_startstop.c | 69 | ||||
-rw-r--r-- | src/transport/transport-testing-main.c | 3 | ||||
-rw-r--r-- | src/transport/transport-testing.c | 2 |
6 files changed, 302 insertions, 545 deletions
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c index a64dd6172..96e11b7de 100644 --- a/src/transport/test_transport_address_switch.c +++ b/src/transport/test_transport_address_switch.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2011 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V. |
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 |
@@ -33,19 +33,20 @@ | |||
33 | * addresses in connected state and a test message was successfully transmitted | 33 | * addresses in connected state and a test message was successfully transmitted |
34 | * after this switch. | 34 | * after this switch. |
35 | * | 35 | * |
36 | * Since it is not possible to trigger an address switch from | 36 | * Since it is not possible to trigger an address switch from outside, |
37 | * outside, the test still passes when no address switching attempt takes | 37 | * the test returns "77" (skipped) when no address switching attempt |
38 | * place. It fails if an address switch attempt fails. | 38 | * takes place. It fails if an address switch attempt fails. |
39 | * | ||
40 | * NOTE: The test seems largely useless right now, as we simply NEVER | ||
41 | * switch addresses under the test conditions. However, it may be a | ||
42 | * good starting point for a future test. For now, it always times | ||
43 | * out and returns "77" (skipped), so we set the timeout suitably low. | ||
39 | */ | 44 | */ |
40 | #include "platform.h" | 45 | #include "platform.h" |
41 | #include "gnunet_transport_service.h" | 46 | #include "gnunet_transport_service.h" |
42 | #include "gnunet_ats_service.h" | 47 | #include "gnunet_ats_service.h" |
43 | #include "gauger.h" | ||
44 | #include "transport-testing.h" | 48 | #include "transport-testing.h" |
45 | 49 | ||
46 | /* | ||
47 | * Testcase specific declarations | ||
48 | */ | ||
49 | 50 | ||
50 | GNUNET_NETWORK_STRUCT_BEGIN | 51 | GNUNET_NETWORK_STRUCT_BEGIN |
51 | struct TestMessage | 52 | struct TestMessage |
@@ -68,84 +69,42 @@ GNUNET_NETWORK_STRUCT_END | |||
68 | /** | 69 | /** |
69 | * Testcase timeout | 70 | * Testcase timeout |
70 | */ | 71 | */ |
71 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 72 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
72 | 73 | ||
73 | /** | 74 | /** |
74 | * How long until we give up on transmitting the message? | 75 | * How long until we give up on transmitting the message? |
75 | */ | 76 | */ |
76 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 77 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
77 | 78 | ||
78 | #define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
79 | 79 | ||
80 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | ||
80 | 81 | ||
81 | /** | ||
82 | * Timeout task to send messages | ||
83 | */ | ||
84 | static struct GNUNET_SCHEDULER_Task *die_task; | ||
85 | |||
86 | |||
87 | static struct GNUNET_SCHEDULER_Task *delayed_end_task; | ||
88 | |||
89 | /** | ||
90 | * Measurement task to send messages | ||
91 | */ | ||
92 | static struct GNUNET_SCHEDULER_Task *measure_task; | 82 | static struct GNUNET_SCHEDULER_Task *measure_task; |
93 | 83 | ||
94 | |||
95 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | ||
96 | static char *cfg_file_p1; | ||
97 | static struct GNUNET_STATISTICS_Handle *p1_stat; | ||
98 | |||
99 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
100 | static char *cfg_file_p2; | ||
101 | static struct GNUNET_STATISTICS_Handle *p2_stat; | ||
102 | |||
103 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *sender; | ||
104 | |||
105 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver; | ||
106 | |||
107 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | 84 | static struct GNUNET_TRANSPORT_TransmitHandle *th; |
108 | 85 | ||
109 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; | ||
110 | |||
111 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; | ||
112 | |||
113 | static int test_connected; | ||
114 | |||
115 | static int res; | ||
116 | |||
117 | |||
118 | /** | 86 | /** |
119 | * Statistics about peer 1 | 87 | * Statistics we track per peer. |
120 | */ | 88 | */ |
121 | static unsigned int p1_addresses_avail; | 89 | struct PeerStats |
122 | static unsigned int p1_switch_attempts; | 90 | { |
123 | static unsigned int p1_switch_success; | 91 | struct GNUNET_STATISTICS_Handle *stat; |
124 | static unsigned int p1_switch_fail; | ||
125 | 92 | ||
93 | unsigned int addresses_avail; | ||
126 | 94 | ||
127 | /** | 95 | unsigned int switch_attempts; |
128 | * Statistics about peer 2 | ||
129 | */ | ||
130 | static unsigned int p2_switch_attempts; | ||
131 | static unsigned int p2_switch_success; | ||
132 | static unsigned int p2_switch_fail; | ||
133 | static unsigned int p2_addresses_avail; | ||
134 | 96 | ||
135 | /** | 97 | unsigned int switch_success; |
136 | * Transmission statistics | 98 | |
137 | */ | 99 | unsigned int switch_fail; |
100 | }; | ||
101 | |||
102 | static struct PeerStats stats[2]; | ||
138 | 103 | ||
139 | /* Amount of data transfered since last switch attempt */ | 104 | /* Amount of data transfered since last switch attempt */ |
140 | static unsigned long long bytes_sent_after_switch; | 105 | static unsigned long long bytes_sent_after_switch; |
141 | static unsigned long long bytes_recv_after_switch; | ||
142 | |||
143 | 106 | ||
144 | #if VERBOSE | 107 | static unsigned long long bytes_recv_after_switch; |
145 | #define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | ||
146 | #else | ||
147 | #define OKPP do { ok++; } while (0) | ||
148 | #endif | ||
149 | 108 | ||
150 | 109 | ||
151 | static int | 110 | static int |
@@ -155,17 +114,12 @@ stat_start_attempt_cb (void *cls, | |||
155 | uint64_t value, | 114 | uint64_t value, |
156 | int is_persistent) | 115 | int is_persistent) |
157 | { | 116 | { |
158 | if (cls == p1) | 117 | struct PeerStats *stat = cls; |
159 | { | ||
160 | p1_switch_attempts++; | ||
161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(1:s)"); | ||
162 | } | ||
163 | else if (cls == p2) | ||
164 | { | ||
165 | p2_switch_attempts++; | ||
166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(2:s)"); | ||
167 | } | ||
168 | 118 | ||
119 | stat->switch_attempts++; | ||
120 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
121 | "Switch attempted (%p)", | ||
122 | stat); | ||
169 | bytes_recv_after_switch = 0; | 123 | bytes_recv_after_switch = 0; |
170 | bytes_sent_after_switch = 0; | 124 | bytes_sent_after_switch = 0; |
171 | 125 | ||
@@ -180,17 +134,12 @@ stat_success_attempt_cb (void *cls, | |||
180 | uint64_t value, | 134 | uint64_t value, |
181 | int is_persistent) | 135 | int is_persistent) |
182 | { | 136 | { |
183 | if (cls == p1) | 137 | struct PeerStats *stat = cls; |
184 | { | ||
185 | p1_switch_success++; | ||
186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(1:+)"); | ||
187 | } | ||
188 | if (cls == p2) | ||
189 | { | ||
190 | p2_switch_success++; | ||
191 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(2:+)"); | ||
192 | } | ||
193 | 138 | ||
139 | stat->switch_success++; | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
141 | "Switch succeeded (%p)", | ||
142 | stat); | ||
194 | return GNUNET_OK; | 143 | return GNUNET_OK; |
195 | } | 144 | } |
196 | 145 | ||
@@ -202,20 +151,15 @@ stat_fail_attempt_cb (void *cls, | |||
202 | uint64_t value, | 151 | uint64_t value, |
203 | int is_persistent) | 152 | int is_persistent) |
204 | { | 153 | { |
154 | struct PeerStats *stat = cls; | ||
155 | |||
205 | if (value == 0) | 156 | if (value == 0) |
206 | return GNUNET_OK; | 157 | return GNUNET_OK; |
207 | 158 | ||
208 | if (cls == p1) | 159 | stat->switch_fail++; |
209 | { | 160 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
210 | p1_switch_fail++; | 161 | "Switch failed (%p)", |
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(1:-)"); | 162 | stat); |
212 | } | ||
213 | if (cls == p2) | ||
214 | { | ||
215 | p2_switch_fail++; | ||
216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(2:-)"); | ||
217 | } | ||
218 | |||
219 | return GNUNET_OK; | 163 | return GNUNET_OK; |
220 | } | 164 | } |
221 | 165 | ||
@@ -227,206 +171,148 @@ stat_addresses_available (void *cls, | |||
227 | uint64_t value, | 171 | uint64_t value, |
228 | int is_persistent) | 172 | int is_persistent) |
229 | { | 173 | { |
230 | if (cls == p1) | 174 | struct PeerStats *stat = cls; |
231 | { | 175 | |
232 | p1_addresses_avail++; | 176 | stat->addresses_avail++; |
233 | } | ||
234 | if (cls == p2) | ||
235 | { | ||
236 | p2_addresses_avail++; | ||
237 | } | ||
238 | return GNUNET_OK; | 177 | return GNUNET_OK; |
239 | } | 178 | } |
240 | 179 | ||
241 | 180 | ||
181 | /** | ||
182 | * List of statistics entries we care about. | ||
183 | */ | ||
184 | static struct WatchEntry { | ||
185 | |||
186 | /** | ||
187 | * Name of the statistic we watch. | ||
188 | */ | ||
189 | const char *stat_name; | ||
190 | |||
191 | /** | ||
192 | * Handler to register; | ||
193 | */ | ||
194 | GNUNET_STATISTICS_Iterator stat_handler; | ||
195 | } watches[] = { | ||
196 | { "# Attempts to switch addresses", &stat_start_attempt_cb }, | ||
197 | { "# Successful attempts to switch addresses", &stat_success_attempt_cb }, | ||
198 | { "# Failed attempts to switch addresses (failed to send CONNECT CONT)", &stat_fail_attempt_cb }, | ||
199 | { "# Failed attempts to switch addresses (failed to send CONNECT)", &stat_fail_attempt_cb }, | ||
200 | { "# Failed attempts to switch addresses (no response)", &stat_fail_attempt_cb }, | ||
201 | { "# transport addresses", &stat_addresses_available }, | ||
202 | { NULL, NULL } | ||
203 | }; | ||
204 | |||
205 | |||
242 | static void | 206 | static void |
243 | clean_up () | 207 | custom_shutdown (void *cls) |
244 | { | 208 | { |
245 | if (measure_task != NULL) | 209 | int result; |
210 | |||
211 | if (NULL != measure_task) | ||
246 | { | 212 | { |
247 | GNUNET_SCHEDULER_cancel (measure_task); | 213 | GNUNET_SCHEDULER_cancel (measure_task); |
248 | measure_task = NULL; | 214 | measure_task = NULL; |
249 | } | 215 | } |
250 | 216 | if (0 == stats[0].switch_attempts + stats[1].switch_attempts) | |
251 | if (delayed_end_task != NULL) | ||
252 | { | 217 | { |
253 | GNUNET_SCHEDULER_cancel (delayed_end_task); | 218 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
254 | delayed_end_task = NULL; | 219 | "Test did not work, as peers didn't switch (flawed testcase)!\n"); |
220 | ccc->global_ret = 77; | ||
255 | } | 221 | } |
256 | 222 | else | |
257 | if (die_task != NULL) | ||
258 | { | 223 | { |
259 | GNUNET_SCHEDULER_cancel (die_task); | 224 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
260 | die_task = NULL; | 225 | "Fail (timeout)! No transmission after switch! Stopping peers\n"); |
226 | ccc->global_ret = GNUNET_SYSERR; | ||
261 | } | 227 | } |
262 | 228 | ||
263 | if (NULL != p1_stat) | 229 | /* stop statistics */ |
264 | { | 230 | for (unsigned int i=0;i<2;i++) |
265 | GNUNET_STATISTICS_watch_cancel (p1_stat, "transport", | ||
266 | "# Attempts to switch addresses", | ||
267 | stat_start_attempt_cb, p1); | ||
268 | GNUNET_STATISTICS_watch_cancel (p1_stat, "transport", | ||
269 | "# Successful attempts to switch addresses", | ||
270 | stat_success_attempt_cb, p1); | ||
271 | GNUNET_STATISTICS_watch_cancel (p1_stat, "transport", | ||
272 | "# Failed attempts to switch addresses (failed to send CONNECT CONT)", | ||
273 | stat_fail_attempt_cb, p1); | ||
274 | GNUNET_STATISTICS_watch_cancel (p1_stat, "transport", | ||
275 | "# Failed attempts to switch addresses (failed to send CONNECT)", | ||
276 | stat_fail_attempt_cb, p1); | ||
277 | GNUNET_STATISTICS_watch_cancel (p1_stat, "transport", | ||
278 | "# Failed attempts to switch addresses (no response)", | ||
279 | stat_fail_attempt_cb, p1); | ||
280 | GNUNET_STATISTICS_watch (p1_stat, "transport", | ||
281 | "# transport addresses", | ||
282 | stat_addresses_available, p1); | ||
283 | GNUNET_STATISTICS_destroy (p1_stat, GNUNET_NO); | ||
284 | p1_stat = NULL; | ||
285 | } | ||
286 | if (NULL != p2_stat) | ||
287 | { | 231 | { |
288 | GNUNET_STATISTICS_watch_cancel (p2_stat, "transport", | 232 | if (NULL != stats[i].stat) |
289 | "# Attempts to switch addresses", stat_start_attempt_cb, p2); | 233 | { |
290 | GNUNET_STATISTICS_watch_cancel (p2_stat, "transport", | 234 | for (unsigned int j=0;NULL != watches[j].stat_name; j++) |
291 | "# Successful attempts to switch addresses", stat_success_attempt_cb, p2); | 235 | GNUNET_STATISTICS_watch_cancel (stats[i].stat, |
292 | GNUNET_STATISTICS_watch_cancel (p2_stat, "transport", | 236 | "transport", |
293 | "# Failed attempts to switch addresses (failed to send CONNECT CONT)", | 237 | watches[j].stat_name, |
294 | stat_fail_attempt_cb, p2); | 238 | watches[j].stat_handler, |
295 | GNUNET_STATISTICS_watch_cancel (p2_stat, "transport", | 239 | &stats[i]); |
296 | "# Failed attempts to switch addresses (failed to send CONNECT)", | 240 | |
297 | stat_fail_attempt_cb, p2); | 241 | GNUNET_STATISTICS_destroy (stats[i].stat, |
298 | GNUNET_STATISTICS_watch_cancel (p2_stat, "transport", | 242 | GNUNET_NO); |
299 | "# Failed attempts to switch addresses (no response)", | 243 | stats[i].stat = NULL; |
300 | stat_fail_attempt_cb, p2); | 244 | } |
301 | GNUNET_STATISTICS_watch (p2_stat, "transport", | ||
302 | "# transport addresses", | ||
303 | stat_addresses_available, p2); | ||
304 | GNUNET_STATISTICS_destroy (p2_stat, GNUNET_NO); | ||
305 | p2_stat = NULL; | ||
306 | } | 245 | } |
307 | 246 | if (NULL != th) | |
308 | if (th != NULL) | ||
309 | { | 247 | { |
310 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 248 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
311 | th = NULL; | 249 | th = NULL; |
312 | } | 250 | } |
313 | if (cc != NULL) | ||
314 | { | ||
315 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
316 | cc = NULL; | ||
317 | } | ||
318 | if (p1 != NULL) | ||
319 | { | ||
320 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
321 | p1 = NULL; | ||
322 | } | ||
323 | if (p2 != NULL) | ||
324 | { | ||
325 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
326 | p2 = NULL; | ||
327 | } | ||
328 | } | ||
329 | 251 | ||
330 | 252 | result = 0; | |
331 | static void | ||
332 | end () | ||
333 | { | ||
334 | int result = 0; | ||
335 | |||
336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
337 | "Stopping peers\n"); | ||
338 | |||
339 | delayed_end_task = NULL; | ||
340 | FPRINTF (stderr, "\n"); | 253 | FPRINTF (stderr, "\n"); |
341 | if (p1_switch_attempts > 0) | 254 | if (stats[0].switch_attempts > 0) |
342 | { | 255 | { |
343 | FPRINTF (stderr, | 256 | FPRINTF (stderr, |
344 | "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", | 257 | "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", |
345 | p1_switch_attempts, | 258 | stats[0].switch_attempts, |
346 | p1_switch_success, | 259 | stats[0].switch_success, |
347 | p1_switch_fail); | 260 | stats[0].switch_fail); |
348 | if (p1_switch_success != p1_switch_attempts) | 261 | if (stats[0].switch_success != stats[0].switch_attempts) |
349 | { | 262 | { |
350 | GNUNET_break (0); | 263 | GNUNET_break (0); |
351 | result ++; | 264 | result ++; |
352 | } | 265 | } |
353 | } | 266 | } |
354 | else if (p1_addresses_avail > 1) | 267 | else if (stats[0].addresses_avail > 1) |
355 | { | 268 | { |
356 | FPRINTF (stderr, | 269 | FPRINTF (stderr, |
357 | "Peer 1 had %u addresses available, but did not try to switch\n", | 270 | "Peer 1 had %u addresses available, but did not try to switch\n", |
358 | p1_addresses_avail); | 271 | stats[0].addresses_avail); |
359 | } | 272 | } |
360 | if (p2_switch_attempts > 0) | 273 | if (stats[1].switch_attempts > 0) |
361 | { | 274 | { |
362 | FPRINTF (stderr, | 275 | FPRINTF (stderr, |
363 | "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", | 276 | "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", |
364 | p2_switch_attempts, | 277 | stats[1].switch_attempts, |
365 | p2_switch_success, | 278 | stats[1].switch_success, |
366 | p2_switch_fail); | 279 | stats[1].switch_fail); |
367 | if (p2_switch_success != p2_switch_attempts) | 280 | if (stats[1].switch_success != stats[1].switch_attempts) |
368 | { | 281 | { |
369 | GNUNET_break (0); | 282 | GNUNET_break (0); |
370 | result++; | 283 | result++; |
371 | } | 284 | } |
372 | } | 285 | } |
373 | else if (p2_addresses_avail > 1) | 286 | else if (stats[1].addresses_avail > 1) |
374 | { | 287 | { |
375 | FPRINTF (stderr, | 288 | FPRINTF (stderr, |
376 | "Peer 2 had %u addresses available, but did not try to switch\n", | 289 | "Peer 2 had %u addresses available, but did not try to switch\n", |
377 | p2_addresses_avail); | 290 | stats[1].addresses_avail); |
378 | } | 291 | } |
379 | 292 | ||
380 | if ( ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) && | 293 | if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && |
381 | (bytes_sent_after_switch == 0) ) | 294 | (bytes_sent_after_switch == 0) ) |
382 | { | 295 | { |
383 | FPRINTF (stderr, "No data sent after switching!\n"); | 296 | FPRINTF (stderr, "No data sent after switching!\n"); |
384 | GNUNET_break (0); | 297 | GNUNET_break (0); |
385 | res++; | 298 | result++; |
386 | } | 299 | } |
387 | if ( ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) && | 300 | if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && |
388 | (bytes_recv_after_switch == 0) ) | 301 | (bytes_recv_after_switch == 0) ) |
389 | { | 302 | { |
390 | FPRINTF (stderr, "No data received after switching!\n"); | 303 | FPRINTF (stderr, "No data received after switching!\n"); |
391 | GNUNET_break (0); | 304 | GNUNET_break (0); |
392 | res++; | 305 | result++; |
393 | } | 306 | } |
394 | 307 | if (0 != result) | |
395 | clean_up(); | 308 | ccc->global_ret = GNUNET_SYSERR; |
396 | |||
397 | res = result; | ||
398 | } | ||
399 | |||
400 | |||
401 | static void | ||
402 | end_badly () | ||
403 | { | ||
404 | die_task = NULL; | ||
405 | clean_up(); | ||
406 | if (0 == p1_switch_attempts + p2_switch_attempts) | ||
407 | { | ||
408 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
409 | "Test did not work, as peers didn't switch (flawed testcase)!\n"); | ||
410 | res = 0; | ||
411 | } | ||
412 | else | ||
413 | { | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
415 | "Fail (timeout)! No transmission after switch! Stopping peers\n"); | ||
416 | res = GNUNET_YES; | ||
417 | } | ||
418 | if (test_connected == GNUNET_YES) | ||
419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
420 | "Peers got connected\n"); | ||
421 | else | ||
422 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
423 | "Peers got NOT EVEN connected\n"); | ||
424 | } | 309 | } |
425 | 310 | ||
426 | 311 | ||
427 | static void | 312 | static void |
428 | notify_receive (void *cls, | 313 | notify_receive (void *cls, |
429 | const struct GNUNET_PeerIdentity *peer, | 314 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
315 | const struct GNUNET_PeerIdentity *sender, | ||
430 | const struct GNUNET_MessageHeader *message) | 316 | const struct GNUNET_MessageHeader *message) |
431 | { | 317 | { |
432 | const struct TestMessage *hdr; | 318 | const struct TestMessage *hdr; |
@@ -435,28 +321,30 @@ notify_receive (void *cls, | |||
435 | if (MTYPE != ntohs (message->type)) | 321 | if (MTYPE != ntohs (message->type)) |
436 | return; | 322 | return; |
437 | 323 | ||
438 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 324 | { |
439 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 325 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
440 | 326 | ||
441 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 327 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
442 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", p->no, ps, | 328 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", |
443 | ntohl (hdr->num), | 329 | receiver->no, |
444 | ntohs (message->size), | 330 | ps, |
445 | GNUNET_i2s (peer)); | 331 | ntohl (hdr->num), |
446 | if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) && | 332 | ntohs (message->size), |
447 | (p1_switch_attempts == p1_switch_fail + p1_switch_success) && | 333 | GNUNET_i2s (sender)); |
448 | (p2_switch_attempts == p2_switch_fail + p2_switch_success) ) | 334 | GNUNET_free (ps); |
335 | } | ||
336 | if ( ((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && | ||
337 | (stats[0].switch_attempts == stats[0].switch_fail + stats[0].switch_success) && | ||
338 | (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success) ) | ||
449 | { | 339 | { |
450 | bytes_recv_after_switch += ntohs(hdr->header.size); | 340 | bytes_recv_after_switch += ntohs(hdr->header.size); |
451 | if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0)) | 341 | if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0)) |
452 | { | 342 | { |
453 | /* A peer switched addresses and sent and received data after the | 343 | /* A peer switched addresses and sent and received data after the |
454 | * switch operations */ | 344 | * switch operations */ |
455 | end (); | 345 | GNUNET_SCHEDULER_shutdown (); |
456 | } | 346 | } |
457 | } | 347 | } |
458 | |||
459 | GNUNET_free(ps); | ||
460 | } | 348 | } |
461 | 349 | ||
462 | 350 | ||
@@ -472,10 +360,8 @@ notify_ready (void *cls, size_t size, void *buf) | |||
472 | { | 360 | { |
473 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 361 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
474 | "Timeout occurred while waiting for transmit_ready for message\n"); | 362 | "Timeout occurred while waiting for transmit_ready for message\n"); |
475 | if (NULL != die_task) | 363 | ccc->global_ret = GNUNET_SYSERR; |
476 | GNUNET_SCHEDULER_cancel (die_task); | 364 | GNUNET_SCHEDULER_shutdown (); |
477 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
478 | res = 1; | ||
479 | return 0; | 365 | return 0; |
480 | } | 366 | } |
481 | 367 | ||
@@ -489,27 +375,32 @@ notify_ready (void *cls, size_t size, void *buf) | |||
489 | GNUNET_memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage)); | 375 | GNUNET_memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage)); |
490 | memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct TestMessage)); | 376 | memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct TestMessage)); |
491 | 377 | ||
492 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 378 | { |
493 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 379 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); |
494 | "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", | 380 | |
495 | (unsigned int) (counter - 1), | 381 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
496 | MSIZE, | 382 | "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", |
497 | sender->no, | 383 | (unsigned int) (counter - 1), |
498 | GNUNET_i2s (&sender->id), | 384 | MSIZE, |
499 | receiver->no, | 385 | ccc->p[1]->no, |
500 | receiver_s); | 386 | GNUNET_i2s (&ccc->p[1]->id), |
501 | GNUNET_free(receiver_s); | 387 | ccc->p[0]->no, |
388 | receiver_s); | ||
389 | GNUNET_free(receiver_s); | ||
390 | } | ||
502 | 391 | ||
503 | if (th == NULL) | 392 | if (th == NULL) |
504 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, | 393 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, |
505 | &p1->id, | 394 | &ccc->p[0]->id, |
506 | MSIZE, | 395 | MSIZE, |
507 | TIMEOUT_TRANSMIT, | 396 | TIMEOUT_TRANSMIT, |
508 | ¬ify_ready, NULL); | 397 | ¬ify_ready, |
398 | NULL); | ||
509 | 399 | ||
510 | if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) && | 400 | if ( ( (stats[0].switch_attempts >= 1) || |
511 | (p1_switch_attempts == p1_switch_fail + p1_switch_success) && | 401 | (stats[1].switch_attempts >= 1) ) && |
512 | (p2_switch_attempts == p2_switch_fail + p2_switch_success) ) | 402 | (stats[0].switch_attempts == stats[0].switch_fail + stats[0].switch_success) && |
403 | (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success) ) | ||
513 | { | 404 | { |
514 | bytes_sent_after_switch += MSIZE; | 405 | bytes_sent_after_switch += MSIZE; |
515 | } | 406 | } |
@@ -518,32 +409,10 @@ notify_ready (void *cls, size_t size, void *buf) | |||
518 | 409 | ||
519 | 410 | ||
520 | static void | 411 | static void |
521 | notify_connect (void *cls, | ||
522 | const struct GNUNET_PeerIdentity *peer) | ||
523 | { | ||
524 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
525 | |||
526 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
527 | "Peer %u (`%4s') connected to us!\n", | ||
528 | p->no, | ||
529 | GNUNET_i2s (peer)); | ||
530 | } | ||
531 | |||
532 | |||
533 | static void | ||
534 | notify_disconnect (void *cls, | 412 | notify_disconnect (void *cls, |
535 | const struct GNUNET_PeerIdentity *peer) | 413 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
414 | const struct GNUNET_PeerIdentity *other) | ||
536 | { | 415 | { |
537 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
538 | |||
539 | if (NULL != p1) | ||
540 | { | ||
541 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
542 | "Peer %u (`%4s') disconnected early!\n", | ||
543 | p->no, | ||
544 | GNUNET_i2s (peer)); | ||
545 | GNUNET_SCHEDULER_shutdown (); | ||
546 | } | ||
547 | if (NULL != th) | 416 | if (NULL != th) |
548 | { | 417 | { |
549 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 418 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
@@ -553,24 +422,13 @@ notify_disconnect (void *cls, | |||
553 | 422 | ||
554 | 423 | ||
555 | static void | 424 | static void |
556 | sendtask () | ||
557 | { | ||
558 | /* Transmit test messages */ | ||
559 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, | ||
560 | &p1->id, MSIZE, | ||
561 | TIMEOUT_TRANSMIT, | ||
562 | ¬ify_ready, NULL); | ||
563 | } | ||
564 | |||
565 | |||
566 | static void | ||
567 | progress_indicator (void *cls) | 425 | progress_indicator (void *cls) |
568 | { | 426 | { |
569 | static int counter; | 427 | static int counter; |
570 | 428 | ||
571 | measure_task = NULL; | 429 | measure_task = NULL; |
572 | counter++; | 430 | counter++; |
573 | if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) | 431 | if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter) |
574 | { | 432 | { |
575 | FPRINTF (stderr, "%s", ".\n"); | 433 | FPRINTF (stderr, "%s", ".\n"); |
576 | } | 434 | } |
@@ -578,184 +436,73 @@ progress_indicator (void *cls) | |||
578 | { | 436 | { |
579 | FPRINTF (stderr, "%s", "."); | 437 | FPRINTF (stderr, "%s", "."); |
580 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 438 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
581 | &progress_indicator, NULL); | 439 | &progress_indicator, |
440 | NULL); | ||
582 | } | 441 | } |
583 | } | 442 | } |
584 | 443 | ||
585 | 444 | ||
586 | static void | 445 | static void |
587 | testing_connect_cb (void *cls) | 446 | connected_cb (void *cls) |
588 | { | 447 | { |
589 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 448 | for (unsigned int i=0;i<2;i++) |
590 | 449 | { | |
591 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 450 | stats[i].stat = GNUNET_STATISTICS_create ("transport", |
592 | "Peers connected: %u (%s) <-> %u (%s)\n", | 451 | ccc->p[i]->cfg); |
593 | p1->no, p1_c, p2->no, | 452 | if (NULL == stats[i].stat) |
594 | GNUNET_i2s (&p2->id)); | 453 | { |
595 | GNUNET_free (p1_c); | 454 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
596 | 455 | "Fail! Could not create statistics for peers!\n"); | |
597 | cc = NULL; | 456 | ccc->global_ret = GNUNET_SYSERR; |
598 | test_connected = GNUNET_YES; | 457 | GNUNET_SCHEDULER_shutdown (); |
599 | 458 | return; | |
600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 459 | } |
601 | "(i:s/+/-) \t i == peer 1/2, s/+/- : switch attempt/switch ok/switch fail\n"); | 460 | for (unsigned int j=0;NULL != watches[j].stat_name; j++) |
602 | 461 | { | |
462 | GNUNET_STATISTICS_watch (stats[i].stat, | ||
463 | "transport", | ||
464 | watches[j].stat_name, | ||
465 | watches[j].stat_handler, | ||
466 | &stats[i]); | ||
467 | } | ||
468 | } | ||
603 | /* Show progress */ | 469 | /* Show progress */ |
470 | ccc->global_ret = GNUNET_OK; | ||
604 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 471 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
605 | &progress_indicator, | 472 | &progress_indicator, |
606 | NULL); | 473 | NULL); |
607 | /* Peers are connected, start transmit test messages */ | 474 | /* Peers are connected, start transmit test messages */ |
608 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); | 475 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, |
609 | } | 476 | &ccc->p[0]->id, MSIZE, |
610 | 477 | TIMEOUT_TRANSMIT, | |
611 | 478 | ¬ify_ready, NULL); | |
612 | static void | ||
613 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | ||
614 | { | ||
615 | static int started; | ||
616 | started++; | ||
617 | |||
618 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
619 | "Peer %u (`%s') started\n", | ||
620 | p->no, | ||
621 | GNUNET_i2s (&p->id)); | ||
622 | if (started != 2) | ||
623 | return; | ||
624 | 479 | ||
625 | test_connected = GNUNET_NO; | ||
626 | sender = p2; | ||
627 | receiver = p1; | ||
628 | |||
629 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id)); | ||
630 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
631 | "Test tries to send from %u (%s) -> peer %u (%s)\n", | ||
632 | sender->no, | ||
633 | sender_c, | ||
634 | receiver->no, | ||
635 | GNUNET_i2s (&receiver->id)); | ||
636 | GNUNET_free (sender_c); | ||
637 | |||
638 | /* Connect the peers */ | ||
639 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, | ||
640 | p2, | ||
641 | &testing_connect_cb, | ||
642 | NULL); | ||
643 | } | 480 | } |
644 | 481 | ||
645 | 482 | ||
646 | static void | ||
647 | run (void *cls, | ||
648 | char * const *args, | ||
649 | const char *cfgfile, | ||
650 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
651 | { | ||
652 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
653 | |||
654 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, | ||
655 | ¬ify_receive, ¬ify_connect, ¬ify_disconnect, &start_cb, NULL); | ||
656 | |||
657 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, | ||
658 | ¬ify_receive, ¬ify_connect, ¬ify_disconnect, &start_cb, NULL); | ||
659 | |||
660 | if ((p1 == NULL )|| (p2 == NULL)) | ||
661 | { | ||
662 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | ||
663 | GNUNET_SCHEDULER_shutdown (); | ||
664 | return; | ||
665 | } | ||
666 | |||
667 | /* Start to watch statistics for peer 1 */ | ||
668 | p1_stat = GNUNET_STATISTICS_create ("transport", p1->cfg); | ||
669 | GNUNET_STATISTICS_watch (p1_stat, "transport", | ||
670 | "# Attempts to switch addresses", | ||
671 | stat_start_attempt_cb, p1); | ||
672 | GNUNET_STATISTICS_watch (p1_stat, "transport", | ||
673 | "# Successful attempts to switch addresses", | ||
674 | stat_success_attempt_cb, p1); | ||
675 | GNUNET_STATISTICS_watch (p1_stat, "transport", | ||
676 | "# Failed attempts to switch addresses (failed to send CONNECT CONT)", | ||
677 | stat_fail_attempt_cb, p1); | ||
678 | GNUNET_STATISTICS_watch (p1_stat, "transport", | ||
679 | "# Failed attempts to switch addresses (failed to send CONNECT)", | ||
680 | stat_fail_attempt_cb, p1); | ||
681 | GNUNET_STATISTICS_watch (p1_stat, "transport", | ||
682 | "# Failed attempts to switch addresses (no response)", | ||
683 | stat_fail_attempt_cb, p1); | ||
684 | GNUNET_STATISTICS_watch (p1_stat, "transport", | ||
685 | "# transport addresses", | ||
686 | stat_addresses_available, p1); | ||
687 | |||
688 | /* Start to watch statistics for peer 2 */ | ||
689 | p2_stat = GNUNET_STATISTICS_create ("transport", p2->cfg); | ||
690 | GNUNET_STATISTICS_watch (p2_stat, "transport", | ||
691 | "# Attempts to switch addresses", | ||
692 | stat_start_attempt_cb, p2); | ||
693 | GNUNET_STATISTICS_watch (p2_stat, "transport", | ||
694 | "# Successful attempts to switch addresses", | ||
695 | stat_success_attempt_cb, p2); | ||
696 | GNUNET_STATISTICS_watch (p2_stat, "transport", | ||
697 | "# Failed attempts to switch addresses (failed to send CONNECT CONT)", | ||
698 | stat_fail_attempt_cb, p2); | ||
699 | GNUNET_STATISTICS_watch (p2_stat, "transport", | ||
700 | "# Failed attempts to switch addresses (failed to send CONNECT)", | ||
701 | stat_fail_attempt_cb, p2); | ||
702 | GNUNET_STATISTICS_watch (p2_stat, "transport", | ||
703 | "# Failed attempts to switch addresses (no response)", | ||
704 | stat_fail_attempt_cb, p2); | ||
705 | GNUNET_STATISTICS_watch (p2_stat, "transport", | ||
706 | "# transport addresses", | ||
707 | stat_addresses_available, p2); | ||
708 | |||
709 | if ((p1_stat == NULL )|| (p2_stat == NULL)) | ||
710 | { | ||
711 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
712 | "Fail! Could not create statistics for peers!\n"); | ||
713 | GNUNET_SCHEDULER_shutdown (); | ||
714 | return; | ||
715 | } | ||
716 | } | ||
717 | |||
718 | int | 483 | int |
719 | main (int argc, char *argv[]) | 484 | main (int argc, |
485 | char *argv[]) | ||
720 | { | 486 | { |
721 | char *test_plugin; | 487 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
722 | char *test_source; | 488 | .connect_continuation = &connected_cb, |
723 | char *test_name; | 489 | .config_file = "test_transport_startonly.conf", |
724 | 490 | .rec = ¬ify_receive, | |
725 | static char *argv_new[] = { "test-transport-address-switch", "-c", | 491 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
726 | "test_transport_startonly.conf", NULL }; | 492 | .nd = ¬ify_disconnect, |
727 | 493 | .shutdown_task = &custom_shutdown, | |
728 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 494 | .timeout = TIMEOUT |
729 | GNUNET_GETOPT_OPTION_END }; | 495 | }; |
730 | 496 | ccc = &my_ccc; | |
731 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); | 497 | int ret; |
732 | 498 | ||
733 | GNUNET_log_setup (test_name, "WARNING", NULL ); | 499 | ret = GNUNET_TRANSPORT_TESTING_main (2, |
734 | 500 | &GNUNET_TRANSPORT_TESTING_connect_check, | |
735 | test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__); | 501 | ccc); |
736 | test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], | 502 | if (77 == ret) |
737 | test_source); | 503 | return 77; |
738 | 504 | if (GNUNET_OK != ret) | |
739 | tth = GNUNET_TRANSPORT_TESTING_init (); | 505 | return 1; |
740 | 506 | return 0; | |
741 | cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 1); | ||
742 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Using cfg [%u] : %s \n", 1, cfg_file_p1); | ||
743 | cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 2); | ||
744 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Using cfg [%u] : %s \n", 2, cfg_file_p2); | ||
745 | |||
746 | GNUNET_PROGRAM_run ((sizeof(argv_new) / sizeof(char *)) - 1, argv_new, | ||
747 | test_name, "nohelp", options, &run, NULL ); | ||
748 | |||
749 | GNUNET_free(cfg_file_p1); | ||
750 | GNUNET_free(cfg_file_p2); | ||
751 | |||
752 | GNUNET_free(test_source); | ||
753 | GNUNET_free(test_plugin); | ||
754 | GNUNET_free(test_name); | ||
755 | |||
756 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
757 | |||
758 | return res; | ||
759 | } | 507 | } |
760 | |||
761 | /* end of test_transport_address_switch.c */ | 508 | /* end of test_transport_address_switch.c */ |
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c index 770c5a22f..070a4124c 100644 --- a/src/transport/test_transport_api_disconnect.c +++ b/src/transport/test_transport_api_disconnect.c | |||
@@ -21,7 +21,9 @@ | |||
21 | * @file transport/test_transport_api_disconnect.c | 21 | * @file transport/test_transport_api_disconnect.c |
22 | * @brief base test case for transport implementations | 22 | * @brief base test case for transport implementations |
23 | * | 23 | * |
24 | * This test case tests disconnect notifications in peer shutdown | 24 | * This test case tests disconnect notifications in peer shutdown. |
25 | * Starts two peers, has them connect, sends a message in between, | ||
26 | * stops one peer, expects the others to send a disconnect notification. | ||
25 | */ | 27 | */ |
26 | #include "platform.h" | 28 | #include "platform.h" |
27 | #include "gnunet_transport_service.h" | 29 | #include "gnunet_transport_service.h" |
diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c index 2f36e080a..2d06bf668 100644 --- a/src/transport/test_transport_testing_restart.c +++ b/src/transport/test_transport_testing_restart.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2016 GNUnet e.V. |
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 |
@@ -21,52 +21,48 @@ | |||
21 | * @file transport/test_transport_testing_restart.c | 21 | * @file transport/test_transport_testing_restart.c |
22 | * @brief test case for transport testing library: | 22 | * @brief test case for transport testing library: |
23 | * start the peer, get the HELLO message, restart and stop the peer | 23 | * start the peer, get the HELLO message, restart and stop the peer |
24 | * | ||
25 | */ | 24 | */ |
26 | #include "platform.h" | 25 | #include "platform.h" |
27 | #include "gnunet_transport_service.h" | 26 | #include "gnunet_transport_service.h" |
28 | #include "transport-testing.h" | 27 | #include "transport-testing.h" |
29 | 28 | ||
30 | /** | ||
31 | * How long until we give up on transmitting the message? | ||
32 | */ | ||
33 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 29 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
34 | 30 | ||
35 | struct GNUNET_SCHEDULER_Task * timeout_task; | 31 | |
32 | static struct GNUNET_SCHEDULER_Task *timeout_task; | ||
36 | 33 | ||
37 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p; | 34 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p; |
38 | 35 | ||
39 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; | 36 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; |
37 | |||
38 | static int ret; | ||
40 | 39 | ||
41 | static int ret = 0; | ||
42 | 40 | ||
43 | static void | 41 | static void |
44 | end () | 42 | end () |
45 | { | 43 | { |
46 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | 44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
47 | 45 | "Stopping peers\n"); | |
48 | if (timeout_task != NULL) | 46 | if (NULL != timeout_task) |
49 | GNUNET_SCHEDULER_cancel (timeout_task); | 47 | GNUNET_SCHEDULER_cancel (timeout_task); |
50 | 48 | if (NULL != p) | |
51 | GNUNET_TRANSPORT_TESTING_stop_peer (p); | 49 | GNUNET_TRANSPORT_TESTING_stop_peer (p); |
52 | GNUNET_TRANSPORT_TESTING_done (tth); | 50 | if (NULL != tth) |
51 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
53 | } | 52 | } |
54 | 53 | ||
54 | |||
55 | static void | 55 | static void |
56 | end_badly () | 56 | end_badly () |
57 | { | 57 | { |
58 | timeout_task = NULL; | 58 | timeout_task = NULL; |
59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 59 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
60 | 60 | "Timeout!\n"); | |
61 | if (NULL != p) | 61 | end (); |
62 | GNUNET_TRANSPORT_TESTING_stop_peer (p); | ||
63 | |||
64 | if (NULL != tth) | ||
65 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
66 | |||
67 | ret = GNUNET_SYSERR; | 62 | ret = GNUNET_SYSERR; |
68 | } | 63 | } |
69 | 64 | ||
65 | |||
70 | static void | 66 | static void |
71 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 67 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
72 | void *cls) | 68 | void *cls) |
@@ -76,7 +72,7 @@ restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | |||
76 | p->no, | 72 | p->no, |
77 | GNUNET_i2s (&p->id)); | 73 | GNUNET_i2s (&p->id)); |
78 | ret = 0; | 74 | ret = 0; |
79 | GNUNET_SCHEDULER_add_now (&end, NULL); | 75 | end (); |
80 | } | 76 | } |
81 | 77 | ||
82 | 78 | ||
@@ -84,7 +80,7 @@ static void | |||
84 | restart_task () | 80 | restart_task () |
85 | { | 81 | { |
86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
87 | "Peer %u (`%s') restarting, \n", | 83 | "Peer %u (`%s') restarting\n", |
88 | p->no, | 84 | p->no, |
89 | GNUNET_i2s (&p->id)); | 85 | GNUNET_i2s (&p->id)); |
90 | GNUNET_TRANSPORT_TESTING_restart_peer (p, | 86 | GNUNET_TRANSPORT_TESTING_restart_peer (p, |
@@ -94,26 +90,30 @@ restart_task () | |||
94 | 90 | ||
95 | 91 | ||
96 | static void | 92 | static void |
97 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | 93 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
94 | void *cls) | ||
98 | { | 95 | { |
99 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') successfully started\n", | 96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
97 | "Peer %u (`%s') successfully started\n", | ||
100 | p->no, | 98 | p->no, |
101 | GNUNET_i2s (&p->id)); | 99 | GNUNET_i2s (&p->id)); |
102 | 100 | GNUNET_SCHEDULER_add_now (&restart_task, | |
103 | GNUNET_SCHEDULER_add_now (&restart_task, NULL); | 101 | NULL); |
104 | } | 102 | } |
105 | 103 | ||
106 | 104 | ||
107 | static void | 105 | static void |
108 | run (void *cls, char *const *args, const char *cfgfile, | 106 | run (void *cls, |
107 | char *const *args, | ||
108 | const char *cfgfile, | ||
109 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 109 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
110 | { | 110 | { |
111 | ret = 1; | 111 | ret = 1; |
112 | tth = GNUNET_TRANSPORT_TESTING_init (); | 112 | tth = GNUNET_TRANSPORT_TESTING_init (); |
113 | GNUNET_assert (NULL != tth); | 113 | GNUNET_assert (NULL != tth); |
114 | 114 | ||
115 | timeout_task = | 115 | timeout_task |
116 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 116 | = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
117 | &end_badly, | 117 | &end_badly, |
118 | NULL); | 118 | NULL); |
119 | p = GNUNET_TRANSPORT_TESTING_start_peer(tth, | 119 | p = GNUNET_TRANSPORT_TESTING_start_peer(tth, |
@@ -126,33 +126,37 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
126 | NULL); /* closure */ | 126 | NULL); /* closure */ |
127 | if (NULL == p) | 127 | if (NULL == p) |
128 | { | 128 | { |
129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); | 129 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
130 | if (timeout_task != NULL) | 130 | "Failed to start peer\n"); |
131 | GNUNET_SCHEDULER_cancel (timeout_task); | 131 | end (); |
132 | timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 132 | ret = 1; |
133 | } | 133 | } |
134 | } | 134 | } |
135 | 135 | ||
136 | |||
136 | int | 137 | int |
137 | main (int argc, char *argv[]) | 138 | main (int argc, |
139 | char *argv[]) | ||
138 | { | 140 | { |
139 | GNUNET_log_setup ("test_transport_testing_restart", | ||
140 | "WARNING", | ||
141 | NULL); | ||
142 | |||
143 | char *const argv_1[] = { "test_transport_testing_restart", | 141 | char *const argv_1[] = { "test_transport_testing_restart", |
144 | "-c", | 142 | "-c", |
145 | "test_transport_api_data.conf", | 143 | "test_transport_api_data.conf", |
146 | NULL | 144 | NULL |
147 | }; | 145 | }; |
148 | |||
149 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 146 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
150 | GNUNET_GETOPT_OPTION_END | 147 | GNUNET_GETOPT_OPTION_END |
151 | }; | 148 | }; |
152 | 149 | ||
153 | GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1, | 150 | GNUNET_log_setup ("test_transport_testing_restart", |
154 | "test_transport_testing_restart", "nohelp", options, &run, &ret); | 151 | "WARNING", |
155 | 152 | NULL); | |
153 | GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, | ||
154 | argv_1, | ||
155 | "test_transport_testing_restart", | ||
156 | "nohelp", | ||
157 | options, | ||
158 | &run, | ||
159 | NULL); | ||
156 | return ret; | 160 | return ret; |
157 | } | 161 | } |
158 | 162 | ||
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c index 6263f4d18..c516d4277 100644 --- a/src/transport/test_transport_testing_startstop.c +++ b/src/transport/test_transport_testing_startstop.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2016 GNUnet e.V. |
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 |
@@ -21,67 +21,65 @@ | |||
21 | * @file transport/test_transport_testing_startstop.c | 21 | * @file transport/test_transport_testing_startstop.c |
22 | * @brief test case for transport testing library: | 22 | * @brief test case for transport testing library: |
23 | * start the peer, get the HELLO message and stop the peer | 23 | * start the peer, get the HELLO message and stop the peer |
24 | * | ||
25 | */ | 24 | */ |
26 | #include "platform.h" | 25 | #include "platform.h" |
27 | #include "gnunet_transport_service.h" | 26 | #include "gnunet_transport_service.h" |
28 | #include "transport-testing.h" | 27 | #include "transport-testing.h" |
29 | 28 | ||
30 | /** | ||
31 | * How long until we give up on transmitting the message? | ||
32 | */ | ||
33 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 29 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
34 | 30 | ||
35 | struct GNUNET_SCHEDULER_Task * timeout_task; | 31 | |
32 | static struct GNUNET_SCHEDULER_Task *timeout_task; | ||
36 | 33 | ||
37 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p; | 34 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p; |
38 | 35 | ||
39 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; | 36 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; |
37 | |||
38 | static int ret; | ||
40 | 39 | ||
41 | static int ret = 0; | ||
42 | 40 | ||
43 | static void | 41 | static void |
44 | end () | 42 | end () |
45 | { | 43 | { |
46 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | 44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
47 | 45 | "Stopping peers\n"); | |
48 | if (timeout_task != NULL) | 46 | if (NULL != timeout_task) |
49 | GNUNET_SCHEDULER_cancel (timeout_task); | 47 | GNUNET_SCHEDULER_cancel (timeout_task); |
50 | 48 | if (NULL != p) | |
51 | GNUNET_TRANSPORT_TESTING_stop_peer (p); | 49 | GNUNET_TRANSPORT_TESTING_stop_peer (p); |
52 | GNUNET_TRANSPORT_TESTING_done (tth); | 50 | if (NULL != tth) |
51 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
53 | } | 52 | } |
54 | 53 | ||
54 | |||
55 | static void | 55 | static void |
56 | end_badly () | 56 | end_badly () |
57 | { | 57 | { |
58 | timeout_task = NULL; | 58 | timeout_task = NULL; |
59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 59 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
60 | 60 | "Timeout!\n"); | |
61 | if (NULL != p) | 61 | end (); |
62 | GNUNET_TRANSPORT_TESTING_stop_peer (p); | ||
63 | |||
64 | if (NULL != tth) | ||
65 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
66 | |||
67 | ret = GNUNET_SYSERR; | 62 | ret = GNUNET_SYSERR; |
68 | } | 63 | } |
69 | 64 | ||
70 | 65 | ||
71 | static void | 66 | static void |
72 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | 67 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
68 | void *cls) | ||
73 | { | 69 | { |
74 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') successfully started\n", | 70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
71 | "Peer %u (`%s') successfully started\n", | ||
75 | p->no, | 72 | p->no, |
76 | GNUNET_i2s (&p->id)); | 73 | GNUNET_i2s (&p->id)); |
77 | |||
78 | ret = 0; | 74 | ret = 0; |
79 | GNUNET_SCHEDULER_add_now (&end, NULL); | 75 | end (); |
80 | } | 76 | } |
81 | 77 | ||
82 | 78 | ||
83 | static void | 79 | static void |
84 | run (void *cls, char *const *args, const char *cfgfile, | 80 | run (void *cls, |
81 | char *const *args, | ||
82 | const char *cfgfile, | ||
85 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 83 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
86 | { | 84 | { |
87 | ret = 1; | 85 | ret = 1; |
@@ -110,25 +108,28 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
110 | } | 108 | } |
111 | } | 109 | } |
112 | 110 | ||
111 | |||
113 | int | 112 | int |
114 | main (int argc, char *argv[]) | 113 | main (int argc, char *argv[]) |
115 | { | 114 | { |
116 | GNUNET_log_setup ("test_transport_testing_startstop", | ||
117 | "WARNING", | ||
118 | NULL); | ||
119 | |||
120 | char *const argv_1[] = { "test_transport_testing", | 115 | char *const argv_1[] = { "test_transport_testing", |
121 | "-c", | 116 | "-c", |
122 | "test_transport_api_data.conf", | 117 | "test_transport_api_data.conf", |
123 | NULL | 118 | NULL |
124 | }; | 119 | }; |
125 | |||
126 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 120 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
127 | GNUNET_GETOPT_OPTION_END | 121 | GNUNET_GETOPT_OPTION_END |
128 | }; | 122 | }; |
129 | 123 | ||
130 | GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1, | 124 | GNUNET_log_setup ("test_transport_testing_startstop", |
131 | "test_transport_testing_startstop", "nohelp", options, &run, &ret); | 125 | "WARNING", |
126 | NULL); | ||
127 | GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, | ||
128 | argv_1, | ||
129 | "test_transport_testing_startstop", "nohelp", | ||
130 | options, | ||
131 | &run, | ||
132 | &ret); | ||
132 | 133 | ||
133 | return ret; | 134 | return ret; |
134 | } | 135 | } |
diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c index 0b3840296..b8dbb9c03 100644 --- a/src/transport/transport-testing-main.c +++ b/src/transport/transport-testing-main.c | |||
@@ -113,7 +113,8 @@ do_timeout (void *cls) | |||
113 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | 113 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; |
114 | 114 | ||
115 | ccc->timeout_task = NULL; | 115 | ccc->timeout_task = NULL; |
116 | GNUNET_break (0); /* signal timeout */ | 116 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
117 | "Testcase timed out\n"); | ||
117 | ccc->global_ret = GNUNET_SYSERR; | 118 | ccc->global_ret = GNUNET_SYSERR; |
118 | GNUNET_SCHEDULER_shutdown (); | 119 | GNUNET_SCHEDULER_shutdown (); |
119 | } | 120 | } |
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index a2f91d761..95f4eb671 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c | |||
@@ -637,6 +637,8 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth) | |||
637 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p; | 637 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p; |
638 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t; | 638 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t; |
639 | 639 | ||
640 | if (NULL == tth) | ||
641 | return; | ||
640 | cc = tth->cc_head; | 642 | cc = tth->cc_head; |
641 | while (NULL != cc) | 643 | while (NULL != cc) |
642 | { | 644 | { |