summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/TCP_test.c52
-rw-r--r--auto_tests/dht_test.c19
-rw-r--r--auto_tests/onion_test.c27
3 files changed, 70 insertions, 28 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c
index 898c5e08..36db0332 100644
--- a/auto_tests/TCP_test.c
+++ b/auto_tests/TCP_test.c
@@ -21,6 +21,29 @@
21 21
22#define NUM_PORTS 3 22#define NUM_PORTS 3
23 23
24#ifndef USE_IPV6
25#define USE_IPV6 1
26#endif
27
28#if !USE_IPV6
29# undef TOX_AF_INET6
30# define TOX_AF_INET6 TOX_AF_INET
31# define get_ip6_loopback get_ip4_loopback
32#endif
33
34static inline IP get_loopback()
35{
36 IP ip;
37#if USE_IPV6
38 ip.family = TOX_AF_INET6;
39 ip.ip6 = get_ip6_loopback();
40#else
41 ip.family = TOX_AF_INET;
42 ip.ip4 = get_ip4_loopback();
43#endif
44 return ip;
45}
46
24static uint16_t ports[NUM_PORTS] = {1234, 33445, 25643}; 47static uint16_t ports[NUM_PORTS] = {1234, 33445, 25643};
25 48
26START_TEST(test_basic) 49START_TEST(test_basic)
@@ -28,14 +51,13 @@ START_TEST(test_basic)
28 uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; 51 uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
29 uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; 52 uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
30 crypto_new_keypair(self_public_key, self_secret_key); 53 crypto_new_keypair(self_public_key, self_secret_key);
31 TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); 54 TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, NULL);
32 ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server"); 55 ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
33 ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports"); 56 ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports");
34 57
35 Socket sock = net_socket(TOX_AF_INET6, TOX_SOCK_STREAM, TOX_PROTO_TCP); 58 Socket sock = net_socket(TOX_AF_INET6, TOX_SOCK_STREAM, TOX_PROTO_TCP);
36 IP_Port ip_port_loopback; 59 IP_Port ip_port_loopback;
37 ip_port_loopback.ip.family = TOX_AF_INET6; 60 ip_port_loopback.ip = get_loopback();
38 ip_port_loopback.ip.ip6 = get_ip6_loopback();
39 ip_port_loopback.port = net_htons(ports[rand() % NUM_PORTS]); 61 ip_port_loopback.port = net_htons(ports[rand() % NUM_PORTS]);
40 62
41 int ret = net_connect(sock, ip_port_loopback); 63 int ret = net_connect(sock, ip_port_loopback);
@@ -133,9 +155,7 @@ static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s)
133 Socket sock = net_socket(TOX_AF_INET6, TOX_SOCK_STREAM, TOX_PROTO_TCP); 155 Socket sock = net_socket(TOX_AF_INET6, TOX_SOCK_STREAM, TOX_PROTO_TCP);
134 156
135 IP_Port ip_port_loopback; 157 IP_Port ip_port_loopback;
136 ip_port_loopback.ip.family = TOX_AF_INET6; 158 ip_port_loopback.ip = get_loopback();
137 ip_port_loopback.ip.ip6.uint64[0] = 0;
138 ip_port_loopback.ip.ip4 = get_ip4_loopback();
139 ip_port_loopback.port = net_htons(ports[rand() % NUM_PORTS]); 159 ip_port_loopback.port = net_htons(ports[rand() % NUM_PORTS]);
140 160
141 int ret = net_connect(sock, ip_port_loopback); 161 int ret = net_connect(sock, ip_port_loopback);
@@ -215,7 +235,7 @@ START_TEST(test_some)
215 uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; 235 uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
216 uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; 236 uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
217 crypto_new_keypair(self_public_key, self_secret_key); 237 crypto_new_keypair(self_public_key, self_secret_key);
218 TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); 238 TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, NULL);
219 ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server"); 239 ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
220 ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports"); 240 ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports");
221 241
@@ -392,7 +412,7 @@ START_TEST(test_client)
392 uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; 412 uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
393 uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; 413 uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
394 crypto_new_keypair(self_public_key, self_secret_key); 414 crypto_new_keypair(self_public_key, self_secret_key);
395 TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); 415 TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, NULL);
396 ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server"); 416 ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
397 ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports"); 417 ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports");
398 418
@@ -402,8 +422,7 @@ START_TEST(test_client)
402 IP_Port ip_port_tcp_s; 422 IP_Port ip_port_tcp_s;
403 423
404 ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); 424 ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]);
405 ip_port_tcp_s.ip.family = TOX_AF_INET6; 425 ip_port_tcp_s.ip = get_loopback();
406 ip_port_tcp_s.ip.ip6 = get_ip6_loopback();
407 TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0); 426 TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0);
408 c_sleep(50); 427 c_sleep(50);
409 do_TCP_connection(conn, NULL); 428 do_TCP_connection(conn, NULL);
@@ -500,8 +519,7 @@ START_TEST(test_client_invalid)
500 IP_Port ip_port_tcp_s; 519 IP_Port ip_port_tcp_s;
501 520
502 ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); 521 ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]);
503 ip_port_tcp_s.ip.family = TOX_AF_INET6; 522 ip_port_tcp_s.ip = get_loopback();
504 ip_port_tcp_s.ip.ip6 = get_ip6_loopback();
505 TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0); 523 TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0);
506 c_sleep(50); 524 c_sleep(50);
507 do_TCP_connection(conn, NULL); 525 do_TCP_connection(conn, NULL);
@@ -553,7 +571,7 @@ START_TEST(test_tcp_connection)
553 uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; 571 uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
554 uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; 572 uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
555 crypto_new_keypair(self_public_key, self_secret_key); 573 crypto_new_keypair(self_public_key, self_secret_key);
556 TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); 574 TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, NULL);
557 ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key"); 575 ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key");
558 576
559 TCP_Proxy_Info proxy_info; 577 TCP_Proxy_Info proxy_info;
@@ -569,8 +587,7 @@ START_TEST(test_tcp_connection)
569 IP_Port ip_port_tcp_s; 587 IP_Port ip_port_tcp_s;
570 588
571 ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); 589 ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]);
572 ip_port_tcp_s.ip.family = TOX_AF_INET6; 590 ip_port_tcp_s.ip = get_loopback();
573 ip_port_tcp_s.ip.ip6 = get_ip6_loopback();
574 591
575 int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123); 592 int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123);
576 ck_assert_msg(connection == 0, "Connection id wrong"); 593 ck_assert_msg(connection == 0, "Connection id wrong");
@@ -662,7 +679,7 @@ START_TEST(test_tcp_connection2)
662 uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; 679 uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
663 uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; 680 uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
664 crypto_new_keypair(self_public_key, self_secret_key); 681 crypto_new_keypair(self_public_key, self_secret_key);
665 TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); 682 TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, NULL);
666 ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key"); 683 ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key");
667 684
668 TCP_Proxy_Info proxy_info; 685 TCP_Proxy_Info proxy_info;
@@ -678,8 +695,7 @@ START_TEST(test_tcp_connection2)
678 IP_Port ip_port_tcp_s; 695 IP_Port ip_port_tcp_s;
679 696
680 ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]); 697 ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]);
681 ip_port_tcp_s.ip.family = TOX_AF_INET6; 698 ip_port_tcp_s.ip = get_loopback();
682 ip_port_tcp_s.ip.ip6 = get_ip6_loopback();
683 699
684 int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123); 700 int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123);
685 ck_assert_msg(connection == 0, "Connection id wrong"); 701 ck_assert_msg(connection == 0, "Connection id wrong");
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c
index 5a4f8005..3125454a 100644
--- a/auto_tests/dht_test.c
+++ b/auto_tests/dht_test.c
@@ -25,6 +25,22 @@ static bool enable_broken_tests = false;
25 memcpy(&x,swap_temp,sizeof(x)); \ 25 memcpy(&x,swap_temp,sizeof(x)); \
26 } while(0) 26 } while(0)
27 27
28#ifndef USE_IPV6
29#define USE_IPV6 1
30#endif
31
32static inline IP get_loopback()
33{
34 IP ip;
35#if USE_IPV6
36 ip.family = TOX_AF_INET6;
37 ip.ip6 = get_ip6_loopback();
38#else
39 ip.family = TOX_AF_INET;
40 ip.ip4 = get_ip4_loopback();
41#endif
42 return ip;
43}
28 44
29static void mark_bad(IPPTsPng *ipptp) 45static void mark_bad(IPPTsPng *ipptp)
30{ 46{
@@ -615,8 +631,7 @@ loop_top:
615 631
616 for (i = 0; i < NUM_DHT; ++i) { 632 for (i = 0; i < NUM_DHT; ++i) {
617 IP_Port ip_port; 633 IP_Port ip_port;
618 ip_init(&ip_port.ip, 1); 634 ip_port.ip = get_loopback();
619 ip_port.ip.ip6.uint8[15] = 1;
620 ip_port.port = net_htons(DHT_DEFAULT_PORT + i); 635 ip_port.port = net_htons(DHT_DEFAULT_PORT + i);
621 DHT_bootstrap(dhts[(i - 1) % NUM_DHT], ip_port, dhts[i]->self_public_key); 636 DHT_bootstrap(dhts[(i - 1) % NUM_DHT], ip_port, dhts[i]->self_public_key);
622 } 637 }
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c
index a0d4f4bc..16acf676 100644
--- a/auto_tests/onion_test.c
+++ b/auto_tests/onion_test.c
@@ -19,6 +19,22 @@
19 19
20#include "helpers.h" 20#include "helpers.h"
21 21
22#ifndef USE_IPV6
23#define USE_IPV6 1
24#endif
25
26static inline IP get_loopback()
27{
28 IP ip;
29#if USE_IPV6
30 ip.family = TOX_AF_INET6;
31 ip.ip6 = get_ip6_loopback();
32#else
33 ip.family = TOX_AF_INET;
34 ip.ip4 = get_ip4_loopback();
35#endif
36 return ip;
37}
22static void do_onion(Onion *onion) 38static void do_onion(Onion *onion)
23{ 39{
24 networking_poll(onion->net, NULL); 40 networking_poll(onion->net, NULL);
@@ -141,9 +157,7 @@ static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, ui
141 157
142START_TEST(test_basic) 158START_TEST(test_basic)
143{ 159{
144 IP ip; 160 IP ip = get_loopback();
145 ip_init(&ip, 1);
146 ip.ip6.uint8[15] = 1;
147 Onion *onion1 = new_onion(new_DHT(NULL, new_networking(NULL, ip, 34567), true)); 161 Onion *onion1 = new_onion(new_DHT(NULL, new_networking(NULL, ip, 34567), true));
148 Onion *onion2 = new_onion(new_DHT(NULL, new_networking(NULL, ip, 34568), true)); 162 Onion *onion2 = new_onion(new_DHT(NULL, new_networking(NULL, ip, 34568), true));
149 ck_assert_msg((onion1 != NULL) && (onion2 != NULL), "Onion failed initializing."); 163 ck_assert_msg((onion1 != NULL) && (onion2 != NULL), "Onion failed initializing.");
@@ -281,8 +295,7 @@ typedef struct {
281 295
282static Onions *new_onions(uint16_t port) 296static Onions *new_onions(uint16_t port)
283{ 297{
284 IP ip; 298 IP ip = get_loopback();
285 ip_init(&ip, 1);
286 ip.ip6.uint8[15] = 1; 299 ip.ip6.uint8[15] = 1;
287 Onions *on = (Onions *)malloc(sizeof(Onions)); 300 Onions *on = (Onions *)malloc(sizeof(Onions));
288 DHT *dht = new_DHT(NULL, new_networking(NULL, ip, port), true); 301 DHT *dht = new_DHT(NULL, new_networking(NULL, ip, port), true);
@@ -386,9 +399,7 @@ START_TEST(test_announce)
386 ck_assert_msg(onions[i] != 0, "Failed to create onions. %u"); 399 ck_assert_msg(onions[i] != 0, "Failed to create onions. %u");
387 } 400 }
388 401
389 IP ip; 402 IP ip = get_loopback();
390 ip_init(&ip, 1);
391 ip.ip6.uint8[15] = 1;
392 403
393 for (i = 3; i < NUM_ONIONS; ++i) { 404 for (i = 3; i < NUM_ONIONS; ++i) {
394 IP_Port ip_port = {ip, onions[i - 1]->onion->net->port}; 405 IP_Port ip_port = {ip, onions[i - 1]->onion->net->port};