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
33 if (pthread_attr_init (&a
) != 0)
35 puts ("attr_init failed");
39 pthread_mutexattr_t ma
;
41 if (pthread_mutexattr_init (&ma
) != 0)
43 puts ("mutexattr_init failed");
47 pthread_rwlockattr_t rwa
;
49 if (pthread_rwlockattr_init (&rwa
) != 0)
51 puts ("rwlockattr_init failed");
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
);
70 printf ("attr_setdetachstate with value %ld succeeded\n", r
);
75 puts ("attr_setdetachstate didn't return EINVAL");
80 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
82 puts ("attr_getdetachstate failed");
86 if (s
!= PTHREAD_CREATE_JOINABLE
)
89 detach state changed to %d by invalid setdetachstate call\n", s
);
94 if (r
!= PTHREAD_INHERIT_SCHED
&& r
!= PTHREAD_EXPLICIT_SCHED
)
96 int e
= pthread_attr_setinheritsched (&a
, r
);
100 printf ("attr_setinheritsched with value %ld succeeded\n", r
);
105 puts ("attr_setinheritsched didn't return EINVAL");
110 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
112 puts ("attr_getinheritsched failed");
116 if (s
!= PTHREAD_INHERIT_SCHED
)
119 inheritsched changed to %d by invalid setinheritsched call\n", s
);
124 if (r
!= SCHED_OTHER
&& r
!= SCHED_RR
&& r
!= SCHED_FIFO
)
126 int e
= pthread_attr_setschedpolicy (&a
, r
);
130 printf ("attr_setschedpolicy with value %ld succeeded\n", r
);
135 puts ("attr_setschedpolicy didn't return EINVAL");
140 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
142 puts ("attr_getschedpolicy failed");
146 if (s
!= SCHED_OTHER
)
149 schedpolicy changed to %d by invalid setschedpolicy call\n", s
);
154 if (r
!= PTHREAD_SCOPE_SYSTEM
&& r
!= PTHREAD_SCOPE_PROCESS
)
156 int e
= pthread_attr_setscope (&a
, r
);
160 printf ("attr_setscope with value %ld succeeded\n", r
);
165 puts ("attr_setscope didn't return EINVAL");
170 if (pthread_attr_getscope (&a
, &s
) != 0)
172 puts ("attr_getscope failed");
176 if (s
!= PTHREAD_SCOPE_SYSTEM
)
179 contentionscope changed to %d by invalid setscope call\n", s
);
184 if (r
!= PTHREAD_PROCESS_PRIVATE
&& r
!= PTHREAD_PROCESS_SHARED
)
186 int e
= pthread_mutexattr_setpshared (&ma
, r
);
190 printf ("mutexattr_setpshared with value %ld succeeded\n", r
);
195 puts ("mutexattr_setpshared didn't return EINVAL");
200 if (pthread_mutexattr_getpshared (&ma
, &s
) != 0)
202 puts ("mutexattr_getpshared failed");
206 if (s
!= PTHREAD_PROCESS_PRIVATE
)
209 pshared changed to %d by invalid mutexattr_setpshared call\n", s
);
213 e
= pthread_rwlockattr_setpshared (&rwa
, r
);
217 printf ("rwlockattr_setpshared with value %ld succeeded\n", r
);
222 puts ("rwlockattr_setpshared didn't return EINVAL");
226 if (pthread_rwlockattr_getpshared (&rwa
, &s
) != 0)
228 puts ("rwlockattr_getpshared failed");
232 if (s
!= PTHREAD_PROCESS_PRIVATE
)
235 pshared changed to %d by invalid rwlockattr_setpshared call\n", s
);
240 if (r
!= PTHREAD_CANCEL_ENABLE
&& r
!= PTHREAD_CANCEL_DISABLE
)
242 int e
= pthread_setcancelstate (r
, NULL
);
246 printf ("setcancelstate with value %ld succeeded\n", r
);
252 puts ("setcancelstate didn't return EINVAL");
257 if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE
, &s
) != 0)
259 puts ("setcancelstate failed for PTHREAD_CANCEL_ENABLE");
263 if (s
!= PTHREAD_CANCEL_ENABLE
)
265 puts ("invalid setcancelstate changed state");
270 if (r
!= PTHREAD_CANCEL_DEFERRED
&& r
!= PTHREAD_CANCEL_ASYNCHRONOUS
)
272 int e
= pthread_setcanceltype (r
, NULL
);
276 printf ("setcanceltype with value %ld succeeded\n", r
);
282 puts ("setcanceltype didn't return EINVAL");
287 if (pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, &s
) != 0)
289 puts ("setcanceltype failed for PTHREAD_CANCEL_DEFERRED");
293 if (s
!= PTHREAD_CANCEL_DEFERRED
)
295 puts ("invalid setcanceltype changed state");
305 #define TEST_FUNCTION do_test ()
306 #include "../test-skeleton.c"