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
32 if (pthread_attr_init (&a
) != 0)
34 puts ("attr_init failed");
38 /* Check default value of detach state. */
40 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
42 puts ("1st attr_getdestachstate failed");
45 if (s
!= PTHREAD_CREATE_JOINABLE
)
48 default detach state wrong: %d, expected %d (PTHREAD_CREATE_JOINABLE)\n",
49 s
, PTHREAD_CREATE_JOINABLE
);
53 int e
= pthread_attr_setdetachstate (&a
, PTHREAD_CREATE_DETACHED
);
56 puts ("1st attr_setdetachstate failed");
59 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
61 puts ("2nd attr_getdestachstate failed");
64 if (s
!= PTHREAD_CREATE_DETACHED
)
66 puts ("PTHREAD_CREATE_DETACHED set, but not given back");
70 e
= pthread_attr_setdetachstate (&a
, PTHREAD_CREATE_JOINABLE
);
73 puts ("2nd attr_setdetachstate failed");
76 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
78 puts ("3rd attr_getdestachstate failed");
81 if (s
!= PTHREAD_CREATE_JOINABLE
)
83 puts ("PTHREAD_CREATE_JOINABLE set, but not given back");
89 if (pthread_attr_getguardsize (&a
, &g
) != 0)
91 puts ("1st attr_getguardsize failed");
94 if (g
!= (size_t) sysconf (_SC_PAGESIZE
))
96 printf ("default guardsize %zu, expected %ld (PAGESIZE)\n",
97 g
, sysconf (_SC_PAGESIZE
));
101 e
= pthread_attr_setguardsize (&a
, 0);
104 puts ("1st attr_setguardsize failed");
107 if (pthread_attr_getguardsize (&a
, &g
) != 0)
109 puts ("2nd attr_getguardsize failed");
114 printf ("guardsize set to zero but %zu returned\n", g
);
118 e
= pthread_attr_setguardsize (&a
, 1);
121 puts ("2nd attr_setguardsize failed");
124 if (pthread_attr_getguardsize (&a
, &g
) != 0)
126 puts ("3rd attr_getguardsize failed");
131 printf ("guardsize set to 1 but %zu returned\n", g
);
136 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
138 puts ("1st attr_getinheritsched failed");
141 /* XXX What is the correct default value. */
142 if (s
!= PTHREAD_INHERIT_SCHED
&& s
!= PTHREAD_EXPLICIT_SCHED
)
144 puts ("incorrect default value for inheritsched");
148 e
= pthread_attr_setinheritsched (&a
, PTHREAD_EXPLICIT_SCHED
);
151 puts ("1st attr_setinheritsched failed");
154 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
156 puts ("2nd attr_getinheritsched failed");
159 if (s
!= PTHREAD_EXPLICIT_SCHED
)
161 printf ("inheritsched set to PTHREAD_EXPLICIT_SCHED, but got %d\n", s
);
165 e
= pthread_attr_setinheritsched (&a
, PTHREAD_INHERIT_SCHED
);
168 puts ("2nd attr_setinheritsched failed");
171 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
173 puts ("3rd attr_getinheritsched failed");
176 if (s
!= PTHREAD_INHERIT_SCHED
)
178 printf ("inheritsched set to PTHREAD_INHERIT_SCHED, but got %d\n", s
);
183 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
185 puts ("1st attr_getschedpolicy failed");
188 /* XXX What is the correct default value. */
189 if (s
!= SCHED_OTHER
&& s
!= SCHED_FIFO
&& s
!= SCHED_RR
)
191 puts ("incorrect default value for schedpolicy");
195 e
= pthread_attr_setschedpolicy (&a
, SCHED_RR
);
198 puts ("1st attr_setschedpolicy failed");
201 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
203 puts ("2nd attr_getschedpolicy failed");
208 printf ("schedpolicy set to SCHED_RR, but got %d\n", s
);
212 e
= pthread_attr_setschedpolicy (&a
, SCHED_FIFO
);
215 puts ("2nd attr_setschedpolicy failed");
218 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
220 puts ("3rd attr_getschedpolicy failed");
225 printf ("schedpolicy set to SCHED_FIFO, but got %d\n", s
);
229 e
= pthread_attr_setschedpolicy (&a
, SCHED_OTHER
);
232 puts ("3rd attr_setschedpolicy failed");
235 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
237 puts ("4th attr_getschedpolicy failed");
240 if (s
!= SCHED_OTHER
)
242 printf ("schedpolicy set to SCHED_OTHER, but got %d\n", s
);
247 if (pthread_attr_getscope (&a
, &s
) != 0)
249 puts ("1st attr_getscope failed");
252 /* XXX What is the correct default value. */
253 if (s
!= PTHREAD_SCOPE_SYSTEM
&& s
!= PTHREAD_SCOPE_PROCESS
)
255 puts ("incorrect default value for contentionscope");
259 e
= pthread_attr_setscope (&a
, PTHREAD_SCOPE_PROCESS
);
264 puts ("1st attr_setscope failed");
267 if (pthread_attr_getscope (&a
, &s
) != 0)
269 puts ("2nd attr_getscope failed");
272 if (s
!= PTHREAD_SCOPE_PROCESS
)
275 contentionscope set to PTHREAD_SCOPE_PROCESS, but got %d\n", s
);
280 e
= pthread_attr_setscope (&a
, PTHREAD_SCOPE_SYSTEM
);
283 puts ("2nd attr_setscope failed");
286 if (pthread_attr_getscope (&a
, &s
) != 0)
288 puts ("3rd attr_getscope failed");
291 if (s
!= PTHREAD_SCOPE_SYSTEM
)
293 printf ("contentionscope set to PTHREAD_SCOPE_SYSTEM, but got %d\n", s
);
298 e
= pthread_attr_setstack (&a
, buf
, 1);
301 puts ("setstack with size 1 did not produce EINVAL");
305 e
= pthread_attr_setstacksize (&a
, 1);
308 puts ("setstacksize with size 1 did not produce EINVAL");
316 #define TEST_FUNCTION do_test ()
317 #include "../test-skeleton.c"