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