fix(test): tests use ipv6 by default, even with USE_IPV6 set to 0

This commit is contained in:
Green Sky 2023-12-14 00:56:56 +01:00
parent 29fc5ea1f7
commit d3b935f63f
No known key found for this signature in database
6 changed files with 44 additions and 14 deletions

View File

@ -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) {
@ -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);
@ -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;
}
@ -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.

View File

@ -13,9 +13,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 */
#ifdef FORCE_TESTS_IPV6
#ifndef USE_IPV6
#define USE_IPV6 1
#endif
#ifdef TOX_LOCALHOST
#undef TOX_LOCALHOST
#endif
#if USE_IPV6
#define TOX_LOCALHOST "::1"
#else
#define TOX_LOCALHOST "127.0.0.1"

View File

@ -13,9 +13,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 */
#ifdef FORCE_TESTS_IPV6
#ifndef USE_IPV6
#define USE_IPV6 1
#endif
#ifdef TOX_LOCALHOST
#undef TOX_LOCALHOST
#endif
#if USE_IPV6
#define TOX_LOCALHOST "::1"
#else
#define TOX_LOCALHOST "127.0.0.1"

View File

@ -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"
@ -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);
@ -138,6 +141,7 @@ 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]);
@ -145,12 +149,14 @@ static void test_few_clients(void)
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);

View File

@ -13,9 +13,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 */
#ifdef FORCE_TESTS_IPV6
#ifndef USE_IPV6
#define USE_IPV6 1
#endif
#ifdef TOX_LOCALHOST
#undef TOX_LOCALHOST
#endif
#if USE_IPV6
#define TOX_LOCALHOST "::1"
#else
#define TOX_LOCALHOST "127.0.0.1"

View File

@ -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));
return -1;
}