diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-02-14 16:33:08 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-02-17 17:08:37 +0000 |
commit | 746c624a09b3a31e7d82aa8cb945d7a6ea3fdb64 (patch) | |
tree | d14042a48082b0891b9c6032ef953f15d56310ae | |
parent | 82662d4e16937997c36d2090a17c3b2389fa4ad5 (diff) |
Add static asserts for all the struct sizes in toxcore.
This forces us to record size changes (for LP64) and helps estimate
memory consumption of internal data structures.
-rw-r--r-- | auto_tests/monolith_test.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/auto_tests/monolith_test.cpp b/auto_tests/monolith_test.cpp index b1e13448..b09d8985 100644 --- a/auto_tests/monolith_test.cpp +++ b/auto_tests/monolith_test.cpp | |||
@@ -125,7 +125,107 @@ namespace version_test | |||
125 | #include "version_test.c" | 125 | #include "version_test.c" |
126 | } | 126 | } |
127 | 127 | ||
128 | #define PRINT_SIZE 0 | ||
129 | |||
130 | template<typename T, size_t Expected, size_t Actual = sizeof(T)> | ||
131 | void check_size(char const *type) | ||
132 | { | ||
133 | #if PRINT_SIZE | ||
134 | printf("CHECK_SIZE(%s, %zu);\n", type, Actual); | ||
135 | #else | ||
136 | static_assert(Actual == Expected, "Bad sizeof - see template expansion errors for details"); | ||
137 | #endif | ||
138 | } | ||
139 | |||
140 | #define CHECK_SIZE(TYPE, SIZE) check_size<TYPE, SIZE>(#TYPE) | ||
141 | |||
142 | /** | ||
143 | * The main function static-asserts that we are aware of all the sizes of all | ||
144 | * the structs it toxcore. If you find this failing after you make a change, | ||
145 | * switch on the PRINT_SIZE above and copy the number into this function. | ||
146 | */ | ||
128 | int main(int argc, char *argv[]) | 147 | int main(int argc, char *argv[]) |
129 | { | 148 | { |
149 | #if defined(__x86_64__) && defined(__LP64__) | ||
150 | // toxcore/DHT | ||
151 | CHECK_SIZE(Client_data, 496); | ||
152 | CHECK_SIZE(Cryptopacket_Handles, 16); | ||
153 | CHECK_SIZE(DHT, 676528); | ||
154 | CHECK_SIZE(DHT_Friend, 5104); | ||
155 | CHECK_SIZE(Hardening, 144); | ||
156 | CHECK_SIZE(IPPTs, 40); | ||
157 | CHECK_SIZE(IPPTsPng, 232); | ||
158 | CHECK_SIZE(NAT, 48); | ||
159 | CHECK_SIZE(Node_format, 64); | ||
160 | CHECK_SIZE(Shared_Key, 80); | ||
161 | CHECK_SIZE(Shared_Keys, 81920); | ||
162 | // toxcore/friend_connection | ||
163 | CHECK_SIZE(Friend_Conn, 1784); | ||
164 | CHECK_SIZE(Friend_Connections, 72); | ||
165 | // toxcore/friend_requests | ||
166 | CHECK_SIZE(Friend_Requests, 1080); | ||
167 | // toxcore/group | ||
168 | CHECK_SIZE(Group_c, 728); | ||
169 | CHECK_SIZE(Group_Chats, 2112); | ||
170 | CHECK_SIZE(Group_Peer, 480); | ||
171 | // toxcore/list | ||
172 | CHECK_SIZE(BS_LIST, 32); | ||
173 | // toxcore/logger | ||
174 | CHECK_SIZE(Logger, 24); | ||
175 | // toxcore/Messenger | ||
176 | CHECK_SIZE(File_Transfers, 72); | ||
177 | CHECK_SIZE(Friend, 39264); | ||
178 | CHECK_SIZE(Messenger, 2008); | ||
179 | CHECK_SIZE(Messenger_Options, 72); | ||
180 | CHECK_SIZE(Receipts, 16); | ||
181 | // toxcore/net_crypto | ||
182 | CHECK_SIZE(Crypto_Connection, 525392); | ||
183 | CHECK_SIZE(Net_Crypto, 272); | ||
184 | CHECK_SIZE(New_Connection, 168); | ||
185 | CHECK_SIZE(Packet_Data, 1384); | ||
186 | CHECK_SIZE(Packets_Array, 262152); | ||
187 | // toxcore/network | ||
188 | CHECK_SIZE(IP, 24); | ||
189 | CHECK_SIZE(IP4, 4); | ||
190 | #if USE_IPV6 | ||
191 | CHECK_SIZE(IP6, 16); | ||
192 | #endif | ||
193 | CHECK_SIZE(IP_Port, 32); | ||
194 | CHECK_SIZE(Networking_Core, 4112); | ||
195 | CHECK_SIZE(Packet_Handler, 16); | ||
196 | // toxcore/onion_announce | ||
197 | CHECK_SIZE(Cmp_data, 296); | ||
198 | CHECK_SIZE(Onion_Announce, 128048); | ||
199 | CHECK_SIZE(Onion_Announce_Entry, 288); | ||
200 | // toxcore/onion_client | ||
201 | CHECK_SIZE(Last_Pinged, 40); | ||
202 | CHECK_SIZE(Onion_Client, 15816); | ||
203 | CHECK_SIZE(Onion_Client_Cmp_data, 176); | ||
204 | CHECK_SIZE(Onion_Client_Paths, 2520); | ||
205 | CHECK_SIZE(Onion_Friend, 1936); | ||
206 | CHECK_SIZE(Onion_Friend, 1936); | ||
207 | CHECK_SIZE(Onion_Node, 168); | ||
208 | // toxcore/onion | ||
209 | CHECK_SIZE(Onion, 245832); | ||
210 | CHECK_SIZE(Onion_Path, 392); | ||
211 | // toxcore/ping_array | ||
212 | CHECK_SIZE(Ping_Array, 24); | ||
213 | CHECK_SIZE(Ping_Array_Entry, 32); | ||
214 | // toxcore/ping | ||
215 | CHECK_SIZE(Ping, 2072); | ||
216 | // toxcore/TCP_client | ||
217 | CHECK_SIZE(TCP_Client_Connection, 12064); | ||
218 | CHECK_SIZE(TCP_Proxy_Info, 40); | ||
219 | // toxcore/TCP_connection | ||
220 | CHECK_SIZE(TCP_con, 112); | ||
221 | CHECK_SIZE(TCP_Connections, 200); | ||
222 | CHECK_SIZE(TCP_Connection_to, 112); | ||
223 | // toxcore/TCP_server | ||
224 | CHECK_SIZE(TCP_Priority_List, 16); | ||
225 | CHECK_SIZE(TCP_Secure_Connection, 11816); | ||
226 | CHECK_SIZE(TCP_Server, 6049952); // 6MB! | ||
227 | // toxcore/tox | ||
228 | CHECK_SIZE(Tox_Options, 64); | ||
229 | #endif | ||
130 | return 0; | 230 | return 0; |
131 | } | 231 | } |