* locales/as_IN: Fix currency_symbol, abday for Sunday, abmon for
[glibc/pb-stable.git] / nptl / tst-attr2.c
bloba60598dd7e38b61a9b7c8fbd29fdd0badb54b7c1
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <pthread.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
27 int
28 do_test (void)
30 pthread_attr_t a;
32 if (pthread_attr_init (&a) != 0)
34 puts ("attr_init failed");
35 exit (1);
38 /* Check default value of detach state. */
39 int s;
40 if (pthread_attr_getdetachstate (&a, &s) != 0)
42 puts ("1st attr_getdestachstate failed");
43 exit (1);
45 if (s != PTHREAD_CREATE_JOINABLE)
47 printf ("\
48 default detach state wrong: %d, expected %d (PTHREAD_CREATE_JOINABLE)\n",
49 s, PTHREAD_CREATE_JOINABLE);
50 exit (1);
53 int e = pthread_attr_setdetachstate (&a, PTHREAD_CREATE_DETACHED);
54 if (e != 0)
56 puts ("1st attr_setdetachstate failed");
57 exit (1);
59 if (pthread_attr_getdetachstate (&a, &s) != 0)
61 puts ("2nd attr_getdestachstate failed");
62 exit (1);
64 if (s != PTHREAD_CREATE_DETACHED)
66 puts ("PTHREAD_CREATE_DETACHED set, but not given back");
67 exit (1);
70 e = pthread_attr_setdetachstate (&a, PTHREAD_CREATE_JOINABLE);
71 if (e != 0)
73 puts ("2nd attr_setdetachstate failed");
74 exit (1);
76 if (pthread_attr_getdetachstate (&a, &s) != 0)
78 puts ("3rd attr_getdestachstate failed");
79 exit (1);
81 if (s != PTHREAD_CREATE_JOINABLE)
83 puts ("PTHREAD_CREATE_JOINABLE set, but not given back");
84 exit (1);
88 size_t g;
89 if (pthread_attr_getguardsize (&a, &g) != 0)
91 puts ("1st attr_getguardsize failed");
92 exit (1);
94 if (g != (size_t) sysconf (_SC_PAGESIZE))
96 printf ("default guardsize %zu, expected %ld (PAGESIZE)\n",
97 g, sysconf (_SC_PAGESIZE));
98 exit (1);
101 e = pthread_attr_setguardsize (&a, 0);
102 if (e != 0)
104 puts ("1st attr_setguardsize failed");
105 exit (1);
107 if (pthread_attr_getguardsize (&a, &g) != 0)
109 puts ("2nd attr_getguardsize failed");
110 exit (1);
112 if (g != 0)
114 printf ("guardsize set to zero but %zu returned\n", g);
115 exit (1);
118 e = pthread_attr_setguardsize (&a, 1);
119 if (e != 0)
121 puts ("2nd attr_setguardsize failed");
122 exit (1);
124 if (pthread_attr_getguardsize (&a, &g) != 0)
126 puts ("3rd attr_getguardsize failed");
127 exit (1);
129 if (g != 1)
131 printf ("guardsize set to 1 but %zu returned\n", g);
132 exit (1);
136 if (pthread_attr_getinheritsched (&a, &s) != 0)
138 puts ("1st attr_getinheritsched failed");
139 exit (1);
141 /* XXX What is the correct default value. */
142 if (s != PTHREAD_INHERIT_SCHED && s != PTHREAD_EXPLICIT_SCHED)
144 puts ("incorrect default value for inheritsched");
145 exit (1);
148 e = pthread_attr_setinheritsched (&a, PTHREAD_EXPLICIT_SCHED);
149 if (e != 0)
151 puts ("1st attr_setinheritsched failed");
152 exit (1);
154 if (pthread_attr_getinheritsched (&a, &s) != 0)
156 puts ("2nd attr_getinheritsched failed");
157 exit (1);
159 if (s != PTHREAD_EXPLICIT_SCHED)
161 printf ("inheritsched set to PTHREAD_EXPLICIT_SCHED, but got %d\n", s);
162 exit (1);
165 e = pthread_attr_setinheritsched (&a, PTHREAD_INHERIT_SCHED);
166 if (e != 0)
168 puts ("2nd attr_setinheritsched failed");
169 exit (1);
171 if (pthread_attr_getinheritsched (&a, &s) != 0)
173 puts ("3rd attr_getinheritsched failed");
174 exit (1);
176 if (s != PTHREAD_INHERIT_SCHED)
178 printf ("inheritsched set to PTHREAD_INHERIT_SCHED, but got %d\n", s);
179 exit (1);
183 if (pthread_attr_getschedpolicy (&a, &s) != 0)
185 puts ("1st attr_getschedpolicy failed");
186 exit (1);
188 /* XXX What is the correct default value. */
189 if (s != SCHED_OTHER && s != SCHED_FIFO && s != SCHED_RR)
191 puts ("incorrect default value for schedpolicy");
192 exit (1);
195 e = pthread_attr_setschedpolicy (&a, SCHED_RR);
196 if (e != 0)
198 puts ("1st attr_setschedpolicy failed");
199 exit (1);
201 if (pthread_attr_getschedpolicy (&a, &s) != 0)
203 puts ("2nd attr_getschedpolicy failed");
204 exit (1);
206 if (s != SCHED_RR)
208 printf ("schedpolicy set to SCHED_RR, but got %d\n", s);
209 exit (1);
212 e = pthread_attr_setschedpolicy (&a, SCHED_FIFO);
213 if (e != 0)
215 puts ("2nd attr_setschedpolicy failed");
216 exit (1);
218 if (pthread_attr_getschedpolicy (&a, &s) != 0)
220 puts ("3rd attr_getschedpolicy failed");
221 exit (1);
223 if (s != SCHED_FIFO)
225 printf ("schedpolicy set to SCHED_FIFO, but got %d\n", s);
226 exit (1);
229 e = pthread_attr_setschedpolicy (&a, SCHED_OTHER);
230 if (e != 0)
232 puts ("3rd attr_setschedpolicy failed");
233 exit (1);
235 if (pthread_attr_getschedpolicy (&a, &s) != 0)
237 puts ("4th attr_getschedpolicy failed");
238 exit (1);
240 if (s != SCHED_OTHER)
242 printf ("schedpolicy set to SCHED_OTHER, but got %d\n", s);
243 exit (1);
247 if (pthread_attr_getscope (&a, &s) != 0)
249 puts ("1st attr_getscope failed");
250 exit (1);
252 /* XXX What is the correct default value. */
253 if (s != PTHREAD_SCOPE_SYSTEM && s != PTHREAD_SCOPE_PROCESS)
255 puts ("incorrect default value for contentionscope");
256 exit (1);
259 e = pthread_attr_setscope (&a, PTHREAD_SCOPE_PROCESS);
260 if (e != ENOTSUP)
262 if (e != 0)
264 puts ("1st attr_setscope failed");
265 exit (1);
267 if (pthread_attr_getscope (&a, &s) != 0)
269 puts ("2nd attr_getscope failed");
270 exit (1);
272 if (s != PTHREAD_SCOPE_PROCESS)
274 printf ("\
275 contentionscope set to PTHREAD_SCOPE_PROCESS, but got %d\n", s);
276 exit (1);
280 e = pthread_attr_setscope (&a, PTHREAD_SCOPE_SYSTEM);
281 if (e != 0)
283 puts ("2nd attr_setscope failed");
284 exit (1);
286 if (pthread_attr_getscope (&a, &s) != 0)
288 puts ("3rd attr_getscope failed");
289 exit (1);
291 if (s != PTHREAD_SCOPE_SYSTEM)
293 printf ("contentionscope set to PTHREAD_SCOPE_SYSTEM, but got %d\n", s);
294 exit (1);
297 char buf[1];
298 e = pthread_attr_setstack (&a, buf, 1);
299 if (e != EINVAL)
301 puts ("setstack with size 1 did not produce EINVAL");
302 exit (1);
305 e = pthread_attr_setstacksize (&a, 1);
306 if (e != EINVAL)
308 puts ("setstacksize with size 1 did not produce EINVAL");
309 exit (1);
312 return 0;
316 #define TEST_FUNCTION do_test ()
317 #include "../test-skeleton.c"