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