Skip to content

Commit

Permalink
test: Make ERROR logging fatal in tests.
Browse files Browse the repository at this point in the history
This doesn't currently work, because we get a lot of errors during tests.
This should not happen. Either those errors are warnings, or something is
wrong with either the code or the test.
  • Loading branch information
iphydf committed Dec 11, 2021
1 parent d66adbe commit e3feadf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
5 changes: 5 additions & 0 deletions testing/misc_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ void print_debug_log(Tox *m, Tox_Log_Level level, const char *file, uint32_t lin

uint32_t index = user_data ? *(uint32_t *)user_data : 0;
fprintf(stderr, "[#%u] %s %s:%u\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message);

if (level == TOX_LOG_LEVEL_ERROR) {
fputs("Aborting test program\n", stderr);
abort();
}
}

Tox *tox_new_log_lan(struct Tox_Options *options, Tox_Err_New *err, void *log_user_data, bool lan_discovery)
Expand Down
12 changes: 6 additions & 6 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,22 +498,22 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
uint32_t *message_id)
{
if (type > MESSAGE_ACTION) {
LOGGER_ERROR(m->log, "Message type %d is invalid", type);
LOGGER_WARNING(m->log, "Message type %d is invalid", type);
return -5;
}

if (!friend_is_valid(m, friendnumber)) {
LOGGER_ERROR(m->log, "Friend number %d is invalid", friendnumber);
LOGGER_WARNING(m->log, "Friend number %d is invalid", friendnumber);
return -1;
}

if (length >= MAX_CRYPTO_DATA_SIZE) {
LOGGER_ERROR(m->log, "Message length %u is too large", length);
LOGGER_WARNING(m->log, "Message length %u is too large", length);
return -2;
}

if (m->friendlist[friendnumber].status != FRIEND_ONLINE) {
LOGGER_ERROR(m->log, "Friend %d is not online", friendnumber);
LOGGER_WARNING(m->log, "Friend %d is not online", friendnumber);
return -3;
}

Expand All @@ -528,8 +528,8 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
m->friendlist[friendnumber].friendcon_id), packet, length + 1, 0);

if (packet_num == -1) {
LOGGER_ERROR(m->log, "Failed to write crypto packet for message of length %d to friend %d",
length, friendnumber);
LOGGER_WARNING(m->log, "Failed to write crypto packet for message of length %d to friend %d",
length, friendnumber);
return -4;
}

Expand Down
2 changes: 2 additions & 0 deletions toxcore/ccompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#ifndef C_TOXCORE_TOXCORE_CCOMPAT_H
#define C_TOXCORE_TOXCORE_CCOMPAT_H

#include <assert.h>

//!TOKSTYLE-

// Variable length arrays.
Expand Down
4 changes: 2 additions & 2 deletions toxcore/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,8 @@ static int cmp_u64(uint64_t a, uint64_t b)
/* Order peers with friends first and with more recently active earlier */
static int cmp_frozen(const void *a, const void *b)
{
const Group_Peer *pa = (const Group_Peer *) a;
const Group_Peer *pb = (const Group_Peer *) b;
const Group_Peer *pa = (const Group_Peer *)a;
const Group_Peer *pb = (const Group_Peer *)b;

if (pa->is_friend ^ pb->is_friend) {
return pa->is_friend ? -1 : 1;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void logger_write(const Logger *log, Logger_Level level, const char *file, int l
// The full path may contain PII of the person compiling toxcore (their
// username and directory layout).
const char *filename = strrchr(file, '/');
file = filename ? filename + 1 : file;
file = filename != nullptr ? filename + 1 : file;
#if defined(_WIN32) || defined(__CYGWIN__)
// On Windows, the path separator *may* be a backslash, so we look for that
// one too.
Expand Down
19 changes: 14 additions & 5 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,18 @@ uint16_t net_port(const Networking_Core *net)
int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint16_t length)
{
if (net_family_is_unspec(net->family)) { /* Socket not initialized */
LOGGER_ERROR(net->log, "attempted to send message of length %u on uninitialised socket", (unsigned)length);
// TODO(iphydf): Make this an error. Currently, the onion client calls
// this via DHT getnodes.
LOGGER_WARNING(net->log, "attempted to send message of length %u on uninitialised socket", (unsigned)length);
return -1;
}

/* socket TOX_AF_INET, but target IP NOT: can't send */
if (net_family_is_ipv4(net->family) && !net_family_is_ipv4(ip_port.ip.family)) {
LOGGER_ERROR(net->log, "attempted to send message with network family %d (probably IPv6) on IPv4 socket",
ip_port.ip.family.value);
// 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",
ip_port.ip.family.value);
return -1;
}

Expand Down Expand Up @@ -552,6 +556,8 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint1
addr6->sin6_flowinfo = 0;
addr6->sin6_scope_id = 0;
} else {
// TODO(iphydf): Make this an error. Currently this fails sometimes when
// called from DHT.c:do_ping_and_sendnode_requests.
LOGGER_WARNING(net->log, "unknown address type: %d", ip_port.ip.family.value);
return -1;
}
Expand Down Expand Up @@ -655,12 +661,15 @@ void networking_poll(Networking_Core *net, void *userdata)
continue;
}

if (!(net->packethandlers[data[0]].function)) {
packet_handler_cb *const cb = net->packethandlers[data[0]].function;
void *const object = net->packethandlers[data[0]].object;

if (cb == nullptr) {
LOGGER_WARNING(net->log, "[%02u] -- Packet has no handler", data[0]);
continue;
}

net->packethandlers[data[0]].function(net->packethandlers[data[0]].object, ip_port, data, length, userdata);
cb(object, ip_port, data, length, userdata);
}
}

Expand Down
15 changes: 7 additions & 8 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,15 +706,16 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub
return 0;
}

unsigned int i;

lock(tox);

for (i = 0; i < count; ++i) {
for (int32_t i = 0; i < count; ++i) {
root[i].port = net_htons(port);

onion_add_bs_path_node(tox->m->onion_c, root[i], public_key);
dht_bootstrap(tox->m->dht, root[i], public_key);

if (!tox->m->options.udp_disabled) {
dht_bootstrap(tox->m->dht, root[i], public_key);
}
}

unlock(tox);
Expand Down Expand Up @@ -747,19 +748,17 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t

IP_Port *root;

int32_t count = net_getipport(host, &root, TOX_SOCK_STREAM);
const int32_t count = net_getipport(host, &root, TOX_SOCK_STREAM);

if (count == -1) {
net_freeipport(root);
SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST);
return 0;
}

unsigned int i;

lock(tox);

for (i = 0; i < count; ++i) {
for (int32_t i = 0; i < count; ++i) {
root[i].port = net_htons(port);

add_tcp_relay(tox->m->net_crypto, root[i], public_key);
Expand Down

0 comments on commit e3feadf

Please sign in to comment.