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, see
17 <http://www.gnu.org/licenses/>. */
32 if (pthread_attr_init (&a
) != 0)
34 puts ("attr_init failed");
38 pthread_mutexattr_t ma
;
40 if (pthread_mutexattr_init (&ma
) != 0)
42 puts ("mutexattr_init failed");
46 pthread_rwlockattr_t rwa
;
48 if (pthread_rwlockattr_init (&rwa
) != 0)
50 puts ("rwlockattr_init failed");
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
);
69 printf ("attr_setdetachstate with value %ld succeeded\n", r
);
74 puts ("attr_setdetachstate didn't return EINVAL");
79 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
81 puts ("attr_getdetachstate failed");
85 if (s
!= PTHREAD_CREATE_JOINABLE
)
88 detach state changed to %d by invalid setdetachstate call\n", s
);
93 if (r
!= PTHREAD_INHERIT_SCHED
&& r
!= PTHREAD_EXPLICIT_SCHED
)
95 int e
= pthread_attr_setinheritsched (&a
, r
);
99 printf ("attr_setinheritsched with value %ld succeeded\n", r
);
104 puts ("attr_setinheritsched didn't return EINVAL");
109 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
111 puts ("attr_getinheritsched failed");
115 if (s
!= PTHREAD_INHERIT_SCHED
)
118 inheritsched changed to %d by invalid setinheritsched call\n", s
);
123 if (r
!= SCHED_OTHER
&& r
!= SCHED_RR
&& r
!= SCHED_FIFO
)
125 int e
= pthread_attr_setschedpolicy (&a
, r
);
129 printf ("attr_setschedpolicy with value %ld succeeded\n", r
);
134 puts ("attr_setschedpolicy didn't return EINVAL");
139 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
141 puts ("attr_getschedpolicy failed");
145 if (s
!= SCHED_OTHER
)
148 schedpolicy changed to %d by invalid setschedpolicy call\n", s
);
153 if (r
!= PTHREAD_SCOPE_SYSTEM
&& r
!= PTHREAD_SCOPE_PROCESS
)
155 int e
= pthread_attr_setscope (&a
, r
);
159 printf ("attr_setscope with value %ld succeeded\n", r
);
164 puts ("attr_setscope didn't return EINVAL");
169 if (pthread_attr_getscope (&a
, &s
) != 0)
171 puts ("attr_getscope failed");
175 if (s
!= PTHREAD_SCOPE_SYSTEM
)
178 contentionscope changed to %d by invalid setscope call\n", s
);
183 if (r
!= PTHREAD_PROCESS_PRIVATE
&& r
!= PTHREAD_PROCESS_SHARED
)
185 int e
= pthread_mutexattr_setpshared (&ma
, r
);
189 printf ("mutexattr_setpshared with value %ld succeeded\n", r
);
194 puts ("mutexattr_setpshared didn't return EINVAL");
199 if (pthread_mutexattr_getpshared (&ma
, &s
) != 0)
201 puts ("mutexattr_getpshared failed");
205 if (s
!= PTHREAD_PROCESS_PRIVATE
)
208 pshared changed to %d by invalid mutexattr_setpshared call\n", s
);
212 e
= pthread_rwlockattr_setpshared (&rwa
, r
);
216 printf ("rwlockattr_setpshared with value %ld succeeded\n", r
);
221 puts ("rwlockattr_setpshared didn't return EINVAL");
225 if (pthread_rwlockattr_getpshared (&rwa
, &s
) != 0)
227 puts ("rwlockattr_getpshared failed");
231 if (s
!= PTHREAD_PROCESS_PRIVATE
)
234 pshared changed to %d by invalid rwlockattr_setpshared call\n", s
);
239 if (r
!= PTHREAD_CANCEL_ENABLE
&& r
!= PTHREAD_CANCEL_DISABLE
)
241 int e
= pthread_setcancelstate (r
, NULL
);
245 printf ("setcancelstate with value %ld succeeded\n", r
);
251 puts ("setcancelstate didn't return EINVAL");
256 if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE
, &s
) != 0)
258 puts ("setcancelstate failed for PTHREAD_CANCEL_ENABLE");
262 if (s
!= PTHREAD_CANCEL_ENABLE
)
264 puts ("invalid setcancelstate changed state");
269 if (r
!= PTHREAD_CANCEL_DEFERRED
&& r
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
271 int e
= pthread_setcanceltype (r
, NULL
);
275 printf ("setcanceltype with value %ld succeeded\n", r
);
281 puts ("setcanceltype didn't return EINVAL");
286 if (pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &s
) != 0)
288 puts ("setcanceltype failed for PTHREAD_CANCEL_DEFERRED");
292 if (s
!= PTHREAD_CANCEL_DEFERRED
)
294 puts ("invalid setcanceltype changed state");
304 #define TEST_FUNCTION do_test ()
305 #include "../test-skeleton.c"