mirror of
https://github.com/openvswitch/ovs
synced 2025-10-25 15:07:05 +00:00
The header files that check-structs checks should only contain big-endian data, never native-endian data, so disallow uint<N>_t entirely. (We had a couple of mistakes in this area until recently.) uint8_t is an obvious exception. Reported-by: Simon Horman <horms@verge.net.au> Reviewed-by: Simon Horman <horms@verge.net.au> Signed-off-by: Ben Pfaff <blp@nicira.com>
57 lines
1.3 KiB
Plaintext
57 lines
1.3 KiB
Plaintext
AT_BANNER([struct alignment checker unit tests])
|
|
|
|
m4_define([check_structs], [$top_srcdir/build-aux/check-structs])
|
|
m4_define([RUN_STRUCT_CHECKER],
|
|
[AT_KEYWORDS([check-structs])
|
|
AT_SKIP_IF([test $HAVE_PYTHON = no])
|
|
AT_DATA([test.h], [$1
|
|
])
|
|
AT_CHECK_UNQUOTED([$PYTHON check_structs test.h], [$2], [$3], [$4])])
|
|
|
|
AT_SETUP([check struct tail padding])
|
|
RUN_STRUCT_CHECKER(
|
|
[struct xyz {
|
|
ovs_be16 x;
|
|
};],
|
|
[1], [],
|
|
[test.h:3: warning: struct xyz needs 2 bytes of tail padding
|
|
])
|
|
AT_CLEANUP
|
|
|
|
AT_SETUP([check struct internal alignment])
|
|
RUN_STRUCT_CHECKER(
|
|
[struct xyzzy {
|
|
ovs_be16 x;
|
|
ovs_be32 y;
|
|
};],
|
|
[1], [],
|
|
[test.h:3: warning: struct xyzzy member y is 2 bytes short of 4-byte alignment
|
|
])
|
|
AT_CLEANUP
|
|
|
|
AT_SETUP([check struct declared size])
|
|
RUN_STRUCT_CHECKER(
|
|
[struct wibble {
|
|
ovs_be64 z;
|
|
};
|
|
OFP_ASSERT(sizeof(struct wibble) == 12);
|
|
],
|
|
[1], [],
|
|
[test.h:4: warning: struct wibble is 8 bytes long but declared as 12
|
|
])
|
|
AT_CLEANUP
|
|
|
|
AT_SETUP([check wrong struct's declared size])
|
|
RUN_STRUCT_CHECKER(
|
|
[struct moo {
|
|
ovs_be64 bar;
|
|
};
|
|
OFP_ASSERT(sizeof(struct moo) == 8);
|
|
struct wibble {
|
|
ovs_be64 z;
|
|
};
|
|
OFP_ASSERT(sizeof(struct moo) == 8);
|
|
], [1], [], [test.h:8: warning: checking size of struct moo but struct wibble was most recently defined
|
|
])
|
|
AT_CLEANUP
|