add local exec tls align test
authorSzabolcs Nagy <nsz@port70.net>
Fri, 25 May 2018 20:02:47 +0000 (20:02 +0000)
committerSzabolcs Nagy <nsz@port70.net>
Fri, 25 May 2018 21:30:00 +0000 (21:30 +0000)
src/functional/tls_local_exec.c [new file with mode: 0644]

diff --git a/src/functional/tls_local_exec.c b/src/functional/tls_local_exec.c
new file mode 100644 (file)
index 0000000..c6ec558
--- /dev/null
@@ -0,0 +1,54 @@
+#include <stdint.h>
+#include <pthread.h>
+#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;
+}