Remove ENOSYS math/ function stubs.
[glibc.git] / nptl / tst-attr1.c
blob1da7f3ba0105e1894bb922e7c41c5b24bb459fb2
1 /* Copyright (C) 2003-2017 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 int i;
30 pthread_attr_t a;
32 if (pthread_attr_init (&a) != 0)
34 puts ("attr_init failed");
35 exit (1);
38 pthread_mutexattr_t ma;
40 if (pthread_mutexattr_init (&ma) != 0)
42 puts ("mutexattr_init failed");
43 exit (1);
46 pthread_rwlockattr_t rwa;
48 if (pthread_rwlockattr_init (&rwa) != 0)
50 puts ("rwlockattr_init failed");
51 exit (1);
54 /* XXX Remove if default value is clear. */
55 pthread_attr_setinheritsched (&a, PTHREAD_INHERIT_SCHED);
56 pthread_attr_setschedpolicy (&a, SCHED_OTHER);
57 pthread_attr_setscope (&a, PTHREAD_SCOPE_SYSTEM);
59 for (i = 0; i < 10000; ++i)
61 long int r = random ();
63 if (r != PTHREAD_CREATE_DETACHED && r != PTHREAD_CREATE_JOINABLE)
65 int e = pthread_attr_setdetachstate (&a, r);
67 if (e == 0)
69 printf ("attr_setdetachstate with value %ld succeeded\n", r);
70 exit (1);
72 if (e != EINVAL)
74 puts ("attr_setdetachstate didn't return EINVAL");
75 exit (1);
78 int s;
79 if (pthread_attr_getdetachstate (&a, &s) != 0)
81 puts ("attr_getdetachstate failed");
82 exit (1);
85 if (s != PTHREAD_CREATE_JOINABLE)
87 printf ("\
88 detach state changed to %d by invalid setdetachstate call\n", s);
89 exit (1);
93 if (r != PTHREAD_INHERIT_SCHED && r != PTHREAD_EXPLICIT_SCHED)
95 int e = pthread_attr_setinheritsched (&a, r);
97 if (e == 0)
99 printf ("attr_setinheritsched with value %ld succeeded\n", r);
100 exit (1);
102 if (e != EINVAL)
104 puts ("attr_setinheritsched didn't return EINVAL");
105 exit (1);
108 int s;
109 if (pthread_attr_getinheritsched (&a, &s) != 0)
111 puts ("attr_getinheritsched failed");
112 exit (1);
115 if (s != PTHREAD_INHERIT_SCHED)
117 printf ("\
118 inheritsched changed to %d by invalid setinheritsched call\n", s);
119 exit (1);
123 if (r != SCHED_OTHER && r != SCHED_RR && r != SCHED_FIFO)
125 int e = pthread_attr_setschedpolicy (&a, r);
127 if (e == 0)
129 printf ("attr_setschedpolicy with value %ld succeeded\n", r);
130 exit (1);
132 if (e != EINVAL)
134 puts ("attr_setschedpolicy didn't return EINVAL");
135 exit (1);
138 int s;
139 if (pthread_attr_getschedpolicy (&a, &s) != 0)
141 puts ("attr_getschedpolicy failed");
142 exit (1);
145 if (s != SCHED_OTHER)
147 printf ("\
148 schedpolicy changed to %d by invalid setschedpolicy call\n", s);
149 exit (1);
153 if (r != PTHREAD_SCOPE_SYSTEM && r != PTHREAD_SCOPE_PROCESS)
155 int e = pthread_attr_setscope (&a, r);
157 if (e == 0)
159 printf ("attr_setscope with value %ld succeeded\n", r);
160 exit (1);
162 if (e != EINVAL)
164 puts ("attr_setscope didn't return EINVAL");
165 exit (1);
168 int s;
169 if (pthread_attr_getscope (&a, &s) != 0)
171 puts ("attr_getscope failed");
172 exit (1);
175 if (s != PTHREAD_SCOPE_SYSTEM)
177 printf ("\
178 contentionscope changed to %d by invalid setscope call\n", s);
179 exit (1);
183 if (r != PTHREAD_PROCESS_PRIVATE && r != PTHREAD_PROCESS_SHARED)
185 int e = pthread_mutexattr_setpshared (&ma, r);
187 if (e == 0)
189 printf ("mutexattr_setpshared with value %ld succeeded\n", r);
190 exit (1);
192 if (e != EINVAL)
194 puts ("mutexattr_setpshared didn't return EINVAL");
195 exit (1);
198 int s;
199 if (pthread_mutexattr_getpshared (&ma, &s) != 0)
201 puts ("mutexattr_getpshared failed");
202 exit (1);
205 if (s != PTHREAD_PROCESS_PRIVATE)
207 printf ("\
208 pshared changed to %d by invalid mutexattr_setpshared call\n", s);
209 exit (1);
212 e = pthread_rwlockattr_setpshared (&rwa, r);
214 if (e == 0)
216 printf ("rwlockattr_setpshared with value %ld succeeded\n", r);
217 exit (1);
219 if (e != EINVAL)
221 puts ("rwlockattr_setpshared didn't return EINVAL");
222 exit (1);
225 if (pthread_rwlockattr_getpshared (&rwa, &s) != 0)
227 puts ("rwlockattr_getpshared failed");
228 exit (1);
231 if (s != PTHREAD_PROCESS_PRIVATE)
233 printf ("\
234 pshared changed to %d by invalid rwlockattr_setpshared call\n", s);
235 exit (1);
239 if (r != PTHREAD_CANCEL_ENABLE && r != PTHREAD_CANCEL_DISABLE)
241 int e = pthread_setcancelstate (r, NULL);
243 if (e == 0)
245 printf ("setcancelstate with value %ld succeeded\n", r);
246 exit (1);
249 if (e != EINVAL)
251 puts ("setcancelstate didn't return EINVAL");
252 exit (1);
255 int s;
256 if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, &s) != 0)
258 puts ("setcancelstate failed for PTHREAD_CANCEL_ENABLE");
259 exit (1);
262 if (s != PTHREAD_CANCEL_ENABLE)
264 puts ("invalid setcancelstate changed state");
265 exit (1);
269 if (r != PTHREAD_CANCEL_DEFERRED && r != PTHREAD_CANCEL_ASYNCHRONOUS)
271 int e = pthread_setcanceltype (r, NULL);
273 if (e == 0)
275 printf ("setcanceltype with value %ld succeeded\n", r);
276 exit (1);
279 if (e != EINVAL)
281 puts ("setcanceltype didn't return EINVAL");
282 exit (1);
285 int s;
286 if (pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &s) != 0)
288 puts ("setcanceltype failed for PTHREAD_CANCEL_DEFERRED");
289 exit (1);
292 if (s != PTHREAD_CANCEL_DEFERRED)
294 puts ("invalid setcanceltype changed state");
295 exit (1);
300 return 0;
304 #define TEST_FUNCTION do_test ()
305 #include "../test-skeleton.c"