(initshells): Check for integer overflows.
[glibc/history.git] / nptl / tst-attr1.c
blob13b62a69de1282846f167e56e081630b360ecc9e
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 int i;
31 pthread_attr_t a;
33 if (pthread_attr_init (&a) != 0)
35 puts ("attr_init failed");
36 exit (1);
39 pthread_mutexattr_t ma;
41 if (pthread_mutexattr_init (&ma) != 0)
43 puts ("mutexattr_init failed");
44 exit (1);
47 pthread_rwlockattr_t rwa;
49 if (pthread_rwlockattr_init (&rwa) != 0)
51 puts ("rwlockattr_init failed");
52 exit (1);
55 /* XXX Remove if default value is clear. */
56 pthread_attr_setinheritsched (&a, PTHREAD_INHERIT_SCHED);
57 pthread_attr_setschedpolicy (&a, SCHED_OTHER);
58 pthread_attr_setscope (&a, PTHREAD_SCOPE_SYSTEM);
60 for (i = 0; i < 10000; ++i)
62 long int r = random ();
64 if (r != PTHREAD_CREATE_DETACHED && r != PTHREAD_CREATE_JOINABLE)
66 int e = pthread_attr_setdetachstate (&a, r);
68 if (e == 0)
70 printf ("attr_setdetachstate with value %ld succeeded\n", r);
71 exit (1);
73 if (e != EINVAL)
75 puts ("attr_setdetachstate didn't return EINVAL");
76 exit (1);
79 int s;
80 if (pthread_attr_getdetachstate (&a, &s) != 0)
82 puts ("attr_getdetachstate failed");
83 exit (1);
86 if (s != PTHREAD_CREATE_JOINABLE)
88 printf ("\
89 detach state changed to %d by invalid setdetachstate call\n", s);
90 exit (1);
94 if (r != PTHREAD_INHERIT_SCHED && r != PTHREAD_EXPLICIT_SCHED)
96 int e = pthread_attr_setinheritsched (&a, r);
98 if (e == 0)
100 printf ("attr_setinheritsched with value %ld succeeded\n", r);
101 exit (1);
103 if (e != EINVAL)
105 puts ("attr_setinheritsched didn't return EINVAL");
106 exit (1);
109 int s;
110 if (pthread_attr_getinheritsched (&a, &s) != 0)
112 puts ("attr_getinheritsched failed");
113 exit (1);
116 if (s != PTHREAD_INHERIT_SCHED)
118 printf ("\
119 inheritsched changed to %d by invalid setinheritsched call\n", s);
120 exit (1);
124 if (r != SCHED_OTHER && r != SCHED_RR && r != SCHED_FIFO)
126 int e = pthread_attr_setschedpolicy (&a, r);
128 if (e == 0)
130 printf ("attr_setschedpolicy with value %ld succeeded\n", r);
131 exit (1);
133 if (e != EINVAL)
135 puts ("attr_setschedpolicy didn't return EINVAL");
136 exit (1);
139 int s;
140 if (pthread_attr_getschedpolicy (&a, &s) != 0)
142 puts ("attr_getschedpolicy failed");
143 exit (1);
146 if (s != SCHED_OTHER)
148 printf ("\
149 schedpolicy changed to %d by invalid setschedpolicy call\n", s);
150 exit (1);
154 if (r != PTHREAD_SCOPE_SYSTEM && r != PTHREAD_SCOPE_PROCESS)
156 int e = pthread_attr_setscope (&a, r);
158 if (e == 0)
160 printf ("attr_setscope with value %ld succeeded\n", r);
161 exit (1);
163 if (e != EINVAL)
165 puts ("attr_setscope didn't return EINVAL");
166 exit (1);
169 int s;
170 if (pthread_attr_getscope (&a, &s) != 0)
172 puts ("attr_getscope failed");
173 exit (1);
176 if (s != PTHREAD_SCOPE_SYSTEM)
178 printf ("\
179 contentionscope changed to %d by invalid setscope call\n", s);
180 exit (1);
184 if (r != PTHREAD_PROCESS_PRIVATE && r != PTHREAD_PROCESS_SHARED)
186 int e = pthread_mutexattr_setpshared (&ma, r);
188 if (e == 0)
190 printf ("mutexattr_setpshared with value %ld succeeded\n", r);
191 exit (1);
193 if (e != EINVAL)
195 puts ("mutexattr_setpshared didn't return EINVAL");
196 exit (1);
199 int s;
200 if (pthread_mutexattr_getpshared (&ma, &s) != 0)
202 puts ("mutexattr_getpshared failed");
203 exit (1);
206 if (s != PTHREAD_PROCESS_PRIVATE)
208 printf ("\
209 pshared changed to %d by invalid mutexattr_setpshared call\n", s);
210 exit (1);
213 e = pthread_rwlockattr_setpshared (&rwa, r);
215 if (e == 0)
217 printf ("rwlockattr_setpshared with value %ld succeeded\n", r);
218 exit (1);
220 if (e != EINVAL)
222 puts ("rwlockattr_setpshared didn't return EINVAL");
223 exit (1);
226 if (pthread_rwlockattr_getpshared (&rwa, &s) != 0)
228 puts ("rwlockattr_getpshared failed");
229 exit (1);
232 if (s != PTHREAD_PROCESS_PRIVATE)
234 printf ("\
235 pshared changed to %d by invalid rwlockattr_setpshared call\n", s);
236 exit (1);
240 if (r != PTHREAD_CANCEL_ENABLE && r != PTHREAD_CANCEL_DISABLE)
242 int e = pthread_setcancelstate (r, NULL);
244 if (e == 0)
246 printf ("setcancelstate with value %ld succeeded\n", r);
247 exit (1);
250 if (e != EINVAL)
252 puts ("setcancelstate didn't return EINVAL");
253 exit (1);
256 int s;
257 if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, &s) != 0)
259 puts ("setcancelstate failed for PTHREAD_CANCEL_ENABLE");
260 exit (1);
263 if (s != PTHREAD_CANCEL_ENABLE)
265 puts ("invalid setcancelstate changed state");
266 exit (1);
270 if (r != PTHREAD_CANCEL_DEFERRED && r != PTHREAD_CANCEL_ASYNCHRONOUS)
272 int e = pthread_setcanceltype (r, NULL);
274 if (e == 0)
276 printf ("setcanceltype with value %ld succeeded\n", r);
277 exit (1);
280 if (e != EINVAL)
282 puts ("setcanceltype didn't return EINVAL");
283 exit (1);
286 int s;
287 if (pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &s) != 0)
289 puts ("setcanceltype failed for PTHREAD_CANCEL_DEFERRED");
290 exit (1);
293 if (s != PTHREAD_CANCEL_DEFERRED)
295 puts ("invalid setcanceltype changed state");
296 exit (1);
301 return 0;
305 #define TEST_FUNCTION do_test ()
306 #include "../test-skeleton.c"