diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-10 18:16:17 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-10 18:16:17 +0000 |
commit | 6bfa05291c469d0aba00e85456ceadf8b433601c (patch) | |
tree | 2d8d1a29d1d254ed934b3a03764f56a4ed1931b4 /src/transport/test_transport_api_reliability.c | |
parent | 64cf4ccedaffc379b253e9c08594ef520957a09f (diff) | |
download | gnunet-6bfa05291c469d0aba00e85456ceadf8b433601c.tar.gz gnunet-6bfa05291c469d0aba00e85456ceadf8b433601c.zip |
adapt test_transport_api_reliability to new testing API
Diffstat (limited to 'src/transport/test_transport_api_reliability.c')
-rw-r--r-- | src/transport/test_transport_api_reliability.c | 469 |
1 files changed, 120 insertions, 349 deletions
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 94865f438..e1ce4da18 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.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 |
@@ -61,70 +61,24 @@ | |||
61 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60 * FACTOR) | 61 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60 * FACTOR) |
62 | 62 | ||
63 | 63 | ||
64 | GNUNET_NETWORK_STRUCT_BEGIN | ||
65 | |||
64 | /** | 66 | /** |
65 | * Struct for the test message | 67 | * Struct for the test message |
66 | */ | 68 | */ |
67 | GNUNET_NETWORK_STRUCT_BEGIN | ||
68 | |||
69 | struct TestMessage | 69 | struct TestMessage |
70 | { | 70 | { |
71 | struct GNUNET_MessageHeader header; | 71 | struct GNUNET_MessageHeader header; |
72 | uint32_t num; | 72 | uint32_t num GNUNET_PACKED; |
73 | }; | 73 | }; |
74 | GNUNET_NETWORK_STRUCT_END | 74 | GNUNET_NETWORK_STRUCT_END |
75 | 75 | ||
76 | 76 | ||
77 | /** | 77 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
78 | * Name of the plugin to test | ||
79 | */ | ||
80 | static char *test_plugin; | ||
81 | 78 | ||
82 | /** | ||
83 | * Name of the test | ||
84 | */ | ||
85 | static char *test_name; | ||
86 | |||
87 | /** | ||
88 | * Return value of the test | ||
89 | */ | ||
90 | static int ok; | ||
91 | |||
92 | /** | ||
93 | * Context of peer 1 | ||
94 | */ | ||
95 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | ||
96 | |||
97 | /** | ||
98 | * Configuration file of peer 1 | ||
99 | */ | ||
100 | static char *cfg_file_p1; | ||
101 | |||
102 | /** | ||
103 | * Context of peer 2 | ||
104 | */ | ||
105 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
106 | |||
107 | /** | ||
108 | * Configuration file of peer 1 | ||
109 | */ | ||
110 | static char *cfg_file_p2; | ||
111 | |||
112 | /** | ||
113 | * Timeout task | ||
114 | */ | ||
115 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
116 | |||
117 | /** | ||
118 | * Transport transmit handle used | ||
119 | */ | ||
120 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | 79 | static struct GNUNET_TRANSPORT_TransmitHandle *th; |
121 | 80 | ||
122 | /** | 81 | /** |
123 | * Transport testing handle | ||
124 | */ | ||
125 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; | ||
126 | |||
127 | /* | ||
128 | * Total amount of bytes sent | 82 | * Total amount of bytes sent |
129 | */ | 83 | */ |
130 | static unsigned long long total_bytes; | 84 | static unsigned long long total_bytes; |
@@ -149,142 +103,11 @@ static int msg_sent; | |||
149 | */ | 103 | */ |
150 | static int msg_recv; | 104 | static int msg_recv; |
151 | 105 | ||
152 | static int test_connected; | ||
153 | |||
154 | static int test_sending; | ||
155 | |||
156 | static int test_send_timeout; | ||
157 | |||
158 | |||
159 | /** | 106 | /** |
160 | * Bitmap storing which messages were received | 107 | * Bitmap storing which messages were received |
161 | */ | 108 | */ |
162 | static char bitmap[TOTAL_MSGS / 8]; | 109 | static char bitmap[TOTAL_MSGS / 8]; |
163 | 110 | ||
164 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; | ||
165 | |||
166 | /* | ||
167 | * END Testcase specific declarations | ||
168 | */ | ||
169 | |||
170 | #if VERBOSE | ||
171 | #define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | ||
172 | #else | ||
173 | #define OKPP do { ok++; } while (0) | ||
174 | #endif | ||
175 | |||
176 | |||
177 | static int | ||
178 | get_bit (const char *map, unsigned int bit); | ||
179 | |||
180 | |||
181 | static void | ||
182 | end () | ||
183 | { | ||
184 | unsigned long long delta; | ||
185 | unsigned long long rate; | ||
186 | char *value_name; | ||
187 | unsigned int i; | ||
188 | |||
189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
190 | "Stopping peers\n"); | ||
191 | |||
192 | /* Calculcate statistics */ | ||
193 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; | ||
194 | rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); | ||
195 | FPRINTF (stderr, | ||
196 | "\nThroughput was %llu KiBytes/s\n", | ||
197 | rate); | ||
198 | |||
199 | GNUNET_asprintf (&value_name, | ||
200 | "unreliable_%s", | ||
201 | test_plugin); | ||
202 | GAUGER ("TRANSPORT", | ||
203 | value_name, | ||
204 | (int) rate, | ||
205 | "kb/s"); | ||
206 | GNUNET_free (value_name); | ||
207 | |||
208 | if (die_task != NULL) | ||
209 | GNUNET_SCHEDULER_cancel (die_task); | ||
210 | |||
211 | if (th != NULL) | ||
212 | { | ||
213 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
214 | th = NULL; | ||
215 | } | ||
216 | if (cc != NULL) | ||
217 | { | ||
218 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
219 | cc = NULL; | ||
220 | } | ||
221 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
222 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
223 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
224 | ok = 0; | ||
225 | for (i = 0; i < TOTAL_MSGS; i++) | ||
226 | { | ||
227 | if (get_bit (bitmap, i) == 0) | ||
228 | { | ||
229 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
230 | "Did not receive message %d\n", | ||
231 | i); | ||
232 | ok = -1; | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
237 | |||
238 | static void | ||
239 | end_badly () | ||
240 | { | ||
241 | unsigned int i; | ||
242 | |||
243 | die_task = NULL; | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
245 | "Fail! Stopping peers\n"); | ||
246 | if (test_connected == GNUNET_YES) | ||
247 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
248 | "Peers got connected\n"); | ||
249 | else | ||
250 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
251 | "Peers got NOT connected\n"); | ||
252 | |||
253 | if (test_sending == GNUNET_NO) | ||
254 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
255 | "Testcase did not send any messages before timeout\n"); | ||
256 | if (test_send_timeout == GNUNET_YES) | ||
257 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
258 | "Test had timeout while waiting to send data\n"); | ||
259 | for (i = 0; i < TOTAL_MSGS; i++) | ||
260 | { | ||
261 | if (get_bit (bitmap, i) == 0) | ||
262 | { | ||
263 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
264 | "Did not receive message %u\n", | ||
265 | i); | ||
266 | ok = -1; | ||
267 | } | ||
268 | } | ||
269 | |||
270 | if (th != NULL) | ||
271 | { | ||
272 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
273 | th = NULL; | ||
274 | } | ||
275 | if (cc != NULL) | ||
276 | { | ||
277 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
278 | cc = NULL; | ||
279 | } | ||
280 | if (p1 != NULL) | ||
281 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
282 | if (p2 != NULL) | ||
283 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
284 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
285 | ok = GNUNET_SYSERR; | ||
286 | } | ||
287 | |||
288 | 111 | ||
289 | static unsigned int | 112 | static unsigned int |
290 | get_size (unsigned int iter) | 113 | get_size (unsigned int iter) |
@@ -335,10 +158,11 @@ set_bit (unsigned int bitIdx) | |||
335 | * @param map the bitmap | 158 | * @param map the bitmap |
336 | * @param bit index from bitmap | 159 | * @param bit index from bitmap |
337 | * | 160 | * |
338 | * @return Bit \a bit from hashcode \a code | 161 | * @return Bit @a bit from @a map |
339 | */ | 162 | */ |
340 | static int | 163 | static int |
341 | get_bit (const char *map, unsigned int bit) | 164 | get_bit (const char *map, |
165 | unsigned int bit) | ||
342 | { | 166 | { |
343 | if (bit > TOTAL_MSGS) | 167 | if (bit > TOTAL_MSGS) |
344 | { | 168 | { |
@@ -353,7 +177,56 @@ get_bit (const char *map, unsigned int bit) | |||
353 | 177 | ||
354 | 178 | ||
355 | static void | 179 | static void |
356 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 180 | custom_shutdown (void *cls) |
181 | { | ||
182 | unsigned long long delta; | ||
183 | unsigned long long rate; | ||
184 | unsigned int i; | ||
185 | int ok; | ||
186 | |||
187 | if (NULL != th) | ||
188 | { | ||
189 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
190 | th = NULL; | ||
191 | } | ||
192 | /* Calculcate statistics */ | ||
193 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; | ||
194 | rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); | ||
195 | FPRINTF (stderr, | ||
196 | "\nThroughput was %llu KiBytes/s\n", | ||
197 | rate); | ||
198 | { | ||
199 | char *value_name; | ||
200 | GNUNET_asprintf (&value_name, | ||
201 | "unreliable_%s", | ||
202 | ccc->test_plugin); | ||
203 | GAUGER ("TRANSPORT", | ||
204 | value_name, | ||
205 | (int) rate, | ||
206 | "kb/s"); | ||
207 | GNUNET_free (value_name); | ||
208 | } | ||
209 | |||
210 | ok = 0; | ||
211 | for (i = 0; i < TOTAL_MSGS; i++) | ||
212 | { | ||
213 | if (get_bit (bitmap, i) == 0) | ||
214 | { | ||
215 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
216 | "Did not receive message %d\n", | ||
217 | i); | ||
218 | ok = -1; | ||
219 | } | ||
220 | } | ||
221 | if (0 != ok) | ||
222 | ccc->global_ret = GNUNET_SYSERR; /* fail: messages missing! */ | ||
223 | } | ||
224 | |||
225 | |||
226 | static void | ||
227 | notify_receive (void *cls, | ||
228 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | ||
229 | const struct GNUNET_PeerIdentity *sender, | ||
357 | const struct GNUNET_MessageHeader *message) | 230 | const struct GNUNET_MessageHeader *message) |
358 | { | 231 | { |
359 | static int n; | 232 | static int n; |
@@ -373,11 +246,12 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
373 | { | 246 | { |
374 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 247 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
375 | "Expected message %u of size %u, got %u bytes of message %u\n", | 248 | "Expected message %u of size %u, got %u bytes of message %u\n", |
376 | ntohl (hdr->num), s, ntohs (message->size), ntohl (hdr->num)); | 249 | ntohl (hdr->num), |
377 | if (NULL != die_task) | 250 | s, |
378 | GNUNET_SCHEDULER_cancel (die_task); | 251 | ntohs (message->size), |
379 | test_sending = GNUNET_YES; | 252 | ntohl (hdr->num)); |
380 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 253 | ccc->global_ret = GNUNET_SYSERR; |
254 | GNUNET_SCHEDULER_shutdown (); | ||
381 | return; | 255 | return; |
382 | } | 256 | } |
383 | 257 | ||
@@ -386,11 +260,10 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
386 | { | 260 | { |
387 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 261 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
388 | "Expected message %u with bits %u, but body did not match\n", | 262 | "Expected message %u with bits %u, but body did not match\n", |
389 | ntohl (hdr->num), (unsigned char) n); | 263 | ntohl (hdr->num), |
390 | if (NULL != die_task) | 264 | (unsigned char) n); |
391 | GNUNET_SCHEDULER_cancel (die_task); | 265 | ccc->global_ret = GNUNET_SYSERR; |
392 | test_sending = GNUNET_YES; | 266 | GNUNET_SCHEDULER_shutdown (); |
393 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
394 | return; | 267 | return; |
395 | } | 268 | } |
396 | #if VERBOSE | 269 | #if VERBOSE |
@@ -410,23 +283,22 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
410 | ntohl (hdr->num), | 283 | ntohl (hdr->num), |
411 | TOTAL_MSGS); | 284 | TOTAL_MSGS); |
412 | } | 285 | } |
413 | test_sending = GNUNET_YES; | ||
414 | if (0 == (n % (TOTAL_MSGS / 100))) | 286 | if (0 == (n % (TOTAL_MSGS / 100))) |
415 | { | 287 | { |
416 | FPRINTF (stderr, "%s", "."); | 288 | FPRINTF (stderr, "%s", "."); |
417 | if (NULL != die_task) | ||
418 | GNUNET_SCHEDULER_cancel (die_task); | ||
419 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
420 | } | 289 | } |
421 | if (n == TOTAL_MSGS) | 290 | if (n == TOTAL_MSGS) |
422 | { | 291 | { |
423 | end (); | 292 | /* end testcase with success */ |
293 | GNUNET_SCHEDULER_shutdown (); | ||
424 | } | 294 | } |
425 | } | 295 | } |
426 | 296 | ||
427 | 297 | ||
428 | static size_t | 298 | static size_t |
429 | notify_ready (void *cls, size_t size, void *buf) | 299 | notify_ready (void *cls, |
300 | size_t size, | ||
301 | void *buf) | ||
430 | { | 302 | { |
431 | static int n; | 303 | static int n; |
432 | char *cbuf = buf; | 304 | char *cbuf = buf; |
@@ -435,17 +307,14 @@ notify_ready (void *cls, size_t size, void *buf) | |||
435 | unsigned int ret; | 307 | unsigned int ret; |
436 | 308 | ||
437 | th = NULL; | 309 | th = NULL; |
438 | 310 | if (NULL == buf) | |
439 | if (buf == NULL) | ||
440 | { | 311 | { |
441 | test_send_timeout = GNUNET_YES; | ||
442 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 312 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
443 | "Timeout occurred while waiting for transmit_ready for msg %u of %u\n", | 313 | "Timeout occurred while waiting for transmit_ready for msg %u of %u\n", |
444 | msg_scheduled, TOTAL_MSGS); | 314 | msg_scheduled, |
445 | if (NULL != die_task) | 315 | TOTAL_MSGS); |
446 | GNUNET_SCHEDULER_cancel (die_task); | 316 | GNUNET_SCHEDULER_shutdown (); |
447 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 317 | ccc->global_ret = 42; |
448 | ok = 42; | ||
449 | return 0; | 318 | return 0; |
450 | } | 319 | } |
451 | ret = 0; | 320 | ret = 0; |
@@ -467,7 +336,7 @@ notify_ready (void *cls, size_t size, void *buf) | |||
467 | ret += s - sizeof (struct TestMessage); | 336 | ret += s - sizeof (struct TestMessage); |
468 | 337 | ||
469 | #if VERBOSE | 338 | #if VERBOSE |
470 | if (n % 5000 == 0) | 339 | if (0 == n % 5000) |
471 | { | 340 | { |
472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
473 | "Sending message %u of size %u\n", | 342 | "Sending message %u of size %u\n", |
@@ -483,24 +352,27 @@ notify_ready (void *cls, size_t size, void *buf) | |||
483 | while ((size - ret >= s) && (n < TOTAL_MSGS)); | 352 | while ((size - ret >= s) && (n < TOTAL_MSGS)); |
484 | if (n < TOTAL_MSGS) | 353 | if (n < TOTAL_MSGS) |
485 | { | 354 | { |
486 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, | 355 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, |
356 | &ccc->p[0]->id, | ||
357 | s, | ||
487 | TIMEOUT_TRANSMIT, | 358 | TIMEOUT_TRANSMIT, |
488 | ¬ify_ready, NULL); | 359 | ¬ify_ready, |
360 | NULL); | ||
489 | msg_scheduled = n; | 361 | msg_scheduled = n; |
490 | } | 362 | } |
491 | else | 363 | else |
492 | { | 364 | { |
493 | FPRINTF (stderr, "%s", "\n"); | 365 | FPRINTF (stderr, |
366 | "%s", | ||
367 | "\n"); | ||
494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
495 | "All messages scheduled to be sent\n"); | 369 | "All messages scheduled to be sent\n"); |
496 | if (NULL != die_task) | ||
497 | GNUNET_SCHEDULER_cancel (die_task); | ||
498 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
499 | } | 370 | } |
500 | if (n % 5000 == 0) | 371 | if (0 == n % 5000) |
501 | { | 372 | { |
502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
503 | "Returning total message block of size %u\n", ret); | 374 | "Returning total message block of size %u\n", |
375 | ret); | ||
504 | } | 376 | } |
505 | total_bytes += ret; | 377 | total_bytes += ret; |
506 | return ret; | 378 | return ret; |
@@ -508,103 +380,33 @@ notify_ready (void *cls, size_t size, void *buf) | |||
508 | 380 | ||
509 | 381 | ||
510 | static void | 382 | static void |
511 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
512 | { | ||
513 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
514 | "Peer `%4s' connected to us (%p)!\n", | ||
515 | GNUNET_i2s (peer), cls); | ||
516 | } | ||
517 | |||
518 | |||
519 | static void | ||
520 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
521 | { | ||
522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
523 | "Peer `%4s' disconnected (%p)!\n", | ||
524 | GNUNET_i2s (peer), cls); | ||
525 | if (th != NULL) | ||
526 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
527 | th = NULL; | ||
528 | } | ||
529 | |||
530 | |||
531 | static void | ||
532 | sendtask (void *cls) | 383 | sendtask (void *cls) |
533 | { | 384 | { |
534 | start_time = GNUNET_TIME_absolute_get (); | 385 | start_time = GNUNET_TIME_absolute_get (); |
535 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
536 | "Starting to send %u messages\n", | 387 | "Starting to send %u messages\n", |
537 | TOTAL_MSGS); | 388 | TOTAL_MSGS); |
538 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), | 389 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, |
539 | TIMEOUT_TRANSMIT, ¬ify_ready, | 390 | &ccc->p[0]->id, |
540 | NULL); | 391 | get_size (0), |
541 | } | 392 | TIMEOUT_TRANSMIT, |
542 | 393 | ¬ify_ready, | |
543 | |||
544 | static void | ||
545 | testing_connect_cb (void *cls) | ||
546 | { | ||
547 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
548 | |||
549 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
550 | "Peers connected: %s <-> %s\n", | ||
551 | p1_c, | ||
552 | GNUNET_i2s (&p2->id)); | ||
553 | GNUNET_free (p1_c); | ||
554 | |||
555 | test_connected = GNUNET_YES; | ||
556 | cc = NULL; | ||
557 | |||
558 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
559 | } | ||
560 | |||
561 | |||
562 | static void | ||
563 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | ||
564 | { | ||
565 | static int started; | ||
566 | started++; | ||
567 | |||
568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
569 | "Peer %u (`%s') started\n", | ||
570 | p->no, | ||
571 | GNUNET_i2s (&p->id)); | ||
572 | |||
573 | if (started != 2) | ||
574 | return; | ||
575 | |||
576 | test_connected = GNUNET_NO; | ||
577 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, | ||
578 | NULL); | 394 | NULL); |
579 | |||
580 | } | 395 | } |
581 | 396 | ||
582 | 397 | ||
583 | static void | 398 | static void |
584 | run (void *cls, | 399 | notify_disconnect (void *cls, |
585 | char *const *args, | 400 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
586 | const char *cfgfile, | 401 | const struct GNUNET_PeerIdentity *other) |
587 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
588 | { | 402 | { |
589 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 403 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, |
590 | &end_badly, NULL); | 404 | me, |
591 | test_send_timeout = GNUNET_NO; | 405 | other); |
592 | 406 | if (NULL != th) | |
593 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, | ||
594 | ¬ify_receive, ¬ify_connect, | ||
595 | ¬ify_disconnect, &start_cb, | ||
596 | NULL); | ||
597 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, | ||
598 | ¬ify_receive, ¬ify_connect, | ||
599 | ¬ify_disconnect, &start_cb, | ||
600 | NULL); | ||
601 | if ((p1 == NULL) || (p2 == NULL)) | ||
602 | { | 407 | { |
603 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | 408 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
604 | if (die_task != NULL) | 409 | th = NULL; |
605 | GNUNET_SCHEDULER_cancel (die_task); | ||
606 | //die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
607 | return; | ||
608 | } | 410 | } |
609 | } | 411 | } |
610 | 412 | ||
@@ -612,55 +414,24 @@ run (void *cls, | |||
612 | int | 414 | int |
613 | main (int argc, char *argv[]) | 415 | main (int argc, char *argv[]) |
614 | { | 416 | { |
615 | char *test_source; | 417 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
616 | int ret; | 418 | .connect_continuation = &sendtask, |
617 | 419 | .config_file = "test_transport_api_data.conf", | |
618 | static char *const argv_new[] = { | 420 | .rec = ¬ify_receive, |
619 | "test-transport-api-reliability", | 421 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
620 | "-c", | 422 | .nd = ¬ify_disconnect, |
621 | "test_transport_api_data.conf", | 423 | .shutdown_task = &custom_shutdown, |
622 | NULL | 424 | .timeout = TIMEOUT |
623 | }; | ||
624 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
625 | GNUNET_GETOPT_OPTION_END | ||
626 | }; | 425 | }; |
627 | 426 | ||
628 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); | 427 | ccc = &my_ccc; |
629 | GNUNET_log_setup (test_name, | 428 | if (GNUNET_OK != |
630 | "WARNING", | 429 | GNUNET_TRANSPORT_TESTING_main (2, |
631 | NULL); | 430 | &GNUNET_TRANSPORT_TESTING_connect_check, |
632 | test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__); | 431 | ccc)) |
633 | test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], | 432 | return 1; |
634 | test_source); | 433 | return 0; |
635 | |||
636 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
637 | |||
638 | cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 1); | ||
639 | cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 2); | ||
640 | |||
641 | #if WRITECONFIG | ||
642 | setTransportOptions ("test_transport_api_data.conf"); | ||
643 | #endif | ||
644 | ok = GNUNET_SYSERR; | ||
645 | |||
646 | ret = GNUNET_PROGRAM_run ((sizeof (argv_new) / sizeof (char *)) - 1, | ||
647 | argv_new, test_name, | ||
648 | "nohelp", options, | ||
649 | &run, &ok); | ||
650 | if (GNUNET_SYSERR == ret) | ||
651 | { | ||
652 | fprintf (stderr, | ||
653 | "Test failed: %d\n", | ||
654 | ok); | ||
655 | ok = -1; | ||
656 | } | ||
657 | GNUNET_free (cfg_file_p1); | ||
658 | GNUNET_free (cfg_file_p2); | ||
659 | GNUNET_free (test_source); | ||
660 | GNUNET_free (test_plugin); | ||
661 | GNUNET_free (test_name); | ||
662 | |||
663 | return ok; | ||
664 | } | 434 | } |
665 | 435 | ||
436 | |||
666 | /* end of test_transport_api_reliability.c */ | 437 | /* end of test_transport_api_reliability.c */ |