10 #include "unaligned.h"
13 static const char memory[8] = {
14 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef
17 static const uint64_t intval64 = 0x0123456789abcdef;
18 static const uint32_t intval32 = 0x01234567;
19 static const uint16_t intval16 = 0x0123;
23 static int setup(void **state)
25 return posix_memalign(state, 16, 2 * SIZE);
28 static int teardown(void **state)
35 #define make_test(bits, offset) \
36 static void test_ ## bits ## _ ## offset(void **state) \
39 uint8_t *c = *state; \
40 uint8_t *p = *state + SIZE; \
43 assert_in_range(len, 1, SIZE); \
44 assert_in_range(offset + len, 1, SIZE); \
45 memset(c, 0, 2 * SIZE); \
46 memcpy(c + offset, memory, len); \
48 u = get_unaligned_be##bits(c + offset); \
49 assert_int_equal(u, intval##bits); \
50 put_unaligned_be##bits(u, p + offset); \
51 assert_memory_equal(c + offset, p + offset, len); \
69 int test_unaligned(void)
71 const struct CMUnitTest tests[] = {
72 cmocka_unit_test(test_16_0),
73 cmocka_unit_test(test_16_1),
74 cmocka_unit_test(test_32_0),
75 cmocka_unit_test(test_32_1),
76 cmocka_unit_test(test_32_2),
77 cmocka_unit_test(test_32_3),
78 cmocka_unit_test(test_64_0),
79 cmocka_unit_test(test_64_1),
80 cmocka_unit_test(test_64_2),
81 cmocka_unit_test(test_64_3),
82 cmocka_unit_test(test_64_4),
83 cmocka_unit_test(test_64_5),
84 cmocka_unit_test(test_64_6),
85 cmocka_unit_test(test_64_7),
87 return cmocka_run_group_tests(tests, setup, teardown);
94 ret += test_unaligned();