Skip to content

Commit d3b935f

Browse files
committed
fix(test): tests use ipv6 by default, even with USE_IPV6 set to 0
1 parent 29fc5ea commit d3b935f

File tree

6 files changed

+44
-14
lines changed

6 files changed

+44
-14
lines changed

auto_tests/auto_test_support.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#define ABORT_ON_LOG_ERROR true
1414
#endif
1515

16+
#ifndef USE_IPV6
17+
#define USE_IPV6 1
18+
#endif
19+
1620
Run_Auto_Options default_run_auto_options(void)
1721
{
1822
return (Run_Auto_Options) {
@@ -193,6 +197,7 @@ void reload(AutoTox *autotox)
193197

194198
struct Tox_Options *const options = tox_options_new(nullptr);
195199
ck_assert(options != nullptr);
200+
tox_options_set_ipv6_enabled(options, USE_IPV6);
196201
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
197202
tox_options_set_savedata_data(options, autotox->save_state, autotox->save_size);
198203
autotox->tox = tox_new_log(options, nullptr, &autotox->index);
@@ -214,6 +219,8 @@ static void initialise_autotox(struct Tox_Options *options, AutoTox *autotox, ui
214219
struct Tox_Options *default_opts = tox_options_new(nullptr);
215220
ck_assert(default_opts != nullptr);
216221

222+
tox_options_set_ipv6_enabled(default_opts, USE_IPV6);
223+
217224
if (options == nullptr) {
218225
options = default_opts;
219226
}
@@ -426,6 +433,7 @@ Tox *tox_new_log_lan(struct Tox_Options *options, Tox_Err_New *err, void *log_us
426433

427434
assert(log_options != nullptr);
428435

436+
tox_options_set_ipv6_enabled(log_options, USE_IPV6);
429437
tox_options_set_local_discovery_enabled(log_options, lan_discovery);
430438
// Use a higher start port for non-LAN-discovery tests so it's more likely for the LAN discovery
431439
// test to get the default port 33445.

auto_tests/file_streaming_test.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
#include "auto_test_support.h"
1414
#include "check_compat.h"
1515

16-
/* The Travis-CI container responds poorly to ::1 as a localhost address
17-
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
18-
#ifdef FORCE_TESTS_IPV6
16+
#ifndef USE_IPV6
17+
#define USE_IPV6 1
18+
#endif
19+
20+
#ifdef TOX_LOCALHOST
21+
#undef TOX_LOCALHOST
22+
#endif
23+
#if USE_IPV6
1924
#define TOX_LOCALHOST "::1"
2025
#else
2126
#define TOX_LOCALHOST "127.0.0.1"

auto_tests/file_transfer_test.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
#include "auto_test_support.h"
1414
#include "check_compat.h"
1515

16-
/* The Travis-CI container responds poorly to ::1 as a localhost address
17-
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
18-
#ifdef FORCE_TESTS_IPV6
16+
#ifndef USE_IPV6
17+
#define USE_IPV6 1
18+
#endif
19+
20+
#ifdef TOX_LOCALHOST
21+
#undef TOX_LOCALHOST
22+
#endif
23+
#if USE_IPV6
1924
#define TOX_LOCALHOST "::1"
2025
#else
2126
#define TOX_LOCALHOST "127.0.0.1"

auto_tests/save_load_test.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
#include "auto_test_support.h"
1515
#include "check_compat.h"
1616

17-
/* The Travis-CI container responds poorly to ::1 as a localhost address
18-
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
17+
#ifndef USE_IPV6
18+
#define USE_IPV6 1
19+
#endif
20+
1921
#ifdef TOX_LOCALHOST
2022
#undef TOX_LOCALHOST
2123
#endif
22-
#ifdef FORCE_TESTS_IPV6
24+
#if USE_IPV6
2325
#define TOX_LOCALHOST "::1"
2426
#else
2527
#define TOX_LOCALHOST "127.0.0.1"
@@ -74,6 +76,7 @@ static void reload_tox(Tox **tox, struct Tox_Options *const in_opts, void *user_
7476
}
7577

7678
struct Tox_Options *const options = (in_opts == nullptr) ? tox_options_new(nullptr) : in_opts;
79+
tox_options_set_ipv6_enabled(options, USE_IPV6);
7780

7881
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
7982

@@ -138,19 +141,22 @@ static void test_few_clients(void)
138141
time_t con_time = 0, cur_time = time(nullptr);
139142

140143
struct Tox_Options *opts1 = tox_options_new(nullptr);
144+
tox_options_set_ipv6_enabled(opts1, USE_IPV6);
141145
tox_options_set_tcp_port(opts1, TCP_RELAY_PORT);
142146
Tox_Err_New t_n_error;
143147
Tox *tox1 = tox_new_log(opts1, &t_n_error, &index[0]);
144148
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error);
145149
tox_options_free(opts1);
146150

147151
struct Tox_Options *opts2 = tox_options_new(nullptr);
152+
tox_options_set_ipv6_enabled(opts2, USE_IPV6);
148153
tox_options_set_udp_enabled(opts2, false);
149154
tox_options_set_local_discovery_enabled(opts2, false);
150155
Tox *tox2 = tox_new_log(opts2, &t_n_error, &index[1]);
151156
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error);
152157

153158
struct Tox_Options *opts3 = tox_options_new(nullptr);
159+
tox_options_set_ipv6_enabled(opts3, USE_IPV6);
154160
tox_options_set_local_discovery_enabled(opts3, false);
155161
Tox *tox3 = tox_new_log(opts3, &t_n_error, &index[2]);
156162
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error);

auto_tests/tox_many_tcp_test.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
#include "auto_test_support.h"
1414
#include "check_compat.h"
1515

16-
/* The Travis-CI container responds poorly to ::1 as a localhost address
17-
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
18-
#ifdef FORCE_TESTS_IPV6
16+
#ifndef USE_IPV6
17+
#define USE_IPV6 1
18+
#endif
19+
20+
#ifdef TOX_LOCALHOST
21+
#undef TOX_LOCALHOST
22+
#endif
23+
#if USE_IPV6
1924
#define TOX_LOCALHOST "::1"
2025
#else
2126
#define TOX_LOCALHOST "127.0.0.1"

toxcore/network.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,9 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe
946946
if (net_family_is_ipv4(net->family) && !net_family_is_ipv4(ipp_copy.ip.family)) {
947947
// TODO(iphydf): Make this an error. Occasionally we try to send to an
948948
// all-zero ip_port.
949-
LOGGER_WARNING(net->log, "attempted to send message with network family %d (probably IPv6) on IPv4 socket",
950-
ipp_copy.ip.family.value);
949+
Ip_Ntoa ip_str;
950+
LOGGER_WARNING(net->log, "attempted to send message with network family %d (probably IPv6) on IPv4 socket (%s)",
951+
ipp_copy.ip.family.value, net_ip_ntoa(&ipp_copy.ip, &ip_str));
951952
return -1;
952953
}
953954

0 commit comments

Comments
 (0)