Merge commit 'ff3512a77e6690b0fa2bdaf691cca5317eb32367' into net_prof
This commit is contained in:
@ -9,7 +9,9 @@ if(TARGET toxcore_static)
|
||||
else()
|
||||
target_link_libraries(auto_test_support PRIVATE toxcore_shared)
|
||||
endif()
|
||||
if(TARGET PThreads4W::PThreads4W)
|
||||
if(TARGET pthreads4w::pthreads4w)
|
||||
target_link_libraries(auto_test_support PRIVATE pthreads4w::pthreads4w)
|
||||
elseif(TARGET PThreads4W::PThreads4W)
|
||||
target_link_libraries(auto_test_support PRIVATE PThreads4W::PThreads4W)
|
||||
elseif(TARGET Threads::Threads)
|
||||
target_link_libraries(auto_test_support PRIVATE Threads::Threads)
|
||||
@ -23,7 +25,9 @@ function(auto_test target)
|
||||
else()
|
||||
target_link_libraries(auto_${target}_test PRIVATE toxcore_shared)
|
||||
endif()
|
||||
if(TARGET PThreads4W::PThreads4W)
|
||||
if(TARGET pthreads4w::pthreads4w)
|
||||
target_link_libraries(auto_${target}_test PRIVATE pthreads4w::pthreads4w)
|
||||
elseif(TARGET PThreads4W::PThreads4W)
|
||||
target_link_libraries(auto_${target}_test PRIVATE PThreads4W::PThreads4W)
|
||||
elseif(TARGET Threads::Threads)
|
||||
target_link_libraries(auto_${target}_test PRIVATE Threads::Threads)
|
||||
@ -67,6 +71,7 @@ auto_test(invalid_udp_proxy)
|
||||
auto_test(lan_discovery)
|
||||
auto_test(lossless_packet)
|
||||
auto_test(lossy_packet)
|
||||
auto_test(netprof)
|
||||
auto_test(network)
|
||||
auto_test(onion)
|
||||
auto_test(overflow_recvq)
|
||||
@ -98,7 +103,10 @@ if(BUILD_TOXAV)
|
||||
auto_test(toxav_basic)
|
||||
auto_test(toxav_many)
|
||||
|
||||
if(MSVC)
|
||||
if(TARGET libvpx::libvpx)
|
||||
target_link_libraries(auto_toxav_basic_test PRIVATE libvpx::libvpx)
|
||||
target_link_libraries(auto_toxav_many_test PRIVATE libvpx::libvpx)
|
||||
elseif(TARGET PkgConfig::VPX)
|
||||
target_link_libraries(auto_toxav_basic_test PRIVATE PkgConfig::VPX)
|
||||
target_link_libraries(auto_toxav_many_test PRIVATE PkgConfig::VPX)
|
||||
else()
|
||||
|
34
external/toxcore/c-toxcore/auto_tests/TCP_test.c
vendored
34
external/toxcore/c-toxcore/auto_tests/TCP_test.c
vendored
@ -53,7 +53,7 @@ static void test_basic(void)
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
Logger *logger = logger_new(mem);
|
||||
logger_callback_log(logger, print_debug_logger, nullptr, nullptr);
|
||||
|
||||
// Attempt to create a new TCP_Server instance.
|
||||
@ -74,7 +74,7 @@ static void test_basic(void)
|
||||
for (uint8_t i = 0; i < NUM_PORTS; i++) {
|
||||
sock = net_socket(ns, net_family_ipv6(), TOX_SOCK_STREAM, TOX_PROTO_TCP);
|
||||
localhost.port = net_htons(ports[i]);
|
||||
bool ret = net_connect(mem, logger, sock, &localhost);
|
||||
bool ret = net_connect(ns, mem, logger, sock, &localhost);
|
||||
ck_assert_msg(ret, "Failed to connect to created TCP relay server on port %d (%d).", ports[i], errno);
|
||||
|
||||
// Leave open one connection for the next test.
|
||||
@ -111,12 +111,12 @@ static void test_basic(void)
|
||||
|
||||
// Sending the handshake
|
||||
ck_assert_msg(net_send(ns, logger, sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||
&localhost) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||
&localhost, nullptr) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||
"An attempt to send the initial handshake minus last byte failed.");
|
||||
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost) == 1,
|
||||
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost, nullptr) == 1,
|
||||
"The attempt to send the last byte of handshake failed.");
|
||||
|
||||
free(handshake);
|
||||
@ -155,7 +155,7 @@ static void test_basic(void)
|
||||
msg_length = sizeof(r_req) - i;
|
||||
}
|
||||
|
||||
ck_assert_msg(net_send(ns, logger, sock, r_req + i, msg_length, &localhost) == msg_length,
|
||||
ck_assert_msg(net_send(ns, logger, sock, r_req + i, msg_length, &localhost, nullptr) == msg_length,
|
||||
"Failed to send request after completing the handshake.");
|
||||
i += msg_length;
|
||||
|
||||
@ -213,7 +213,7 @@ static struct sec_TCP_con *new_tcp_con(const Logger *logger, const Memory *mem,
|
||||
localhost.ip = get_loopback();
|
||||
localhost.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||
|
||||
bool ok = net_connect(mem, logger, sock, &localhost);
|
||||
bool ok = net_connect(ns, mem, logger, sock, &localhost);
|
||||
ck_assert_msg(ok, "Failed to connect to the test TCP relay server.");
|
||||
|
||||
uint8_t f_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
@ -234,12 +234,12 @@ static struct sec_TCP_con *new_tcp_con(const Logger *logger, const Memory *mem,
|
||||
"Failed to encrypt the outgoing handshake.");
|
||||
|
||||
ck_assert_msg(net_send(ns, logger, sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||
&localhost) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||
&localhost, nullptr) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||
"Failed to send the first portion of the handshake to the TCP relay server.");
|
||||
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost) == 1,
|
||||
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost, nullptr) == 1,
|
||||
"Failed to send last byte of handshake.");
|
||||
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
@ -283,7 +283,7 @@ static int write_packet_tcp_test_connection(const Logger *logger, struct sec_TCP
|
||||
localhost.ip = get_loopback();
|
||||
localhost.port = 0;
|
||||
|
||||
ck_assert_msg(net_send(con->ns, logger, con->sock, packet, packet_size, &localhost) == packet_size,
|
||||
ck_assert_msg(net_send(con->ns, logger, con->sock, packet, packet_size, &localhost, nullptr) == packet_size,
|
||||
"Failed to send a packet.");
|
||||
return 0;
|
||||
}
|
||||
@ -312,7 +312,7 @@ static void test_some(void)
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
Logger *logger = logger_new(mem);
|
||||
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
@ -506,7 +506,7 @@ static void test_client(void)
|
||||
const Memory *mem = os_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Logger *logger = logger_new();
|
||||
Logger *logger = logger_new(mem);
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
@ -524,7 +524,7 @@ static void test_client(void)
|
||||
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||
ip_port_tcp_s.ip = get_loopback();
|
||||
|
||||
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr);
|
||||
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr, nullptr);
|
||||
// TCP sockets might need a moment before they can be written to.
|
||||
c_sleep(50);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
@ -560,7 +560,7 @@ static void test_client(void)
|
||||
crypto_new_keypair(rng, f2_public_key, f2_secret_key);
|
||||
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||
TCP_Client_Connection *conn2 = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f2_public_key,
|
||||
f2_secret_key, nullptr);
|
||||
f2_secret_key, nullptr, nullptr);
|
||||
c_sleep(50);
|
||||
|
||||
// The client should call this function (defined earlier) during the routing process.
|
||||
@ -643,7 +643,7 @@ static void test_client_invalid(void)
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
Logger *logger = logger_new(mem);
|
||||
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
@ -657,7 +657,7 @@ static void test_client_invalid(void)
|
||||
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||
ip_port_tcp_s.ip = get_loopback();
|
||||
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s,
|
||||
self_public_key, f_public_key, f_secret_key, nullptr);
|
||||
self_public_key, f_public_key, f_secret_key, nullptr, nullptr);
|
||||
|
||||
// Run the client's main loop but not the server.
|
||||
mono_time_update(mono_time);
|
||||
@ -721,7 +721,7 @@ static void test_tcp_connection(void)
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
Logger *logger = logger_new(mem);
|
||||
|
||||
tcp_data_callback_called = 0;
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
@ -834,7 +834,7 @@ static void test_tcp_connection2(void)
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
Logger *logger = logger_new(mem);
|
||||
|
||||
tcp_oobdata_callback_called = 0;
|
||||
tcp_data_callback_called = 0;
|
||||
|
@ -57,7 +57,7 @@ static void test_store_data(void)
|
||||
const Memory *mem = os_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Logger *log = logger_new();
|
||||
Logger *log = logger_new(mem);
|
||||
ck_assert(log != nullptr);
|
||||
logger_callback_log(log, print_debug_logger, nullptr, nullptr);
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
|
@ -3,8 +3,6 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <sodium.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
@ -14,13 +12,10 @@
|
||||
#include "check_compat.h"
|
||||
|
||||
static unsigned char test_salt[TOX_PASS_SALT_LENGTH] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F};
|
||||
static unsigned char known_key[TOX_PASS_KEY_LENGTH] = {0x29, 0x36, 0x1c, 0x9e, 0x65, 0xbb, 0x46, 0x8b, 0xde, 0xa1, 0xac, 0xf, 0xd5, 0x11, 0x81, 0xc8, 0x29, 0x28, 0x17, 0x23, 0xa6, 0xc3, 0x6b, 0x77, 0x2e, 0xd7, 0xd3, 0x10, 0xeb, 0xd2, 0xf7, 0xc8};
|
||||
static unsigned char known_key[CRYPTO_SHARED_KEY_SIZE] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1};
|
||||
static const char *pw = "hunter2";
|
||||
static unsigned int pwlen = 7;
|
||||
|
||||
static unsigned char known_key2[CRYPTO_SHARED_KEY_SIZE] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1};
|
||||
// same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat
|
||||
|
||||
/* cause I'm shameless */
|
||||
static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
|
||||
{
|
||||
@ -33,20 +28,6 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
|
||||
}
|
||||
}
|
||||
|
||||
static void test_known_kdf(void)
|
||||
{
|
||||
unsigned char out[CRYPTO_SHARED_KEY_SIZE];
|
||||
int16_t res = crypto_pwhash_scryptsalsa208sha256(out,
|
||||
CRYPTO_SHARED_KEY_SIZE,
|
||||
pw,
|
||||
pwlen,
|
||||
test_salt,
|
||||
crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE * 8,
|
||||
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE);
|
||||
ck_assert_msg(res != -1, "crypto function failed");
|
||||
ck_assert_msg(memcmp(out, known_key, CRYPTO_SHARED_KEY_SIZE) == 0, "derived key is wrong");
|
||||
}
|
||||
|
||||
static void test_save_friend(void)
|
||||
{
|
||||
Tox *tox1 = tox_new_log(nullptr, nullptr, nullptr);
|
||||
@ -101,7 +82,7 @@ static void test_save_friend(void)
|
||||
Tox_Pass_Key *key = tox_pass_key_derive((const uint8_t *)"123qweasdzxc", 12, &keyerr);
|
||||
ck_assert_msg(key != nullptr, "pass key allocation failure");
|
||||
memcpy((uint8_t *)key, test_salt, TOX_PASS_SALT_LENGTH);
|
||||
memcpy((uint8_t *)key + TOX_PASS_SALT_LENGTH, known_key2, TOX_PASS_KEY_LENGTH);
|
||||
memcpy((uint8_t *)key + TOX_PASS_SALT_LENGTH, known_key, TOX_PASS_KEY_LENGTH);
|
||||
size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
|
||||
uint8_t *encdata2 = (uint8_t *)malloc(size2);
|
||||
ck_assert(encdata2 != nullptr);
|
||||
@ -224,7 +205,6 @@ static void test_keys(void)
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
test_known_kdf();
|
||||
test_save_friend();
|
||||
test_keys();
|
||||
|
||||
|
@ -112,7 +112,7 @@ static Forwarding_Subtox *new_forwarding_subtox(const Memory *mem, bool no_udp,
|
||||
Forwarding_Subtox *subtox = (Forwarding_Subtox *)calloc(1, sizeof(Forwarding_Subtox));
|
||||
ck_assert(subtox != nullptr);
|
||||
|
||||
subtox->log = logger_new();
|
||||
subtox->log = logger_new(mem);
|
||||
ck_assert(subtox->log != nullptr);
|
||||
logger_callback_log(subtox->log, print_debug_logger, nullptr, index);
|
||||
subtox->mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
|
@ -10,44 +10,57 @@
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
#include "../testing/misc_tools.h"
|
||||
|
||||
#include "auto_test_support.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#define FR_MESSAGE "Gentoo"
|
||||
#define REQUEST_MESSAGE "Hello, I would like to be your friend. Please respond."
|
||||
|
||||
static void accept_friend_request(const Tox_Event_Friend_Request *event,
|
||||
void *userdata)
|
||||
typedef struct Callback_Data {
|
||||
Tox *tox1; // request sender
|
||||
Tox *tox2; // request receiver
|
||||
uint8_t message[TOX_MAX_FRIEND_REQUEST_LENGTH];
|
||||
uint16_t length;
|
||||
} Callback_Data;
|
||||
|
||||
static void accept_friend_request(const Tox_Event_Friend_Request *event, void *userdata)
|
||||
{
|
||||
Tox *state_tox = (Tox *)userdata;
|
||||
Callback_Data *cb_data = (Callback_Data *)userdata;
|
||||
|
||||
const uint8_t *public_key = tox_event_friend_request_get_public_key(event);
|
||||
const uint8_t *data = tox_event_friend_request_get_message(event);
|
||||
const size_t length = tox_event_friend_request_get_message_length(event);
|
||||
|
||||
ck_assert_msg(length == sizeof(FR_MESSAGE) && memcmp(FR_MESSAGE, data, sizeof(FR_MESSAGE)) == 0,
|
||||
ck_assert_msg(length == cb_data->length && memcmp(cb_data->message, data, cb_data->length) == 0,
|
||||
"unexpected friend request message");
|
||||
tox_friend_add_norequest(state_tox, public_key, nullptr);
|
||||
|
||||
fprintf(stderr, "Tox2 accepts friend request.\n");
|
||||
|
||||
Tox_Err_Friend_Add err;
|
||||
tox_friend_add_norequest(cb_data->tox2, public_key, &err);
|
||||
|
||||
ck_assert_msg(err == TOX_ERR_FRIEND_ADD_OK, "tox_friend_add_norequest failed: %d", err);
|
||||
}
|
||||
|
||||
static void iterate2_wait(const Tox_Dispatch *dispatch, Tox *tox1, Tox *tox2)
|
||||
static void iterate2_wait(const Tox_Dispatch *dispatch, Callback_Data *cb_data)
|
||||
{
|
||||
Tox_Err_Events_Iterate err;
|
||||
Tox_Events *events;
|
||||
|
||||
events = tox_events_iterate(tox1, true, &err);
|
||||
events = tox_events_iterate(cb_data->tox1, true, &err);
|
||||
ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK);
|
||||
tox_dispatch_invoke(dispatch, events, tox1);
|
||||
tox_dispatch_invoke(dispatch, events, cb_data);
|
||||
tox_events_free(events);
|
||||
|
||||
events = tox_events_iterate(tox2, true, &err);
|
||||
events = tox_events_iterate(cb_data->tox2, true, &err);
|
||||
ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK);
|
||||
tox_dispatch_invoke(dispatch, events, tox2);
|
||||
tox_dispatch_invoke(dispatch, events, cb_data);
|
||||
tox_events_free(events);
|
||||
|
||||
c_sleep(ITERATION_INTERVAL);
|
||||
}
|
||||
|
||||
static void test_friend_request(void)
|
||||
static void test_friend_request(const uint8_t *message, uint16_t length)
|
||||
{
|
||||
printf("Initialising 2 toxes.\n");
|
||||
uint32_t index[] = { 1, 2 };
|
||||
@ -60,7 +73,7 @@ static void test_friend_request(void)
|
||||
tox_events_init(tox1);
|
||||
tox_events_init(tox2);
|
||||
|
||||
printf("Bootstrapping tox2 off tox1.\n");
|
||||
printf("Bootstrapping Tox2 off Tox1.\n");
|
||||
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(tox1, dht_key);
|
||||
const uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr);
|
||||
@ -70,25 +83,36 @@ static void test_friend_request(void)
|
||||
Tox_Dispatch *dispatch = tox_dispatch_new(nullptr);
|
||||
ck_assert(dispatch != nullptr);
|
||||
|
||||
Callback_Data cb_data = {nullptr};
|
||||
cb_data.tox1 = tox1;
|
||||
cb_data.tox2 = tox2;
|
||||
|
||||
ck_assert(length <= sizeof(cb_data.message));
|
||||
memcpy(cb_data.message, message, length);
|
||||
cb_data.length = length;
|
||||
|
||||
do {
|
||||
iterate2_wait(dispatch, tox1, tox2);
|
||||
iterate2_wait(dispatch, &cb_data);
|
||||
} while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE ||
|
||||
tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE);
|
||||
|
||||
printf("Toxes are online, took %lu seconds.\n", (unsigned long)(time(nullptr) - cur_time));
|
||||
const time_t con_time = time(nullptr);
|
||||
|
||||
printf("Tox1 adds tox2 as friend, tox2 accepts.\n");
|
||||
printf("Tox1 adds Tox2 as friend. Waiting for Tox2 to accept.\n");
|
||||
tox_events_callback_friend_request(dispatch, accept_friend_request);
|
||||
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(tox2, address);
|
||||
|
||||
const uint32_t test = tox_friend_add(tox1, address, (const uint8_t *)FR_MESSAGE, sizeof(FR_MESSAGE), nullptr);
|
||||
Tox_Err_Friend_Add err;
|
||||
const uint32_t test = tox_friend_add(tox1, address, message, length, &err);
|
||||
|
||||
ck_assert_msg(err == TOX_ERR_FRIEND_ADD_OK, "tox_friend_add failed: %d", err);
|
||||
ck_assert_msg(test == 0, "failed to add friend error code: %u", test);
|
||||
|
||||
do {
|
||||
iterate2_wait(dispatch, tox1, tox2);
|
||||
iterate2_wait(dispatch, &cb_data);
|
||||
} while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP ||
|
||||
tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP);
|
||||
|
||||
@ -104,6 +128,20 @@ int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
test_friend_request();
|
||||
fprintf(stderr, "Testing friend request with the smallest allowed message length.\n");
|
||||
test_friend_request((const uint8_t *)"a", 1);
|
||||
|
||||
fprintf(stderr, "Testing friend request with an average sized message length.\n");
|
||||
test_friend_request((const uint8_t *)REQUEST_MESSAGE, sizeof(REQUEST_MESSAGE) - 1);
|
||||
|
||||
uint8_t long_message[TOX_MAX_FRIEND_REQUEST_LENGTH];
|
||||
|
||||
for (uint16_t i = 0; i < sizeof(long_message); ++i) {
|
||||
long_message[i] = 'a';
|
||||
}
|
||||
|
||||
fprintf(stderr, "Testing friend request with the largest allowed message length.\n");
|
||||
test_friend_request(long_message, sizeof(long_message));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
121
external/toxcore/c-toxcore/auto_tests/netprof_test.c
vendored
Normal file
121
external/toxcore/c-toxcore/auto_tests/netprof_test.c
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
/** Auto Tests: basic network profile functionality test (UDP only)
|
||||
* TODO(JFreegman): test TCP packets as well
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../toxcore/tox_private.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "auto_test_support.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#define NUM_TOXES 2
|
||||
|
||||
static void test_netprof(AutoTox *autotoxes)
|
||||
{
|
||||
// Send some messages to create fake traffic
|
||||
for (size_t i = 0; i < 256; ++i) {
|
||||
for (uint32_t j = 0; j < NUM_TOXES; ++j) {
|
||||
tox_friend_send_message(autotoxes[j].tox, 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"test", 4, nullptr);
|
||||
}
|
||||
|
||||
iterate_all_wait(autotoxes, NUM_TOXES, ITERATION_INTERVAL);
|
||||
}
|
||||
|
||||
// idle traffic for a while
|
||||
for (size_t i = 0; i < 100; ++i) {
|
||||
iterate_all_wait(autotoxes, NUM_TOXES, ITERATION_INTERVAL);
|
||||
}
|
||||
|
||||
const Tox *tox1 = autotoxes[0].tox;
|
||||
|
||||
const uint64_t UDP_count_sent1 = tox_netprof_get_packet_total_count(tox1, TOX_NETPROF_PACKET_TYPE_UDP,
|
||||
TOX_NETPROF_DIRECTION_SENT);
|
||||
const uint64_t UDP_count_recv1 = tox_netprof_get_packet_total_count(tox1, TOX_NETPROF_PACKET_TYPE_UDP,
|
||||
TOX_NETPROF_DIRECTION_RECV);
|
||||
const uint64_t TCP_count_sent1 = tox_netprof_get_packet_total_count(tox1, TOX_NETPROF_PACKET_TYPE_TCP,
|
||||
TOX_NETPROF_DIRECTION_SENT);
|
||||
const uint64_t TCP_count_recv1 = tox_netprof_get_packet_total_count(tox1, TOX_NETPROF_PACKET_TYPE_TCP,
|
||||
TOX_NETPROF_DIRECTION_RECV);
|
||||
|
||||
const uint64_t UDP_bytes_sent1 = tox_netprof_get_packet_total_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP,
|
||||
TOX_NETPROF_DIRECTION_SENT);
|
||||
const uint64_t UDP_bytes_recv1 = tox_netprof_get_packet_total_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP,
|
||||
TOX_NETPROF_DIRECTION_RECV);
|
||||
const uint64_t TCP_bytes_sent1 = tox_netprof_get_packet_total_bytes(tox1, TOX_NETPROF_PACKET_TYPE_TCP,
|
||||
TOX_NETPROF_DIRECTION_SENT);
|
||||
const uint64_t TCP_bytes_recv1 = tox_netprof_get_packet_total_bytes(tox1, TOX_NETPROF_PACKET_TYPE_TCP,
|
||||
TOX_NETPROF_DIRECTION_RECV);
|
||||
|
||||
ck_assert(UDP_count_recv1 > 0 && UDP_count_sent1 > 0);
|
||||
ck_assert(UDP_bytes_recv1 > 0 && UDP_bytes_sent1 > 0);
|
||||
|
||||
(void)TCP_count_sent1;
|
||||
(void)TCP_bytes_sent1;
|
||||
(void)TCP_bytes_recv1;
|
||||
(void)TCP_count_recv1;
|
||||
|
||||
uint64_t total_sent_count = 0;
|
||||
uint64_t total_recv_count = 0;
|
||||
uint64_t total_sent_bytes = 0;
|
||||
uint64_t total_recv_bytes = 0;
|
||||
|
||||
// tox1 makes sure the sum value of all packet ID's is equal to the totals
|
||||
for (size_t i = 0; i < 256; ++i) {
|
||||
// this id isn't valid for UDP packets but we still want to call the
|
||||
// functions and make sure they return some non-zero value
|
||||
if (i == TOX_NETPROF_PACKET_ID_TCP_DATA) {
|
||||
ck_assert(tox_netprof_get_packet_id_count(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||
TOX_NETPROF_DIRECTION_SENT) > 0);
|
||||
ck_assert(tox_netprof_get_packet_id_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||
TOX_NETPROF_DIRECTION_SENT) > 0);
|
||||
ck_assert(tox_netprof_get_packet_id_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||
TOX_NETPROF_DIRECTION_SENT) > 0);
|
||||
ck_assert(tox_netprof_get_packet_id_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||
TOX_NETPROF_DIRECTION_RECV) > 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
total_sent_count += tox_netprof_get_packet_id_count(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||
TOX_NETPROF_DIRECTION_SENT);
|
||||
total_recv_count += tox_netprof_get_packet_id_count(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||
TOX_NETPROF_DIRECTION_RECV);
|
||||
|
||||
total_sent_bytes += tox_netprof_get_packet_id_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||
TOX_NETPROF_DIRECTION_SENT);
|
||||
total_recv_bytes += tox_netprof_get_packet_id_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||
TOX_NETPROF_DIRECTION_RECV);
|
||||
}
|
||||
|
||||
const uint64_t total_packets = total_sent_count + total_recv_count;
|
||||
ck_assert_msg(total_packets == UDP_count_sent1 + UDP_count_recv1,
|
||||
"%" PRIu64 "does not match %" PRIu64 "\n", total_packets, UDP_count_sent1 + UDP_count_recv1);
|
||||
|
||||
ck_assert_msg(total_sent_count == UDP_count_sent1, "%" PRIu64 " does not match %" PRIu64 "\n", total_sent_count, UDP_count_sent1);
|
||||
ck_assert_msg(total_recv_count == UDP_count_recv1, "%" PRIu64 " does not match %" PRIu64"\n", total_recv_count, UDP_count_recv1);
|
||||
|
||||
|
||||
const uint64_t total_bytes = total_sent_bytes + total_recv_bytes;
|
||||
ck_assert_msg(total_bytes == UDP_bytes_sent1 + UDP_bytes_recv1,
|
||||
"%" PRIu64 "does not match %" PRIu64 "\n", total_bytes, UDP_bytes_sent1 + UDP_bytes_recv1);
|
||||
|
||||
ck_assert_msg(total_sent_bytes == UDP_bytes_sent1, "%" PRIu64 " does not match %" PRIu64 "\n", total_sent_bytes, UDP_bytes_sent1);
|
||||
ck_assert_msg(total_recv_bytes == UDP_bytes_recv1, "%" PRIu64 " does not match %" PRIu64 "\n", total_recv_bytes, UDP_bytes_recv1);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
Run_Auto_Options autotox_opts = default_run_auto_options();
|
||||
autotox_opts.graph = GRAPH_COMPLETE;
|
||||
|
||||
run_auto_test(nullptr, NUM_TOXES, test_netprof, 0, &autotox_opts);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#undef NUM_TOXES
|
@ -23,12 +23,15 @@ static void test_addr_resolv_localhost(void)
|
||||
const Network *ns = os_network();
|
||||
ck_assert(ns != nullptr);
|
||||
|
||||
const Memory *mem = os_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
const char localhost[] = "localhost";
|
||||
|
||||
IP ip;
|
||||
ip_init(&ip, 0); // ipv6enabled = 0
|
||||
|
||||
bool res = addr_resolve_or_parse_ip(ns, localhost, &ip, nullptr);
|
||||
bool res = addr_resolve_or_parse_ip(ns, mem, localhost, &ip, nullptr, true);
|
||||
|
||||
int error = net_error();
|
||||
char *strerror = net_new_strerror(error);
|
||||
@ -42,14 +45,14 @@ static void test_addr_resolv_localhost(void)
|
||||
net_ip_ntoa(&ip, &ip_str));
|
||||
|
||||
ip_init(&ip, 1); // ipv6enabled = 1
|
||||
res = addr_resolve_or_parse_ip(ns, localhost, &ip, nullptr);
|
||||
res = addr_resolve_or_parse_ip(ns, mem, localhost, &ip, nullptr, true);
|
||||
|
||||
#if USE_IPV6
|
||||
|
||||
int localhost_split = 0;
|
||||
|
||||
if (!net_family_is_ipv6(ip.family)) {
|
||||
res = addr_resolve_or_parse_ip(ns, "ip6-localhost", &ip, nullptr);
|
||||
res = addr_resolve_or_parse_ip(ns, mem, "ip6-localhost", &ip, nullptr, true);
|
||||
localhost_split = 1;
|
||||
}
|
||||
|
||||
@ -75,7 +78,7 @@ static void test_addr_resolv_localhost(void)
|
||||
ip.family = net_family_unspec();
|
||||
IP extra;
|
||||
ip_reset(&extra);
|
||||
res = addr_resolve_or_parse_ip(ns, localhost, &ip, &extra);
|
||||
res = addr_resolve_or_parse_ip(ns, mem, localhost, &ip, &extra, true);
|
||||
error = net_error();
|
||||
strerror = net_new_strerror(error);
|
||||
ck_assert_msg(res, "Resolver failed: %d, %s", error, strerror);
|
||||
|
@ -228,9 +228,9 @@ static void test_basic(void)
|
||||
const Random *rng = os_random();
|
||||
ck_assert(rng != nullptr);
|
||||
|
||||
Logger *log1 = logger_new();
|
||||
Logger *log1 = logger_new(mem);
|
||||
logger_callback_log(log1, print_debug_logger, nullptr, &index[0]);
|
||||
Logger *log2 = logger_new();
|
||||
Logger *log2 = logger_new(mem);
|
||||
logger_callback_log(log2, print_debug_logger, nullptr, &index[1]);
|
||||
|
||||
Mono_Time *mono_time1 = mono_time_new(mem, nullptr, nullptr);
|
||||
@ -329,7 +329,7 @@ static void test_basic(void)
|
||||
CRYPTO_PUBLIC_KEY_SIZE) != 0);
|
||||
|
||||
c_sleep(1000);
|
||||
Logger *log3 = logger_new();
|
||||
Logger *log3 = logger_new(mem);
|
||||
logger_callback_log(log3, print_debug_logger, nullptr, &index[2]);
|
||||
|
||||
Mono_Time *mono_time3 = mono_time_new(mem, nullptr, nullptr);
|
||||
@ -412,7 +412,7 @@ static Onions *new_onions(const Memory *mem, const Random *rng, uint16_t port, u
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
on->log = logger_new();
|
||||
on->log = logger_new(mem);
|
||||
|
||||
if (!on->log) {
|
||||
free(on);
|
||||
|
Reference in New Issue
Block a user