add local exec tls align test
[libc-test] / src / functional / tls_local_exec.c
1 #include <stdint.h>
2 #include <pthread.h>
3 #include "test.h"
4
5 static __thread char d1 = 11;
6 static __thread char d64 __attribute__ ((aligned(64))) = 22;
7 static __thread char d4096 __attribute__ ((aligned(4096))) = 33;
8 static __thread char z1 = 0;
9 static __thread char z64 __attribute__ ((aligned(64))) = 0;
10 static __thread char z4096 __attribute__ ((aligned(4096))) = 0;
11
12 static int tnum;
13
14 #define CHECK(c, fmt, ...) do{ \
15         if (!(c)) \
16                 t_error("[thread %d]: "#c" failed"fmt".\n", tnum, __VA_ARGS__); \
17 }while(0)
18
19 static unsigned ptrmod(void *p, unsigned m)
20 {
21         volatile unsigned n = (uintptr_t)p;
22         return n % m;
23 }
24
25 static void *check(void *arg)
26 {
27         tnum++;
28
29         CHECK(d1 == 11, " want 11 got %d", d1);
30         CHECK(d64 == 22, " want 22 got %d", d64);
31         CHECK(d4096 == 33, " want 33 got %d", d4096);
32
33         CHECK(ptrmod(&d64, 64) == 0, " address is %p, want 64 byte alignment", &d64);
34         CHECK(ptrmod(&d4096, 4096) == 0, " address is %p, want 4096 byte alignment", &d4096);
35
36         CHECK(z1 == 0, " want 0 got %d", z1);
37         CHECK(z64 == 0, " want 0 got %d", z64);
38         CHECK(z4096 == 0, " want 0 got %d", z4096);
39
40         CHECK(ptrmod(&z64, 64) == 0, " address is %p, want 64 byte alignment", &z64);
41         CHECK(ptrmod(&z4096, 4096) == 0, " address is %p, want 4096 byte alignment", &z4096);
42         return 0;
43 }
44
45 int main()
46 {
47         pthread_t td;
48
49         check(0);
50         CHECK(pthread_create(&td, 0, check, 0) == 0, "", "");
51         CHECK(pthread_join(td, 0) == 0, "", "");
52
53         return t_status;
54 }