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