]>
Commit | Line | Data |
---|---|---|
cb323159 A |
1 | #include <stdint.h> |
2 | #include <darwintest.h> | |
3 | #include <darwintest_utils.h> | |
4 | ||
5 | #include "../libkern/os/ptrtools.h" | |
6 | ||
7 | #define CHECK_ALIGNMENT(T) \ | |
8 | { \ | |
9 | T *__p; \ | |
10 | T_QUIET; T_EXPECT_EQ_ULONG(__alignof__(*__p), sizeof(*__p), #T " native alignment"); \ | |
11 | T_ASSERT_EQ_ULONG(__alignof__(os_unaligned_deref(__p)), 1UL, #T " alignment"); \ | |
12 | } | |
13 | ||
14 | T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); | |
15 | ||
16 | struct A { | |
17 | int a; | |
18 | }; | |
19 | ||
20 | T_DECL(os_unaligned, "Unaligned pointer access") | |
21 | { | |
22 | int x = 0x914842; | |
23 | int *p = &x; | |
24 | ||
25 | T_ASSERT_EQ_INT(os_unaligned_deref(p), x, "load"); | |
26 | os_unaligned_deref(&x) = INT_MIN; | |
27 | T_ASSERT_EQ_INT(x, INT_MIN, "store"); | |
28 | ||
29 | CHECK_ALIGNMENT(unsigned); | |
30 | CHECK_ALIGNMENT(long long); | |
31 | CHECK_ALIGNMENT(uintptr_t); | |
32 | CHECK_ALIGNMENT(int16_t); | |
33 | CHECK_ALIGNMENT(uint64_t); | |
34 | CHECK_ALIGNMENT(struct A); | |
35 | CHECK_ALIGNMENT(void *); | |
36 | } |