Hurd: fix mode type for openat
[glibc.git] / nptl / tst-attr2.c
blobe8f9cc986f12b5dc365cda11631e917c9e326a81
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.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <pthread.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
26 int
27 do_test (void)
29 pthread_attr_t a;
31 if (pthread_attr_init (&a) != 0)
33 puts ("attr_init failed");
34 exit (1);
37 /* Check default value of detach state. */
38 int s;
39 if (pthread_attr_getdetachstate (&a, &s) != 0)
41 puts ("1st attr_getdestachstate failed");
42 exit (1);
44 if (s != PTHREAD_CREATE_JOINABLE)
46 printf ("\
47 default detach state wrong: %d, expected %d (PTHREAD_CREATE_JOINABLE)\n",
48 s, PTHREAD_CREATE_JOINABLE);
49 exit (1);
52 int e = pthread_attr_setdetachstate (&a, PTHREAD_CREATE_DETACHED);
53 if (e != 0)
55 puts ("1st attr_setdetachstate failed");
56 exit (1);
58 if (pthread_attr_getdetachstate (&a, &s) != 0)
60 puts ("2nd attr_getdestachstate failed");
61 exit (1);
63 if (s != PTHREAD_CREATE_DETACHED)
65 puts ("PTHREAD_CREATE_DETACHED set, but not given back");
66 exit (1);
69 e = pthread_attr_setdetachstate (&a, PTHREAD_CREATE_JOINABLE);
70 if (e != 0)
72 puts ("2nd attr_setdetachstate failed");
73 exit (1);
75 if (pthread_attr_getdetachstate (&a, &s) != 0)
77 puts ("3rd attr_getdestachstate failed");
78 exit (1);
80 if (s != PTHREAD_CREATE_JOINABLE)
82 puts ("PTHREAD_CREATE_JOINABLE set, but not given back");
83 exit (1);
87 size_t g;
88 if (pthread_attr_getguardsize (&a, &g) != 0)
90 puts ("1st attr_getguardsize failed");
91 exit (1);
93 if (g != (size_t) sysconf (_SC_PAGESIZE))
95 printf ("default guardsize %zu, expected %ld (PAGESIZE)\n",
96 g, sysconf (_SC_PAGESIZE));
97 exit (1);
100 e = pthread_attr_setguardsize (&a, 0);
101 if (e != 0)
103 puts ("1st attr_setguardsize failed");
104 exit (1);
106 if (pthread_attr_getguardsize (&a, &g) != 0)
108 puts ("2nd attr_getguardsize failed");
109 exit (1);
111 if (g != 0)
113 printf ("guardsize set to zero but %zu returned\n", g);
114 exit (1);
117 e = pthread_attr_setguardsize (&a, 1);
118 if (e != 0)
120 puts ("2nd attr_setguardsize failed");
121 exit (1);
123 if (pthread_attr_getguardsize (&a, &g) != 0)
125 puts ("3rd attr_getguardsize failed");
126 exit (1);
128 if (g != 1)
130 printf ("guardsize set to 1 but %zu returned\n", g);
131 exit (1);
135 if (pthread_attr_getinheritsched (&a, &s) != 0)
137 puts ("1st attr_getinheritsched failed");
138 exit (1);
140 /* XXX What is the correct default value. */
141 if (s != PTHREAD_INHERIT_SCHED && s != PTHREAD_EXPLICIT_SCHED)
143 puts ("incorrect default value for inheritsched");
144 exit (1);
147 e = pthread_attr_setinheritsched (&a, PTHREAD_EXPLICIT_SCHED);
148 if (e != 0)
150 puts ("1st attr_setinheritsched failed");
151 exit (1);
153 if (pthread_attr_getinheritsched (&a, &s) != 0)
155 puts ("2nd attr_getinheritsched failed");
156 exit (1);
158 if (s != PTHREAD_EXPLICIT_SCHED)
160 printf ("inheritsched set to PTHREAD_EXPLICIT_SCHED, but got %d\n", s);
161 exit (1);
164 e = pthread_attr_setinheritsched (&a, PTHREAD_INHERIT_SCHED);
165 if (e != 0)
167 puts ("2nd attr_setinheritsched failed");
168 exit (1);
170 if (pthread_attr_getinheritsched (&a, &s) != 0)
172 puts ("3rd attr_getinheritsched failed");
173 exit (1);
175 if (s != PTHREAD_INHERIT_SCHED)
177 printf ("inheritsched set to PTHREAD_INHERIT_SCHED, but got %d\n", s);
178 exit (1);
182 if (pthread_attr_getschedpolicy (&a, &s) != 0)
184 puts ("1st attr_getschedpolicy failed");
185 exit (1);
187 /* XXX What is the correct default value. */
188 if (s != SCHED_OTHER && s != SCHED_FIFO && s != SCHED_RR)
190 puts ("incorrect default value for schedpolicy");
191 exit (1);
194 e = pthread_attr_setschedpolicy (&a, SCHED_RR);
195 if (e != 0)
197 puts ("1st attr_setschedpolicy failed");
198 exit (1);
200 if (pthread_attr_getschedpolicy (&a, &s) != 0)
202 puts ("2nd attr_getschedpolicy failed");
203 exit (1);
205 if (s != SCHED_RR)
207 printf ("schedpolicy set to SCHED_RR, but got %d\n", s);
208 exit (1);
211 e = pthread_attr_setschedpolicy (&a, SCHED_FIFO);
212 if (e != 0)
214 puts ("2nd attr_setschedpolicy failed");
215 exit (1);
217 if (pthread_attr_getschedpolicy (&a, &s) != 0)
219 puts ("3rd attr_getschedpolicy failed");
220 exit (1);
222 if (s != SCHED_FIFO)
224 printf ("schedpolicy set to SCHED_FIFO, but got %d\n", s);
225 exit (1);
228 e = pthread_attr_setschedpolicy (&a, SCHED_OTHER);
229 if (e != 0)
231 puts ("3rd attr_setschedpolicy failed");
232 exit (1);
234 if (pthread_attr_getschedpolicy (&a, &s) != 0)
236 puts ("4th attr_getschedpolicy failed");
237 exit (1);
239 if (s != SCHED_OTHER)
241 printf ("schedpolicy set to SCHED_OTHER, but got %d\n", s);
242 exit (1);
246 if (pthread_attr_getscope (&a, &s) != 0)
248 puts ("1st attr_getscope failed");
249 exit (1);
251 /* XXX What is the correct default value. */
252 if (s != PTHREAD_SCOPE_SYSTEM && s != PTHREAD_SCOPE_PROCESS)
254 puts ("incorrect default value for contentionscope");
255 exit (1);
258 e = pthread_attr_setscope (&a, PTHREAD_SCOPE_PROCESS);
259 if (e != ENOTSUP)
261 if (e != 0)
263 puts ("1st attr_setscope failed");
264 exit (1);
266 if (pthread_attr_getscope (&a, &s) != 0)
268 puts ("2nd attr_getscope failed");
269 exit (1);
271 if (s != PTHREAD_SCOPE_PROCESS)
273 printf ("\
274 contentionscope set to PTHREAD_SCOPE_PROCESS, but got %d\n", s);
275 exit (1);
279 e = pthread_attr_setscope (&a, PTHREAD_SCOPE_SYSTEM);
280 if (e != 0)
282 puts ("2nd attr_setscope failed");
283 exit (1);
285 if (pthread_attr_getscope (&a, &s) != 0)
287 puts ("3rd attr_getscope failed");
288 exit (1);
290 if (s != PTHREAD_SCOPE_SYSTEM)
292 printf ("contentionscope set to PTHREAD_SCOPE_SYSTEM, but got %d\n", s);
293 exit (1);
296 char buf[1];
297 e = pthread_attr_setstack (&a, buf, 1);
298 if (e != EINVAL)
300 puts ("setstack with size 1 did not produce EINVAL");
301 exit (1);
304 e = pthread_attr_setstacksize (&a, 1);
305 if (e != EINVAL)
307 puts ("setstacksize with size 1 did not produce EINVAL");
308 exit (1);
311 return 0;
315 #define TEST_FUNCTION do_test ()
316 #include "../test-skeleton.c"