1 /* Copyright (C) 2003-2022 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/>. */
31 if (pthread_attr_init (&a
) != 0)
33 puts ("attr_init failed");
37 pthread_mutexattr_t ma
;
39 if (pthread_mutexattr_init (&ma
) != 0)
41 puts ("mutexattr_init failed");
45 pthread_rwlockattr_t rwa
;
47 if (pthread_rwlockattr_init (&rwa
) != 0)
49 puts ("rwlockattr_init failed");
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
);
68 printf ("attr_setdetachstate with value %ld succeeded\n", r
);
73 puts ("attr_setdetachstate didn't return EINVAL");
78 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
80 puts ("attr_getdetachstate failed");
84 if (s
!= PTHREAD_CREATE_JOINABLE
)
87 detach state changed to %d by invalid setdetachstate call\n", s
);
92 if (r
!= PTHREAD_INHERIT_SCHED
&& r
!= PTHREAD_EXPLICIT_SCHED
)
94 int e
= pthread_attr_setinheritsched (&a
, r
);
98 printf ("attr_setinheritsched with value %ld succeeded\n", r
);
103 puts ("attr_setinheritsched didn't return EINVAL");
108 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
110 puts ("attr_getinheritsched failed");
114 if (s
!= PTHREAD_INHERIT_SCHED
)
117 inheritsched changed to %d by invalid setinheritsched call\n", s
);
122 if (r
!= SCHED_OTHER
&& r
!= SCHED_RR
&& r
!= SCHED_FIFO
)
124 int e
= pthread_attr_setschedpolicy (&a
, r
);
128 printf ("attr_setschedpolicy with value %ld succeeded\n", r
);
133 puts ("attr_setschedpolicy didn't return EINVAL");
138 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
140 puts ("attr_getschedpolicy failed");
144 if (s
!= SCHED_OTHER
)
147 schedpolicy changed to %d by invalid setschedpolicy call\n", s
);
152 if (r
!= PTHREAD_SCOPE_SYSTEM
&& r
!= PTHREAD_SCOPE_PROCESS
)
154 int e
= pthread_attr_setscope (&a
, r
);
158 printf ("attr_setscope with value %ld succeeded\n", r
);
163 puts ("attr_setscope didn't return EINVAL");
168 if (pthread_attr_getscope (&a
, &s
) != 0)
170 puts ("attr_getscope failed");
174 if (s
!= PTHREAD_SCOPE_SYSTEM
)
177 contentionscope changed to %d by invalid setscope call\n", s
);
182 if (r
!= PTHREAD_PROCESS_PRIVATE
&& r
!= PTHREAD_PROCESS_SHARED
)
184 int e
= pthread_mutexattr_setpshared (&ma
, r
);
188 printf ("mutexattr_setpshared with value %ld succeeded\n", r
);
193 puts ("mutexattr_setpshared didn't return EINVAL");
198 if (pthread_mutexattr_getpshared (&ma
, &s
) != 0)
200 puts ("mutexattr_getpshared failed");
204 if (s
!= PTHREAD_PROCESS_PRIVATE
)
207 pshared changed to %d by invalid mutexattr_setpshared call\n", s
);
211 e
= pthread_rwlockattr_setpshared (&rwa
, r
);
215 printf ("rwlockattr_setpshared with value %ld succeeded\n", r
);
220 puts ("rwlockattr_setpshared didn't return EINVAL");
224 if (pthread_rwlockattr_getpshared (&rwa
, &s
) != 0)
226 puts ("rwlockattr_getpshared failed");
230 if (s
!= PTHREAD_PROCESS_PRIVATE
)
233 pshared changed to %d by invalid rwlockattr_setpshared call\n", s
);
238 if (r
!= PTHREAD_CANCEL_ENABLE
&& r
!= PTHREAD_CANCEL_DISABLE
)
240 int e
= pthread_setcancelstate (r
, NULL
);
244 printf ("setcancelstate with value %ld succeeded\n", r
);
250 puts ("setcancelstate didn't return EINVAL");
255 if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE
, &s
) != 0)
257 puts ("setcancelstate failed for PTHREAD_CANCEL_ENABLE");
261 if (s
!= PTHREAD_CANCEL_ENABLE
)
263 puts ("invalid setcancelstate changed state");
268 if (r
!= PTHREAD_CANCEL_DEFERRED
&& r
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
270 int e
= pthread_setcanceltype (r
, NULL
);
274 printf ("setcanceltype with value %ld succeeded\n", r
);
280 puts ("setcanceltype didn't return EINVAL");
285 if (pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &s
) != 0)
287 puts ("setcanceltype failed for PTHREAD_CANCEL_DEFERRED");
291 if (s
!= PTHREAD_CANCEL_DEFERRED
)
293 puts ("invalid setcanceltype changed state");
303 #define TEST_FUNCTION do_test ()
304 #include "../test-skeleton.c"