]> git.proxmox.com Git - mirror_ovs.git/blob - tests/check-structs.at
tests: Refactor the iptables accept rule.
[mirror_ovs.git] / tests / check-structs.at
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],
5 [AT_KEYWORDS([check-structs])
6 AT_DATA([test.h], [$1
7 ])
8 AT_CHECK_UNQUOTED([$PYTHON3 check_structs test.h], [$2], [$3], [$4])])
9
10 AT_SETUP([check struct tail padding])
11 RUN_STRUCT_CHECKER(
12 [struct xyz {
13 ovs_be16 x;
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 {
23 ovs_be16 x;
24 ovs_be32 y;
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 {
34 ovs_be64 z;
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
42
43 AT_SETUP([check wrong struct's declared size])
44 RUN_STRUCT_CHECKER(
45 [struct moo {
46 ovs_be64 bar;
47 };
48 OFP_ASSERT(sizeof(struct moo) == 8);
49 struct wibble {
50 ovs_be64 z;
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