Allow _Qp_fgt in sparc64 localplt.data
[glibc.git] / nptl / tst-attr2.c
blob11be2a77d8e6b152016ec06c8cd35ec781ab056e
1 /* Copyright (C) 2003-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
25 int
26 do_test (void)
28 pthread_attr_t a;
30 if (pthread_attr_init (&a) != 0)
32 puts ("attr_init failed");
33 exit (1);
36 /* Check default value of detach state. */
37 int s;
38 if (pthread_attr_getdetachstate (&a, &s) != 0)
40 puts ("1st attr_getdestachstate failed");
41 exit (1);
43 if (s != PTHREAD_CREATE_JOINABLE)
45 printf ("\
46 default detach state wrong: %d, expected %d (PTHREAD_CREATE_JOINABLE)\n",
47 s, PTHREAD_CREATE_JOINABLE);
48 exit (1);
51 int e = pthread_attr_setdetachstate (&a, PTHREAD_CREATE_DETACHED);
52 if (e != 0)
54 puts ("1st attr_setdetachstate failed");
55 exit (1);
57 if (pthread_attr_getdetachstate (&a, &s) != 0)
59 puts ("2nd attr_getdestachstate failed");
60 exit (1);
62 if (s != PTHREAD_CREATE_DETACHED)
64 puts ("PTHREAD_CREATE_DETACHED set, but not given back");
65 exit (1);
68 e = pthread_attr_setdetachstate (&a, PTHREAD_CREATE_JOINABLE);
69 if (e != 0)
71 puts ("2nd attr_setdetachstate failed");
72 exit (1);
74 if (pthread_attr_getdetachstate (&a, &s) != 0)
76 puts ("3rd attr_getdestachstate failed");
77 exit (1);
79 if (s != PTHREAD_CREATE_JOINABLE)
81 puts ("PTHREAD_CREATE_JOINABLE set, but not given back");
82 exit (1);
86 size_t g;
87 if (pthread_attr_getguardsize (&a, &g) != 0)
89 puts ("1st attr_getguardsize failed");
90 exit (1);
92 if (g != (size_t) sysconf (_SC_PAGESIZE))
94 printf ("default guardsize %zu, expected %ld (PAGESIZE)\n",
95 g, sysconf (_SC_PAGESIZE));
96 exit (1);
99 e = pthread_attr_setguardsize (&a, 0);
100 if (e != 0)
102 puts ("1st attr_setguardsize failed");
103 exit (1);
105 if (pthread_attr_getguardsize (&a, &g) != 0)
107 puts ("2nd attr_getguardsize failed");
108 exit (1);
110 if (g != 0)
112 printf ("guardsize set to zero but %zu returned\n", g);
113 exit (1);
116 e = pthread_attr_setguardsize (&a, 1);
117 if (e != 0)
119 puts ("2nd attr_setguardsize failed");
120 exit (1);
122 if (pthread_attr_getguardsize (&a, &g) != 0)
124 puts ("3rd attr_getguardsize failed");
125 exit (1);
127 if (g != 1)
129 printf ("guardsize set to 1 but %zu returned\n", g);
130 exit (1);
134 if (pthread_attr_getinheritsched (&a, &s) != 0)
136 puts ("1st attr_getinheritsched failed");
137 exit (1);
139 /* XXX What is the correct default value. */
140 if (s != PTHREAD_INHERIT_SCHED && s != PTHREAD_EXPLICIT_SCHED)
142 puts ("incorrect default value for inheritsched");
143 exit (1);
146 e = pthread_attr_setinheritsched (&a, PTHREAD_EXPLICIT_SCHED);
147 if (e != 0)
149 puts ("1st attr_setinheritsched failed");
150 exit (1);
152 if (pthread_attr_getinheritsched (&a, &s) != 0)
154 puts ("2nd attr_getinheritsched failed");
155 exit (1);
157 if (s != PTHREAD_EXPLICIT_SCHED)
159 printf ("inheritsched set to PTHREAD_EXPLICIT_SCHED, but got %d\n", s);
160 exit (1);
163 e = pthread_attr_setinheritsched (&a, PTHREAD_INHERIT_SCHED);
164 if (e != 0)
166 puts ("2nd attr_setinheritsched failed");
167 exit (1);
169 if (pthread_attr_getinheritsched (&a, &s) != 0)
171 puts ("3rd attr_getinheritsched failed");
172 exit (1);
174 if (s != PTHREAD_INHERIT_SCHED)
176 printf ("inheritsched set to PTHREAD_INHERIT_SCHED, but got %d\n", s);
177 exit (1);
181 if (pthread_attr_getschedpolicy (&a, &s) != 0)
183 puts ("1st attr_getschedpolicy failed");
184 exit (1);
186 /* XXX What is the correct default value. */
187 if (s != SCHED_OTHER && s != SCHED_FIFO && s != SCHED_RR)
189 puts ("incorrect default value for schedpolicy");
190 exit (1);
193 e = pthread_attr_setschedpolicy (&a, SCHED_RR);
194 if (e != 0)
196 puts ("1st attr_setschedpolicy failed");
197 exit (1);
199 if (pthread_attr_getschedpolicy (&a, &s) != 0)
201 puts ("2nd attr_getschedpolicy failed");
202 exit (1);
204 if (s != SCHED_RR)
206 printf ("schedpolicy set to SCHED_RR, but got %d\n", s);
207 exit (1);
210 e = pthread_attr_setschedpolicy (&a, SCHED_FIFO);
211 if (e != 0)
213 puts ("2nd attr_setschedpolicy failed");
214 exit (1);
216 if (pthread_attr_getschedpolicy (&a, &s) != 0)
218 puts ("3rd attr_getschedpolicy failed");
219 exit (1);
221 if (s != SCHED_FIFO)
223 printf ("schedpolicy set to SCHED_FIFO, but got %d\n", s);
224 exit (1);
227 e = pthread_attr_setschedpolicy (&a, SCHED_OTHER);
228 if (e != 0)
230 puts ("3rd attr_setschedpolicy failed");
231 exit (1);
233 if (pthread_attr_getschedpolicy (&a, &s) != 0)
235 puts ("4th attr_getschedpolicy failed");
236 exit (1);
238 if (s != SCHED_OTHER)
240 printf ("schedpolicy set to SCHED_OTHER, but got %d\n", s);
241 exit (1);
245 if (pthread_attr_getscope (&a, &s) != 0)
247 puts ("1st attr_getscope failed");
248 exit (1);
250 /* XXX What is the correct default value. */
251 if (s != PTHREAD_SCOPE_SYSTEM && s != PTHREAD_SCOPE_PROCESS)
253 puts ("incorrect default value for contentionscope");
254 exit (1);
257 e = pthread_attr_setscope (&a, PTHREAD_SCOPE_PROCESS);
258 if (e != ENOTSUP)
260 if (e != 0)
262 puts ("1st attr_setscope failed");
263 exit (1);
265 if (pthread_attr_getscope (&a, &s) != 0)
267 puts ("2nd attr_getscope failed");
268 exit (1);
270 if (s != PTHREAD_SCOPE_PROCESS)
272 printf ("\
273 contentionscope set to PTHREAD_SCOPE_PROCESS, but got %d\n", s);
274 exit (1);
278 e = pthread_attr_setscope (&a, PTHREAD_SCOPE_SYSTEM);
279 if (e != 0)
281 puts ("2nd attr_setscope failed");
282 exit (1);
284 if (pthread_attr_getscope (&a, &s) != 0)
286 puts ("3rd attr_getscope failed");
287 exit (1);
289 if (s != PTHREAD_SCOPE_SYSTEM)
291 printf ("contentionscope set to PTHREAD_SCOPE_SYSTEM, but got %d\n", s);
292 exit (1);
295 char buf[1];
296 e = pthread_attr_setstack (&a, buf, 1);
297 if (e != EINVAL)
299 puts ("setstack with size 1 did not produce EINVAL");
300 exit (1);
303 e = pthread_attr_setstacksize (&a, 1);
304 if (e != EINVAL)
306 puts ("setstacksize with size 1 did not produce EINVAL");
307 exit (1);
310 return 0;
314 #define TEST_FUNCTION do_test ()
315 #include "../test-skeleton.c"