summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-07-17 01:18:04 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-07-22 02:34:30 +0000
commitf627a26a7b1c3619ba66f84b87092ff8ba7a95b6 (patch)
treec72c950fab473dc9bec4b5329d251b790e55443d /auto_tests
parent7245ac11ef9be2420c8356c12acc79f93ea211bb (diff)
Run Clang global static analysis on Travis.
This uses a single .cc file containing almost all the code in the repository to perform whole program analysis.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/BUILD.bazel24
-rw-r--r--auto_tests/conference_peer_nick_test.c2
-rw-r--r--auto_tests/conference_test.c2
-rw-r--r--auto_tests/file_transfer_test.c14
-rw-r--r--auto_tests/monolith_test.cc254
-rw-r--r--auto_tests/tox_many_test.c32
-rw-r--r--auto_tests/tox_one_test.c23
7 files changed, 28 insertions, 323 deletions
diff --git a/auto_tests/BUILD.bazel b/auto_tests/BUILD.bazel
index 21c403ab..a5ef7645 100644
--- a/auto_tests/BUILD.bazel
+++ b/auto_tests/BUILD.bazel
@@ -25,32 +25,10 @@ test_sizes = {
25 deps = [ 25 deps = [
26 ":check_compat", 26 ":check_compat",
27 ":run_auto_test", 27 ":run_auto_test",
28 "//c-toxcore/other:monolith",
29 "//c-toxcore/testing:misc_tools", 28 "//c-toxcore/testing:misc_tools",
30 "//c-toxcore/toxav", 29 "//c-toxcore/toxav",
31 "//c-toxcore/toxcore", 30 "//c-toxcore/toxcore",
31 "//c-toxcore/toxcore:DHT_srcs",
32 "//c-toxcore/toxencryptsave", 32 "//c-toxcore/toxencryptsave",
33 ], 33 ],
34) for src in glob(["*_test.c"])] 34) for src in glob(["*_test.c"])]
35
36cc_library(
37 name = "monolith",
38 hdrs = glob([
39 "*.c",
40 "*.h",
41 ]),
42)
43
44cc_test(
45 name = "monolith_test",
46 size = "small",
47 srcs = ["monolith_test.cc"],
48 copts = ["-Wno-sign-compare"],
49 deps = [
50 ":check_compat",
51 ":monolith",
52 ":run_auto_test",
53 "//c-toxcore/other:monolith",
54 "//c-toxcore/testing:misc_tools",
55 ],
56)
diff --git a/auto_tests/conference_peer_nick_test.c b/auto_tests/conference_peer_nick_test.c
index 4d54f1fb..e99d3b79 100644
--- a/auto_tests/conference_peer_nick_test.c
+++ b/auto_tests/conference_peer_nick_test.c
@@ -65,7 +65,7 @@ static void rebuild_peer_list(Tox *tox)
65 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, 65 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
66 "failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err); 66 "failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err);
67 67
68 uint8_t *const name = malloc(size); 68 uint8_t *const name = (uint8_t *)malloc(size);
69 tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err); 69 tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err);
70 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, 70 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
71 "failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err); 71 "failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err);
diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c
index 92e805c9..2bdee78f 100644
--- a/auto_tests/conference_test.c
+++ b/auto_tests/conference_test.c
@@ -234,7 +234,7 @@ static void test_many_group(void)
234 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); 234 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
235 235
236 ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)." 236 ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)."
237 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %u\n\n", 237 "\n\t\t\tExpected: %d but tox_instance(%u) only has: %u\n\n",
238 NUM_GROUP_TOX, i, (unsigned)peer_count); 238 NUM_GROUP_TOX, i, (unsigned)peer_count);
239 239
240 uint8_t title[2048]; 240 uint8_t title[2048];
diff --git a/auto_tests/file_transfer_test.c b/auto_tests/file_transfer_test.c
index a6e45431..94bdb42f 100644
--- a/auto_tests/file_transfer_test.c
+++ b/auto_tests/file_transfer_test.c
@@ -140,20 +140,18 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi
140 m_send_reached = 1; 140 m_send_reached = 1;
141 } 141 }
142 142
143 TOX_ERR_FILE_SEND_CHUNK error;
144 VLA(uint8_t, f_data, length); 143 VLA(uint8_t, f_data, length);
145 memset(f_data, sending_num, length); 144 memset(f_data, sending_num, length);
146 145
147 if (tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error)) { 146 TOX_ERR_FILE_SEND_CHUNK error;
148 ++sending_num; 147 tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error);
149 sending_pos += length;
150 } else {
151 ck_abort_msg("Could not send chunk, error num=%d pos=%d len=%d", (int)error, (int)position, (int)length);
152 }
153 148
154 if (error != TOX_ERR_FILE_SEND_CHUNK_OK) { 149 if (error != TOX_ERR_FILE_SEND_CHUNK_OK) {
155 ck_abort_msg("Wrong error code"); 150 ck_abort_msg("Could not send chunk, error num=%d pos=%d len=%d", (int)error, (int)position, (int)length);
156 } 151 }
152
153 ++sending_num;
154 sending_pos += length;
157} 155}
158 156
159 157
diff --git a/auto_tests/monolith_test.cc b/auto_tests/monolith_test.cc
deleted file mode 100644
index 5b1b910d..00000000
--- a/auto_tests/monolith_test.cc
+++ /dev/null
@@ -1,254 +0,0 @@
1/* Nop-test, just to make sure our code compiles as C++.
2 */
3
4#ifdef __FreeBSD__
5// Include this here, because _XOPEN_SOURCE hides symbols we need.
6//
7// https://lists.freebsd.org/pipermail/freebsd-standards/2004-March/000474.html.
8#include <net/if.h>
9#endif
10
11#ifdef __APPLE__
12#define _DARWIN_C_SOURCE
13#endif
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include "../other/monolith.h"
20#define DHT_C_INCLUDED
21
22#include "../testing/misc_tools.c"
23#include "check_compat.h"
24
25#include <ctype.h>
26
27namespace TCP_test {
28int main(void);
29#include "TCP_test.c"
30} // namespace TCP_test
31namespace bootstrap_test {
32int main(void);
33#include "bootstrap_test.c"
34} // namespace bootstrap_test
35namespace conference_simple_test {
36int main(void);
37#include "conference_simple_test.c"
38} // namespace conference_simple_test
39namespace conference_test {
40int main(void);
41#include "conference_test.c"
42} // namespace conference_test
43namespace crypto_test {
44int main(void);
45#include "crypto_test.c"
46} // namespace crypto_test
47namespace dht_test {
48int main(void);
49#include "dht_test.c"
50} // namespace dht_test
51namespace encryptsave_test {
52int main(void);
53#include "encryptsave_test.c"
54} // namespace encryptsave_test
55namespace file_saving_test {
56int main(void);
57#include "file_saving_test.c"
58} // namespace file_saving_test
59namespace friend_request_test {
60int main(void);
61#include "friend_request_test.c"
62} // namespace friend_request_test
63namespace lan_discovery_test {
64int main(void);
65#include "lan_discovery_test.c"
66} // namespace lan_discovery_test
67namespace lossless_packet_test {
68int main(void);
69#include "lossless_packet_test.c"
70} // namespace lossless_packet_test
71namespace lossy_packet_test {
72int main(void);
73#include "lossy_packet_test.c"
74} // namespace lossy_packet_test
75namespace messenger_test {
76int main(void);
77#include "messenger_test.c"
78} // namespace messenger_test
79namespace network_test {
80int main(void);
81#include "network_test.c"
82} // namespace network_test
83namespace onion_test {
84int main(void);
85#include "onion_test.c"
86} // namespace onion_test
87namespace save_friend_test {
88int main(void);
89#include "save_friend_test.c"
90} // namespace save_friend_test
91namespace save_load_test {
92int main(void);
93#include "save_load_test.c"
94} // namespace save_load_test
95namespace send_message_test {
96int main(void);
97#include "send_message_test.c"
98} // namespace send_message_test
99namespace set_name_test {
100int main(void);
101#include "set_name_test.c"
102} // namespace set_name_test
103namespace set_status_message_test {
104int main(void);
105#include "set_status_message_test.c"
106} // namespace set_status_message_test
107namespace skeleton_test {
108int main(void);
109#include "skeleton_test.c"
110} // namespace skeleton_test
111namespace toxav_basic_test {
112int main(void);
113#include "toxav_basic_test.c"
114} // namespace toxav_basic_test
115namespace toxav_many_test {
116int main(void);
117#include "toxav_many_test.c"
118} // namespace toxav_many_test
119namespace tox_many_tcp_test {
120int main(void);
121#include "tox_many_tcp_test.c"
122} // namespace tox_many_tcp_test
123namespace tox_many_test {
124int main(void);
125#include "tox_many_test.c"
126} // namespace tox_many_test
127namespace tox_one_test {
128int main(void);
129#include "tox_one_test.c"
130} // namespace tox_one_test
131namespace tox_strncasecmp_test {
132int main(void);
133#include "tox_strncasecmp_test.c"
134} // namespace tox_strncasecmp_test
135namespace typing_test {
136int main(void);
137#include "typing_test.c"
138} // namespace typing_test
139namespace version_test {
140int main(void);
141#include "version_test.c"
142} // namespace version_test
143
144#define PRINT_SIZE 0
145
146template <typename T, size_t Expected, size_t Actual = sizeof(T)>
147void check_size(char const *type) {
148#if PRINT_SIZE
149 printf("CHECK_SIZE(%s, %zu);\n", type, Actual);
150#else
151 static_assert(Actual == Expected, "Bad sizeof - see template expansion errors for details");
152#endif
153}
154
155#define CHECK_SIZE(TYPE, SIZE) check_size<TYPE, SIZE>(#TYPE)
156
157/**
158 * The main function static-asserts that we are aware of all the sizes of all
159 * the structs it toxcore. If you find this failing after you make a change,
160 * switch on the PRINT_SIZE above and copy the number into this function.
161 */
162int main(int argc, char *argv[]) {
163 static_assert(sizeof(uint64_t) >= sizeof(size_t),
164 "Assumption violated: size_t is more than 64 bits wide");
165
166#if defined(__x86_64__) && defined(__LP64__)
167 // toxcore/DHT
168 CHECK_SIZE(Client_data, 496);
169 CHECK_SIZE(Cryptopacket_Handler, 16);
170 CHECK_SIZE(DHT, 676528);
171 CHECK_SIZE(DHT_Friend, 5104);
172 CHECK_SIZE(Hardening, 144);
173 CHECK_SIZE(IPPTs, 40);
174 CHECK_SIZE(IPPTsPng, 232);
175 CHECK_SIZE(NAT, 48);
176 CHECK_SIZE(Node_format, 64);
177 CHECK_SIZE(Shared_Key, 80);
178 CHECK_SIZE(Shared_Keys, 81920);
179 // toxcore/friend_connection
180 CHECK_SIZE(Friend_Conn, 1784);
181 CHECK_SIZE(Friend_Connections, 72);
182 // toxcore/friend_requests
183 CHECK_SIZE(Friend_Requests, 1080);
184 // toxcore/group
185 CHECK_SIZE(Group_c, 728);
186 CHECK_SIZE(Group_Chats, 2120);
187 CHECK_SIZE(Group_Peer, 480);
188 // toxcore/list
189 CHECK_SIZE(BS_List, 32);
190 // toxcore/logger
191 CHECK_SIZE(Logger, 24);
192 // toxcore/Messenger
193 CHECK_SIZE(File_Transfers, 72);
194 CHECK_SIZE(Friend, 39264);
195 CHECK_SIZE(Messenger, 2008);
196 CHECK_SIZE(Messenger_Options, 72);
197 CHECK_SIZE(Receipts, 16);
198 // toxcore/net_crypto
199#ifdef __linux__
200 CHECK_SIZE(Crypto_Connection, 525392);
201 CHECK_SIZE(Net_Crypto, 272);
202#endif
203 CHECK_SIZE(New_Connection, 168);
204 CHECK_SIZE(Packet_Data, 1384);
205 CHECK_SIZE(Packets_Array, 262152);
206 // toxcore/network
207 CHECK_SIZE(IP, 24);
208 CHECK_SIZE(IP4, 4);
209#if USE_IPV6
210 CHECK_SIZE(IP6, 16);
211#endif
212 CHECK_SIZE(IP_Port, 32);
213 CHECK_SIZE(Networking_Core, 4112);
214 CHECK_SIZE(Packet_Handler, 16);
215 // toxcore/onion_announce
216 CHECK_SIZE(Cmp_data, 296);
217 CHECK_SIZE(Onion_Announce, 128048);
218 CHECK_SIZE(Onion_Announce_Entry, 288);
219 // toxcore/onion_client
220 CHECK_SIZE(Last_Pinged, 40);
221 CHECK_SIZE(Onion_Client, 15816);
222 CHECK_SIZE(Onion_Client_Cmp_data, 176);
223 CHECK_SIZE(Onion_Client_Paths, 2520);
224 CHECK_SIZE(Onion_Friend, 1936);
225 CHECK_SIZE(Onion_Friend, 1936);
226 CHECK_SIZE(Onion_Node, 168);
227 // toxcore/onion
228 CHECK_SIZE(Onion, 245832);
229 CHECK_SIZE(Onion_Path, 392);
230 // toxcore/ping_array
231 CHECK_SIZE(Ping_Array, 24);
232 CHECK_SIZE(Ping_Array_Entry, 32);
233 // toxcore/ping
234 CHECK_SIZE(Ping, 2072);
235 // toxcore/TCP_client
236 CHECK_SIZE(TCP_Client_Connection, 12064);
237 CHECK_SIZE(TCP_Proxy_Info, 40);
238 // toxcore/TCP_connection
239 CHECK_SIZE(TCP_con, 112);
240 CHECK_SIZE(TCP_Connections, 200);
241 CHECK_SIZE(TCP_Connection_to, 112);
242 // toxcore/TCP_server
243 CHECK_SIZE(TCP_Priority_List, 16);
244 CHECK_SIZE(TCP_Secure_Connection, 11816);
245#ifdef TCP_SERVER_USE_EPOLL
246 CHECK_SIZE(TCP_Server, 6049968); // 6MB!
247#else
248 CHECK_SIZE(TCP_Server, 6049952); // 6MB!
249#endif
250 // toxcore/tox
251 CHECK_SIZE(Tox_Options, 64);
252#endif
253 return 0;
254}
diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c
index ff217e87..49933234 100644
--- a/auto_tests/tox_many_test.c
+++ b/auto_tests/tox_many_test.c
@@ -24,16 +24,16 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
24} 24}
25 25
26 26
27#define NUM_TOXES 90 27#define TCP_TEST_NUM_TOXES 90
28#define NUM_FRIENDS 50 28#define TCP_TEST_NUM_FRIENDS 50
29 29
30static void test_many_clients(void) 30static void test_many_clients(void)
31{ 31{
32 time_t cur_time = time(nullptr); 32 time_t cur_time = time(nullptr);
33 Tox *toxes[NUM_TOXES]; 33 Tox *toxes[TCP_TEST_NUM_TOXES];
34 uint32_t index[NUM_TOXES]; 34 uint32_t index[TCP_TEST_NUM_TOXES];
35 35
36 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 36 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
37 index[i] = i + 1; 37 index[i] = i + 1;
38 toxes[i] = tox_new_log(nullptr, nullptr, &index[i]); 38 toxes[i] = tox_new_log(nullptr, nullptr, &index[i]);
39 ck_assert_msg(toxes[i] != nullptr, "failed to create tox instances %u", i); 39 ck_assert_msg(toxes[i] != nullptr, "failed to create tox instances %u", i);
@@ -43,22 +43,22 @@ static void test_many_clients(void)
43 struct { 43 struct {
44 uint16_t tox1; 44 uint16_t tox1;
45 uint16_t tox2; 45 uint16_t tox2;
46 } pairs[NUM_FRIENDS]; 46 } pairs[TCP_TEST_NUM_FRIENDS];
47 47
48 uint8_t address[TOX_ADDRESS_SIZE]; 48 uint8_t address[TOX_ADDRESS_SIZE];
49 49
50 uint32_t num_f = 0; 50 uint32_t num_f = 0;
51 51
52 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 52 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
53 num_f += tox_self_get_friend_list_size(toxes[i]); 53 num_f += tox_self_get_friend_list_size(toxes[i]);
54 } 54 }
55 55
56 ck_assert_msg(num_f == 0, "bad num friends: %u", num_f); 56 ck_assert_msg(num_f == 0, "bad num friends: %u", num_f);
57 57
58 for (uint32_t i = 0; i < NUM_FRIENDS; ++i) { 58 for (uint32_t i = 0; i < TCP_TEST_NUM_FRIENDS; ++i) {
59loop_top: 59loop_top:
60 pairs[i].tox1 = random_u32() % NUM_TOXES; 60 pairs[i].tox1 = random_u32() % TCP_TEST_NUM_TOXES;
61 pairs[i].tox2 = (pairs[i].tox1 + random_u32() % (NUM_TOXES - 1) + 1) % NUM_TOXES; 61 pairs[i].tox2 = (pairs[i].tox1 + random_u32() % (TCP_TEST_NUM_TOXES - 1) + 1) % TCP_TEST_NUM_TOXES;
62 62
63 for (uint32_t j = 0; j < i; ++j) { 63 for (uint32_t j = 0; j < i; ++j) {
64 if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) { 64 if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) {
@@ -84,18 +84,18 @@ loop_top:
84 ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "failed to add friend error code: %i", test); 84 ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "failed to add friend error code: %i", test);
85 } 85 }
86 86
87 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 87 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
88 num_f += tox_self_get_friend_list_size(toxes[i]); 88 num_f += tox_self_get_friend_list_size(toxes[i]);
89 } 89 }
90 90
91 ck_assert_msg(num_f == NUM_FRIENDS, "bad num friends: %u", num_f); 91 ck_assert_msg(num_f == TCP_TEST_NUM_FRIENDS, "bad num friends: %u", num_f);
92 92
93 uint16_t last_count = 0; 93 uint16_t last_count = 0;
94 94
95 while (1) { 95 while (1) {
96 uint16_t counter = 0; 96 uint16_t counter = 0;
97 97
98 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 98 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
99 for (uint32_t j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) { 99 for (uint32_t j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) {
100 if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_UDP) { 100 if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_UDP) {
101 ++counter; 101 ++counter;
@@ -108,18 +108,18 @@ loop_top:
108 last_count = counter; 108 last_count = counter;
109 } 109 }
110 110
111 if (counter == NUM_FRIENDS * 2) { 111 if (counter == TCP_TEST_NUM_FRIENDS * 2) {
112 break; 112 break;
113 } 113 }
114 114
115 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 115 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
116 tox_iterate(toxes[i], nullptr); 116 tox_iterate(toxes[i], nullptr);
117 } 117 }
118 118
119 c_sleep(50); 119 c_sleep(50);
120 } 120 }
121 121
122 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 122 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
123 tox_kill(toxes[i]); 123 tox_kill(toxes[i]);
124 } 124 }
125 125
diff --git a/auto_tests/tox_one_test.c b/auto_tests/tox_one_test.c
index 69ec4461..28f18c29 100644
--- a/auto_tests/tox_one_test.c
+++ b/auto_tests/tox_one_test.c
@@ -28,7 +28,7 @@ static void set_random_name_and_status_message(Tox *tox, uint8_t *name, uint8_t
28 } 28 }
29} 29}
30 30
31START_TEST(test_one) 31static void test_one(void)
32{ 32{
33 uint8_t name[TOX_MAX_NAME_LENGTH]; 33 uint8_t name[TOX_MAX_NAME_LENGTH];
34 uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH]; 34 uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH];
@@ -128,30 +128,13 @@ START_TEST(test_one)
128 tox_kill(tox1); 128 tox_kill(tox1);
129 tox_kill(tox2); 129 tox_kill(tox2);
130} 130}
131END_TEST
132 131
133 132
134static Suite *tox_suite(void)
135{
136 Suite *s = suite_create("Tox one");
137
138 DEFTESTCASE(one);
139
140 return s;
141}
142
143int main(void) 133int main(void)
144{ 134{
145 setvbuf(stdout, nullptr, _IONBF, 0); 135 setvbuf(stdout, nullptr, _IONBF, 0);
146 136
147 Suite *tox = tox_suite(); 137 test_one();
148 SRunner *test_runner = srunner_create(tox);
149
150 int number_failed = 0;
151 srunner_run_all(test_runner, CK_NORMAL);
152 number_failed = srunner_ntests_failed(test_runner);
153
154 srunner_free(test_runner);
155 138
156 return number_failed; 139 return 0;
157} 140}