]>
Commit | Line | Data |
---|---|---|
05b3c97b BP |
1 | AT_BANNER([struct alignment checker unit tests]) |
2 | ||
3 | m4_define([check_structs], [$top_srcdir/build-aux/check-structs]) | |
4 | m4_define([RUN_STRUCT_CHECKER], | |
f937ccc2 | 5 | [AT_KEYWORDS([check-structs]) |
05b3c97b BP |
6 | AT_DATA([test.h], [$1 |
7 | ]) | |
1ca0323e | 8 | AT_CHECK_UNQUOTED([$PYTHON3 check_structs test.h], [$2], [$3], [$4])]) |
05b3c97b BP |
9 | |
10 | AT_SETUP([check struct tail padding]) | |
11 | RUN_STRUCT_CHECKER( | |
12 | [struct xyz { | |
cd03c7c8 | 13 | ovs_be16 x; |
05b3c97b BP |
14 | };], |
15 | [1], [], | |
16 | [test.h:3: warning: struct xyz needs 2 bytes of tail padding | |
17 | ]) | |
18 | AT_CLEANUP | |
19 | ||
20 | AT_SETUP([check struct internal alignment]) | |
21 | RUN_STRUCT_CHECKER( | |
22 | [struct xyzzy { | |
cd03c7c8 BP |
23 | ovs_be16 x; |
24 | ovs_be32 y; | |
05b3c97b BP |
25 | };], |
26 | [1], [], | |
27 | [test.h:3: warning: struct xyzzy member y is 2 bytes short of 4-byte alignment | |
28 | ]) | |
29 | AT_CLEANUP | |
30 | ||
31 | AT_SETUP([check struct declared size]) | |
32 | RUN_STRUCT_CHECKER( | |
33 | [struct wibble { | |
cd03c7c8 | 34 | ovs_be64 z; |
05b3c97b BP |
35 | }; |
36 | OFP_ASSERT(sizeof(struct wibble) == 12); | |
37 | ], | |
38 | [1], [], | |
39 | [test.h:4: warning: struct wibble is 8 bytes long but declared as 12 | |
40 | ]) | |
41 | AT_CLEANUP | |
f937ccc2 BP |
42 | |
43 | AT_SETUP([check wrong struct's declared size]) | |
44 | RUN_STRUCT_CHECKER( | |
45 | [struct moo { | |
cd03c7c8 | 46 | ovs_be64 bar; |
f937ccc2 BP |
47 | }; |
48 | OFP_ASSERT(sizeof(struct moo) == 8); | |
49 | struct wibble { | |
cd03c7c8 | 50 | ovs_be64 z; |
f937ccc2 BP |
51 | }; |
52 | OFP_ASSERT(sizeof(struct moo) == 8); | |
53 | ], [1], [], [test.h:8: warning: checking size of struct moo but struct wibble was most recently defined | |
54 | ]) | |
55 | AT_CLEANUP |