Print this page
7159 libc-tests build failed on sparc
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/test/libc-tests/tests/threads/pthread_attr_get_np.c
+++ new/usr/src/test/libc-tests/tests/threads/pthread_attr_get_np.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright 2016 Joyent, Inc.
14 14 */
15 15
16 16 /*
17 17 * Test and verify that pthrad_attr_get_np works as we expect.
18 18 *
19 19 * Verify the following:
20 20 * o ESRCH
21 21 * o stack size is set to a valid value after a thread is created.
22 22 * o main thread can grab an alternate thread's info.
23 23 * o custom guard size is honored
24 24 * o detach state
25 25 * - detached 1
26 26 * - joinable 2
27 27 * - changing 2
28 28 * o daemon state
29 29 * - enabled 1
30 30 * - disabled 2
31 31 * o scope
32 32 * - system 1
33 33 * - process 2
34 34 * o inheritable
35 35 * - inherit 1
36 36 * - explicit 2
37 37 * o priority
38 38 * - honors change 2
39 39 * o policy
40 40 * - honours change 2
41 41 *
42 42 *
43 43 * For each of the cases above we explicitly go through and create the set of
44 44 * attributes as marked above and then inside of a thread, verify that the
45 45 * attributes match what we expect. Because each case ends up in creating a
46 46 * detached thread, we opt to have both it and the main thread enter a barrier
47 47 * to indicate that we have completed the test successfully.
48 48 */
49 49
50 50 #include <errno.h>
51 51 #include <limits.h>
52 52 #include <stdio.h>
53 53 #include <pthread.h>
54 54 #include <unistd.h>
55 55 #include <ucontext.h>
56 56 #include <sched.h>
57 57 #include <strings.h>
58 58 #include <stdlib.h>
59 59
60 60 #include <sys/procfs.h>
61 61 #include <sys/debug.h>
62 62
63 63 /*
64 64 * Currently these are only defined in thr_uberdata.h. Rather than trying and
65 65 * fight with libc headers, just explicitly define them here.
66 66 */
67 67 #define PTHREAD_CREATE_DAEMON_NP 0x100 /* = THR_DAEMON */
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
68 68 #define PTHREAD_CREATE_NONDAEMON_NP 0
69 69 extern int pthread_attr_setdaemonstate_np(pthread_attr_t *, int);
70 70 extern int pthread_attr_getdaemonstate_np(const pthread_attr_t *, int *);
71 71
72 72 #define PGN_TEST_PRI 23
73 73
74 74 static pthread_attr_t pgn_attr;
75 75 static pthread_attr_t pgn_thr_attr;
76 76 static pthread_barrier_t pgn_barrier;
77 77
78 -#ifdef __sparc
79 -#define gregs __gregs
80 -#endif
81 78
82 79 /*
83 80 * Verify that the stack pointer of a context is consistent with where the
84 81 * attributes indicate.
85 82 */
86 83 static void
87 84 pgn_verif_thr_stack(pthread_attr_t *attr)
88 85 {
89 86 size_t stksz;
90 87 void *stk;
91 88 ucontext_t ctx;
92 89 uint32_t sp;
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
93 90
94 91 VERIFY0(getcontext(&ctx));
95 92 VERIFY0(pthread_attr_getstack(attr, &stk, &stksz));
96 93 VERIFY3P(stk, !=, NULL);
97 94 VERIFY3S(stksz, !=, 0);
98 95 sp = ctx.uc_mcontext.gregs[R_SP];
99 96 VERIFY3U(sp, >, (uintptr_t)stk);
100 97 VERIFY3U(sp, <, (uintptr_t)stk + stksz);
101 98 }
102 99
103 -#ifdef __sparc
104 -#undef gregs
105 -#endif
106 100
107 101 static void
108 102 pgn_test_fini(void)
109 103 {
110 104 int ret;
111 105
112 106 ret = pthread_barrier_wait(&pgn_barrier);
113 107 VERIFY(ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD);
114 108 VERIFY0(pthread_attr_destroy(&pgn_attr));
115 109 VERIFY0(pthread_attr_destroy(&pgn_thr_attr));
116 110 VERIFY0(pthread_barrier_destroy(&pgn_barrier));
117 111 }
118 112
119 113 static void
120 114 pgn_test_init(void)
121 115 {
122 116 VERIFY0(pthread_attr_init(&pgn_attr));
123 117 VERIFY0(pthread_attr_init(&pgn_thr_attr));
124 118 VERIFY0(pthread_barrier_init(&pgn_barrier, NULL, 2));
125 119 }
126 120
127 121 /* ARGSUSED */
128 122 static void *
129 123 pgn_set_one_thr(void *arg)
130 124 {
131 125 int odetach, ndetach;
132 126 int odaemon, ndaemon;
133 127 int oscope, nscope;
134 128 int oinherit, ninherit;
135 129
136 130 VERIFY0(pthread_attr_get_np(pthread_self(), &pgn_attr));
137 131 pgn_verif_thr_stack(&pgn_attr);
138 132
139 133 VERIFY0(pthread_attr_getdetachstate(&pgn_thr_attr, &odetach));
140 134 VERIFY0(pthread_attr_getdetachstate(&pgn_attr, &ndetach));
141 135
142 136 VERIFY3S(odetach, ==, ndetach);
143 137 VERIFY3S(ndetach, ==, PTHREAD_CREATE_DETACHED);
144 138
145 139 VERIFY0(pthread_attr_getdaemonstate_np(&pgn_thr_attr, &odaemon));
146 140 VERIFY0(pthread_attr_getdaemonstate_np(&pgn_attr, &ndaemon));
147 141
148 142 VERIFY3S(odaemon, ==, ndaemon);
149 143 VERIFY3S(ndaemon, ==, PTHREAD_CREATE_DAEMON_NP);
150 144
151 145 VERIFY0(pthread_attr_getscope(&pgn_thr_attr, &oscope));
152 146 VERIFY0(pthread_attr_getscope(&pgn_attr, &nscope));
153 147
154 148 VERIFY3S(oscope, ==, nscope);
155 149 VERIFY3S(nscope, ==, PTHREAD_SCOPE_SYSTEM);
156 150
157 151 VERIFY0(pthread_attr_getinheritsched(&pgn_thr_attr, &oinherit));
158 152 VERIFY0(pthread_attr_getinheritsched(&pgn_attr, &ninherit));
159 153
160 154 VERIFY3S(oinherit, ==, ninherit);
161 155 VERIFY3S(ninherit, ==, PTHREAD_INHERIT_SCHED);
162 156
163 157 VERIFY3S(pthread_barrier_wait(&pgn_barrier), !=, 1);
164 158 return (NULL);
165 159 }
166 160
167 161 static void
168 162 pgn_set_one(void)
169 163 {
170 164 int ret;
171 165 pthread_t thr;
172 166
173 167 pgn_test_init();
174 168
175 169 VERIFY0(pthread_attr_setdetachstate(&pgn_thr_attr,
176 170 PTHREAD_CREATE_DETACHED));
177 171 VERIFY0(pthread_attr_setdaemonstate_np(&pgn_thr_attr,
178 172 PTHREAD_CREATE_DAEMON_NP));
179 173 VERIFY0(pthread_attr_setscope(&pgn_thr_attr, PTHREAD_SCOPE_SYSTEM));
180 174 VERIFY0(pthread_attr_setinheritsched(&pgn_thr_attr,
181 175 PTHREAD_INHERIT_SCHED));
182 176
183 177 VERIFY0(pthread_create(&thr, &pgn_thr_attr, pgn_set_one_thr, NULL));
184 178
185 179 /*
186 180 * Verify it's not joinable.
187 181 */
188 182 ret = pthread_join(thr, NULL);
189 183 VERIFY3S(ret, ==, EINVAL);
190 184
191 185 /*
192 186 * At this point we let the test continue and wait on the barrier. We'll
193 187 * wake up when the other thread is done.
194 188 */
195 189 pgn_test_fini();
196 190 }
197 191
198 192 /* ARGSUSED */
199 193 static void *
200 194 pgn_set_two_thr(void *arg)
201 195 {
202 196 int odetach, ndetach;
203 197 int odaemon, ndaemon;
204 198 int oscope, nscope;
205 199 int oinherit, ninherit;
206 200 int opolicy, npolicy;
207 201 struct sched_param oparam, nparam;
208 202
209 203 VERIFY0(pthread_attr_get_np(pthread_self(), &pgn_attr));
210 204 pgn_verif_thr_stack(&pgn_attr);
211 205
212 206 VERIFY0(pthread_attr_getdetachstate(&pgn_thr_attr, &odetach));
213 207 VERIFY0(pthread_attr_getdetachstate(&pgn_attr, &ndetach));
214 208
215 209 VERIFY3S(odetach, ==, ndetach);
216 210 VERIFY3S(ndetach, ==, PTHREAD_CREATE_JOINABLE);
217 211
218 212 VERIFY0(pthread_attr_getdaemonstate_np(&pgn_thr_attr, &odaemon));
219 213 VERIFY0(pthread_attr_getdaemonstate_np(&pgn_attr, &ndaemon));
220 214
221 215 VERIFY3S(odaemon, ==, ndaemon);
222 216 VERIFY3S(ndaemon, ==, PTHREAD_CREATE_NONDAEMON_NP);
223 217
224 218 VERIFY0(pthread_attr_getscope(&pgn_thr_attr, &oscope));
225 219 VERIFY0(pthread_attr_getscope(&pgn_attr, &nscope));
226 220
227 221 VERIFY3S(oscope, ==, nscope);
228 222 VERIFY3S(nscope, ==, PTHREAD_SCOPE_PROCESS);
229 223
230 224 VERIFY0(pthread_attr_getinheritsched(&pgn_thr_attr, &oinherit));
231 225 VERIFY0(pthread_attr_getinheritsched(&pgn_attr, &ninherit));
232 226
233 227 VERIFY3S(oinherit, ==, ninherit);
234 228 VERIFY3S(ninherit, ==, PTHREAD_EXPLICIT_SCHED);
235 229
236 230 VERIFY0(pthread_attr_getschedpolicy(&pgn_thr_attr, &opolicy));
237 231 VERIFY0(pthread_attr_getschedpolicy(&pgn_attr, &npolicy));
238 232
239 233 VERIFY3S(opolicy, ==, npolicy);
240 234 VERIFY3S(npolicy, ==, SCHED_FSS);
241 235
242 236 /*
243 237 * Now that we've validated the basics, go ahead and test the changes,
244 238 * which include making sure that we see updates via
245 239 * pthread_setschedparam() and pthread_detach().
246 240 */
247 241 VERIFY0(pthread_detach(pthread_self()));
248 242
249 243 opolicy = SCHED_FX;
250 244 oparam.sched_priority = PGN_TEST_PRI;
251 245 VERIFY0(pthread_setschedparam(pthread_self(), opolicy, &oparam));
252 246
253 247 VERIFY0(pthread_attr_get_np(pthread_self(), &pgn_attr));
254 248 VERIFY0(pthread_attr_getdetachstate(&pgn_attr, &ndetach));
255 249
256 250 VERIFY3S(odetach, !=, ndetach);
257 251 VERIFY3S(ndetach, ==, PTHREAD_CREATE_DETACHED);
258 252
259 253 VERIFY0(pthread_attr_getschedpolicy(&pgn_attr, &npolicy));
260 254 VERIFY0(pthread_attr_getschedparam(&pgn_attr, &nparam));
261 255
262 256 VERIFY3S(opolicy, ==, npolicy);
263 257 VERIFY3S(npolicy, ==, SCHED_FX);
264 258
265 259 VERIFY3S(oparam.sched_priority, ==, nparam.sched_priority);
266 260 VERIFY3S(nparam.sched_priority, ==, PGN_TEST_PRI);
267 261
268 262 VERIFY3S(pthread_barrier_wait(&pgn_barrier), !=, 1);
269 263
270 264 return (NULL);
271 265 }
272 266
273 267 static void
274 268 pgn_set_two(void)
275 269 {
276 270 pthread_t thr;
277 271
278 272 pgn_test_init();
279 273
280 274 VERIFY0(pthread_attr_setdetachstate(&pgn_thr_attr,
281 275 PTHREAD_CREATE_JOINABLE));
282 276 VERIFY0(pthread_attr_setdaemonstate_np(&pgn_thr_attr,
283 277 PTHREAD_CREATE_NONDAEMON_NP));
284 278 VERIFY0(pthread_attr_setscope(&pgn_thr_attr, PTHREAD_SCOPE_PROCESS));
285 279 VERIFY0(pthread_attr_setinheritsched(&pgn_thr_attr,
286 280 PTHREAD_EXPLICIT_SCHED));
287 281 VERIFY0(pthread_attr_setschedpolicy(&pgn_thr_attr, SCHED_FSS));
288 282
289 283 VERIFY0(pthread_create(&thr, &pgn_thr_attr, pgn_set_two_thr, NULL));
290 284
291 285 /*
292 286 * At this point we let the test continue and wait on the barrier. We'll
293 287 * wake up when the other thread is done.
294 288 */
295 289 pgn_test_fini();
296 290 }
297 291
298 292 /* ARGSUSED */
299 293 static void *
300 294 pgn_set_three_thr(void *arg)
301 295 {
302 296 VERIFY3S(pthread_barrier_wait(&pgn_barrier), !=, 1);
303 297
304 298 return (NULL);
305 299 }
306 300
307 301 void
308 302 pgn_set_three(void)
309 303 {
310 304 pthread_t thr;
311 305 pthread_attr_t altattr, selfattr;
312 306 void *altstk, *selfstk;
313 307 size_t altsz, selfsz;
314 308
315 309 VERIFY0(pthread_attr_init(&altattr));
316 310 VERIFY0(pthread_attr_init(&selfattr));
317 311 pgn_test_init();
318 312
319 313 VERIFY0(pthread_create(&thr, NULL, pgn_set_three_thr, NULL));
320 314
321 315 VERIFY0(pthread_attr_get_np(thr, &altattr));
322 316 VERIFY0(pthread_attr_get_np(pthread_self(), &selfattr));
323 317
324 318 VERIFY0(pthread_attr_getstack(&selfattr, &selfstk, &selfsz));
325 319 VERIFY0(pthread_attr_getstack(&altattr, &altstk, &altsz));
326 320 VERIFY3P(altstk, !=, selfstk);
327 321
328 322 pgn_test_fini();
329 323 VERIFY0(pthread_attr_destroy(&selfattr));
330 324 VERIFY0(pthread_attr_destroy(&altattr));
331 325 }
332 326
333 327 int
334 328 main(void)
335 329 {
336 330 int ret;
337 331
338 332 VERIFY0(pthread_attr_init(&pgn_attr));
339 333
340 334 ret = pthread_attr_get_np(UINT32_MAX, &pgn_attr);
341 335 VERIFY3S(ret, ==, ESRCH);
342 336
343 337 pgn_set_one();
344 338 pgn_set_two();
345 339 pgn_set_three();
346 340
347 341 exit(0);
348 342 }
↓ open down ↓ |
233 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX