1 /* Copyright (C) 2003-2024 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/>. */
30 if (pthread_attr_init (&a
) != 0)
32 puts ("attr_init failed");
36 /* Check default value of detach state. */
38 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
40 puts ("1st attr_getdestachstate failed");
43 if (s
!= PTHREAD_CREATE_JOINABLE
)
46 default detach state wrong: %d, expected %d (PTHREAD_CREATE_JOINABLE)\n",
47 s
, PTHREAD_CREATE_JOINABLE
);
51 int e
= pthread_attr_setdetachstate (&a
, PTHREAD_CREATE_DETACHED
);
54 puts ("1st attr_setdetachstate failed");
57 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
59 puts ("2nd attr_getdestachstate failed");
62 if (s
!= PTHREAD_CREATE_DETACHED
)
64 puts ("PTHREAD_CREATE_DETACHED set, but not given back");
68 e
= pthread_attr_setdetachstate (&a
, PTHREAD_CREATE_JOINABLE
);
71 puts ("2nd attr_setdetachstate failed");
74 if (pthread_attr_getdetachstate (&a
, &s
) != 0)
76 puts ("3rd attr_getdestachstate failed");
79 if (s
!= PTHREAD_CREATE_JOINABLE
)
81 puts ("PTHREAD_CREATE_JOINABLE set, but not given back");
87 if (pthread_attr_getguardsize (&a
, &g
) != 0)
89 puts ("1st attr_getguardsize failed");
92 if (g
!= (size_t) sysconf (_SC_PAGESIZE
))
94 printf ("default guardsize %zu, expected %ld (PAGESIZE)\n",
95 g
, sysconf (_SC_PAGESIZE
));
99 e
= pthread_attr_setguardsize (&a
, 0);
102 puts ("1st attr_setguardsize failed");
105 if (pthread_attr_getguardsize (&a
, &g
) != 0)
107 puts ("2nd attr_getguardsize failed");
112 printf ("guardsize set to zero but %zu returned\n", g
);
116 e
= pthread_attr_setguardsize (&a
, 1);
119 puts ("2nd attr_setguardsize failed");
122 if (pthread_attr_getguardsize (&a
, &g
) != 0)
124 puts ("3rd attr_getguardsize failed");
129 printf ("guardsize set to 1 but %zu returned\n", g
);
134 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
136 puts ("1st attr_getinheritsched failed");
139 /* XXX What is the correct default value. */
140 if (s
!= PTHREAD_INHERIT_SCHED
&& s
!= PTHREAD_EXPLICIT_SCHED
)
142 puts ("incorrect default value for inheritsched");
146 e
= pthread_attr_setinheritsched (&a
, PTHREAD_EXPLICIT_SCHED
);
149 puts ("1st attr_setinheritsched failed");
152 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
154 puts ("2nd attr_getinheritsched failed");
157 if (s
!= PTHREAD_EXPLICIT_SCHED
)
159 printf ("inheritsched set to PTHREAD_EXPLICIT_SCHED, but got %d\n", s
);
163 e
= pthread_attr_setinheritsched (&a
, PTHREAD_INHERIT_SCHED
);
166 puts ("2nd attr_setinheritsched failed");
169 if (pthread_attr_getinheritsched (&a
, &s
) != 0)
171 puts ("3rd attr_getinheritsched failed");
174 if (s
!= PTHREAD_INHERIT_SCHED
)
176 printf ("inheritsched set to PTHREAD_INHERIT_SCHED, but got %d\n", s
);
181 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
183 puts ("1st attr_getschedpolicy failed");
186 /* XXX What is the correct default value. */
187 if (s
!= SCHED_OTHER
&& s
!= SCHED_FIFO
&& s
!= SCHED_RR
)
189 puts ("incorrect default value for schedpolicy");
193 e
= pthread_attr_setschedpolicy (&a
, SCHED_RR
);
196 puts ("1st attr_setschedpolicy failed");
199 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
201 puts ("2nd attr_getschedpolicy failed");
206 printf ("schedpolicy set to SCHED_RR, but got %d\n", s
);
210 e
= pthread_attr_setschedpolicy (&a
, SCHED_FIFO
);
213 puts ("2nd attr_setschedpolicy failed");
216 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
218 puts ("3rd attr_getschedpolicy failed");
223 printf ("schedpolicy set to SCHED_FIFO, but got %d\n", s
);
227 e
= pthread_attr_setschedpolicy (&a
, SCHED_OTHER
);
230 puts ("3rd attr_setschedpolicy failed");
233 if (pthread_attr_getschedpolicy (&a
, &s
) != 0)
235 puts ("4th attr_getschedpolicy failed");
238 if (s
!= SCHED_OTHER
)
240 printf ("schedpolicy set to SCHED_OTHER, but got %d\n", s
);
245 if (pthread_attr_getscope (&a
, &s
) != 0)
247 puts ("1st attr_getscope failed");
250 /* XXX What is the correct default value. */
251 if (s
!= PTHREAD_SCOPE_SYSTEM
&& s
!= PTHREAD_SCOPE_PROCESS
)
253 puts ("incorrect default value for contentionscope");
257 e
= pthread_attr_setscope (&a
, PTHREAD_SCOPE_PROCESS
);
262 puts ("1st attr_setscope failed");
265 if (pthread_attr_getscope (&a
, &s
) != 0)
267 puts ("2nd attr_getscope failed");
270 if (s
!= PTHREAD_SCOPE_PROCESS
)
273 contentionscope set to PTHREAD_SCOPE_PROCESS, but got %d\n", s
);
278 e
= pthread_attr_setscope (&a
, PTHREAD_SCOPE_SYSTEM
);
281 puts ("2nd attr_setscope failed");
284 if (pthread_attr_getscope (&a
, &s
) != 0)
286 puts ("3rd attr_getscope failed");
289 if (s
!= PTHREAD_SCOPE_SYSTEM
)
291 printf ("contentionscope set to PTHREAD_SCOPE_SYSTEM, but got %d\n", s
);
296 e
= pthread_attr_setstack (&a
, buf
, 1);
299 puts ("setstack with size 1 did not produce EINVAL");
303 e
= pthread_attr_setstacksize (&a
, 1);
306 puts ("setstacksize with size 1 did not produce EINVAL");
314 #define TEST_FUNCTION do_test ()
315 #include "../test-skeleton.c"