From: Antti Kantee Date: Tue, 20 Jan 2015 16:46:29 +0000 (+0100) Subject: add @mato's tls tester, simplified+automated a bit X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=52dab0306643d5421aeeb6a3b13adce1cb7a359a;p=rumpuser-xen.git add @mato's tls tester, simplified+automated a bit --- diff --git a/Makefile b/Makefile index 4436814..32a29ea 100644 --- 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 diff --git a/tests/libstdtests/rumpkern_demo.c b/tests/libstdtests/rumpkern_demo.c index 0e45a18..96167c3 100644 --- a/tests/libstdtests/rumpkern_demo.c +++ b/tests/libstdtests/rumpkern_demo.c @@ -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 index 0000000..552a91b --- /dev/null +++ b/tests/libstdtests/tls_test.c @@ -0,0 +1,69 @@ +/* Simple test for TLS support */ +#ifdef __x86_64__ +#include + +#include +#include +#include +#include +#include + +#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