add __tls_get_new regression test
[libc-test] / src / regression / tls_get_new-dtv.c
1 // __tls_get_new did not allocate new dtv for threads properly
2 #include <pthread.h>
3 #include <dlfcn.h>
4 #include "test.h"
5
6 #define N 10
7
8 #define T(c) ((c) || (t_error(#c " failed\n"),0))
9
10 static pthread_barrier_t b;
11 static void *mod;
12
13 static void *start(void *a)
14 {
15         void *(*f)(void);
16
17         pthread_barrier_wait(&b);
18         T(f = dlsym(mod, "f"));
19         f();
20         return 0;
21 }
22
23 int main()
24 {
25         pthread_t td[N];
26         int i;
27
28         pthread_barrier_init(&b, 0, N+1);
29         for (i=0; i<N; i++)
30                 T(!pthread_create(td+i, 0, start, 0));
31
32         T(mod = dlopen("tls_get_new-dtv_dso.so", RTLD_NOW));
33         pthread_barrier_wait(&b);
34
35         for (i=0; i<N; i++)
36                 T(!pthread_join(td[i], 0));
37         return t_status;
38 }