From 54066f338f185f2fbd6694d9a4877f42cbfa21c8 Mon Sep 17 00:00:00 2001 From: iphydf Date: Thu, 9 Aug 2018 23:53:39 +0000 Subject: Reduce the number of times `unix_time_update` is called. Reduced by, e.g.: * `file_transfer_test`: 33% of the `clock_gettime` calls. * `tox_many_test`: 53% of the `clock_gettime` calls. Other tests will see similar improvements. Real world applications will be closer to 40-50% improvement, since tox_many_test has 100 nodes, while file_transfer_test has 2 nodes. --- auto_tests/TCP_test.c | 6 ++++++ auto_tests/dht_test.c | 57 +++++++++++++++++-------------------------------- auto_tests/onion_test.c | 6 ++++++ 3 files changed, 32 insertions(+), 37 deletions(-) (limited to 'auto_tests') diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index 07266543..52ecad77 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c @@ -39,6 +39,7 @@ static inline IP get_loopback() static void do_TCP_server_delay(TCP_Server *tcp_s, int delay) { c_sleep(delay); + unix_time_update(); do_TCP_server(tcp_s); c_sleep(delay); } @@ -141,6 +142,7 @@ START_TEST(test_basic) i += msg_length; c_sleep(50); + unix_time_update(); do_TCP_server(tcp_s); } @@ -477,6 +479,7 @@ START_TEST(test_client) const uint8_t LOOP_SIZE = 3; for (uint8_t i = 0; i < LOOP_SIZE; i++) { + unix_time_update(); do_TCP_connection(conn, nullptr); // Run the connection loop. // The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_TCP_connection() calls. @@ -584,6 +587,7 @@ START_TEST(test_client_invalid) TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr); // Run the client's main loop but not the server. + unix_time_update(); do_TCP_connection(conn, nullptr); c_sleep(50); @@ -592,11 +596,13 @@ START_TEST(test_client_invalid) TCP_CLIENT_CONNECTING, tcp_con_status(conn)); // After 5s... c_sleep(5000); + unix_time_update(); do_TCP_connection(conn, nullptr); ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.", TCP_CLIENT_CONNECTING, tcp_con_status(conn)); // 11s... (Should wait for 10 before giving up.) c_sleep(6000); + unix_time_update(); do_TCP_connection(conn, nullptr); ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %d, is: %d.", TCP_CLIENT_DISCONNECTED, tcp_con_status(conn)); diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 8b96f09a..2f273727 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c @@ -389,21 +389,19 @@ static void test_addto_lists(IP ip) logger_kill(log); } -START_TEST(test_addto_lists_ipv4) +static void test_addto_lists_ipv4(void) { IP ip; ip_init(&ip, 0); test_addto_lists(ip); } -END_TEST -START_TEST(test_addto_lists_ipv6) +static void test_addto_lists_ipv6(void) { IP ip; ip_init(&ip, 1); test_addto_lists(ip); } -END_TEST #define DHT_DEFAULT_PORT (TOX_PORT_DEFAULT + 1000) @@ -580,7 +578,7 @@ static void test_list_main(void) } -START_TEST(test_list) +static void test_list(void) { uint8_t i; @@ -588,7 +586,6 @@ START_TEST(test_list) test_list_main(); } } -END_TEST static void ip_callback(void *data, int32_t number, IP_Port ip_port) { @@ -596,13 +593,15 @@ static void ip_callback(void *data, int32_t number, IP_Port ip_port) #define NUM_DHT_FRIENDS 20 -START_TEST(test_DHT_test) +static void test_DHT_test(void) { uint32_t to_comp = 8394782; DHT *dhts[NUM_DHT]; Logger *logs[NUM_DHT]; uint32_t index[NUM_DHT]; + unix_time_update(); + uint32_t i, j; for (i = 0; i < NUM_DHT; ++i) { @@ -664,6 +663,7 @@ loop_top: } for (i = 0; i < NUM_DHT; ++i) { + unix_time_update(); networking_poll(dhts[i]->net, nullptr); do_dht(dhts[i]); } @@ -678,9 +678,8 @@ loop_top: logger_kill(logs[i]); } } -END_TEST -START_TEST(test_dht_create_packet) +static void test_dht_create_packet(void) { uint8_t plain[100] = {0}; uint8_t pkt[1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + sizeof(plain) + CRYPTO_MAC_SIZE]; @@ -697,7 +696,6 @@ START_TEST(test_dht_create_packet) printf("Create Packet Successful!\n"); } -END_TEST #define MAX_COUNT 3 @@ -750,7 +748,7 @@ static void random_ip(IP_Port *ipp, int family) #define PACKED_NODES_SIZE (SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE) -START_TEST(test_dht_node_packing) +static void test_dht_node_packing(void) { const uint16_t length = MAX_COUNT * PACKED_NODES_SIZE; uint8_t *data = (uint8_t *)malloc(length); @@ -789,38 +787,23 @@ START_TEST(test_dht_node_packing) free(data); } -END_TEST - -static Suite *dht_suite(void) -{ - Suite *s = suite_create("DHT"); - DEFTESTCASE(dht_create_packet); - DEFTESTCASE(dht_node_packing); - - DEFTESTCASE_SLOW(list, 20); - DEFTESTCASE_SLOW(DHT_test, 50); - - if (enable_broken_tests) { - DEFTESTCASE(addto_lists_ipv4); - DEFTESTCASE(addto_lists_ipv6); - } - - return s; -} int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); - Suite *dht = dht_suite(); - SRunner *test_runner = srunner_create(dht); + unix_time_update(); - uint8_t number_failed = 0; - //srunner_set_fork_status(test_runner, CK_NOFORK); - srunner_run_all(test_runner, CK_NORMAL); - number_failed = srunner_ntests_failed(test_runner); + test_dht_create_packet(); + test_dht_node_packing(); - srunner_free(test_runner); + test_list(); + test_DHT_test(); + + if (enable_broken_tests) { + test_addto_lists_ipv4(); + test_addto_lists_ipv6(); + } - return number_failed; + return 0; } diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 18b7b523..0a9a0577 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -31,6 +31,8 @@ static inline IP get_loopback() } static void do_onion(Onion *onion) { + unix_time_update(); + networking_poll(onion->net, nullptr); do_dht(onion->dht); } @@ -327,6 +329,8 @@ static Onions *new_onions(uint16_t port, uint32_t *index) return nullptr; } + unix_time_update(); + logger_callback_log(on->log, (logger_cb *)print_debug_log, nullptr, index); Networking_Core *net = new_networking(on->log, ip, port); @@ -385,6 +389,8 @@ static Onions *new_onions(uint16_t port, uint32_t *index) static void do_onions(Onions *on) { + unix_time_update(); + networking_poll(on->onion->net, nullptr); do_dht(on->onion->dht); do_onion_client(on->onion_c); -- cgit v1.2.3