Skip to content

Commit

Permalink
fix(test): tests use ipv6 by default, even with USE_IPV6 set to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky committed Jan 15, 2024
1 parent d30c81a commit f81d8d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
8 changes: 8 additions & 0 deletions auto_tests/auto_test_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#define ABORT_ON_LOG_ERROR true
#endif

#ifndef USE_IPV6
#define USE_IPV6 1
#endif

Run_Auto_Options default_run_auto_options(void)
{
return (Run_Auto_Options) {
Expand Down Expand Up @@ -193,6 +197,7 @@ void reload(AutoTox *autotox)

struct Tox_Options *const options = tox_options_new(nullptr);
ck_assert(options != nullptr);
tox_options_set_ipv6_enabled(options, USE_IPV6);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, autotox->save_state, autotox->save_size);
autotox->tox = tox_new_log(options, nullptr, &autotox->index);
Expand All @@ -214,6 +219,8 @@ static void initialise_autotox(struct Tox_Options *options, AutoTox *autotox, ui
struct Tox_Options *default_opts = tox_options_new(nullptr);
ck_assert(default_opts != nullptr);

tox_options_set_ipv6_enabled(default_opts, USE_IPV6);

if (options == nullptr) {
options = default_opts;
}
Expand Down Expand Up @@ -426,6 +433,7 @@ Tox *tox_new_log_lan(struct Tox_Options *options, Tox_Err_New *err, void *log_us

assert(log_options != nullptr);

tox_options_set_ipv6_enabled(log_options, USE_IPV6);
tox_options_set_local_discovery_enabled(log_options, lan_discovery);
// Use a higher start port for non-LAN-discovery tests so it's more likely for the LAN discovery
// test to get the default port 33445.
Expand Down
12 changes: 9 additions & 3 deletions auto_tests/save_load_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
#include "auto_test_support.h"
#include "check_compat.h"

/* The Travis-CI container responds poorly to ::1 as a localhost address
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
#ifndef USE_IPV6
#define USE_IPV6 1
#endif

#ifdef TOX_LOCALHOST
#undef TOX_LOCALHOST
#endif
#ifdef FORCE_TESTS_IPV6
#if USE_IPV6
#define TOX_LOCALHOST "::1"
#else
#define TOX_LOCALHOST "127.0.0.1"
Expand Down Expand Up @@ -74,6 +76,7 @@ static void reload_tox(Tox **tox, struct Tox_Options *const in_opts, void *user_
}

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

tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);

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

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

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

struct Tox_Options *opts3 = tox_options_new(nullptr);
tox_options_set_ipv6_enabled(opts3, USE_IPV6);
tox_options_set_local_discovery_enabled(opts3, false);
Tox *tox3 = tox_new_log(opts3, &t_n_error, &index[2]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error);
Expand Down
5 changes: 3 additions & 2 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,9 @@ int send_packet(const Networking_Core *net, const IP_Port *ip_port, Packet packe
if (net_family_is_ipv4(net->family) && !net_family_is_ipv4(ipp_copy.ip.family)) {
// TODO(iphydf): Make this an error. Occasionally we try to send to an
// all-zero ip_port.
LOGGER_WARNING(net->log, "attempted to send message with network family %d (probably IPv6) on IPv4 socket",
ipp_copy.ip.family.value);
Ip_Ntoa ip_str;
LOGGER_WARNING(net->log, "attempted to send message with network family %d (probably IPv6) on IPv4 socket (%s)",
ipp_copy.ip.family.value, net_ip_ntoa(&ipp_copy.ip, &ip_str));

Check warning on line 951 in toxcore/network.c

View check run for this annotation

Codecov / codecov/patch

toxcore/network.c#L949-L951

Added lines #L949 - L951 were not covered by tests
return -1;
}

Expand Down

0 comments on commit f81d8d5

Please sign in to comment.