summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-08-09 23:53:39 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-08-16 21:01:38 +0000
commit54066f338f185f2fbd6694d9a4877f42cbfa21c8 (patch)
treee056e50af1009bf373c040812e46cd1de8de9979 /auto_tests
parent31ea1aa06e59d24d5196b17be9a7105d85c25080 (diff)
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.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/TCP_test.c6
-rw-r--r--auto_tests/dht_test.c57
-rw-r--r--auto_tests/onion_test.c6
3 files changed, 32 insertions, 37 deletions
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()
39static void do_TCP_server_delay(TCP_Server *tcp_s, int delay) 39static void do_TCP_server_delay(TCP_Server *tcp_s, int delay)
40{ 40{
41 c_sleep(delay); 41 c_sleep(delay);
42 unix_time_update();
42 do_TCP_server(tcp_s); 43 do_TCP_server(tcp_s);
43 c_sleep(delay); 44 c_sleep(delay);
44} 45}
@@ -141,6 +142,7 @@ START_TEST(test_basic)
141 i += msg_length; 142 i += msg_length;
142 143
143 c_sleep(50); 144 c_sleep(50);
145 unix_time_update();
144 do_TCP_server(tcp_s); 146 do_TCP_server(tcp_s);
145 } 147 }
146 148
@@ -477,6 +479,7 @@ START_TEST(test_client)
477 const uint8_t LOOP_SIZE = 3; 479 const uint8_t LOOP_SIZE = 3;
478 480
479 for (uint8_t i = 0; i < LOOP_SIZE; i++) { 481 for (uint8_t i = 0; i < LOOP_SIZE; i++) {
482 unix_time_update();
480 do_TCP_connection(conn, nullptr); // Run the connection loop. 483 do_TCP_connection(conn, nullptr); // Run the connection loop.
481 484
482 // The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_TCP_connection() calls. 485 // 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)
584 TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr); 587 TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr);
585 588
586 // Run the client's main loop but not the server. 589 // Run the client's main loop but not the server.
590 unix_time_update();
587 do_TCP_connection(conn, nullptr); 591 do_TCP_connection(conn, nullptr);
588 c_sleep(50); 592 c_sleep(50);
589 593
@@ -592,11 +596,13 @@ START_TEST(test_client_invalid)
592 TCP_CLIENT_CONNECTING, tcp_con_status(conn)); 596 TCP_CLIENT_CONNECTING, tcp_con_status(conn));
593 // After 5s... 597 // After 5s...
594 c_sleep(5000); 598 c_sleep(5000);
599 unix_time_update();
595 do_TCP_connection(conn, nullptr); 600 do_TCP_connection(conn, nullptr);
596 ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.", 601 ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.",
597 TCP_CLIENT_CONNECTING, tcp_con_status(conn)); 602 TCP_CLIENT_CONNECTING, tcp_con_status(conn));
598 // 11s... (Should wait for 10 before giving up.) 603 // 11s... (Should wait for 10 before giving up.)
599 c_sleep(6000); 604 c_sleep(6000);
605 unix_time_update();
600 do_TCP_connection(conn, nullptr); 606 do_TCP_connection(conn, nullptr);
601 ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %d, is: %d.", 607 ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %d, is: %d.",
602 TCP_CLIENT_DISCONNECTED, tcp_con_status(conn)); 608 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)
389 logger_kill(log); 389 logger_kill(log);
390} 390}
391 391
392START_TEST(test_addto_lists_ipv4) 392static void test_addto_lists_ipv4(void)
393{ 393{
394 IP ip; 394 IP ip;
395 ip_init(&ip, 0); 395 ip_init(&ip, 0);
396 test_addto_lists(ip); 396 test_addto_lists(ip);
397} 397}
398END_TEST
399 398
400START_TEST(test_addto_lists_ipv6) 399static void test_addto_lists_ipv6(void)
401{ 400{
402 IP ip; 401 IP ip;
403 ip_init(&ip, 1); 402 ip_init(&ip, 1);
404 test_addto_lists(ip); 403 test_addto_lists(ip);
405} 404}
406END_TEST
407 405
408#define DHT_DEFAULT_PORT (TOX_PORT_DEFAULT + 1000) 406#define DHT_DEFAULT_PORT (TOX_PORT_DEFAULT + 1000)
409 407
@@ -580,7 +578,7 @@ static void test_list_main(void)
580} 578}
581 579
582 580
583START_TEST(test_list) 581static void test_list(void)
584{ 582{
585 uint8_t i; 583 uint8_t i;
586 584
@@ -588,7 +586,6 @@ START_TEST(test_list)
588 test_list_main(); 586 test_list_main();
589 } 587 }
590} 588}
591END_TEST
592 589
593static void ip_callback(void *data, int32_t number, IP_Port ip_port) 590static void ip_callback(void *data, int32_t number, IP_Port ip_port)
594{ 591{
@@ -596,13 +593,15 @@ static void ip_callback(void *data, int32_t number, IP_Port ip_port)
596 593
597#define NUM_DHT_FRIENDS 20 594#define NUM_DHT_FRIENDS 20
598 595
599START_TEST(test_DHT_test) 596static void test_DHT_test(void)
600{ 597{
601 uint32_t to_comp = 8394782; 598 uint32_t to_comp = 8394782;
602 DHT *dhts[NUM_DHT]; 599 DHT *dhts[NUM_DHT];
603 Logger *logs[NUM_DHT]; 600 Logger *logs[NUM_DHT];
604 uint32_t index[NUM_DHT]; 601 uint32_t index[NUM_DHT];
605 602
603 unix_time_update();
604
606 uint32_t i, j; 605 uint32_t i, j;
607 606
608 for (i = 0; i < NUM_DHT; ++i) { 607 for (i = 0; i < NUM_DHT; ++i) {
@@ -664,6 +663,7 @@ loop_top:
664 } 663 }
665 664
666 for (i = 0; i < NUM_DHT; ++i) { 665 for (i = 0; i < NUM_DHT; ++i) {
666 unix_time_update();
667 networking_poll(dhts[i]->net, nullptr); 667 networking_poll(dhts[i]->net, nullptr);
668 do_dht(dhts[i]); 668 do_dht(dhts[i]);
669 } 669 }
@@ -678,9 +678,8 @@ loop_top:
678 logger_kill(logs[i]); 678 logger_kill(logs[i]);
679 } 679 }
680} 680}
681END_TEST
682 681
683START_TEST(test_dht_create_packet) 682static void test_dht_create_packet(void)
684{ 683{
685 uint8_t plain[100] = {0}; 684 uint8_t plain[100] = {0};
686 uint8_t pkt[1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + sizeof(plain) + CRYPTO_MAC_SIZE]; 685 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)
697 696
698 printf("Create Packet Successful!\n"); 697 printf("Create Packet Successful!\n");
699} 698}
700END_TEST
701 699
702#define MAX_COUNT 3 700#define MAX_COUNT 3
703 701
@@ -750,7 +748,7 @@ static void random_ip(IP_Port *ipp, int family)
750 748
751#define PACKED_NODES_SIZE (SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE) 749#define PACKED_NODES_SIZE (SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE)
752 750
753START_TEST(test_dht_node_packing) 751static void test_dht_node_packing(void)
754{ 752{
755 const uint16_t length = MAX_COUNT * PACKED_NODES_SIZE; 753 const uint16_t length = MAX_COUNT * PACKED_NODES_SIZE;
756 uint8_t *data = (uint8_t *)malloc(length); 754 uint8_t *data = (uint8_t *)malloc(length);
@@ -789,38 +787,23 @@ START_TEST(test_dht_node_packing)
789 787
790 free(data); 788 free(data);
791} 789}
792END_TEST
793
794static Suite *dht_suite(void)
795{
796 Suite *s = suite_create("DHT");
797 DEFTESTCASE(dht_create_packet);
798 DEFTESTCASE(dht_node_packing);
799
800 DEFTESTCASE_SLOW(list, 20);
801 DEFTESTCASE_SLOW(DHT_test, 50);
802
803 if (enable_broken_tests) {
804 DEFTESTCASE(addto_lists_ipv4);
805 DEFTESTCASE(addto_lists_ipv6);
806 }
807
808 return s;
809}
810 790
811int main(void) 791int main(void)
812{ 792{
813 setvbuf(stdout, nullptr, _IONBF, 0); 793 setvbuf(stdout, nullptr, _IONBF, 0);
814 794
815 Suite *dht = dht_suite(); 795 unix_time_update();
816 SRunner *test_runner = srunner_create(dht);
817 796
818 uint8_t number_failed = 0; 797 test_dht_create_packet();
819 //srunner_set_fork_status(test_runner, CK_NOFORK); 798 test_dht_node_packing();
820 srunner_run_all(test_runner, CK_NORMAL);
821 number_failed = srunner_ntests_failed(test_runner);
822 799
823 srunner_free(test_runner); 800 test_list();
801 test_DHT_test();
802
803 if (enable_broken_tests) {
804 test_addto_lists_ipv4();
805 test_addto_lists_ipv6();
806 }
824 807
825 return number_failed; 808 return 0;
826} 809}
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()
31} 31}
32static void do_onion(Onion *onion) 32static void do_onion(Onion *onion)
33{ 33{
34 unix_time_update();
35
34 networking_poll(onion->net, nullptr); 36 networking_poll(onion->net, nullptr);
35 do_dht(onion->dht); 37 do_dht(onion->dht);
36} 38}
@@ -327,6 +329,8 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
327 return nullptr; 329 return nullptr;
328 } 330 }
329 331
332 unix_time_update();
333
330 logger_callback_log(on->log, (logger_cb *)print_debug_log, nullptr, index); 334 logger_callback_log(on->log, (logger_cb *)print_debug_log, nullptr, index);
331 335
332 Networking_Core *net = new_networking(on->log, ip, port); 336 Networking_Core *net = new_networking(on->log, ip, port);
@@ -385,6 +389,8 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
385 389
386static void do_onions(Onions *on) 390static void do_onions(Onions *on)
387{ 391{
392 unix_time_update();
393
388 networking_poll(on->onion->net, nullptr); 394 networking_poll(on->onion->net, nullptr);
389 do_dht(on->onion->dht); 395 do_dht(on->onion->dht);
390 do_onion_client(on->onion_c); 396 do_onion_client(on->onion_c);