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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/*
* BIRD Library -- Data Type Alignment Tests
*
* (c) 2022 Maria Matejka <mq@jmq.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include "test/birdtest.h"
#include "lib/type.h"
#include "lib/route.h"
#define CHECK_ONE(val) \
for (uint i=0; i<sizeof(val); i++) \
bt_assert(((const u8 *) &val)[i] == (u8) ~0);
#define SET_PADDING(val, name) \
for (uint i=0; i<sizeof(val.PADDING_NAME(name)); i++) \
val.PADDING_NAME(name)[i] = ~0;
static int
t_bval(void)
{
union bval v;
memset(&v, 0, sizeof(v));
v.data = ~0;
SET_PADDING(v, data);
CHECK_ONE(v);
memset(&v, 0, sizeof(v));
v.i = ~0;
SET_PADDING(v, i);
CHECK_ONE(v);
memset(&v, 0, sizeof(v));
v.ptr = (void *) ~0;
CHECK_ONE(v);
memset(&v, 0, sizeof(v));
v.ad = (void *) ~0;
CHECK_ONE(v);
return 1;
}
static int
t_eattr(void)
{
struct eattr e;
memset(&e, 0, sizeof(e));
e.id = ~0;
e.flags = ~0;
e.type = ~0;
e.rfu = ~0;
e.originated = ~0;
e.fresh = ~0;
e.undef = ~0;
memset(&e.u, ~0, sizeof(e.u)); /* Assumes t_bval passed */
SET_PADDING(e, unused);
CHECK_ONE(e);
return 1;
}
int main(int argc, char *argv[])
{
bt_init(argc, argv);
bt_test_suite(t_bval, "Structure alignment test: bval");
bt_test_suite(t_eattr, "Structure alignment test: eattr");
return bt_exit_value();
}
|