From 4f5020522165cf4032a3e5d4d29baf91b581499d Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 25 May 2018 20:02:47 +0000 Subject: [PATCH] add local exec tls align test --- src/functional/tls_local_exec.c | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/functional/tls_local_exec.c diff --git a/src/functional/tls_local_exec.c b/src/functional/tls_local_exec.c new file mode 100644 index 0000000..c6ec558 --- /dev/null +++ b/src/functional/tls_local_exec.c @@ -0,0 +1,54 @@ +#include +#include +#include "test.h" + +static __thread char d1 = 11; +static __thread char d64 __attribute__ ((aligned(64))) = 22; +static __thread char d4096 __attribute__ ((aligned(4096))) = 33; +static __thread char z1 = 0; +static __thread char z64 __attribute__ ((aligned(64))) = 0; +static __thread char z4096 __attribute__ ((aligned(4096))) = 0; + +static int tnum; + +#define CHECK(c, fmt, ...) do{ \ + if (!(c)) \ + t_error("[thread %d]: "#c" failed"fmt".\n", tnum, __VA_ARGS__); \ +}while(0) + +static unsigned ptrmod(void *p, unsigned m) +{ + volatile unsigned n = (uintptr_t)p; + return n % m; +} + +static void *check(void *arg) +{ + tnum++; + + CHECK(d1 == 11, " want 11 got %d", d1); + CHECK(d64 == 22, " want 22 got %d", d64); + CHECK(d4096 == 33, " want 33 got %d", d4096); + + CHECK(ptrmod(&d64, 64) == 0, " address is %p, want 64 byte alignment", &d64); + CHECK(ptrmod(&d4096, 4096) == 0, " address is %p, want 4096 byte alignment", &d4096); + + CHECK(z1 == 0, " want 0 got %d", z1); + CHECK(z64 == 0, " want 0 got %d", z64); + CHECK(z4096 == 0, " want 0 got %d", z4096); + + CHECK(ptrmod(&z64, 64) == 0, " address is %p, want 64 byte alignment", &z64); + CHECK(ptrmod(&z4096, 4096) == 0, " address is %p, want 4096 byte alignment", &z4096); + return 0; +} + +int main() +{ + pthread_t td; + + check(0); + CHECK(pthread_create(&td, 0, check, 0) == 0, "", ""); + CHECK(pthread_join(td, 0) == 0, "", ""); + + return t_status; +} -- 2.20.1