1570af302Sopenharmony_ci#include <stdint.h> 2570af302Sopenharmony_ci#include <string.h> 3570af302Sopenharmony_ci#include <pthread.h> 4570af302Sopenharmony_ci#include "test.h" 5570af302Sopenharmony_ci 6570af302Sopenharmony_cistatic __thread char d1 = 11; 7570af302Sopenharmony_cistatic __thread char d64 __attribute__ ((aligned(64))) = 22; 8570af302Sopenharmony_cistatic __thread char d4096 __attribute__ ((aligned(4096))) = 33; 9570af302Sopenharmony_cistatic __thread char z1 = 0; 10570af302Sopenharmony_cistatic __thread char z64 __attribute__ ((aligned(64))) = 0; 11570af302Sopenharmony_cistatic __thread char z4096 __attribute__ ((aligned(4096))) = 0; 12570af302Sopenharmony_cistatic __thread const char *s1 = "s1"; 13570af302Sopenharmony_ci 14570af302Sopenharmony_cistatic int tnum; 15570af302Sopenharmony_ci 16570af302Sopenharmony_ci#define CHECK(c, fmt, ...) do{ \ 17570af302Sopenharmony_ci if (!(c)) \ 18570af302Sopenharmony_ci t_error("[thread %d]: "#c" failed"fmt".\n", tnum, __VA_ARGS__); \ 19570af302Sopenharmony_ci}while(0) 20570af302Sopenharmony_ci 21570af302Sopenharmony_cistatic unsigned ptrmod(void *p, unsigned m) 22570af302Sopenharmony_ci{ 23570af302Sopenharmony_ci volatile unsigned n = (uintptr_t)p; 24570af302Sopenharmony_ci return n % m; 25570af302Sopenharmony_ci} 26570af302Sopenharmony_ci 27570af302Sopenharmony_cistatic void *check(void *arg) 28570af302Sopenharmony_ci{ 29570af302Sopenharmony_ci tnum++; 30570af302Sopenharmony_ci 31570af302Sopenharmony_ci CHECK(d1 == 11, " want 11 got %d", d1); 32570af302Sopenharmony_ci CHECK(d64 == 22, " want 22 got %d", d64); 33570af302Sopenharmony_ci CHECK(d4096 == 33, " want 33 got %d", d4096); 34570af302Sopenharmony_ci 35570af302Sopenharmony_ci CHECK(ptrmod(&d64, 64) == 0, " address is %p, want 64 byte alignment", &d64); 36570af302Sopenharmony_ci CHECK(ptrmod(&d4096, 4096) == 0, " address is %p, want 4096 byte alignment", &d4096); 37570af302Sopenharmony_ci 38570af302Sopenharmony_ci CHECK(z1 == 0, " want 0 got %d", z1); 39570af302Sopenharmony_ci CHECK(z64 == 0, " want 0 got %d", z64); 40570af302Sopenharmony_ci CHECK(z4096 == 0, " want 0 got %d", z4096); 41570af302Sopenharmony_ci 42570af302Sopenharmony_ci CHECK(ptrmod(&z64, 64) == 0, " address is %p, want 64 byte alignment", &z64); 43570af302Sopenharmony_ci CHECK(ptrmod(&z4096, 4096) == 0, " address is %p, want 4096 byte alignment", &z4096); 44570af302Sopenharmony_ci 45570af302Sopenharmony_ci CHECK(!strcmp(s1, "s1"), " want s1 got %s", s1); 46570af302Sopenharmony_ci return 0; 47570af302Sopenharmony_ci} 48570af302Sopenharmony_ci 49570af302Sopenharmony_ciint main() 50570af302Sopenharmony_ci{ 51570af302Sopenharmony_ci pthread_t td; 52570af302Sopenharmony_ci 53570af302Sopenharmony_ci check(0); 54570af302Sopenharmony_ci CHECK(pthread_create(&td, 0, check, 0) == 0, "", ""); 55570af302Sopenharmony_ci CHECK(pthread_join(td, 0) == 0, "", ""); 56570af302Sopenharmony_ci 57570af302Sopenharmony_ci return t_status; 58570af302Sopenharmony_ci} 59