LoongArch: Use "$fcsr0" instead of "$r0" in _FPU_{GET,SET}CW
[glibc.git] / sysdeps / pthread / tst-attr1.c
blobf1d8809311813972ad8f360b078f82276764685b
1 /* Copyright (C) 2003-2024 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 int i;
29 pthread_attr_t a;
31 if (pthread_attr_init (&a) != 0)
33 puts ("attr_init failed");
34 exit (1);
37 pthread_mutexattr_t ma;
39 if (pthread_mutexattr_init (&ma) != 0)
41 puts ("mutexattr_init failed");
42 exit (1);
45 pthread_rwlockattr_t rwa;
47 if (pthread_rwlockattr_init (&rwa) != 0)
49 puts ("rwlockattr_init failed");
50 exit (1);
53 /* XXX Remove if default value is clear. */
54 pthread_attr_setinheritsched (&a, PTHREAD_INHERIT_SCHED);
55 pthread_attr_setschedpolicy (&a, SCHED_OTHER);
56 pthread_attr_setscope (&a, PTHREAD_SCOPE_SYSTEM);
58 for (i = 0; i < 10000; ++i)
60 long int r = random ();
62 if (r != PTHREAD_CREATE_DETACHED && r != PTHREAD_CREATE_JOINABLE)
64 int e = pthread_attr_setdetachstate (&a, r);
66 if (e == 0)
68 printf ("attr_setdetachstate with value %ld succeeded\n", r);
69 exit (1);
71 if (e != EINVAL)
73 puts ("attr_setdetachstate didn't return EINVAL");
74 exit (1);
77 int s;
78 if (pthread_attr_getdetachstate (&a, &s) != 0)
80 puts ("attr_getdetachstate failed");
81 exit (1);
84 if (s != PTHREAD_CREATE_JOINABLE)
86 printf ("\
87 detach state changed to %d by invalid setdetachstate call\n", s);
88 exit (1);
92 if (r != PTHREAD_INHERIT_SCHED && r != PTHREAD_EXPLICIT_SCHED)
94 int e = pthread_attr_setinheritsched (&a, r);
96 if (e == 0)
98 printf ("attr_setinheritsched with value %ld succeeded\n", r);
99 exit (1);
101 if (e != EINVAL)
103 puts ("attr_setinheritsched didn't return EINVAL");
104 exit (1);
107 int s;
108 if (pthread_attr_getinheritsched (&a, &s) != 0)
110 puts ("attr_getinheritsched failed");
111 exit (1);
114 if (s != PTHREAD_INHERIT_SCHED)
116 printf ("\
117 inheritsched changed to %d by invalid setinheritsched call\n", s);
118 exit (1);
122 if (r != SCHED_OTHER && r != SCHED_RR && r != SCHED_FIFO)
124 int e = pthread_attr_setschedpolicy (&a, r);
126 if (e == 0)
128 printf ("attr_setschedpolicy with value %ld succeeded\n", r);
129 exit (1);
131 if (e != EINVAL)
133 puts ("attr_setschedpolicy didn't return EINVAL");
134 exit (1);
137 int s;
138 if (pthread_attr_getschedpolicy (&a, &s) != 0)
140 puts ("attr_getschedpolicy failed");
141 exit (1);
144 if (s != SCHED_OTHER)
146 printf ("\
147 schedpolicy changed to %d by invalid setschedpolicy call\n", s);
148 exit (1);
152 if (r != PTHREAD_SCOPE_SYSTEM && r != PTHREAD_SCOPE_PROCESS)
154 int e = pthread_attr_setscope (&a, r);
156 if (e == 0)
158 printf ("attr_setscope with value %ld succeeded\n", r);
159 exit (1);
161 if (e != EINVAL)
163 puts ("attr_setscope didn't return EINVAL");
164 exit (1);
167 int s;
168 if (pthread_attr_getscope (&a, &s) != 0)
170 puts ("attr_getscope failed");
171 exit (1);
174 if (s != PTHREAD_SCOPE_SYSTEM)
176 printf ("\
177 contentionscope changed to %d by invalid setscope call\n", s);
178 exit (1);
182 if (r != PTHREAD_PROCESS_PRIVATE && r != PTHREAD_PROCESS_SHARED)
184 int e = pthread_mutexattr_setpshared (&ma, r);
186 if (e == 0)
188 printf ("mutexattr_setpshared with value %ld succeeded\n", r);
189 exit (1);
191 if (e != EINVAL)
193 puts ("mutexattr_setpshared didn't return EINVAL");
194 exit (1);
197 int s;
198 if (pthread_mutexattr_getpshared (&ma, &s) != 0)
200 puts ("mutexattr_getpshared failed");
201 exit (1);
204 if (s != PTHREAD_PROCESS_PRIVATE)
206 printf ("\
207 pshared changed to %d by invalid mutexattr_setpshared call\n", s);
208 exit (1);
211 e = pthread_rwlockattr_setpshared (&rwa, r);
213 if (e == 0)
215 printf ("rwlockattr_setpshared with value %ld succeeded\n", r);
216 exit (1);
218 if (e != EINVAL)
220 puts ("rwlockattr_setpshared didn't return EINVAL");
221 exit (1);
224 if (pthread_rwlockattr_getpshared (&rwa, &s) != 0)
226 puts ("rwlockattr_getpshared failed");
227 exit (1);
230 if (s != PTHREAD_PROCESS_PRIVATE)
232 printf ("\
233 pshared changed to %d by invalid rwlockattr_setpshared call\n", s);
234 exit (1);
238 if (r != PTHREAD_CANCEL_ENABLE && r != PTHREAD_CANCEL_DISABLE)
240 int e = pthread_setcancelstate (r, NULL);
242 if (e == 0)
244 printf ("setcancelstate with value %ld succeeded\n", r);
245 exit (1);
248 if (e != EINVAL)
250 puts ("setcancelstate didn't return EINVAL");
251 exit (1);
254 int s;
255 if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, &s) != 0)
257 puts ("setcancelstate failed for PTHREAD_CANCEL_ENABLE");
258 exit (1);
261 if (s != PTHREAD_CANCEL_ENABLE)
263 puts ("invalid setcancelstate changed state");
264 exit (1);
268 if (r != PTHREAD_CANCEL_DEFERRED && r != PTHREAD_CANCEL_ASYNCHRONOUS)
270 int e = pthread_setcanceltype (r, NULL);
272 if (e == 0)
274 printf ("setcanceltype with value %ld succeeded\n", r);
275 exit (1);
278 if (e != EINVAL)
280 puts ("setcanceltype didn't return EINVAL");
281 exit (1);
284 int s;
285 if (pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &s) != 0)
287 puts ("setcanceltype failed for PTHREAD_CANCEL_DEFERRED");
288 exit (1);
291 if (s != PTHREAD_CANCEL_DEFERRED)
293 puts ("invalid setcanceltype changed state");
294 exit (1);
299 return 0;
303 #define TEST_FUNCTION do_test ()
304 #include "../test-skeleton.c"