Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable lan discovery in most tests. #790

Merged
merged 1 commit into from
Feb 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ auto_test(set_name)
auto_test(set_status_message)
auto_test(simple_conference)
auto_test(skeleton)
auto_test(tcp_relay)
auto_test(tox_many)
auto_test(tox_many_tcp)
auto_test(tox_one)
Expand Down
2 changes: 2 additions & 0 deletions auto_tests/TCP_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,8 @@ static Suite *TCP_suite(void)

int main(int argc, char *argv[])
{
setvbuf(stdout, nullptr, _IONBF, 0);

srand((unsigned int) time(nullptr));

Suite *TCP = TCP_suite();
Expand Down
16 changes: 9 additions & 7 deletions auto_tests/bootstrap_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@ static uint8_t const key[] = {

int main(void)
{
Tox *tox = tox_new_log(nullptr, nullptr, nullptr);
setvbuf(stdout, nullptr, _IONBF, 0);

tox_bootstrap(tox, "node.tox.biribiri.org", 33445, key, nullptr);
Tox *tox_udp = tox_new_log(nullptr, nullptr, nullptr);

tox_bootstrap(tox_udp, "node.tox.biribiri.org", 33445, key, nullptr);

printf("Waiting for connection");

while (tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE) {
while (tox_self_get_connection_status(tox_udp) == TOX_CONNECTION_NONE) {
printf(".");
fflush(stdout);

tox_iterate(tox, nullptr);
c_sleep(1000);
tox_iterate(tox_udp, nullptr);
c_sleep(ITERATION_INTERVAL);
}

printf("Connection: %d\n", tox_self_get_connection_status(tox));
printf("Connection (UDP): %d\n", tox_self_get_connection_status(tox_udp));

tox_kill(tox);
tox_kill(tox_udp);
return 0;
}
57 changes: 20 additions & 37 deletions auto_tests/conference_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
#include "helpers.h"

#define NUM_GROUP_TOX 5
#define GROUP_MESSAGE "Install Gentoo"

static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *user_data)
{
int id = *(int *)user_data;
const int id = *(int *)user_data;

if (connection_status != TOX_CONNECTION_NONE) {
printf("tox #%d: is now connected\n", id);
Expand All @@ -36,7 +37,7 @@ static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_st
static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status,
void *user_data)
{
int id = *(int *)user_data;
const int id = *(int *)user_data;

if (connection_status != TOX_CONNECTION_NONE) {
printf("tox #%d: is now connected to friend %d\n", id, friendnumber);
Expand All @@ -48,7 +49,7 @@ static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX
static void handle_conference_invite(Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *data,
size_t length, void *user_data)
{
int id = *(int *)user_data;
const int id = *(int *)user_data;
ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%d: wrong conference type: %d", id, type);

TOX_ERR_CONFERENCE_JOIN err;
Expand All @@ -75,12 +76,12 @@ static unsigned int num_recv;
static void handle_conference_message(Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, void *user_data)
{
if (length == (sizeof("Install Gentoo") - 1) && memcmp(message, "Install Gentoo", sizeof("Install Gentoo") - 1) == 0) {
if (length == (sizeof(GROUP_MESSAGE) - 1) && memcmp(message, GROUP_MESSAGE, sizeof(GROUP_MESSAGE) - 1) == 0) {
++num_recv;
}
}

START_TEST(test_many_group)
static void test_many_group(void)
{
const time_t test_start_time = time(nullptr);

Expand All @@ -102,18 +103,18 @@ START_TEST(test_many_group)
tox_callback_self_connection_status(toxes[i], &handle_self_connection_status);
tox_callback_friend_connection_status(toxes[i], &handle_friend_connection_status);
tox_callback_conference_invite(toxes[i], &handle_conference_invite);
}

tox_options_free(opts);
if (i != 0) {
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(toxes[0], dht_key);
const uint16_t dht_port = tox_self_get_udp_port(toxes[0], nullptr);

{
TOX_ERR_GET_PORT error;
const uint16_t port = tox_self_get_udp_port(toxes[0], &error);
ck_assert_msg(33445 <= port && port <= 33545,
"First Tox instance did not bind to udp port inside [33445, 33545].\n");
ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error");
tox_bootstrap(toxes[i], "localhost", dht_port, dht_key, nullptr);
}
}

tox_options_free(opts);

printf("creating a chain of friends\n");

for (unsigned i = 1; i < NUM_GROUP_TOX; ++i) {
Expand Down Expand Up @@ -208,8 +209,8 @@ START_TEST(test_many_group)
TOX_ERR_CONFERENCE_SEND_MESSAGE err;
ck_assert_msg(
tox_conference_send_message(
toxes[rand() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"Install Gentoo",
sizeof("Install Gentoo") - 1, &err) != 0, "Failed to send group message.");
toxes[rand() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)GROUP_MESSAGE,
sizeof(GROUP_MESSAGE) - 1, &err) != 0, "Failed to send group message.");
ck_assert_msg(
err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, "Failed to send group message.");
num_recv = 0;
Expand All @@ -236,7 +237,7 @@ START_TEST(test_many_group)
c_sleep(50);
}

for (unsigned i = 0; i < (k - 1); ++i) {
for (unsigned i = 0; i < k - 1; ++i) {
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
Expand All @@ -250,29 +251,11 @@ START_TEST(test_many_group)

printf("test_many_group succeeded, took %d seconds\n", (int)(time(nullptr) - test_start_time));
}
END_TEST

static Suite *tox_suite(void)
{
Suite *s = suite_create("Tox conference");

DEFTESTCASE_SLOW(many_group, 80);

return s;
}

int main(int argc, char *argv[])
{
srand((unsigned int) time(nullptr));

Suite *tox = tox_suite();
SRunner *test_runner = srunner_create(tox);

int number_failed = 0;
srunner_run_all(test_runner, CK_NORMAL);
number_failed = srunner_ntests_failed(test_runner);

srunner_free(test_runner);
setvbuf(stdout, nullptr, _IONBF, 0);

return number_failed;
test_many_group();
return 0;
}
1 change: 1 addition & 0 deletions auto_tests/crypto_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ static Suite *crypto_suite(void)

int main(int argc, char *argv[])
{
setvbuf(stdout, nullptr, _IONBF, 0);
srand((unsigned int) time(nullptr));

Suite *crypto = crypto_suite();
Expand Down
1 change: 1 addition & 0 deletions auto_tests/dht_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ static Suite *dht_suite(void)

int main(int argc, char *argv[])
{
setvbuf(stdout, nullptr, _IONBF, 0);
srand((unsigned int) time(nullptr));

Suite *dht = dht_suite();
Expand Down
1 change: 1 addition & 0 deletions auto_tests/encryptsave_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ static Suite *encryptsave_suite(void)

int main(int argc, char *argv[])
{
setvbuf(stdout, nullptr, _IONBF, 0);
srand((unsigned int) time(nullptr));

Suite *encryptsave = encryptsave_suite();
Expand Down
10 changes: 5 additions & 5 deletions auto_tests/file_saving_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@
#include <stdlib.h>
#include <string.h>

#include "../toxcore/tox.h"
#include "../toxencryptsave/toxencryptsave.h"
#include "helpers.h"

#include "../toxcore/ccompat.h"
#include "../toxencryptsave/toxencryptsave.h"

static const char *pphrase = "bar", *name = "foo", *savefile = "./save";

static void save_data_encrypted(void)
{
struct Tox_Options *options = tox_options_new(nullptr);
Tox *t = tox_new(options, nullptr);
Tox *t = tox_new_log(options, nullptr, nullptr);
tox_options_free(options);

tox_self_set_name(t, (const uint8_t *)name, strlen(name), nullptr);
Expand Down Expand Up @@ -97,7 +96,7 @@ static void load_data_decrypted(void)

TOX_ERR_NEW err;

Tox *t = tox_new(options, &err);
Tox *t = tox_new_log(options, &err, nullptr);

tox_options_free(options);

Expand All @@ -123,6 +122,7 @@ static void load_data_decrypted(void)

int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
save_data_encrypted();
load_data_decrypted();

Expand Down
9 changes: 7 additions & 2 deletions auto_tests/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint3
fprintf(stderr, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message);
}

Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data)
Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery)
{
struct Tox_Options *log_options = options;

if (log_options == nullptr) {
log_options = tox_options_new(nullptr);
// tox_options_set_local_discovery_enabled(log_options, false);
}

assert(log_options != nullptr);

tox_options_set_local_discovery_enabled(log_options, lan_discovery);
tox_options_set_log_callback(log_options, &print_debug_log);
tox_options_set_log_user_data(log_options, log_user_data);
Tox *tox = tox_new(log_options, err);
Expand All @@ -76,4 +76,9 @@ Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_d
return tox;
}

Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data)
{
return tox_new_log_lan(options, err, log_user_data, false);
}

#endif // TOXCORE_TEST_HELPERS_H
5 changes: 3 additions & 2 deletions auto_tests/lan_discovery_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

int main(void)
{
Tox *tox1 = tox_new_log(nullptr, nullptr, nullptr);
Tox *tox2 = tox_new_log(nullptr, nullptr, nullptr);
setvbuf(stdout, nullptr, _IONBF, 0);
Tox *tox1 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true);
Tox *tox2 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true);

printf("Waiting for LAN discovery");

Expand Down
2 changes: 2 additions & 0 deletions auto_tests/messenger_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ static Suite *messenger_suite(void)

int main(int argc, char *argv[])
{
setvbuf(stdout, nullptr, _IONBF, 0);

friend_id = hex_string_to_bin(friend_id_str);
good_id_a = hex_string_to_bin(good_id_a_str);
good_id_b = hex_string_to_bin(good_id_b_str);
Expand Down
1 change: 1 addition & 0 deletions auto_tests/network_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ static Suite *network_suite(void)

int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
srand((unsigned int) time(nullptr));

Suite *network = network_suite();
Expand Down
1 change: 1 addition & 0 deletions auto_tests/onion_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ static Suite *onion_suite(void)

int main(int argc, char *argv[])
{
setvbuf(stdout, nullptr, _IONBF, 0);
srand((unsigned int) time(nullptr));

Suite *onion = onion_suite();
Expand Down
6 changes: 3 additions & 3 deletions auto_tests/resource_leak_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

int main(void)
{
int i;
setvbuf(stdout, nullptr, _IONBF, 0);

puts("Warming up: creating/deleting 10 tox instances");

// Warm-up.
for (i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++) {
Tox *tox = tox_new(nullptr, nullptr);
tox_iterate(tox, nullptr);
tox_kill(tox);
Expand All @@ -38,7 +38,7 @@ int main(void)
#endif
printf("Creating/deleting %d tox instances\n", ITERATIONS);

for (i = 0; i < ITERATIONS; i++) {
for (int i = 0; i < ITERATIONS; i++) {
Tox *tox = tox_new(nullptr, nullptr);
tox_iterate(tox, nullptr);
tox_kill(tox);
Expand Down
19 changes: 14 additions & 5 deletions auto_tests/save_friend_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@ void statuschange_callback(Tox *tox, uint32_t friend_number, const uint8_t *mess

int main(int argc, char *argv[])
{
Tox *tox1 = tox_new_log(nullptr, nullptr, nullptr);
Tox *tox2 = tox_new_log(nullptr, nullptr, nullptr);
setvbuf(stdout, nullptr, _IONBF, 0);

struct test_data to_compare = { { 0 } };
Tox *const tox1 = tox_new_log(nullptr, nullptr, nullptr);
Tox *const tox2 = tox_new_log(nullptr, nullptr, nullptr);

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);

tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr);

struct test_data to_compare = {{0}};

uint8_t public_key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_public_key(tox1, public_key);
Expand Down Expand Up @@ -104,11 +113,11 @@ int main(int argc, char *argv[])
VLA(uint8_t, savedata, save_size);
tox_get_savedata(tox1, savedata);

struct Tox_Options *options = tox_options_new(nullptr);
struct Tox_Options *const options = tox_options_new(nullptr);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, savedata, save_size);

Tox *tox_to_compare = tox_new(options, nullptr);
Tox *const tox_to_compare = tox_new_log(options, nullptr, nullptr);

tox_friend_get_name(tox_to_compare, 0, to_compare.name, nullptr);
tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, nullptr);
Expand Down
4 changes: 3 additions & 1 deletion auto_tests/self_conference_title_change_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ static void cbtitlechange(Tox *tox, uint32_t conference_number, uint32_t peer_nu

int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

uint32_t conference_number;
struct Tox_Options *to = tox_options_new(nullptr);
Tox *t;
TOX_ERR_CONFERENCE_NEW conference_err;
TOX_ERR_CONFERENCE_TITLE title_err;

t = tox_new(to, nullptr);
t = tox_new_log(to, nullptr, nullptr);
tox_options_free(to);

tox_callback_conference_title(t, &cbtitlechange);
Expand Down
4 changes: 3 additions & 1 deletion auto_tests/selfname_change_conference_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ static void cbconfmembers(Tox *tox, uint32_t conference_number, uint32_t peer_nu

int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

struct Tox_Options *to = tox_options_new(nullptr);
Tox *t;
TOX_ERR_CONFERENCE_NEW conference_err;
TOX_ERR_SET_INFO name_err;

t = tox_new(to, nullptr);
t = tox_new_log(to, nullptr, nullptr);
tox_options_free(to);

tox_callback_conference_namelist_change(t, cbconfmembers);
Expand Down
Loading