2010-01-25 10:49:31 -08:00
|
|
|
AT_BANNER([struct alignment checker unit tests])
|
|
|
|
|
|
|
|
|
|
m4_define([check_structs], [$top_srcdir/build-aux/check-structs])
|
|
|
|
|
m4_define([RUN_STRUCT_CHECKER],
|
2011-10-04 09:26:14 -07:00
|
|
|
[AT_KEYWORDS([check-structs])
|
|
|
|
|
AT_SKIP_IF([test $HAVE_PYTHON = no])
|
2010-01-25 10:49:31 -08:00
|
|
|
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 {
|
2012-04-02 09:06:11 -07:00
|
|
|
ovs_be16 x;
|
2010-01-25 10:49:31 -08:00
|
|
|
};],
|
|
|
|
|
[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 {
|
2012-04-02 09:06:11 -07:00
|
|
|
ovs_be16 x;
|
|
|
|
|
ovs_be32 y;
|
2010-01-25 10:49:31 -08:00
|
|
|
};],
|
|
|
|
|
[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 {
|
2012-04-02 09:06:11 -07:00
|
|
|
ovs_be64 z;
|
2010-01-25 10:49:31 -08:00
|
|
|
};
|
|
|
|
|
OFP_ASSERT(sizeof(struct wibble) == 12);
|
|
|
|
|
],
|
|
|
|
|
[1], [],
|
|
|
|
|
[test.h:4: warning: struct wibble is 8 bytes long but declared as 12
|
|
|
|
|
])
|
|
|
|
|
AT_CLEANUP
|
2011-10-04 09:26:14 -07:00
|
|
|
|
|
|
|
|
AT_SETUP([check wrong struct's declared size])
|
|
|
|
|
RUN_STRUCT_CHECKER(
|
|
|
|
|
[struct moo {
|
2012-04-02 09:06:11 -07:00
|
|
|
ovs_be64 bar;
|
2011-10-04 09:26:14 -07:00
|
|
|
};
|
|
|
|
|
OFP_ASSERT(sizeof(struct moo) == 8);
|
|
|
|
|
struct wibble {
|
2012-04-02 09:06:11 -07:00
|
|
|
ovs_be64 z;
|
2011-10-04 09:26:14 -07:00
|
|
|
};
|
|
|
|
|
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
|