]> xenbits.xensource.com Git - rumpuser-xen.git/commitdiff
add @mato's tls tester, simplified+automated a bit
authorAntti Kantee <pooka@iki.fi>
Tue, 20 Jan 2015 16:46:29 +0000 (17:46 +0100)
committerAntti Kantee <pooka@iki.fi>
Tue, 20 Jan 2015 16:59:03 +0000 (17:59 +0100)
Makefile
tests/libstdtests/rumpkern_demo.c
tests/libstdtests/tls_test.c [new file with mode: 0644]

index 4436814bf6ffe8874e4dace24c874e6d3cf9a59b..32a29eaee94c0c7a8b67af320a3a9677fa362a7f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -127,7 +127,8 @@ tests:
 httpd:
        $(APP_TOOLS_MAKE) -C httpd -f Makefile.boot
 
-STDTESTS=tests/libstdtests/rumpkern_demo.c tests/libstdtests/pthread_test.c
+STDTESTS=tests/libstdtests/rumpkern_demo.c tests/libstdtests/pthread_test.c \
+        tests/libstdtests/tls_test.c
 rump-kernel: ${STDTESTS} httpd
        app-tools/rumpapp-xen-cc -o $@ ${STDTESTS} httpd/*.o
 
index 0e45a185d3d8c71d12778858fe0924a059cd561a..96167c335f23658709bb1bec549514dd766b7431 100644 (file)
@@ -375,6 +375,7 @@ dohttpd(void)
 }
 
 void test_pthread(void);
+void test_tls(void);
 
 int
 main(int argc, char *argv[])
@@ -391,6 +392,8 @@ main(int argc, char *argv[])
                dofs();
        if (tests & 0x8)
                test_pthread();
+       if (tests & 0x10)
+               test_tls();
        if (tests & 0x2)
                donet();
        if (tests & 0x4)
diff --git a/tests/libstdtests/tls_test.c b/tests/libstdtests/tls_test.c
new file mode 100644 (file)
index 0000000..552a91b
--- /dev/null
@@ -0,0 +1,69 @@
+/* Simple test for TLS support */
+#ifdef __x86_64__
+#include <sys/types.h>
+
+#include <err.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <sched.h>
+#include <stdio.h>
+
+#define NTHREADS 10
+#define LOOPCNT 1000
+#define IINITIAL 12345678
+
+static __thread unsigned long c;
+static __thread unsigned long i = IINITIAL;
+
+static void *
+wrkthread(void *arg)
+{
+
+       printf ("Thread %d starting\n", (int)(uintptr_t)arg);
+       if (i != IINITIAL) {
+               printf("initial i incorrect: %lu vs. %d\n", i, IINITIAL);
+               return NULL;
+       }
+       i++;
+
+       while (c < LOOPCNT) {
+               c++;
+               sched_yield();
+       }
+       return (void *)(uintptr_t)c;
+}
+
+void
+test_tls(void)
+{
+       pthread_t threads[NTHREADS];
+       int n, rc;
+
+       printf("TLS test\n");
+
+       for (n = 0; n < NTHREADS; n++) {
+               rc = pthread_create(&threads[n], NULL,
+                   wrkthread, (void *)(uintptr_t)n);
+               if (rc != 0) {
+                       errx(1, "pthread_create[%d] failed", n);
+               }
+       }
+
+       for (n = NTHREADS-1; n >= 0; n--) {
+               void *ret;
+               int rv;
+
+               rc = pthread_join(threads[n], &ret);
+               if (rc != 0) {
+                       err(1, "pthread_join[%d] failed", n);
+               }
+               rv = (int)(uintptr_t)ret;
+               if (rv != LOOPCNT)
+                       errx(1, "thread[%d]: expected %d, got %d\n",
+                           n, LOOPCNT, rv);
+       }
+}
+
+#else
+void test_tls(void) {}
+#endif