aboutsummaryrefslogtreecommitdiff
path: root/tests/check-structs.at
blob: a926a0fb5393fe5bcba5e4ef92fae6a2035fdaa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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 {
    uint16_t 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 {
    uint16_t x;
    uint32_t 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 {
    uint64_t 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 {
    uint64_t bar;
};
OFP_ASSERT(sizeof(struct moo) == 8);
struct wibble {
    uint64_t 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