diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-06-25 12:37:46 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-06-29 23:24:20 +0000 |
commit | 706fad1ce88c2104009a3835ee343ff9d8ec8b79 (patch) | |
tree | b2c0d8ccb434515cbbd4e0c9e86ce21f099c11a7 /auto_tests/overflow_sendq_test.c | |
parent | 52f21e32518244f3008efbef073f9d3ac9e68b43 (diff) |
Add a test to try and overflow the send queue in net_crypto.
Diffstat (limited to 'auto_tests/overflow_sendq_test.c')
-rw-r--r-- | auto_tests/overflow_sendq_test.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/auto_tests/overflow_sendq_test.c b/auto_tests/overflow_sendq_test.c new file mode 100644 index 00000000..94f5c12a --- /dev/null +++ b/auto_tests/overflow_sendq_test.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /* Try to overflow the net_crypto packet buffer. | ||
2 | */ | ||
3 | |||
4 | #ifndef _XOPEN_SOURCE | ||
5 | #define _XOPEN_SOURCE 600 | ||
6 | #endif | ||
7 | |||
8 | #include "check_compat.h" | ||
9 | |||
10 | #include "../toxcore/tox.h" | ||
11 | |||
12 | typedef struct State { | ||
13 | uint32_t index; | ||
14 | } State; | ||
15 | |||
16 | #include "run_auto_test.h" | ||
17 | |||
18 | #define NUM_MSGS 40000 | ||
19 | |||
20 | static void net_crypto_overflow_test(Tox **toxes, State *state) | ||
21 | { | ||
22 | const uint8_t message[] = {0}; | ||
23 | bool errored = false; | ||
24 | |||
25 | for (uint32_t i = 0; i < NUM_MSGS; i++) { | ||
26 | TOX_ERR_FRIEND_SEND_MESSAGE err; | ||
27 | tox_friend_send_message(toxes[0], 0, TOX_MESSAGE_TYPE_NORMAL, message, sizeof message, &err); | ||
28 | |||
29 | if (err != TOX_ERR_FRIEND_SEND_MESSAGE_OK) { | ||
30 | errored = true; | ||
31 | } | ||
32 | |||
33 | if (errored) { | ||
34 | // As soon as we get the first error, we expect the same error (SENDQ) | ||
35 | // every time we try to send. | ||
36 | ck_assert_msg(err == TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ, | ||
37 | "expected SENDQ error on message %u, but got %d", i, err); | ||
38 | } else { | ||
39 | ck_assert_msg(err == TOX_ERR_FRIEND_SEND_MESSAGE_OK, | ||
40 | "failed to send message number %u: %d", i, err); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | ck_assert_msg(errored, "expected SENDQ error at some point (increase NUM_MSGS?)"); | ||
45 | } | ||
46 | |||
47 | int main(void) | ||
48 | { | ||
49 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
50 | |||
51 | run_auto_test(2, net_crypto_overflow_test); | ||
52 | return 0; | ||
53 | } | ||