]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/tst-tls3.c
Update.
[thirdparty/glibc.git] / nptl / tst-tls3.c
CommitLineData
ffeb4481
UD
1/* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20#include <dlfcn.h>
21#include <pthread.h>
22#include <signal.h>
23#include <semaphore.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <unistd.h>
27
28
29#define THE_SIG SIGUSR1
30
31
32#define N 10
33static pthread_t th[N];
34
35
36#define CB(n) \
37static void \
38cb##n (void) \
39{ \
40 if (th[n] != pthread_self ()) \
41 { \
42 write (STDOUT_FILENO, "wrong callback\n", 15); \
43 _exit (1); \
44 } \
45}
46CB (0)
47CB (1)
48CB (2)
49CB (3)
50CB (4)
51CB (5)
52CB (6)
53CB (7)
54CB (8)
55CB (9)
56static void (*cbs[]) (void) =
57{
58 cb0, cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9
59};
60
61
62sem_t s;
63
64
65pthread_barrier_t b;
66
67#define TOTAL_SIGS 1000
68int nsigs;
69
70
71int
72do_test (void)
73{
74 if (pthread_barrier_init (&b, NULL, N + 1) != 0)
75 {
76 puts ("barrier_init failed");
77 exit (1);
78 }
79
80 if (sem_init (&s, 0, 0) != 0)
81 {
82 puts ("sem_init failed");
83 exit (1);
84 }
85
86 void *h = dlopen ("tst-tls3mod.so", RTLD_LAZY);
87 if (h == NULL)
88 {
89 puts ("dlopen failed");
90 exit (1);
91 }
92
93 void *(*tf) (void *) = dlsym (h, "tf");
94 if (tf == NULL)
95 {
96 puts ("dlsym for tf failed");
97 exit (1);
98 }
99
100 struct sigaction sa;
101 sa.sa_handler = dlsym (h, "handler");
102 if (sa.sa_handler == NULL)
103 {
104 puts ("dlsym for handler failed");
105 exit (1);
106 }
107 sigemptyset (&sa.sa_mask);
108 sa.sa_flags = 0;
109 if (sigaction (THE_SIG, &sa, NULL) != 0)
110 {
111 puts ("sigaction failed");
112 exit (1);
113 }
114
115 int r;
116 for (r = 0; r < 10; ++r)
117 {
118 int i;
119 for (i = 0; i < N; ++i)
120 if (pthread_create (&th[i], NULL, tf, cbs[i]) != 0)
121 {
122 puts ("pthread_create failed");
123 exit (1);
124 }
125
126 nsigs = 0;
127
128 pthread_barrier_wait (&b);
129
130 sigset_t ss;
131 sigemptyset (&ss);
132 sigaddset (&ss, THE_SIG);
133 if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
134 {
135 puts ("pthread_sigmask failed");
136 exit (1);
137 }
138
139 /* Start sending signals. */
140 for (i = 0; i < TOTAL_SIGS; ++i)
141 {
142 if (kill (getpid (), THE_SIG) != 0)
143 {
144 puts ("kill failed");
145 exit (1);
146 }
147
148 if (sem_wait (&s) != 0)
149 {
150 puts ("sem_wait failed");
151 exit (1);
152 }
153
154 ++nsigs;
155 }
156
157 pthread_barrier_wait (&b);
158
159 if (pthread_sigmask (SIG_UNBLOCK, &ss, NULL) != 0)
160 {
161 puts ("pthread_sigmask failed");
162 exit (1);
163 }
164
165 for (i = 0; i < N; ++i)
166 if (pthread_join (th[i], NULL) != 0)
167 {
168 puts ("join failed");
169 exit (1);
170 }
171 }
172
173 return 0;
174}
175
176
177#define TIMEOUT 5
178#define TEST_FUNCTION do_test ()
179#include "../test-skeleton.c"