Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* Copyright (C) 2003-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
4
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.
9
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.
14
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/>. */
18
19#include <errno.h>
20#include <pthread.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <unistd.h>
24
25
26int
27do_test (void)
28{
29 pthread_attr_t a;
30
31 if (pthread_attr_init (&a) != 0)
32 {
33 puts ("attr_init failed");
34 exit (1);
35 }
36
37 /* Check default value of detach state. */
38 int s;
39 if (pthread_attr_getdetachstate (&a, &s) != 0)
40 {
41 puts ("1st attr_getdestachstate failed");
42 exit (1);
43 }
44 if (s != PTHREAD_CREATE_JOINABLE)
45 {
46 printf ("\
47default detach state wrong: %d, expected %d (PTHREAD_CREATE_JOINABLE)\n",
48 s, PTHREAD_CREATE_JOINABLE);
49 exit (1);
50 }
51
52 int e = pthread_attr_setdetachstate (&a, PTHREAD_CREATE_DETACHED);
53 if (e != 0)
54 {
55 puts ("1st attr_setdetachstate failed");
56 exit (1);
57 }
58 if (pthread_attr_getdetachstate (&a, &s) != 0)
59 {
60 puts ("2nd attr_getdestachstate failed");
61 exit (1);
62 }
63 if (s != PTHREAD_CREATE_DETACHED)
64 {
65 puts ("PTHREAD_CREATE_DETACHED set, but not given back");
66 exit (1);
67 }
68
69 e = pthread_attr_setdetachstate (&a, PTHREAD_CREATE_JOINABLE);
70 if (e != 0)
71 {
72 puts ("2nd attr_setdetachstate failed");
73 exit (1);
74 }
75 if (pthread_attr_getdetachstate (&a, &s) != 0)
76 {
77 puts ("3rd attr_getdestachstate failed");
78 exit (1);
79 }
80 if (s != PTHREAD_CREATE_JOINABLE)
81 {
82 puts ("PTHREAD_CREATE_JOINABLE set, but not given back");
83 exit (1);
84 }
85
86
87 size_t g;
88 if (pthread_attr_getguardsize (&a, &g) != 0)
89 {
90 puts ("1st attr_getguardsize failed");
91 exit (1);
92 }
93 if (g != (size_t) sysconf (_SC_PAGESIZE))
94 {
95 printf ("default guardsize %zu, expected %ld (PAGESIZE)\n",
96 g, sysconf (_SC_PAGESIZE));
97 exit (1);
98 }
99
100 e = pthread_attr_setguardsize (&a, 0);
101 if (e != 0)
102 {
103 puts ("1st attr_setguardsize failed");
104 exit (1);
105 }
106 if (pthread_attr_getguardsize (&a, &g) != 0)
107 {
108 puts ("2nd attr_getguardsize failed");
109 exit (1);
110 }
111 if (g != 0)
112 {
113 printf ("guardsize set to zero but %zu returned\n", g);
114 exit (1);
115 }
116
117 e = pthread_attr_setguardsize (&a, 1);
118 if (e != 0)
119 {
120 puts ("2nd attr_setguardsize failed");
121 exit (1);
122 }
123 if (pthread_attr_getguardsize (&a, &g) != 0)
124 {
125 puts ("3rd attr_getguardsize failed");
126 exit (1);
127 }
128 if (g != 1)
129 {
130 printf ("guardsize set to 1 but %zu returned\n", g);
131 exit (1);
132 }
133
134
135 if (pthread_attr_getinheritsched (&a, &s) != 0)
136 {
137 puts ("1st attr_getinheritsched failed");
138 exit (1);
139 }
140 /* XXX What is the correct default value. */
141 if (s != PTHREAD_INHERIT_SCHED && s != PTHREAD_EXPLICIT_SCHED)
142 {
143 puts ("incorrect default value for inheritsched");
144 exit (1);
145 }
146
147 e = pthread_attr_setinheritsched (&a, PTHREAD_EXPLICIT_SCHED);
148 if (e != 0)
149 {
150 puts ("1st attr_setinheritsched failed");
151 exit (1);
152 }
153 if (pthread_attr_getinheritsched (&a, &s) != 0)
154 {
155 puts ("2nd attr_getinheritsched failed");
156 exit (1);
157 }
158 if (s != PTHREAD_EXPLICIT_SCHED)
159 {
160 printf ("inheritsched set to PTHREAD_EXPLICIT_SCHED, but got %d\n", s);
161 exit (1);
162 }
163
164 e = pthread_attr_setinheritsched (&a, PTHREAD_INHERIT_SCHED);
165 if (e != 0)
166 {
167 puts ("2nd attr_setinheritsched failed");
168 exit (1);
169 }
170 if (pthread_attr_getinheritsched (&a, &s) != 0)
171 {
172 puts ("3rd attr_getinheritsched failed");
173 exit (1);
174 }
175 if (s != PTHREAD_INHERIT_SCHED)
176 {
177 printf ("inheritsched set to PTHREAD_INHERIT_SCHED, but got %d\n", s);
178 exit (1);
179 }
180
181
182 if (pthread_attr_getschedpolicy (&a, &s) != 0)
183 {
184 puts ("1st attr_getschedpolicy failed");
185 exit (1);
186 }
187 /* XXX What is the correct default value. */
188 if (s != SCHED_OTHER && s != SCHED_FIFO && s != SCHED_RR)
189 {
190 puts ("incorrect default value for schedpolicy");
191 exit (1);
192 }
193
194 e = pthread_attr_setschedpolicy (&a, SCHED_RR);
195 if (e != 0)
196 {
197 puts ("1st attr_setschedpolicy failed");
198 exit (1);
199 }
200 if (pthread_attr_getschedpolicy (&a, &s) != 0)
201 {
202 puts ("2nd attr_getschedpolicy failed");
203 exit (1);
204 }
205 if (s != SCHED_RR)
206 {
207 printf ("schedpolicy set to SCHED_RR, but got %d\n", s);
208 exit (1);
209 }
210
211 e = pthread_attr_setschedpolicy (&a, SCHED_FIFO);
212 if (e != 0)
213 {
214 puts ("2nd attr_setschedpolicy failed");
215 exit (1);
216 }
217 if (pthread_attr_getschedpolicy (&a, &s) != 0)
218 {
219 puts ("3rd attr_getschedpolicy failed");
220 exit (1);
221 }
222 if (s != SCHED_FIFO)
223 {
224 printf ("schedpolicy set to SCHED_FIFO, but got %d\n", s);
225 exit (1);
226 }
227
228 e = pthread_attr_setschedpolicy (&a, SCHED_OTHER);
229 if (e != 0)
230 {
231 puts ("3rd attr_setschedpolicy failed");
232 exit (1);
233 }
234 if (pthread_attr_getschedpolicy (&a, &s) != 0)
235 {
236 puts ("4th attr_getschedpolicy failed");
237 exit (1);
238 }
239 if (s != SCHED_OTHER)
240 {
241 printf ("schedpolicy set to SCHED_OTHER, but got %d\n", s);
242 exit (1);
243 }
244
245
246 if (pthread_attr_getscope (&a, &s) != 0)
247 {
248 puts ("1st attr_getscope failed");
249 exit (1);
250 }
251 /* XXX What is the correct default value. */
252 if (s != PTHREAD_SCOPE_SYSTEM && s != PTHREAD_SCOPE_PROCESS)
253 {
254 puts ("incorrect default value for contentionscope");
255 exit (1);
256 }
257
258 e = pthread_attr_setscope (&a, PTHREAD_SCOPE_PROCESS);
259 if (e != ENOTSUP)
260 {
261 if (e != 0)
262 {
263 puts ("1st attr_setscope failed");
264 exit (1);
265 }
266 if (pthread_attr_getscope (&a, &s) != 0)
267 {
268 puts ("2nd attr_getscope failed");
269 exit (1);
270 }
271 if (s != PTHREAD_SCOPE_PROCESS)
272 {
273 printf ("\
274contentionscope set to PTHREAD_SCOPE_PROCESS, but got %d\n", s);
275 exit (1);
276 }
277 }
278
279 e = pthread_attr_setscope (&a, PTHREAD_SCOPE_SYSTEM);
280 if (e != 0)
281 {
282 puts ("2nd attr_setscope failed");
283 exit (1);
284 }
285 if (pthread_attr_getscope (&a, &s) != 0)
286 {
287 puts ("3rd attr_getscope failed");
288 exit (1);
289 }
290 if (s != PTHREAD_SCOPE_SYSTEM)
291 {
292 printf ("contentionscope set to PTHREAD_SCOPE_SYSTEM, but got %d\n", s);
293 exit (1);
294 }
295
296 char buf[1];
297 e = pthread_attr_setstack (&a, buf, 1);
298 if (e != EINVAL)
299 {
300 puts ("setstack with size 1 did not produce EINVAL");
301 exit (1);
302 }
303
304 e = pthread_attr_setstacksize (&a, 1);
305 if (e != EINVAL)
306 {
307 puts ("setstacksize with size 1 did not produce EINVAL");
308 exit (1);
309 }
310
311 return 0;
312}
313
314
315#define TEST_FUNCTION do_test ()
316#include "../test-skeleton.c"
317

Warning: That file was not part of the compilation database. It may have many parsing errors.