]>
Commit | Line | Data |
---|---|---|
3ce1f295 | 1 | /* Copyright (C) 2003, 2004, 2011 Free Software Foundation, Inc. |
ffeb4481 UD |
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> | |
ccf1d573 | 21 | #include <errno.h> |
ffeb4481 UD |
22 | #include <pthread.h> |
23 | #include <signal.h> | |
24 | #include <semaphore.h> | |
c874a32e | 25 | #include <stdint.h> |
ffeb4481 UD |
26 | #include <stdio.h> |
27 | #include <stdlib.h> | |
28 | #include <unistd.h> | |
c874a32e | 29 | #include <pthreaddef.h> |
ffeb4481 UD |
30 | |
31 | #define THE_SIG SIGUSR1 | |
32 | ||
33 | ||
34 | #define N 10 | |
35 | static pthread_t th[N]; | |
36 | ||
37 | ||
38 | #define CB(n) \ | |
39 | static void \ | |
40 | cb##n (void) \ | |
41 | { \ | |
42 | if (th[n] != pthread_self ()) \ | |
43 | { \ | |
44 | write (STDOUT_FILENO, "wrong callback\n", 15); \ | |
45 | _exit (1); \ | |
46 | } \ | |
47 | } | |
48 | CB (0) | |
49 | CB (1) | |
50 | CB (2) | |
51 | CB (3) | |
52 | CB (4) | |
53 | CB (5) | |
54 | CB (6) | |
55 | CB (7) | |
56 | CB (8) | |
57 | CB (9) | |
58 | static void (*cbs[]) (void) = | |
59 | { | |
60 | cb0, cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9 | |
61 | }; | |
62 | ||
63 | ||
64 | sem_t s; | |
65 | ||
66 | ||
67 | pthread_barrier_t b; | |
68 | ||
69 | #define TOTAL_SIGS 1000 | |
70 | int nsigs; | |
71 | ||
72 | ||
73 | int | |
74 | do_test (void) | |
75 | { | |
c874a32e UD |
76 | if ((uintptr_t) pthread_self () & (TCB_ALIGNMENT - 1)) |
77 | { | |
78 | puts ("initial thread's struct pthread not aligned enough"); | |
79 | exit (1); | |
80 | } | |
81 | ||
ffeb4481 UD |
82 | if (pthread_barrier_init (&b, NULL, N + 1) != 0) |
83 | { | |
84 | puts ("barrier_init failed"); | |
85 | exit (1); | |
86 | } | |
87 | ||
88 | if (sem_init (&s, 0, 0) != 0) | |
89 | { | |
90 | puts ("sem_init failed"); | |
91 | exit (1); | |
92 | } | |
93 | ||
94 | void *h = dlopen ("tst-tls3mod.so", RTLD_LAZY); | |
95 | if (h == NULL) | |
96 | { | |
97 | puts ("dlopen failed"); | |
98 | exit (1); | |
99 | } | |
100 | ||
101 | void *(*tf) (void *) = dlsym (h, "tf"); | |
102 | if (tf == NULL) | |
103 | { | |
104 | puts ("dlsym for tf failed"); | |
105 | exit (1); | |
106 | } | |
107 | ||
108 | struct sigaction sa; | |
109 | sa.sa_handler = dlsym (h, "handler"); | |
110 | if (sa.sa_handler == NULL) | |
111 | { | |
112 | puts ("dlsym for handler failed"); | |
113 | exit (1); | |
114 | } | |
115 | sigemptyset (&sa.sa_mask); | |
116 | sa.sa_flags = 0; | |
117 | if (sigaction (THE_SIG, &sa, NULL) != 0) | |
118 | { | |
119 | puts ("sigaction failed"); | |
120 | exit (1); | |
121 | } | |
122 | ||
4d1a02ef UD |
123 | pthread_attr_t a; |
124 | ||
125 | if (pthread_attr_init (&a) != 0) | |
126 | { | |
127 | puts ("attr_init failed"); | |
128 | exit (1); | |
129 | } | |
130 | ||
131 | if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0) | |
132 | { | |
133 | puts ("attr_setstacksize failed"); | |
134 | return 1; | |
135 | } | |
136 | ||
ffeb4481 UD |
137 | int r; |
138 | for (r = 0; r < 10; ++r) | |
139 | { | |
140 | int i; | |
141 | for (i = 0; i < N; ++i) | |
4d1a02ef | 142 | if (pthread_create (&th[i], &a, tf, cbs[i]) != 0) |
ffeb4481 UD |
143 | { |
144 | puts ("pthread_create failed"); | |
145 | exit (1); | |
146 | } | |
147 | ||
148 | nsigs = 0; | |
149 | ||
150 | pthread_barrier_wait (&b); | |
151 | ||
152 | sigset_t ss; | |
153 | sigemptyset (&ss); | |
154 | sigaddset (&ss, THE_SIG); | |
155 | if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0) | |
156 | { | |
157 | puts ("pthread_sigmask failed"); | |
158 | exit (1); | |
159 | } | |
160 | ||
161 | /* Start sending signals. */ | |
162 | for (i = 0; i < TOTAL_SIGS; ++i) | |
163 | { | |
164 | if (kill (getpid (), THE_SIG) != 0) | |
165 | { | |
166 | puts ("kill failed"); | |
167 | exit (1); | |
168 | } | |
169 | ||
ccf1d573 | 170 | if (TEMP_FAILURE_RETRY (sem_wait (&s)) != 0) |
ffeb4481 UD |
171 | { |
172 | puts ("sem_wait failed"); | |
173 | exit (1); | |
174 | } | |
175 | ||
176 | ++nsigs; | |
177 | } | |
178 | ||
179 | pthread_barrier_wait (&b); | |
180 | ||
181 | if (pthread_sigmask (SIG_UNBLOCK, &ss, NULL) != 0) | |
182 | { | |
183 | puts ("pthread_sigmask failed"); | |
184 | exit (1); | |
185 | } | |
186 | ||
187 | for (i = 0; i < N; ++i) | |
188 | if (pthread_join (th[i], NULL) != 0) | |
189 | { | |
190 | puts ("join failed"); | |
191 | exit (1); | |
192 | } | |
193 | } | |
194 | ||
4d1a02ef UD |
195 | if (pthread_attr_destroy (&a) != 0) |
196 | { | |
197 | puts ("attr_destroy failed"); | |
198 | exit (1); | |
199 | } | |
200 | ||
ffeb4481 UD |
201 | return 0; |
202 | } | |
203 | ||
204 | ||
205 | #define TIMEOUT 5 | |
206 | #define TEST_FUNCTION do_test () | |
207 | #include "../test-skeleton.c" |