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 7604e9a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 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
16 changes: 8 additions & 8 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,19 +706,19 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub
return 0;
}

unsigned int i;
if (!tox->m->options.udp_disabled) {
lock(tox);

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

for (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);
}

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

unlock(tox);

net_freeipport(root);

if (count) {
Expand Down

0 comments on commit 7604e9a

Please sign in to comment.