diff options
author | Bart Polot <bart.polot+gnunet@gmail.com> | 2017-03-01 20:05:14 +0100 |
---|---|---|
committer | Bart Polot <bart.polot+gnunet@gmail.com> | 2017-03-01 20:05:14 +0100 |
commit | 3f9a2615b3bd0a55e0c69dba494b4fbfce7b80e9 (patch) | |
tree | f933d1ba0199a9086608a8103627357233a26565 /src | |
parent | 0ef83cf1ca7aebfbbf9544aaad66f40cfdc81f90 (diff) | |
download | gnunet-3f9a2615b3bd0a55e0c69dba494b4fbfce7b80e9.tar.gz gnunet-3f9a2615b3bd0a55e0c69dba494b4fbfce7b80e9.zip |
make total traffic and timeout configurable without recompiling
Diffstat (limited to 'src')
-rw-r--r-- | src/cadet/test_cadet_new.c | 67 |
1 files changed, 47 insertions, 20 deletions
diff --git a/src/cadet/test_cadet_new.c b/src/cadet/test_cadet_new.c index 40d1879ac..374e86bf3 100644 --- a/src/cadet/test_cadet_new.c +++ b/src/cadet/test_cadet_new.c | |||
@@ -43,7 +43,7 @@ struct CadetTestChannelWrapper | |||
43 | }; | 43 | }; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * How many messages to send | 46 | * How many messages to send by default. |
47 | */ | 47 | */ |
48 | #define TOTAL_PACKETS 500 /* Cannot exceed 64k! */ | 48 | #define TOTAL_PACKETS 500 /* Cannot exceed 64k! */ |
49 | 49 | ||
@@ -53,7 +53,7 @@ struct CadetTestChannelWrapper | |||
53 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 53 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Time to wait for stuff that should be rather fast | 56 | * Time to wait by default for stuff that should be rather fast. |
57 | */ | 57 | */ |
58 | #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) | 58 | #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) |
59 | 59 | ||
@@ -84,6 +84,16 @@ static char *test_name; | |||
84 | static int test_backwards = GNUNET_NO; | 84 | static int test_backwards = GNUNET_NO; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | * How many packets to send. | ||
88 | */ | ||
89 | static unsigned int total_packets; | ||
90 | |||
91 | /** | ||
92 | * Time to wait for fast operations. | ||
93 | */ | ||
94 | static struct GNUNET_TIME_Relative short_time; | ||
95 | |||
96 | /** | ||
87 | * How many events have happened | 97 | * How many events have happened |
88 | */ | 98 | */ |
89 | static int ok; | 99 | static int ok; |
@@ -262,10 +272,10 @@ show_end_data (void) | |||
262 | FPRINTF (stderr, "\nResults of test \"%s\"\n", test_name); | 272 | FPRINTF (stderr, "\nResults of test \"%s\"\n", test_name); |
263 | FPRINTF (stderr, "Test time %s\n", | 273 | FPRINTF (stderr, "Test time %s\n", |
264 | GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); | 274 | GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); |
265 | FPRINTF (stderr, "Test bandwidth: %f kb/s\n", 4 * TOTAL_PACKETS * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms | 275 | FPRINTF (stderr, "Test bandwidth: %f kb/s\n", 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms |
266 | FPRINTF (stderr, "Test throughput: %f packets/s\n\n", TOTAL_PACKETS * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms | 276 | FPRINTF (stderr, "Test throughput: %f packets/s\n\n", total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms |
267 | GAUGER ("CADET", test_name, | 277 | GAUGER ("CADET", test_name, |
268 | TOTAL_PACKETS * 1000.0 / (total_time.rel_value_us / 1000), | 278 | total_packets * 1000.0 / (total_time.rel_value_us / 1000), |
269 | "packets/s"); | 279 | "packets/s"); |
270 | } | 280 | } |
271 | 281 | ||
@@ -533,7 +543,7 @@ send_next_msg (void *cls) | |||
533 | GNUNET_assert (NULL != channel); | 543 | GNUNET_assert (NULL != channel); |
534 | GNUNET_assert (SPEED == test); | 544 | GNUNET_assert (SPEED == test); |
535 | send_test_message (channel); | 545 | send_test_message (channel); |
536 | if (data_sent < TOTAL_PACKETS) | 546 | if (data_sent < total_packets) |
537 | { | 547 | { |
538 | /* SPEED test: Send all messages as soon as possible */ | 548 | /* SPEED test: Send all messages as soon as possible */ |
539 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 549 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -563,7 +573,7 @@ reschedule_timeout_task (long line) | |||
563 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
564 | " reschedule timeout every 10 messages\n"); | 574 | " reschedule timeout every 10 messages\n"); |
565 | GNUNET_SCHEDULER_cancel (disconnect_task); | 575 | GNUNET_SCHEDULER_cancel (disconnect_task); |
566 | disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, | 576 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
567 | &gather_stats_and_exit, | 577 | &gather_stats_and_exit, |
568 | (void *) line); | 578 | (void *) line); |
569 | } | 579 | } |
@@ -661,7 +671,7 @@ handle_data (void *cls, const struct GNUNET_MessageHeader *message) | |||
661 | } | 671 | } |
662 | else | 672 | else |
663 | { | 673 | { |
664 | if (data_received < TOTAL_PACKETS) | 674 | if (data_received < total_packets) |
665 | return; | 675 | return; |
666 | } | 676 | } |
667 | } | 677 | } |
@@ -672,7 +682,7 @@ handle_data (void *cls, const struct GNUNET_MessageHeader *message) | |||
672 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received); | 682 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received); |
673 | /* Send more data */ | 683 | /* Send more data */ |
674 | send_test_message (channel); | 684 | send_test_message (channel); |
675 | if (ack_received < TOTAL_PACKETS && SPEED != test) | 685 | if (ack_received < total_packets && SPEED != test) |
676 | return; | 686 | return; |
677 | if (ok == 2 && SPEED == test) | 687 | if (ok == 2 && SPEED == test) |
678 | return; | 688 | return; |
@@ -735,7 +745,7 @@ connect_handler (void *cls, struct GNUNET_CADET_Channel *channel, | |||
735 | if (NULL != disconnect_task) | 745 | if (NULL != disconnect_task) |
736 | { | 746 | { |
737 | GNUNET_SCHEDULER_cancel (disconnect_task); | 747 | GNUNET_SCHEDULER_cancel (disconnect_task); |
738 | disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, | 748 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
739 | &gather_stats_and_exit, | 749 | &gather_stats_and_exit, |
740 | (void *) __LINE__); | 750 | (void *) __LINE__); |
741 | } | 751 | } |
@@ -841,7 +851,7 @@ start_test (void *cls) | |||
841 | 851 | ||
842 | ch->ch = outgoing_ch; | 852 | ch->ch = outgoing_ch; |
843 | 853 | ||
844 | disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, | 854 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
845 | &gather_stats_and_exit, | 855 | &gather_stats_and_exit, |
846 | (void *) __LINE__); | 856 | (void *) __LINE__); |
847 | if (KEEPALIVE == test) | 857 | if (KEEPALIVE == test) |
@@ -916,7 +926,7 @@ tmain (void *cls, | |||
916 | testbed_peers = peers; | 926 | testbed_peers = peers; |
917 | h1 = cadets[0]; | 927 | h1 = cadets[0]; |
918 | h2 = cadets[num_peers - 1]; | 928 | h2 = cadets[num_peers - 1]; |
919 | disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, | 929 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
920 | &disconnect_cadet_peers, | 930 | &disconnect_cadet_peers, |
921 | (void *) __LINE__); | 931 | (void *) __LINE__); |
922 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 932 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
@@ -951,12 +961,29 @@ main (int argc, char *argv[]) | |||
951 | const char *config_file; | 961 | const char *config_file; |
952 | char port_id[] = "test port"; | 962 | char port_id[] = "test port"; |
953 | 963 | ||
954 | GNUNET_CRYPTO_hash (port_id, sizeof (port_id), &port); | 964 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
965 | {'t', "time", "short_time", | ||
966 | gettext_noop ("set short timeout"), | ||
967 | GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &short_time}, | ||
968 | {'m', "messages", "NUM_MESSAGES", | ||
969 | gettext_noop ("set number of messages to send"), | ||
970 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &total_packets}, | ||
971 | |||
972 | GNUNET_GETOPT_OPTION_END | ||
973 | }; | ||
955 | 974 | ||
956 | GNUNET_log_setup ("test", "DEBUG", NULL); | 975 | GNUNET_log_setup ("test", "DEBUG", NULL); |
957 | config_file = "test_cadet.conf"; | ||
958 | 976 | ||
959 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n"); | 977 | total_packets = TOTAL_PACKETS; |
978 | short_time = SHORT_TIME; | ||
979 | if (-1 == GNUNET_GETOPT_run (argv[0], options, argc, argv)) | ||
980 | { | ||
981 | FPRINTF (stderr, "test failed: problem with CLI parameters\n"); | ||
982 | exit (1); | ||
983 | } | ||
984 | |||
985 | config_file = "test_cadet.conf"; | ||
986 | GNUNET_CRYPTO_hash (port_id, sizeof (port_id), &port); | ||
960 | 987 | ||
961 | /* Find out requested size */ | 988 | /* Find out requested size */ |
962 | if (strstr (argv[0], "_2_") != NULL) | 989 | if (strstr (argv[0], "_2_") != NULL) |
@@ -994,11 +1021,11 @@ main (int argc, char *argv[]) | |||
994 | { | 1021 | { |
995 | /* Test is supposed to generate the following callbacks: | 1022 | /* Test is supposed to generate the following callbacks: |
996 | * 1 incoming channel (@dest) | 1023 | * 1 incoming channel (@dest) |
997 | * TOTAL_PACKETS received data packet (@dest) | 1024 | * total_packets received data packet (@dest) |
998 | * TOTAL_PACKETS received data packet (@orig) | 1025 | * total_packets received data packet (@orig) |
999 | * 1 received channel destroy (@dest) | 1026 | * 1 received channel destroy (@dest) |
1000 | */ | 1027 | */ |
1001 | ok_goal = TOTAL_PACKETS * 2 + 2; | 1028 | ok_goal = total_packets * 2 + 2; |
1002 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n"); | 1029 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n"); |
1003 | test = SPEED_ACK; | 1030 | test = SPEED_ACK; |
1004 | test_name = "speed ack"; | 1031 | test_name = "speed ack"; |
@@ -1008,11 +1035,11 @@ main (int argc, char *argv[]) | |||
1008 | /* Test is supposed to generate the following callbacks: | 1035 | /* Test is supposed to generate the following callbacks: |
1009 | * 1 incoming channel (@dest) | 1036 | * 1 incoming channel (@dest) |
1010 | * 1 initial packet (@dest) | 1037 | * 1 initial packet (@dest) |
1011 | * TOTAL_PACKETS received data packet (@dest) | 1038 | * total_packets received data packet (@dest) |
1012 | * 1 received data packet (@orig) | 1039 | * 1 received data packet (@orig) |
1013 | * 1 received channel destroy (@dest) | 1040 | * 1 received channel destroy (@dest) |
1014 | */ | 1041 | */ |
1015 | ok_goal = TOTAL_PACKETS + 4; | 1042 | ok_goal = total_packets + 4; |
1016 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n"); | 1043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n"); |
1017 | if (strstr (argv[0], "_reliable") != NULL) | 1044 | if (strstr (argv[0], "_reliable") != NULL) |
1018 | { | 1045 | { |