1 /* Copyright (C) 2003-2017 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/>. */
31 if (pthread_attr_init (&a
) != 0)
33 puts ("attr_init failed");
37 /* Check default value of detach state. */
39 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
41 puts ("1st attr_getdestachstate failed");
44 if (s
!= PTHREAD_CREATE_JOINABLE
)
47 default detach state wrong: %d, expected %d (PTHREAD_CREATE_JOINABLE)\n",
48 s
, PTHREAD_CREATE_JOINABLE
);
52 int e
= pthread_attr_setdetachstate (&a
, PTHREAD_CREATE_DETACHED
);
55 puts ("1st attr_setdetachstate failed");
58 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
60 puts ("2nd attr_getdestachstate failed");
63 if (s
!= PTHREAD_CREATE_DETACHED
)
65 puts ("PTHREAD_CREATE_DETACHED set, but not given back");
69 e
= pthread_attr_setdetachstate (&a
, PTHREAD_CREATE_JOINABLE
);
72 puts ("2nd attr_setdetachstate failed");
75 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
77 puts ("3rd attr_getdestachstate failed");
80 if (s
!= PTHREAD_CREATE_JOINABLE
)
82 puts ("PTHREAD_CREATE_JOINABLE set, but not given back");
88 if (pthread_attr_getguardsize (&a
, &g
) != 0)
90 puts ("1st attr_getguardsize failed");
93 if (g
!= (size_t) sysconf (_SC_PAGESIZE
))
95 printf ("default guardsize %zu, expected %ld (PAGESIZE)\n",
96 g
, sysconf (_SC_PAGESIZE
));
100 e
= pthread_attr_setguardsize (&a
, 0);
103 puts ("1st attr_setguardsize failed");
106 if (pthread_attr_getguardsize (&a
, &g
) != 0)
108 puts ("2nd attr_getguardsize failed");
113 printf ("guardsize set to zero but %zu returned\n", g
);
117 e
= pthread_attr_setguardsize (&a
, 1);
120 puts ("2nd attr_setguardsize failed");
123 if (pthread_attr_getguardsize (&a
, &g
) != 0)
125 puts ("3rd attr_getguardsize failed");
130 printf ("guardsize set to 1 but %zu returned\n", g
);
135 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
137 puts ("1st attr_getinheritsched failed");
140 /* XXX What is the correct default value. */
141 if (s
!= PTHREAD_INHERIT_SCHED
&& s
!= PTHREAD_EXPLICIT_SCHED
)
143 puts ("incorrect default value for inheritsched");
147 e
= pthread_attr_setinheritsched (&a
, PTHREAD_EXPLICIT_SCHED
);
150 puts ("1st attr_setinheritsched failed");
153 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
155 puts ("2nd attr_getinheritsched failed");
158 if (s
!= PTHREAD_EXPLICIT_SCHED
)
160 printf ("inheritsched set to PTHREAD_EXPLICIT_SCHED, but got %d\n", s
);
164 e
= pthread_attr_setinheritsched (&a
, PTHREAD_INHERIT_SCHED
);
167 puts ("2nd attr_setinheritsched failed");
170 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
172 puts ("3rd attr_getinheritsched failed");
175 if (s
!= PTHREAD_INHERIT_SCHED
)
177 printf ("inheritsched set to PTHREAD_INHERIT_SCHED, but got %d\n", s
);
182 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
184 puts ("1st attr_getschedpolicy failed");
187 /* XXX What is the correct default value. */
188 if (s
!= SCHED_OTHER
&& s
!= SCHED_FIFO
&& s
!= SCHED_RR
)
190 puts ("incorrect default value for schedpolicy");
194 e
= pthread_attr_setschedpolicy (&a
, SCHED_RR
);
197 puts ("1st attr_setschedpolicy failed");
200 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
202 puts ("2nd attr_getschedpolicy failed");
207 printf ("schedpolicy set to SCHED_RR, but got %d\n", s
);
211 e
= pthread_attr_setschedpolicy (&a
, SCHED_FIFO
);
214 puts ("2nd attr_setschedpolicy failed");
217 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
219 puts ("3rd attr_getschedpolicy failed");
224 printf ("schedpolicy set to SCHED_FIFO, but got %d\n", s
);
228 e
= pthread_attr_setschedpolicy (&a
, SCHED_OTHER
);
231 puts ("3rd attr_setschedpolicy failed");
234 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
236 puts ("4th attr_getschedpolicy failed");
239 if (s
!= SCHED_OTHER
)
241 printf ("schedpolicy set to SCHED_OTHER, but got %d\n", s
);
246 if (pthread_attr_getscope (&a
, &s
) != 0)
248 puts ("1st attr_getscope failed");
251 /* XXX What is the correct default value. */
252 if (s
!= PTHREAD_SCOPE_SYSTEM
&& s
!= PTHREAD_SCOPE_PROCESS
)
254 puts ("incorrect default value for contentionscope");
258 e
= pthread_attr_setscope (&a
, PTHREAD_SCOPE_PROCESS
);
263 puts ("1st attr_setscope failed");
266 if (pthread_attr_getscope (&a
, &s
) != 0)
268 puts ("2nd attr_getscope failed");
271 if (s
!= PTHREAD_SCOPE_PROCESS
)
274 contentionscope set to PTHREAD_SCOPE_PROCESS, but got %d\n", s
);
279 e
= pthread_attr_setscope (&a
, PTHREAD_SCOPE_SYSTEM
);
282 puts ("2nd attr_setscope failed");
285 if (pthread_attr_getscope (&a
, &s
) != 0)
287 puts ("3rd attr_getscope failed");
290 if (s
!= PTHREAD_SCOPE_SYSTEM
)
292 printf ("contentionscope set to PTHREAD_SCOPE_SYSTEM, but got %d\n", s
);
297 e
= pthread_attr_setstack (&a
, buf
, 1);
300 puts ("setstack with size 1 did not produce EINVAL");
304 e
= pthread_attr_setstacksize (&a
, 1);
307 puts ("setstacksize with size 1 did not produce EINVAL");
315 #define TEST_FUNCTION do_test ()
316 #include "../test-skeleton.c"