diff options
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/TCP_test.c | 14 | ||||
-rw-r--r-- | auto_tests/network_test.c | 10 | ||||
-rw-r--r-- | auto_tests/resource_leak_test.c | 4 |
3 files changed, 18 insertions, 10 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index 6a439261..a1de4874 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c | |||
@@ -38,7 +38,7 @@ START_TEST(test_basic) | |||
38 | ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server"); | 38 | ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server"); |
39 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports"); | 39 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports"); |
40 | 40 | ||
41 | sock_t sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); | 41 | Socket sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); |
42 | struct sockaddr_in6 addr6_loopback = {0}; | 42 | struct sockaddr_in6 addr6_loopback = {0}; |
43 | addr6_loopback.sin6_family = AF_INET6; | 43 | addr6_loopback.sin6_family = AF_INET6; |
44 | addr6_loopback.sin6_port = htons(ports[rand() % NUM_PORTS]); | 44 | addr6_loopback.sin6_port = htons(ports[rand() % NUM_PORTS]); |
@@ -126,7 +126,7 @@ START_TEST(test_basic) | |||
126 | END_TEST | 126 | END_TEST |
127 | 127 | ||
128 | struct sec_TCP_con { | 128 | struct sec_TCP_con { |
129 | sock_t sock; | 129 | Socket sock; |
130 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 130 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
131 | uint8_t recv_nonce[CRYPTO_NONCE_SIZE]; | 131 | uint8_t recv_nonce[CRYPTO_NONCE_SIZE]; |
132 | uint8_t sent_nonce[CRYPTO_NONCE_SIZE]; | 132 | uint8_t sent_nonce[CRYPTO_NONCE_SIZE]; |
@@ -136,7 +136,7 @@ struct sec_TCP_con { | |||
136 | static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) | 136 | static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) |
137 | { | 137 | { |
138 | struct sec_TCP_con *sec_c = (struct sec_TCP_con *)malloc(sizeof(struct sec_TCP_con)); | 138 | struct sec_TCP_con *sec_c = (struct sec_TCP_con *)malloc(sizeof(struct sec_TCP_con)); |
139 | sock_t sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); | 139 | Socket sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); |
140 | struct sockaddr_in6 addr6_loopback = {0}; | 140 | struct sockaddr_in6 addr6_loopback = {0}; |
141 | addr6_loopback.sin6_family = AF_INET6; | 141 | addr6_loopback.sin6_family = AF_INET6; |
142 | addr6_loopback.sin6_port = htons(ports[rand() % NUM_PORTS]); | 142 | addr6_loopback.sin6_port = htons(ports[rand() % NUM_PORTS]); |
@@ -407,7 +407,7 @@ START_TEST(test_client) | |||
407 | 407 | ||
408 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); | 408 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); |
409 | ip_port_tcp_s.ip.family = AF_INET6; | 409 | ip_port_tcp_s.ip.family = AF_INET6; |
410 | ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback; | 410 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); |
411 | TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0); | 411 | TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0); |
412 | c_sleep(50); | 412 | c_sleep(50); |
413 | do_TCP_connection(conn, NULL); | 413 | do_TCP_connection(conn, NULL); |
@@ -505,7 +505,7 @@ START_TEST(test_client_invalid) | |||
505 | 505 | ||
506 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); | 506 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); |
507 | ip_port_tcp_s.ip.family = AF_INET6; | 507 | ip_port_tcp_s.ip.family = AF_INET6; |
508 | ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback; | 508 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); |
509 | TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0); | 509 | TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0); |
510 | c_sleep(50); | 510 | c_sleep(50); |
511 | do_TCP_connection(conn, NULL); | 511 | do_TCP_connection(conn, NULL); |
@@ -574,7 +574,7 @@ START_TEST(test_tcp_connection) | |||
574 | 574 | ||
575 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); | 575 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); |
576 | ip_port_tcp_s.ip.family = AF_INET6; | 576 | ip_port_tcp_s.ip.family = AF_INET6; |
577 | ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback; | 577 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); |
578 | 578 | ||
579 | int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123); | 579 | int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123); |
580 | ck_assert_msg(connection == 0, "Connection id wrong"); | 580 | ck_assert_msg(connection == 0, "Connection id wrong"); |
@@ -683,7 +683,7 @@ START_TEST(test_tcp_connection2) | |||
683 | 683 | ||
684 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); | 684 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); |
685 | ip_port_tcp_s.ip.family = AF_INET6; | 685 | ip_port_tcp_s.ip.family = AF_INET6; |
686 | ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback; | 686 | get_ip6(&ip_port_tcp_s.ip.ip6, &in6addr_loopback); |
687 | 687 | ||
688 | int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123); | 688 | int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123); |
689 | ck_assert_msg(connection == 0, "Connection id wrong"); | 689 | ck_assert_msg(connection == 0, "Connection id wrong"); |
diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index 2ce6d0b5..ea08c1b8 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #endif | 3 | #endif |
4 | 4 | ||
5 | #include <check.h> | 5 | #include <check.h> |
6 | #include <errno.h> | ||
6 | #include <stdint.h> | 7 | #include <stdint.h> |
7 | #include <stdlib.h> | 8 | #include <stdlib.h> |
8 | #include <string.h> | 9 | #include <string.h> |
@@ -36,8 +37,9 @@ START_TEST(test_addr_resolv_localhost) | |||
36 | 37 | ||
37 | if (res > 0) { | 38 | if (res > 0) { |
38 | ck_assert_msg(ip.family == AF_INET, "Expected family AF_INET, got %u.", ip.family); | 39 | ck_assert_msg(ip.family == AF_INET, "Expected family AF_INET, got %u.", ip.family); |
39 | ck_assert_msg(ip.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", | 40 | struct in_addr addr; |
40 | inet_ntoa(ip.ip4.in_addr)); | 41 | fill_addr4(ip.ip4, &addr); |
42 | ck_assert_msg(ip.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(addr)); | ||
41 | } | 43 | } |
42 | 44 | ||
43 | ip_init(&ip, 1); // ipv6enabled = 1 | 45 | ip_init(&ip, 1); // ipv6enabled = 1 |
@@ -71,8 +73,10 @@ START_TEST(test_addr_resolv_localhost) | |||
71 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", | 73 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", |
72 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 74 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
73 | 75 | ||
76 | struct in_addr addr; | ||
77 | fill_addr4(ip.ip4, &addr); | ||
74 | ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET (%u), got %u.", AF_INET, extra.family); | 78 | ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET (%u), got %u.", AF_INET, extra.family); |
75 | ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(extra.ip4.in_addr)); | 79 | ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(addr)); |
76 | } | 80 | } |
77 | } else { | 81 | } else { |
78 | printf("Localhost seems to be split in two.\n"); | 82 | printf("Localhost seems to be split in two.\n"); |
diff --git a/auto_tests/resource_leak_test.c b/auto_tests/resource_leak_test.c index aab1fcd7..3a87e245 100644 --- a/auto_tests/resource_leak_test.c +++ b/auto_tests/resource_leak_test.c | |||
@@ -1,5 +1,9 @@ | |||
1 | #include "helpers.h" | 1 | #include "helpers.h" |
2 | 2 | ||
3 | #if defined(__AIX__) | ||
4 | # define _XOPEN_SOURCE 1 | ||
5 | #endif | ||
6 | |||
3 | // See man 2 sbrk. | 7 | // See man 2 sbrk. |
4 | #if _BSD_SOURCE || _SVID_SOURCE || \ | 8 | #if _BSD_SOURCE || _SVID_SOURCE || \ |
5 | (_XOPEN_SOURCE >= 500 || \ | 9 | (_XOPEN_SOURCE >= 500 || \ |