summaryrefslogtreecommitdiff
path: root/auto_tests/run_auto_test.h
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-06-25 12:37:46 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-06-29 23:24:20 +0000
commit706fad1ce88c2104009a3835ee343ff9d8ec8b79 (patch)
treeb2c0d8ccb434515cbbd4e0c9e86ce21f099c11a7 /auto_tests/run_auto_test.h
parent52f21e32518244f3008efbef073f9d3ac9e68b43 (diff)
Add a test to try and overflow the send queue in net_crypto.
Diffstat (limited to 'auto_tests/run_auto_test.h')
-rw-r--r--auto_tests/run_auto_test.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/auto_tests/run_auto_test.h b/auto_tests/run_auto_test.h
new file mode 100644
index 00000000..6ae8ad6a
--- /dev/null
+++ b/auto_tests/run_auto_test.h
@@ -0,0 +1,96 @@
1#include "helpers.h"
2
3static bool all_connected(uint32_t tox_count, Tox **toxes)
4{
5 for (uint32_t i = 0; i < tox_count; i++) {
6 if (tox_self_get_connection_status(toxes[i]) == TOX_CONNECTION_NONE) {
7 return false;
8 }
9 }
10
11 return true;
12}
13
14static bool all_friends_connected(uint32_t tox_count, Tox **toxes)
15{
16 for (uint32_t i = 0; i < tox_count; i++) {
17 const size_t friend_count = tox_self_get_friend_list_size(toxes[i]);
18
19 for (size_t j = 0; j < friend_count; j++) {
20 if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_NONE) {
21 return false;
22 }
23 }
24 }
25
26 return true;
27}
28
29static bool iterate_all(uint32_t tox_count, Tox **toxes, State *state)
30{
31 for (uint32_t i = 0; i < tox_count; i++) {
32 tox_iterate(toxes[i], &state[i]);
33 }
34
35 return true;
36}
37
38static void run_auto_test(uint32_t tox_count, void test(Tox **toxes, State *state))
39{
40 printf("initialising %u toxes\n", tox_count);
41 Tox **toxes = (Tox **)calloc(tox_count, sizeof(Tox *));
42 State *state = (State *)calloc(tox_count, sizeof(State));
43
44 for (uint32_t i = 0; i < tox_count; i++) {
45 state[i].index = i;
46 toxes[i] = tox_new_log(nullptr, nullptr, &state[i].index);
47 ck_assert_msg(toxes[i], "failed to create %u tox instances", i + 1);
48 }
49
50 printf("toxes all add each other as friends\n");
51
52 for (uint32_t i = 0; i < tox_count; i++) {
53 for (uint32_t j = 0; j < tox_count; j++) {
54 if (i != j) {
55 uint8_t public_key[TOX_PUBLIC_KEY_SIZE];
56 tox_self_get_public_key(toxes[j], public_key);
57 tox_friend_add_norequest(toxes[i], public_key, nullptr);
58 }
59 }
60 }
61
62
63 printf("bootstrapping all toxes off toxes[0]\n");
64 uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
65 tox_self_get_dht_id(toxes[0], dht_key);
66 const uint16_t dht_port = tox_self_get_udp_port(toxes[0], nullptr);
67
68 for (uint32_t i = 1; i < tox_count; i++) {
69 tox_bootstrap(toxes[i], "localhost", dht_port, dht_key, nullptr);
70 }
71
72 while (!all_connected(tox_count, toxes)) {
73 iterate_all(tox_count, toxes, state);
74
75 c_sleep(ITERATION_INTERVAL);
76 }
77
78 printf("toxes are online\n");
79
80 while (!all_friends_connected(tox_count, toxes)) {
81 iterate_all(tox_count, toxes, state);
82
83 c_sleep(ITERATION_INTERVAL);
84 }
85
86 printf("tox clients connected\n");
87
88 test(toxes, state);
89
90 for (uint32_t i = 0; i < tox_count; i++) {
91 tox_kill(toxes[i]);
92 }
93
94 free(state);
95 free(toxes);
96}