diff options
Diffstat (limited to 'src/transport/test_transport_api_reliability.c')
-rw-r--r-- | src/transport/test_transport_api_reliability.c | 117 |
1 files changed, 73 insertions, 44 deletions
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 91ef81868..fcada3e88 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c | |||
@@ -154,7 +154,6 @@ static int test_send_timeout; | |||
154 | /** | 154 | /** |
155 | * Bitmap storing which messages were received | 155 | * Bitmap storing which messages were received |
156 | */ | 156 | */ |
157 | |||
158 | static char bitmap[TOTAL_MSGS / 8]; | 157 | static char bitmap[TOTAL_MSGS / 8]; |
159 | 158 | ||
160 | static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | 159 | static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; |
@@ -180,17 +179,24 @@ end () | |||
180 | unsigned long long delta; | 179 | unsigned long long delta; |
181 | unsigned long long rate; | 180 | unsigned long long rate; |
182 | char *value_name; | 181 | char *value_name; |
182 | unsigned int i; | ||
183 | 183 | ||
184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | 184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
185 | "Stopping peers\n"); | ||
185 | 186 | ||
186 | /* Calculcate statistics */ | 187 | /* Calculcate statistics */ |
187 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; | 188 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; |
188 | rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); | 189 | rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); |
189 | FPRINTF (stderr, "\nThroughput was %llu KiBytes/s\n", | 190 | FPRINTF (stderr, |
190 | rate); | 191 | "\nThroughput was %llu KiBytes/s\n", |
191 | 192 | rate); | |
192 | GNUNET_asprintf (&value_name, "unreliable_%s", test_plugin); | 193 | |
193 | GAUGER ("TRANSPORT", value_name, (int) rate, | 194 | GNUNET_asprintf (&value_name, |
195 | "unreliable_%s", | ||
196 | test_plugin); | ||
197 | GAUGER ("TRANSPORT", | ||
198 | value_name, | ||
199 | (int) rate, | ||
194 | "kb/s"); | 200 | "kb/s"); |
195 | GNUNET_free (value_name); | 201 | GNUNET_free (value_name); |
196 | 202 | ||
@@ -198,32 +204,32 @@ end () | |||
198 | GNUNET_SCHEDULER_cancel (die_task); | 204 | GNUNET_SCHEDULER_cancel (die_task); |
199 | 205 | ||
200 | if (th != NULL) | 206 | if (th != NULL) |
207 | { | ||
201 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 208 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
202 | th = NULL; | 209 | th = NULL; |
203 | 210 | } | |
204 | if (cc != NULL) | 211 | if (cc != NULL) |
212 | { | ||
205 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); | 213 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); |
206 | cc = NULL; | 214 | cc = NULL; |
207 | 215 | } | |
208 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | 216 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
209 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | 217 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); |
210 | |||
211 | GNUNET_TRANSPORT_TESTING_done (tth); | 218 | GNUNET_TRANSPORT_TESTING_done (tth); |
212 | |||
213 | ok = 0; | 219 | ok = 0; |
214 | |||
215 | int i; | ||
216 | |||
217 | for (i = 0; i < TOTAL_MSGS; i++) | 220 | for (i = 0; i < TOTAL_MSGS; i++) |
218 | { | 221 | { |
219 | if (get_bit (bitmap, i) == 0) | 222 | if (get_bit (bitmap, i) == 0) |
220 | { | 223 | { |
221 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i); | 224 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
225 | "Did not receive message %d\n", | ||
226 | i); | ||
222 | ok = -1; | 227 | ok = -1; |
223 | } | 228 | } |
224 | } | 229 | } |
225 | } | 230 | } |
226 | 231 | ||
232 | |||
227 | static void | 233 | static void |
228 | end_badly () | 234 | end_badly () |
229 | { | 235 | { |
@@ -257,13 +263,15 @@ end_badly () | |||
257 | } | 263 | } |
258 | 264 | ||
259 | if (th != NULL) | 265 | if (th != NULL) |
266 | { | ||
260 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 267 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
261 | th = NULL; | 268 | th = NULL; |
262 | 269 | } | |
263 | if (cc != NULL) | 270 | if (cc != NULL) |
271 | { | ||
264 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); | 272 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); |
265 | cc = NULL; | 273 | cc = NULL; |
266 | 274 | } | |
267 | if (p1 != NULL) | 275 | if (p1 != NULL) |
268 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | 276 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
269 | if (p2 != NULL) | 277 | if (p2 != NULL) |
@@ -294,7 +302,7 @@ get_size (unsigned int iter) | |||
294 | * Sets a bit active in the bitmap. | 302 | * Sets a bit active in the bitmap. |
295 | * | 303 | * |
296 | * @param bitIdx which bit to set | 304 | * @param bitIdx which bit to set |
297 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | 305 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
298 | */ | 306 | */ |
299 | static int | 307 | static int |
300 | set_bit (unsigned int bitIdx) | 308 | set_bit (unsigned int bitIdx) |
@@ -304,7 +312,8 @@ set_bit (unsigned int bitIdx) | |||
304 | 312 | ||
305 | if (bitIdx >= sizeof (bitmap) * 8) | 313 | if (bitIdx >= sizeof (bitmap) * 8) |
306 | { | 314 | { |
307 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "tried to set bit %d of %d(!?!?)\n", | 315 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
316 | "tried to set bit %d of %d(!?!?)\n", | ||
308 | bitIdx, sizeof (bitmap) * 8); | 317 | bitIdx, sizeof (bitmap) * 8); |
309 | return GNUNET_SYSERR; | 318 | return GNUNET_SYSERR; |
310 | } | 319 | } |
@@ -314,6 +323,7 @@ set_bit (unsigned int bitIdx) | |||
314 | return GNUNET_OK; | 323 | return GNUNET_OK; |
315 | } | 324 | } |
316 | 325 | ||
326 | |||
317 | /** | 327 | /** |
318 | * Obtain a bit from bitmap. | 328 | * Obtain a bit from bitmap. |
319 | * @param map the bitmap | 329 | * @param map the bitmap |
@@ -386,8 +396,9 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
386 | if (GNUNET_SYSERR == set_bit (ntohl (hdr->num))) | 396 | if (GNUNET_SYSERR == set_bit (ntohl (hdr->num))) |
387 | { | 397 | { |
388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 398 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
389 | _("Message id %u is bigger than maxmimum number of messages %u expected\n"), | 399 | "Message id %u is bigger than maxmimum number of messages %u expected\n", |
390 | ntohl (hdr->num), TOTAL_MSGS); | 400 | ntohl (hdr->num), |
401 | TOTAL_MSGS); | ||
391 | } | 402 | } |
392 | test_sending = GNUNET_YES; | 403 | test_sending = GNUNET_YES; |
393 | if (0 == (n % (TOTAL_MSGS / 100))) | 404 | if (0 == (n % (TOTAL_MSGS / 100))) |
@@ -448,7 +459,9 @@ notify_ready (void *cls, size_t size, void *buf) | |||
448 | #if VERBOSE | 459 | #if VERBOSE |
449 | if (n % 5000 == 0) | 460 | if (n % 5000 == 0) |
450 | { | 461 | { |
451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u\n", n, | 462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
463 | "Sending message %u of size %u\n", | ||
464 | n, | ||
452 | s); | 465 | s); |
453 | } | 466 | } |
454 | #endif | 467 | #endif |
@@ -468,7 +481,8 @@ notify_ready (void *cls, size_t size, void *buf) | |||
468 | else | 481 | else |
469 | { | 482 | { |
470 | FPRINTF (stderr, "%s", "\n"); | 483 | FPRINTF (stderr, "%s", "\n"); |
471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent\n"); | 484 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
485 | "All messages scheduled to be sent\n"); | ||
472 | if (NULL != die_task) | 486 | if (NULL != die_task) |
473 | GNUNET_SCHEDULER_cancel (die_task); | 487 | GNUNET_SCHEDULER_cancel (die_task); |
474 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 488 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
@@ -501,11 +515,13 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
501 | th = NULL; | 515 | th = NULL; |
502 | } | 516 | } |
503 | 517 | ||
518 | |||
504 | static void | 519 | static void |
505 | sendtask () | 520 | sendtask () |
506 | { | 521 | { |
507 | start_time = GNUNET_TIME_absolute_get (); | 522 | start_time = GNUNET_TIME_absolute_get (); |
508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to send %u messages\n", | 523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
524 | "Starting to send %u messages\n", | ||
509 | TOTAL_MSGS); | 525 | TOTAL_MSGS); |
510 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), | 526 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), |
511 | TIMEOUT_TRANSMIT, ¬ify_ready, | 527 | TIMEOUT_TRANSMIT, ¬ify_ready, |
@@ -517,7 +533,8 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | |||
517 | { | 533 | { |
518 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 534 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); |
519 | 535 | ||
520 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c, | 536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
537 | "Peers connected: %s <-> %s\n", p1_c, | ||
521 | GNUNET_i2s (&p2->id)); | 538 | GNUNET_i2s (&p2->id)); |
522 | GNUNET_free (p1_c); | 539 | GNUNET_free (p1_c); |
523 | 540 | ||
@@ -527,13 +544,16 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | |||
527 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); | 544 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); |
528 | } | 545 | } |
529 | 546 | ||
547 | |||
530 | static void | 548 | static void |
531 | start_cb (struct PeerContext *p, void *cls) | 549 | start_cb (struct PeerContext *p, void *cls) |
532 | { | 550 | { |
533 | static int started; | 551 | static int started; |
534 | started++; | 552 | started++; |
535 | 553 | ||
536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | 554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
555 | "Peer %u (`%s') started\n", | ||
556 | p->no, | ||
537 | GNUNET_i2s (&p->id)); | 557 | GNUNET_i2s (&p->id)); |
538 | 558 | ||
539 | if (started != 2) | 559 | if (started != 2) |
@@ -545,11 +565,15 @@ start_cb (struct PeerContext *p, void *cls) | |||
545 | 565 | ||
546 | } | 566 | } |
547 | 567 | ||
568 | |||
548 | static void | 569 | static void |
549 | run (void *cls, char *const *args, const char *cfgfile, | 570 | run (void *cls, |
571 | char *const *args, | ||
572 | const char *cfgfile, | ||
550 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 573 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
551 | { | 574 | { |
552 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 575 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
576 | &end_badly, NULL); | ||
553 | test_send_timeout = GNUNET_NO; | 577 | test_send_timeout = GNUNET_NO; |
554 | 578 | ||
555 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, | 579 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, |
@@ -577,7 +601,8 @@ main (int argc, char *argv[]) | |||
577 | char *test_source; | 601 | char *test_source; |
578 | int ret; | 602 | int ret; |
579 | 603 | ||
580 | static char *const argv_new[] = { "test-transport-api-reliability", | 604 | static char *const argv_new[] = { |
605 | "test-transport-api-reliability", | ||
581 | "-c", | 606 | "-c", |
582 | "test_transport_api_data.conf", | 607 | "test_transport_api_data.conf", |
583 | NULL | 608 | NULL |
@@ -586,14 +611,15 @@ main (int argc, char *argv[]) | |||
586 | GNUNET_GETOPT_OPTION_END | 611 | GNUNET_GETOPT_OPTION_END |
587 | }; | 612 | }; |
588 | 613 | ||
589 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); | 614 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], |
590 | 615 | &test_name); | |
591 | GNUNET_log_setup (test_name, | 616 | GNUNET_log_setup (test_name, |
592 | "WARNING", | 617 | "WARNING", |
593 | NULL); | 618 | NULL); |
594 | 619 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, | |
595 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); | 620 | &test_source); |
596 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, | 621 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], |
622 | test_source, | ||
597 | &test_plugin); | 623 | &test_plugin); |
598 | 624 | ||
599 | tth = GNUNET_TRANSPORT_TESTING_init (); | 625 | tth = GNUNET_TRANSPORT_TESTING_init (); |
@@ -601,21 +627,24 @@ main (int argc, char *argv[]) | |||
601 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); | 627 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); |
602 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); | 628 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); |
603 | 629 | ||
604 | |||
605 | |||
606 | #if WRITECONFIG | 630 | #if WRITECONFIG |
607 | setTransportOptions ("test_transport_api_data.conf"); | 631 | setTransportOptions ("test_transport_api_data.conf"); |
608 | #endif | 632 | #endif |
609 | ok = GNUNET_SYSERR; | 633 | ok = GNUNET_SYSERR; |
610 | 634 | ||
611 | ret = GNUNET_PROGRAM_run ((sizeof (argv_new) / sizeof (char *)) - 1, argv_new, test_name, | 635 | ret = GNUNET_PROGRAM_run ((sizeof (argv_new) / sizeof (char *)) - 1, |
612 | "nohelp", options, &run, &ok); | 636 | argv_new, test_name, |
637 | "nohelp", options, | ||
638 | &run, &ok); | ||
613 | if (GNUNET_SYSERR == ret) | 639 | if (GNUNET_SYSERR == ret) |
640 | { | ||
641 | fprintf (stderr, | ||
642 | "Test failed: %d\n", | ||
643 | ok); | ||
614 | ok = -1; | 644 | ok = -1; |
615 | 645 | } | |
616 | GNUNET_free (cfg_file_p1); | 646 | GNUNET_free (cfg_file_p1); |
617 | GNUNET_free (cfg_file_p2); | 647 | GNUNET_free (cfg_file_p2); |
618 | |||
619 | GNUNET_free (test_source); | 648 | GNUNET_free (test_source); |
620 | GNUNET_free (test_plugin); | 649 | GNUNET_free (test_plugin); |
621 | GNUNET_free (test_name); | 650 | GNUNET_free (test_name); |