forked from irungentoo/toxcore
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test to try and overflow the send queue in net_crypto.
- Loading branch information
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ cc_library( | |
hdrs = [ | ||
"check_compat.h", | ||
"helpers.h", | ||
"run_auto_test.h", | ||
], | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* Tests that we can make a friend connection. | ||
* | ||
* This is the simplest test that brings up two toxes that can talk to each | ||
* other. It's useful as a copy/pasteable starting point for testing other | ||
* features. | ||
*/ | ||
|
||
#ifndef _XOPEN_SOURCE | ||
#define _XOPEN_SOURCE 600 | ||
#endif | ||
|
||
#include "check_compat.h" | ||
|
||
#include "../toxcore/tox.h" | ||
|
||
typedef struct State | ||
{ | ||
uint32_t index; | ||
} State; | ||
|
||
static void friend_connection_test(Tox *tox0, Tox *tox1, State *state) | ||
{ | ||
// Nothing to do here. When copying this test, add test-specific code here. | ||
} | ||
|
||
#include "run_auto_test.h" | ||
|
||
int main(void) | ||
{ | ||
setvbuf(stdout, nullptr, _IONBF, 0); | ||
|
||
run_auto_test(friend_connection_test); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* Try to overflow the net_crypto packet buffer. | ||
*/ | ||
|
||
#ifndef _XOPEN_SOURCE | ||
#define _XOPEN_SOURCE 600 | ||
#endif | ||
|
||
#include "check_compat.h" | ||
|
||
#include "../toxcore/tox.h" | ||
|
||
typedef struct State | ||
{ | ||
uint32_t index; | ||
} State; | ||
|
||
static void net_crypto_overflow_test(Tox *tox0, Tox *tox1, State *state) | ||
{ | ||
const uint8_t message[] = {0}; | ||
for (uint32_t i = 0; i < 32767; i++) { | ||
TOX_ERR_FRIEND_SEND_MESSAGE err; | ||
tox_friend_send_message(tox0, 0, TOX_MESSAGE_TYPE_NORMAL, message, sizeof message, &err); | ||
ck_assert_msg(err == TOX_ERR_FRIEND_SEND_MESSAGE_OK, "failed to send message number %d: %d", i, err); | ||
} | ||
} | ||
|
||
#include "run_auto_test.h" | ||
|
||
int main(void) | ||
{ | ||
setvbuf(stdout, nullptr, _IONBF, 0); | ||
|
||
run_auto_test(net_crypto_overflow_test); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "helpers.h" | ||
|
||
static void run_auto_test(void test(Tox *tox0, Tox *tox1, State *state)) | ||
{ | ||
printf("initialising 2 toxes\n"); | ||
State state[] = { {0}, {1} }; | ||
Tox *const tox0 = tox_new_log(nullptr, nullptr, &state[0].index); | ||
Tox *const tox1 = tox_new_log(nullptr, nullptr, &state[1].index); | ||
|
||
ck_assert_msg(tox0 && tox1, "failed to create 2 tox instances"); | ||
|
||
printf("tox0 adds tox1 as friend, tox1 adds tox0\n"); | ||
uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; | ||
tox_self_get_public_key(tox1, public_key); | ||
tox_friend_add_norequest(tox0, public_key, nullptr); | ||
tox_self_get_public_key(tox0, public_key); | ||
tox_friend_add_norequest(tox1, public_key, nullptr); | ||
|
||
printf("bootstrapping tox1 off tox0\n"); | ||
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; | ||
tox_self_get_dht_id(tox0, dht_key); | ||
const uint16_t dht_port = tox_self_get_udp_port(tox0, nullptr); | ||
|
||
tox_bootstrap(tox1, "localhost", dht_port, dht_key, nullptr); | ||
|
||
while (tox_self_get_connection_status(tox0) == TOX_CONNECTION_NONE || | ||
tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE) { | ||
tox_iterate(tox0, &state[0]); | ||
tox_iterate(tox1, &state[1]); | ||
|
||
c_sleep(ITERATION_INTERVAL); | ||
} | ||
|
||
printf("toxes are online\n"); | ||
|
||
while (tox_friend_get_connection_status(tox0, 0, nullptr) != TOX_CONNECTION_UDP || | ||
tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP) { | ||
tox_iterate(tox0, &state[0]); | ||
tox_iterate(tox1, &state[1]); | ||
|
||
c_sleep(ITERATION_INTERVAL); | ||
} | ||
|
||
printf("tox clients connected\n"); | ||
|
||
test(tox0, tox1, state); | ||
|
||
tox_kill(tox0); | ||
tox_kill(tox1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters