1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * COPYRIGHT (c) 1989-2009. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions |
---|
9 | * are met: |
---|
10 | * 1. Redistributions of source code must retain the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer. |
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer in the |
---|
14 | * documentation and/or other materials provided with the distribution. |
---|
15 | * |
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
26 | * POSSIBILITY OF SUCH DAMAGE. |
---|
27 | */ |
---|
28 | |
---|
29 | #ifdef HAVE_CONFIG_H |
---|
30 | #include "config.h" |
---|
31 | #endif |
---|
32 | |
---|
33 | #include <pthread.h> |
---|
34 | #include <sched.h> |
---|
35 | |
---|
36 | #define CONFIGURE_INIT |
---|
37 | #include "system.h" |
---|
38 | #include <errno.h> |
---|
39 | #include "tmacros.h" |
---|
40 | #include "pritime.h" |
---|
41 | |
---|
42 | const char rtems_test_name[] = "PSX 7"; |
---|
43 | |
---|
44 | void print_schedparam( |
---|
45 | char *prefix, |
---|
46 | struct sched_param *schedparam |
---|
47 | ); |
---|
48 | |
---|
49 | void print_schedparam( |
---|
50 | char *prefix, |
---|
51 | struct sched_param *schedparam |
---|
52 | ) |
---|
53 | { |
---|
54 | printf( "%ssched priority = %d\n", prefix, schedparam->sched_priority ); |
---|
55 | #if defined(_POSIX_SPORADIC_SERVER) |
---|
56 | printf( "%ssched_ss_low_priority = %d\n", |
---|
57 | prefix, schedparam->sched_ss_low_priority ); |
---|
58 | printf( "%ssched_ss_replenish_period = (%" PRIdtime_t ", %ld)\n", prefix, |
---|
59 | schedparam->sched_ss_repl_period.tv_sec, |
---|
60 | schedparam->sched_ss_repl_period.tv_nsec ); |
---|
61 | printf( "%ssched_sched_ss_initial_budget = (%" PRIdtime_t ", %ld)\n", prefix, |
---|
62 | schedparam->sched_ss_init_budget.tv_sec, |
---|
63 | schedparam->sched_ss_init_budget.tv_nsec ); |
---|
64 | #else |
---|
65 | printf( "%s_POSIX_SPORADIC_SERVER is not defined\n", prefix ); |
---|
66 | #endif |
---|
67 | } |
---|
68 | |
---|
69 | void *POSIX_Init( |
---|
70 | void *argument |
---|
71 | ) |
---|
72 | { |
---|
73 | int status; |
---|
74 | int scope; |
---|
75 | int inheritsched; |
---|
76 | int schedpolicy; |
---|
77 | size_t stacksize; |
---|
78 | size_t guardsize; |
---|
79 | void *stackaddr; |
---|
80 | int detachstate; |
---|
81 | struct sched_param schedparam; |
---|
82 | pthread_attr_t attr; |
---|
83 | pthread_attr_t destroyed_attr; |
---|
84 | |
---|
85 | TEST_BEGIN(); |
---|
86 | |
---|
87 | /* set the time of day, and print our buffer in multiple ways */ |
---|
88 | |
---|
89 | set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 ); |
---|
90 | |
---|
91 | /* get id of this thread */ |
---|
92 | |
---|
93 | Init_id = pthread_self(); |
---|
94 | printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id ); |
---|
95 | |
---|
96 | /* exercise init and destroy */ |
---|
97 | |
---|
98 | puts( "Init - pthread_attr_init - EINVAL (NULL attr)" ); |
---|
99 | status = pthread_attr_init( NULL ); |
---|
100 | fatal_directive_check_status_only( status, EINVAL, "null attribute" ); |
---|
101 | |
---|
102 | puts( "Init - pthread_attr_init - SUCCESSFUL" ); |
---|
103 | status = pthread_attr_init( &attr ); |
---|
104 | posix_service_failed( status, "pthread_attr_init" ); |
---|
105 | |
---|
106 | puts( "Init - initialize and destroy an attribute - SUCCESSFUL" ); |
---|
107 | status = pthread_attr_init( &destroyed_attr ); |
---|
108 | posix_service_failed( status, "pthread_attr_init"); |
---|
109 | |
---|
110 | status = pthread_attr_destroy( &destroyed_attr ); |
---|
111 | posix_service_failed( status, "pthread_attr_destroy"); |
---|
112 | |
---|
113 | puts( "Init - pthread_attr_destroy - EINVAL (NULL attr)" ); |
---|
114 | status = pthread_attr_destroy( NULL ); |
---|
115 | fatal_directive_check_status_only( status, EINVAL, "NULL attribute" ); |
---|
116 | |
---|
117 | puts( "Init - pthread_attr_destroy - EINVAL (not initialized)" ); |
---|
118 | status = pthread_attr_destroy( &destroyed_attr ); |
---|
119 | fatal_directive_check_status_only( status, EINVAL, "not initialized" ); |
---|
120 | |
---|
121 | /* check some errors in pthread_create */ |
---|
122 | |
---|
123 | puts( "Init - pthread_create - EINVAL (attr not initialized)" ); |
---|
124 | status = pthread_create( &Task_id, &destroyed_attr, Task_1, NULL ); |
---|
125 | fatal_directive_check_status_only( status, EINVAL, "attribute not initialized" ); |
---|
126 | |
---|
127 | /* junk stack address */ |
---|
128 | status = pthread_attr_setstackaddr( &attr, (void *)&schedparam ); |
---|
129 | posix_service_failed( status, "setstackaddr"); |
---|
130 | |
---|
131 | /* must go around pthread_attr_setstacksize to set a bad stack size */ |
---|
132 | attr.stacksize = 0; |
---|
133 | |
---|
134 | puts( "Init - pthread_create - EINVAL (stacksize too small)" ); |
---|
135 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
136 | fatal_directive_check_status_only( status, EINVAL, "stacksize too small" ); |
---|
137 | |
---|
138 | /* reset all the fields */ |
---|
139 | status = pthread_attr_init( &attr ); |
---|
140 | posix_service_failed( status, "pthread_attr_init"); |
---|
141 | |
---|
142 | attr.stacksize = rtems_configuration_get_work_space_size() * 10; |
---|
143 | puts( "Init - pthread_create - EAGAIN (stacksize too large)" ); |
---|
144 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
145 | fatal_directive_check_status_only( status, EAGAIN, "stacksize too large" ); |
---|
146 | |
---|
147 | status = pthread_attr_init( &attr ); |
---|
148 | posix_service_failed( status, "pthread_attr_init"); |
---|
149 | |
---|
150 | /* must go around pthread_attr_set routines to set a bad value */ |
---|
151 | attr.inheritsched = -1; |
---|
152 | |
---|
153 | puts( "Init - pthread_create - EINVAL (invalid inherit scheduler)" ); |
---|
154 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
155 | fatal_directive_check_status_only( status, EINVAL, "invalid inherit scheduler" ); |
---|
156 | |
---|
157 | /* check out the error case for system scope not supported */ |
---|
158 | |
---|
159 | status = pthread_attr_init( &attr ); |
---|
160 | posix_service_failed( status, " pthread_attr_init"); |
---|
161 | |
---|
162 | /* must go around pthread_attr_set routines to set a bad value */ |
---|
163 | attr.contentionscope = PTHREAD_SCOPE_SYSTEM; |
---|
164 | |
---|
165 | puts( "Init - pthread_create - ENOTSUP (unsupported system contention scope)" ); |
---|
166 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
167 | fatal_directive_check_status_only( status, ENOTSUP, |
---|
168 | "unsupported system contention scope" ); |
---|
169 | |
---|
170 | status = pthread_attr_init( &attr ); |
---|
171 | posix_service_failed( status, "pthread_attr_init"); |
---|
172 | |
---|
173 | /* now check out pthread_create for inherit scheduler */ |
---|
174 | |
---|
175 | status = pthread_attr_setinheritsched( &attr, PTHREAD_INHERIT_SCHED ); |
---|
176 | posix_service_failed( status, "pthread_attr_setinheritsched"); |
---|
177 | |
---|
178 | puts( "Init - pthread_create - SUCCESSFUL (inherit scheduler)" ); |
---|
179 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
180 | posix_service_failed( status, "pthread_create"); |
---|
181 | |
---|
182 | status = pthread_join( Task_id, NULL ); |
---|
183 | posix_service_failed( status, " pthread_join"); |
---|
184 | |
---|
185 | /* switch to Task_1 */ |
---|
186 | |
---|
187 | /* exercise get and set scope */ |
---|
188 | |
---|
189 | empty_line(); |
---|
190 | |
---|
191 | status = pthread_attr_init( &attr ); |
---|
192 | posix_service_failed( status, "pthread_attr_init"); |
---|
193 | |
---|
194 | puts( "Init - pthread_attr_setscope - EINVAL (NULL attr)" ); |
---|
195 | status = pthread_attr_setscope( NULL, PTHREAD_SCOPE_PROCESS ); |
---|
196 | fatal_directive_check_status_only( status, EINVAL , "NULL attr" ); |
---|
197 | |
---|
198 | puts( "Init - pthread_attr_setscope - ENOTSUP" ); |
---|
199 | status = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ); |
---|
200 | fatal_directive_check_status_only( status, ENOTSUP, "PTHREAD_SCOPE_SYSTEM" ); |
---|
201 | |
---|
202 | puts( "Init - pthread_attr_setscope - EINVAL (not initialized attr)" ); |
---|
203 | status = pthread_attr_setscope( &destroyed_attr, PTHREAD_SCOPE_PROCESS ); |
---|
204 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
205 | |
---|
206 | puts( "Init - pthread_attr_setscope - EINVAL (invalid scope)" ); |
---|
207 | status = pthread_attr_setscope( &attr, -1 ); |
---|
208 | fatal_directive_check_status_only( status, EINVAL, "invalid scope" ); |
---|
209 | |
---|
210 | puts( "Init - pthread_attr_setscope - SUCCESSFUL" ); |
---|
211 | status = pthread_attr_setscope( &attr, PTHREAD_SCOPE_PROCESS ); |
---|
212 | posix_service_failed( status, "pthread_attr_setscope"); |
---|
213 | |
---|
214 | puts( "Init - pthread_attr_getscope - EINVAL (NULL attr)" ); |
---|
215 | status = pthread_attr_getscope( NULL, &scope ); |
---|
216 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
217 | |
---|
218 | puts( "Init - pthread_attr_getscope - EINVAL (NULL scope)" ); |
---|
219 | status = pthread_attr_getscope( &attr, NULL ); |
---|
220 | fatal_directive_check_status_only( status, EINVAL, "NULL scope" ); |
---|
221 | |
---|
222 | puts( "Init - pthread_attr_getscope - EINVAL (not initialized attr)" ); |
---|
223 | status = pthread_attr_getscope( &destroyed_attr, &scope ); |
---|
224 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
225 | |
---|
226 | puts( "Init - pthread_attr_getscope - SUCCESSFUL" ); |
---|
227 | status = pthread_attr_getscope( &attr, &scope ); |
---|
228 | posix_service_failed( status, "pthread_attr_getscope"); |
---|
229 | printf( "Init - current scope attribute = %d\n", scope ); |
---|
230 | |
---|
231 | /* exercise get and set inherit scheduler */ |
---|
232 | |
---|
233 | empty_line(); |
---|
234 | |
---|
235 | puts( "Init - pthread_attr_setinheritsched - EINVAL (NULL attr)" ); |
---|
236 | status = pthread_attr_setinheritsched( NULL, PTHREAD_INHERIT_SCHED ); |
---|
237 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
238 | |
---|
239 | puts( "Init - pthread_attr_setinheritsched - EINVAL (not initialized attr)" ); |
---|
240 | status = |
---|
241 | pthread_attr_setinheritsched( &destroyed_attr, PTHREAD_INHERIT_SCHED ); |
---|
242 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
243 | |
---|
244 | puts( "Init - pthread_attr_setinheritsched - ENOTSUP (invalid inheritsched)" ); |
---|
245 | status = pthread_attr_setinheritsched( &attr, -1 ); |
---|
246 | fatal_directive_check_status_only( status, ENOTSUP, "invalid inheritsched" ); |
---|
247 | |
---|
248 | puts( "Init - pthread_attr_setinheritsched - SUCCESSFUL" ); |
---|
249 | status = pthread_attr_setinheritsched( &attr, PTHREAD_INHERIT_SCHED ); |
---|
250 | posix_service_failed( status, "pthread_attr_setinheritsched"); |
---|
251 | |
---|
252 | puts( "Init - pthread_attr_getinheritsched - EINVAL (NULL attr)" ); |
---|
253 | status = pthread_attr_getinheritsched( NULL, &inheritsched ); |
---|
254 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
255 | |
---|
256 | puts( "Init - pthread_attr_getinheritsched - EINVAL (NULL inheritsched)" ); |
---|
257 | status = pthread_attr_getinheritsched( &attr, NULL ); |
---|
258 | fatal_directive_check_status_only( status, EINVAL, "NULL inheritsched" ); |
---|
259 | |
---|
260 | puts( "Init - pthread_attr_getinheritsched - EINVAL (not initialized attr)" ); |
---|
261 | status = pthread_attr_getinheritsched( &destroyed_attr, &inheritsched ); |
---|
262 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
263 | |
---|
264 | puts( "Init - pthread_attr_getinheritsched - SUCCESSFUL" ); |
---|
265 | status = pthread_attr_getinheritsched( &attr, &inheritsched ); |
---|
266 | posix_service_failed( status, "pthread_attr_getinheritsched"); |
---|
267 | printf( "Init - current inherit scheduler attribute = %d\n", inheritsched ); |
---|
268 | |
---|
269 | /* exercise get and set inherit scheduler */ |
---|
270 | |
---|
271 | empty_line(); |
---|
272 | |
---|
273 | puts( "Init - pthread_attr_setschedpolicy - EINVAL (NULL attr)" ); |
---|
274 | status = pthread_attr_setschedpolicy( NULL, SCHED_FIFO ); |
---|
275 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
276 | |
---|
277 | puts( "Init - pthread_attr_setschedpolicy - EINVAL (not initialized attr)" ); |
---|
278 | status = |
---|
279 | pthread_attr_setschedpolicy( &destroyed_attr, SCHED_OTHER ); |
---|
280 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
281 | |
---|
282 | puts( "Init - pthread_attr_setschedpolicy - ENOTSUP (invalid schedpolicy)" ); |
---|
283 | status = pthread_attr_setschedpolicy( &attr, -1 ); |
---|
284 | fatal_directive_check_status_only( status, ENOTSUP, "invalid schedpolicy" ); |
---|
285 | |
---|
286 | puts( "Init - pthread_attr_setschedpolicy - SUCCESSFUL" ); |
---|
287 | status = pthread_attr_setschedpolicy( &attr, SCHED_RR ); |
---|
288 | posix_service_failed( status, "pthread_attr_setschedpolicy"); |
---|
289 | |
---|
290 | puts( "Init - pthread_attr_getschedpolicy - EINVAL (NULL attr)" ); |
---|
291 | status = pthread_attr_getschedpolicy( NULL, &schedpolicy ); |
---|
292 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
293 | |
---|
294 | puts( "Init - pthread_attr_getschedpolicy - EINVAL (NULL schedpolicy)" ); |
---|
295 | status = pthread_attr_getschedpolicy( &attr, NULL ); |
---|
296 | fatal_directive_check_status_only( status, EINVAL, "NULL schedpolicy" ); |
---|
297 | |
---|
298 | puts( "Init - pthread_attr_getschedpolicy - EINVAL (not initialized attr)" ); |
---|
299 | status = pthread_attr_getschedpolicy( &destroyed_attr, &schedpolicy ); |
---|
300 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
301 | |
---|
302 | puts( "Init - pthread_attr_getschedpolicy - SUCCESSFUL" ); |
---|
303 | status = pthread_attr_getschedpolicy( &attr, &schedpolicy ); |
---|
304 | posix_service_failed( status, "pthread_attr_getschedpolicy"); |
---|
305 | printf( "Init - current scheduler policy attribute = %d\n", schedpolicy ); |
---|
306 | |
---|
307 | /* exercise get and set stack size */ |
---|
308 | |
---|
309 | empty_line(); |
---|
310 | |
---|
311 | puts( "Init - pthread_attr_setstacksize - EINVAL (NULL attr)" ); |
---|
312 | status = pthread_attr_setstacksize( NULL, 0 ); |
---|
313 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
314 | |
---|
315 | puts( "Init - pthread_attr_setstacksize - EINVAL (not initialized attr)" ); |
---|
316 | status = |
---|
317 | pthread_attr_setstacksize( &destroyed_attr, 0 ); |
---|
318 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
319 | |
---|
320 | puts( "Init - pthread_attr_setstacksize - SUCCESSFUL (low stacksize)" ); |
---|
321 | status = pthread_attr_setstacksize( &attr, 0 ); |
---|
322 | posix_service_failed( status, "pthread_attr_setstacksize"); |
---|
323 | |
---|
324 | puts( "Init - pthread_attr_setstacksize - SUCCESSFUL (high stacksize)" ); |
---|
325 | status = pthread_attr_setstacksize( &attr, STACK_MINIMUM_SIZE * 2 ); |
---|
326 | posix_service_failed( status, ""); |
---|
327 | |
---|
328 | puts( "Init - pthread_attr_getstacksize - EINVAL (NULL attr)" ); |
---|
329 | status = pthread_attr_getstacksize( NULL, &stacksize ); |
---|
330 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
331 | |
---|
332 | puts( "Init - pthread_attr_getstacksize - EINVAL (NULL stacksize)" ); |
---|
333 | status = pthread_attr_getstacksize( &attr, NULL ); |
---|
334 | fatal_directive_check_status_only( status, EINVAL, "NULL stacksize" ); |
---|
335 | |
---|
336 | puts( "Init - pthread_attr_getstacksize - EINVAL (not initialized attr)" ); |
---|
337 | status = pthread_attr_getstacksize( &destroyed_attr, &stacksize ); |
---|
338 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
339 | |
---|
340 | puts( "Init - pthread_attr_getstacksize - SUCCESSFUL" ); |
---|
341 | status = pthread_attr_getstacksize( &attr, &stacksize ); |
---|
342 | posix_service_failed( status, "pthread_attr_getstacksize"); |
---|
343 | if ( stacksize == (STACK_MINIMUM_SIZE * 2) ) |
---|
344 | printf( "Init - current stack size attribute is OK\n" ); |
---|
345 | |
---|
346 | /* exercise get and set stack address */ |
---|
347 | empty_line(); |
---|
348 | |
---|
349 | puts( "Init - pthread_attr_setstackaddr - EINVAL (NULL attr)" ); |
---|
350 | status = pthread_attr_setstackaddr( NULL, NULL ); |
---|
351 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
352 | |
---|
353 | puts( "Init - pthread_attr_setstackaddr - EINVAL (not initialized attr)" ); |
---|
354 | status = pthread_attr_setstackaddr( &destroyed_attr, NULL ); |
---|
355 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
356 | |
---|
357 | puts( "Init - pthread_attr_setstackaddr - SUCCESSFUL" ); |
---|
358 | status = pthread_attr_setstackaddr( &attr, 0 ); |
---|
359 | posix_service_failed( status, ""); |
---|
360 | |
---|
361 | /* get stack addr */ |
---|
362 | puts( "Init - pthread_attr_getstackaddr - EINVAL (NULL attr)" ); |
---|
363 | status = pthread_attr_getstackaddr( NULL, &stackaddr ); |
---|
364 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
365 | |
---|
366 | puts( "Init - pthread_attr_getstackaddr - EINVAL (NULL stackaddr)" ); |
---|
367 | status = pthread_attr_getstackaddr( &attr, NULL ); |
---|
368 | fatal_directive_check_status_only( status, EINVAL, "NULL stackaddr" ); |
---|
369 | |
---|
370 | puts( "Init - pthread_attr_getstackaddr - EINVAL (not initialized attr)" ); |
---|
371 | status = pthread_attr_getstackaddr( &destroyed_attr, &stackaddr ); |
---|
372 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
373 | |
---|
374 | puts( "Init - pthread_attr_getstackaddr - SUCCESSFUL" ); |
---|
375 | status = pthread_attr_getstackaddr( &attr, &stackaddr ); |
---|
376 | posix_service_failed( status, "pthread_attr_getstackaddr"); |
---|
377 | printf( "Init - current stack address attribute = %p\n", stackaddr ); |
---|
378 | |
---|
379 | /* exercise get and set stack (as pair) */ |
---|
380 | empty_line(); |
---|
381 | |
---|
382 | puts( "Init - pthread_attr_setstack- EINVAL (NULL attr)" ); |
---|
383 | status = pthread_attr_setstack( NULL, &stackaddr, 1024 ); |
---|
384 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
385 | |
---|
386 | puts( "Init - pthread_attr_setstack- EINVAL (destroyed attr)" ); |
---|
387 | status = pthread_attr_setstack( &destroyed_attr, &stackaddr, 1024 ); |
---|
388 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
389 | |
---|
390 | puts( "Init - pthread_attr_setstack- SUCCESSFUL (< min stack)" ); |
---|
391 | status = pthread_attr_setstack( &attr, stackaddr, 0 ); |
---|
392 | posix_service_failed( status, "OK"); |
---|
393 | |
---|
394 | puts( "Init - pthread_attr_setstack- SUCCESSFUL (big stack)" ); |
---|
395 | status = pthread_attr_setstack( &attr, stackaddr, STACK_MINIMUM_SIZE * 2 ); |
---|
396 | posix_service_failed( status, "OK"); |
---|
397 | |
---|
398 | puts( "Init - pthread_attr_getstack- EINVAL (NULL attr)" ); |
---|
399 | status = pthread_attr_getstack( NULL, &stackaddr, &stacksize ); |
---|
400 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
401 | |
---|
402 | puts( "Init - pthread_attr_getstack- EINVAL (destroyed attr)" ); |
---|
403 | status = pthread_attr_getstack( &destroyed_attr, &stackaddr, &stacksize ); |
---|
404 | fatal_directive_check_status_only( status, EINVAL, "&destroyed attr" ); |
---|
405 | |
---|
406 | puts( "Init - pthread_attr_getstack- EINVAL (NULL stack)" ); |
---|
407 | status = pthread_attr_getstack( &attr, NULL, &stacksize ); |
---|
408 | fatal_directive_check_status_only( status, EINVAL, "&NULL stack" ); |
---|
409 | |
---|
410 | puts( "Init - pthread_attr_getstack- EINVAL (NULL stacksize)" ); |
---|
411 | status = pthread_attr_getstack( &attr, &stackaddr, NULL ); |
---|
412 | fatal_directive_check_status_only( status, EINVAL, "&NULL size" ); |
---|
413 | |
---|
414 | puts( "Init - pthread_attr_getstack- SUCCESSFUL" ); |
---|
415 | status = pthread_attr_getstack( &attr, &stackaddr, &stacksize ); |
---|
416 | posix_service_failed( status, "pthread_attr_getstack"); |
---|
417 | |
---|
418 | /* exercise get and set detach state */ |
---|
419 | empty_line(); |
---|
420 | |
---|
421 | puts( "Init - pthread_attr_setguardsize - EINVAL (NULL attr)" ); |
---|
422 | status = pthread_attr_setguardsize( NULL, 0 ); |
---|
423 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
424 | |
---|
425 | puts( "Init - pthread_attr_setguardsize - EINVAL (not initialized attr)" ); |
---|
426 | status = pthread_attr_setguardsize( &destroyed_attr, 0 ); |
---|
427 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
428 | |
---|
429 | puts( "Init - pthread_attr_setguardsize - SUCCESSFUL (low guardsize)" ); |
---|
430 | status = pthread_attr_setguardsize( &attr, 0 ); |
---|
431 | posix_service_failed( status, "pthread_attr_setguardsize"); |
---|
432 | |
---|
433 | puts( "Init - pthread_attr_setguardsize - SUCCESSFUL (high guardsize)" ); |
---|
434 | status = pthread_attr_setguardsize( &attr, STACK_MINIMUM_SIZE * 2 ); |
---|
435 | posix_service_failed( status, ""); |
---|
436 | |
---|
437 | puts( "Init - pthread_attr_getguardsize - EINVAL (NULL attr)" ); |
---|
438 | status = pthread_attr_getguardsize( NULL, &guardsize ); |
---|
439 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
440 | |
---|
441 | puts( "Init - pthread_attr_getguardsize - EINVAL (NULL guardsize)" ); |
---|
442 | status = pthread_attr_getguardsize( &attr, NULL ); |
---|
443 | fatal_directive_check_status_only( status, EINVAL, "NULL guardsize" ); |
---|
444 | |
---|
445 | puts( "Init - pthread_attr_getguardsize - EINVAL (not initialized attr)" ); |
---|
446 | status = pthread_attr_getguardsize( &destroyed_attr, &guardsize ); |
---|
447 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
448 | |
---|
449 | puts( "Init - pthread_attr_getguardsize - SUCCESSFUL" ); |
---|
450 | status = pthread_attr_getguardsize( &attr, &guardsize ); |
---|
451 | posix_service_failed( status, "pthread_attr_getguardsize"); |
---|
452 | |
---|
453 | /* exercise get and set detach state */ |
---|
454 | empty_line(); |
---|
455 | |
---|
456 | puts( "Init - pthread_attr_setdetachstate - EINVAL (NULL attr)" ); |
---|
457 | status = pthread_attr_setdetachstate( NULL, PTHREAD_CREATE_DETACHED ); |
---|
458 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
459 | |
---|
460 | puts( "Init - pthread_attr_setdetachstate - EINVAL (not initialized attr)" ); |
---|
461 | status = |
---|
462 | pthread_attr_setdetachstate( &destroyed_attr, PTHREAD_CREATE_JOINABLE ); |
---|
463 | fatal_directive_check_status_only( status, EINVAL, "not initialized att" ); |
---|
464 | |
---|
465 | puts( "Init - pthread_attr_setdetachstate - EINVAL (invalid detachstate)" ); |
---|
466 | status = pthread_attr_setdetachstate( &attr, -1 ); |
---|
467 | fatal_directive_check_status_only( status, EINVAL, "invalid detachstate" ); |
---|
468 | |
---|
469 | puts( "Init - pthread_attr_setdetachstate - SUCCESSFUL" ); |
---|
470 | status = pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE ); |
---|
471 | posix_service_failed( status, "pthread_attr_setdetachstate"); |
---|
472 | |
---|
473 | puts( "Init - pthread_attr_getdetachstate - EINVAL (NULL attr)" ); |
---|
474 | status = pthread_attr_getdetachstate( NULL, &detachstate ); |
---|
475 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
476 | |
---|
477 | puts( "Init - pthread_attr_getdetachstate - EINVAL (NULL detatchstate)" ); |
---|
478 | status = pthread_attr_getdetachstate( &attr, NULL ); |
---|
479 | fatal_directive_check_status_only( status, EINVAL, "NULL detatchstate" ); |
---|
480 | |
---|
481 | puts( "Init - pthread_attr_getdetachstate - EINVAL (not initialized attr)" ); |
---|
482 | status = pthread_attr_getdetachstate( &destroyed_attr, &detachstate ); |
---|
483 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
484 | |
---|
485 | puts( "Init - pthread_attr_getdetachstate - SUCCESSFUL" ); |
---|
486 | status = pthread_attr_getdetachstate( &attr, &detachstate ); |
---|
487 | posix_service_failed( status, "pthread_attr_getdetachstate"); |
---|
488 | printf( "Init - current detach state attribute = %d\n", detachstate ); |
---|
489 | |
---|
490 | /* exercise get and set scheduling parameters */ |
---|
491 | |
---|
492 | empty_line(); |
---|
493 | |
---|
494 | puts( "Init - pthread_attr_getschedparam - SUCCESSFUL" ); |
---|
495 | status = pthread_attr_getschedparam( &attr, &schedparam ); |
---|
496 | posix_service_failed( status, "pthread_attr_getschedparam"); |
---|
497 | |
---|
498 | print_schedparam( "Init - ", &schedparam ); |
---|
499 | |
---|
500 | puts( "Init - pthread_attr_setschedparam - EINVAL (NULL attr)" ); |
---|
501 | status = pthread_attr_setschedparam( NULL, &schedparam ); |
---|
502 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
503 | |
---|
504 | puts( "Init - pthread_attr_setschedparam - EINVAL (not initialized attr)" ); |
---|
505 | status = pthread_attr_setschedparam( &destroyed_attr, &schedparam ); |
---|
506 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
507 | |
---|
508 | puts( "Init - pthread_attr_setschedparam - EINVAL (NULL schedparam)" ); |
---|
509 | status = pthread_attr_setschedparam( &attr, NULL ); |
---|
510 | fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" ); |
---|
511 | |
---|
512 | puts( "Init - pthread_attr_setschedparam - SUCCESSFUL" ); |
---|
513 | status = pthread_attr_setschedparam( &attr, &schedparam ); |
---|
514 | posix_service_failed( status, "pthread_attr_setschedparam"); |
---|
515 | |
---|
516 | puts( "Init - pthread_attr_getschedparam - EINVAL (NULL attr)" ); |
---|
517 | status = pthread_attr_getschedparam( NULL, &schedparam ); |
---|
518 | fatal_directive_check_status_only( status, EINVAL, "pthread_attr_getschedparam" ); |
---|
519 | |
---|
520 | puts( "Init - pthread_attr_getschedparam - EINVAL (not initialized attr)" ); |
---|
521 | status = pthread_attr_getschedparam( &destroyed_attr, &schedparam ); |
---|
522 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
523 | |
---|
524 | puts( "Init - pthread_attr_getschedparam - EINVAL (NULL schedparam)" ); |
---|
525 | status = pthread_attr_getschedparam( &attr, NULL ); |
---|
526 | fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" ); |
---|
527 | |
---|
528 | /* exercise pthread_getschedparam */ |
---|
529 | |
---|
530 | empty_line(); |
---|
531 | |
---|
532 | puts( "Init - pthread_getschedparam - EINVAL (NULL policy)" ); |
---|
533 | status = pthread_getschedparam( pthread_self(), NULL, &schedparam ); |
---|
534 | fatal_directive_check_status_only( status, EINVAL, "NULL policy" ); |
---|
535 | |
---|
536 | puts( "Init - pthread_getschedparam - EINVAL (NULL schedparam)" ); |
---|
537 | status = pthread_getschedparam( pthread_self(), &schedpolicy, NULL ); |
---|
538 | fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" ); |
---|
539 | |
---|
540 | puts( "Init - pthread_getschedparam - ESRCH (bad thread)" ); |
---|
541 | status = pthread_getschedparam( (pthread_t) -1, &schedpolicy, &schedparam ); |
---|
542 | fatal_directive_check_status_only( status, ESRCH, "bad thread" ); |
---|
543 | |
---|
544 | puts( "Init - pthread_getschedparam - SUCCESSFUL" ); |
---|
545 | status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); |
---|
546 | posix_service_failed( status, "pthread_getschedparam"); |
---|
547 | |
---|
548 | printf( "Init - policy = %d\n", schedpolicy ); |
---|
549 | |
---|
550 | print_schedparam( "Init - ", &schedparam ); |
---|
551 | |
---|
552 | /* exercise pthread_setschedparam */ |
---|
553 | |
---|
554 | empty_line(); |
---|
555 | |
---|
556 | puts( "Init - pthread_setschedparam - EINVAL (NULL schedparam)" ); |
---|
557 | status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL ); |
---|
558 | fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" ); |
---|
559 | |
---|
560 | schedparam.sched_priority = -1; |
---|
561 | |
---|
562 | puts( "Init - pthread_setschedparam - EINVAL (invalid priority)" ); |
---|
563 | status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL ); |
---|
564 | fatal_directive_check_status_only( status, EINVAL, "invalid priority" ); |
---|
565 | |
---|
566 | /* reset sched_param */ |
---|
567 | status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); |
---|
568 | posix_service_failed( status, "pthread_getschedparam"); |
---|
569 | |
---|
570 | puts( "Init - pthread_setschedparam - EINVAL (invalid policy)" ); |
---|
571 | status = pthread_setschedparam( pthread_self(), -1, &schedparam ); |
---|
572 | fatal_directive_check_status_only( status, EINVAL, "invalid policy" ); |
---|
573 | |
---|
574 | puts( "Init - pthread_setschedparam - ESRCH (invalid thread)" ); |
---|
575 | status = pthread_setschedparam( (pthread_t) -1, SCHED_OTHER, &schedparam ); |
---|
576 | fatal_directive_check_status_only( status, ESRCH, "invalid thread" ); |
---|
577 | |
---|
578 | #if defined(RTEMS_POSIX_API) |
---|
579 | /* now get sporadic server errors */ |
---|
580 | |
---|
581 | schedparam.sched_ss_repl_period.tv_sec = 0; |
---|
582 | schedparam.sched_ss_repl_period.tv_nsec = 0; |
---|
583 | schedparam.sched_ss_init_budget.tv_sec = 1; |
---|
584 | schedparam.sched_ss_init_budget.tv_nsec = 1; |
---|
585 | |
---|
586 | puts( "Init - pthread_setschedparam - EINVAL (replenish == 0)" ); |
---|
587 | status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam ); |
---|
588 | fatal_directive_check_status_only( status, EINVAL, "replenish == 0" ); |
---|
589 | |
---|
590 | schedparam.sched_ss_repl_period.tv_sec = 1; |
---|
591 | schedparam.sched_ss_repl_period.tv_nsec = 1; |
---|
592 | schedparam.sched_ss_init_budget.tv_sec = 0; |
---|
593 | schedparam.sched_ss_init_budget.tv_nsec = 0; |
---|
594 | |
---|
595 | puts( "Init - pthread_setschedparam - EINVAL (budget == 0)" ); |
---|
596 | status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam ); |
---|
597 | fatal_directive_check_status_only( status, EINVAL, "budget == 0" ); |
---|
598 | |
---|
599 | schedparam.sched_ss_repl_period.tv_sec = 1; |
---|
600 | schedparam.sched_ss_repl_period.tv_nsec = 0; |
---|
601 | schedparam.sched_ss_init_budget.tv_sec = 1; |
---|
602 | schedparam.sched_ss_init_budget.tv_nsec = 1; |
---|
603 | |
---|
604 | puts( "Init - pthread_setschedparam - EINVAL (replenish < budget)" ); |
---|
605 | status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam ); |
---|
606 | fatal_directive_check_status_only( status, EINVAL, "replenish < budget" ); |
---|
607 | |
---|
608 | schedparam.sched_ss_repl_period.tv_sec = 2; |
---|
609 | schedparam.sched_ss_repl_period.tv_nsec = 0; |
---|
610 | schedparam.sched_ss_init_budget.tv_sec = 1; |
---|
611 | schedparam.sched_ss_init_budget.tv_nsec = 0; |
---|
612 | schedparam.sched_ss_low_priority = -1; |
---|
613 | |
---|
614 | puts( "Init - pthread_setschedparam - EINVAL (invalid priority)" ); |
---|
615 | status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam ); |
---|
616 | fatal_directive_check_status_only( status, EINVAL, "invalid priority" ); |
---|
617 | |
---|
618 | /* |
---|
619 | * Create a sporadic thread that doesn't need it's priority |
---|
620 | * boosted |
---|
621 | */ |
---|
622 | empty_line(); |
---|
623 | |
---|
624 | puts( "Init - pthread_attr_init - SUCCESSFUL" ); |
---|
625 | status = pthread_attr_init( &attr ); |
---|
626 | posix_service_failed( status, "pthread_attr_init" ); |
---|
627 | |
---|
628 | puts( "Init - pthread_attr_setinheritsched - EXPLICIT - SUCCESSFUL" ); |
---|
629 | status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ); |
---|
630 | rtems_test_assert( !status ); |
---|
631 | |
---|
632 | schedparam.sched_ss_repl_period.tv_sec = 3; |
---|
633 | schedparam.sched_ss_repl_period.tv_nsec = 3; |
---|
634 | schedparam.sched_ss_init_budget.tv_sec = 1; |
---|
635 | schedparam.sched_ss_init_budget.tv_nsec = 1; |
---|
636 | schedparam.sched_priority = sched_get_priority_max( SCHED_FIFO ); |
---|
637 | schedparam.sched_ss_low_priority = sched_get_priority_max( SCHED_FIFO ) - 6; |
---|
638 | |
---|
639 | puts( "Init - pthread_attr_setschedpolicy - SUCCESSFUL" ); |
---|
640 | status = pthread_attr_setschedpolicy( &attr, SCHED_SPORADIC ); |
---|
641 | posix_service_failed( status, "pthread_attr_setschedparam"); |
---|
642 | puts( "Init - pthread_attr_setschedparam - SUCCESSFUL" ); |
---|
643 | status = pthread_attr_setschedparam( &attr, &schedparam ); |
---|
644 | posix_service_failed( status, "pthread_attr_setschedparam"); |
---|
645 | |
---|
646 | status = pthread_create( &Task2_id, &attr, Task_2, NULL ); |
---|
647 | rtems_test_assert( !status ); |
---|
648 | |
---|
649 | status = pthread_join( Task2_id, NULL ); |
---|
650 | posix_service_failed( status, " pthread_join"); |
---|
651 | #endif |
---|
652 | |
---|
653 | TEST_END(); |
---|
654 | rtems_test_exit( 0 ); |
---|
655 | |
---|
656 | return NULL; /* just so the compiler thinks we returned something */ |
---|
657 | } |
---|