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.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #define CONFIGURE_INIT |
---|
13 | #include "system.h" |
---|
14 | #include <errno.h> |
---|
15 | #include "tmacros.h" |
---|
16 | |
---|
17 | void print_schedparam( |
---|
18 | char *prefix, |
---|
19 | struct sched_param *schedparam |
---|
20 | ); |
---|
21 | |
---|
22 | void print_schedparam( |
---|
23 | char *prefix, |
---|
24 | struct sched_param *schedparam |
---|
25 | ) |
---|
26 | { |
---|
27 | printf( "%ssched priority = %d\n", prefix, schedparam->sched_priority ); |
---|
28 | #if defined(_POSIX_SPORADIC_SERVER) |
---|
29 | printf( "%sss_low_priority = %d\n", prefix, schedparam->ss_low_priority ); |
---|
30 | printf( "%sss_replenish_period = (%ld, %ld)\n", prefix, |
---|
31 | schedparam->ss_replenish_period.tv_sec, |
---|
32 | schedparam->ss_replenish_period.tv_nsec ); |
---|
33 | printf( "%sss_initial_budget = (%ld, %ld)\n", prefix, |
---|
34 | schedparam->ss_initial_budget.tv_sec, |
---|
35 | schedparam->ss_initial_budget.tv_nsec ); |
---|
36 | #else |
---|
37 | printf( "%s_POSIX_SPORADIC_SERVER is not defined\n" ); |
---|
38 | #endif |
---|
39 | } |
---|
40 | |
---|
41 | void *POSIX_Init( |
---|
42 | void *argument |
---|
43 | ) |
---|
44 | { |
---|
45 | int status; |
---|
46 | int scope; |
---|
47 | int inheritsched; |
---|
48 | int schedpolicy; |
---|
49 | size_t stacksize; |
---|
50 | void *stackaddr; |
---|
51 | int detachstate; |
---|
52 | struct sched_param schedparam; |
---|
53 | pthread_attr_t attr; |
---|
54 | pthread_attr_t destroyed_attr; |
---|
55 | int clock_allowed; |
---|
56 | |
---|
57 | puts( "\n\n*** POSIX TEST 7 ***" ); |
---|
58 | |
---|
59 | /* set the time of day, and print our buffer in multiple ways */ |
---|
60 | |
---|
61 | set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 ); |
---|
62 | |
---|
63 | /* get id of this thread */ |
---|
64 | |
---|
65 | Init_id = pthread_self(); |
---|
66 | printf( "Init's ID is 0x%08x\n", Init_id ); |
---|
67 | |
---|
68 | /* exercise init and destroy */ |
---|
69 | |
---|
70 | puts( "Init: pthread_attr_init - EINVAL (NULL attr)" ); |
---|
71 | status = pthread_attr_init( NULL ); |
---|
72 | fatal_directive_check_status_only( status, EINVAL, "null attribute" ); |
---|
73 | |
---|
74 | puts( "Init: pthread_attr_init - SUCCESSFUL" ); |
---|
75 | status = pthread_attr_init( &attr ); |
---|
76 | posix_service_failed( status, "pthread_attr_init" ); |
---|
77 | |
---|
78 | puts( "Init: initialize and destroy an attribute - SUCCESSFUL" ); |
---|
79 | status = pthread_attr_init( &destroyed_attr ); |
---|
80 | posix_service_failed( status, "pthread_attr_init"); |
---|
81 | |
---|
82 | status = pthread_attr_destroy( &destroyed_attr ); |
---|
83 | posix_service_failed( status, "pthread_attr_destroy"); |
---|
84 | |
---|
85 | puts( "Init: pthread_attr_destroy - EINVAL (NULL attr)" ); |
---|
86 | status = pthread_attr_destroy( NULL ); |
---|
87 | fatal_directive_check_status_only( status, EINVAL, "NULL attribute" ); |
---|
88 | |
---|
89 | puts( "Init: pthread_attr_destroy - EINVAL (not initialized)" ); |
---|
90 | status = pthread_attr_destroy( &destroyed_attr ); |
---|
91 | fatal_directive_check_status_only( status, EINVAL, "not initialized" ); |
---|
92 | |
---|
93 | /* check some errors in pthread_create */ |
---|
94 | |
---|
95 | puts( "Init: pthread_create - EINVAL (attr not initialized)" ); |
---|
96 | status = pthread_create( &Task_id, &destroyed_attr, Task_1, NULL ); |
---|
97 | fatal_directive_check_status_only( status, EINVAL, "attribute not initialized" ); |
---|
98 | |
---|
99 | /* junk stack address */ |
---|
100 | status = pthread_attr_setstackaddr( &attr, (void *)&schedparam ); |
---|
101 | posix_service_failed( status, "setstackaddr"); |
---|
102 | |
---|
103 | /* must go around pthread_attr_setstacksize to set a bad stack size */ |
---|
104 | attr.stacksize = 0; |
---|
105 | |
---|
106 | puts( "Init: pthread_create - EINVAL (stacksize too small)" ); |
---|
107 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
108 | fatal_directive_check_status_only( status, EINVAL, "stacksize too small" ); |
---|
109 | |
---|
110 | /* reset all the fields */ |
---|
111 | status = pthread_attr_init( &attr ); |
---|
112 | posix_service_failed( status, "pthread_attr_init"); |
---|
113 | |
---|
114 | attr.stacksize = rtems_configuration_get_work_space_size() * 10; |
---|
115 | puts( "Init: pthread_create - EAGAIN (stacksize too large)" ); |
---|
116 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
117 | fatal_directive_check_status_only( status, EAGAIN, "stacksize too large" ); |
---|
118 | |
---|
119 | status = pthread_attr_init( &attr ); |
---|
120 | posix_service_failed( status, "pthread_attr_init"); |
---|
121 | |
---|
122 | /* must go around pthread_attr_set routines to set a bad value */ |
---|
123 | attr.inheritsched = -1; |
---|
124 | |
---|
125 | puts( "Init: pthread_create - EINVAL (invalid inherit scheduler)" ); |
---|
126 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
127 | fatal_directive_check_status_only( status, EINVAL, "invalid inherit scheduler" ); |
---|
128 | |
---|
129 | /* check out the error case for system scope not supported */ |
---|
130 | |
---|
131 | status = pthread_attr_init( &attr ); |
---|
132 | posix_service_failed( status, " pthread_attr_init"); |
---|
133 | |
---|
134 | /* Check out pthread_attr_settime and pthread_attr_gettime */ |
---|
135 | puts( "Init: pthread_attr_settime - EINVAL ( null attribute )" ); |
---|
136 | status = pthread_attr_setcputime( NULL, CLOCK_ENABLED ); |
---|
137 | fatal_directive_check_status_only( status, EINVAL, "null attribute" ); |
---|
138 | |
---|
139 | puts( "Init: pthread_attr_gettime - EINVAL ( null attribute )" ); |
---|
140 | status = pthread_attr_getcputime( NULL, &clock_allowed ); |
---|
141 | fatal_directive_check_status_only( status, EINVAL, " null attribute" ); |
---|
142 | |
---|
143 | puts( "Init: pthread_attr_settime - EINVAL ( is initialized )" ); |
---|
144 | status = pthread_attr_setcputime( &destroyed_attr, CLOCK_ENABLED ); |
---|
145 | fatal_directive_check_status_only( status, EINVAL, "is initialized" ); |
---|
146 | |
---|
147 | puts( "Init: pthread_attr_gettime - EINVAL ( is initialized )" ); |
---|
148 | status = pthread_attr_getcputime( &destroyed_attr, &clock_allowed ); |
---|
149 | fatal_directive_check_status_only( status, EINVAL, "is initialized" ); |
---|
150 | |
---|
151 | puts( "Init: pthread_attr_settime - EINVAL ( invalid clock allowed )" ); |
---|
152 | status = pthread_attr_setcputime( &attr, ~(CLOCK_ENABLED | CLOCK_DISABLED) ); |
---|
153 | fatal_directive_check_status_only( status, EINVAL, "invalid clock allowed" ); |
---|
154 | |
---|
155 | puts( "Init: pthread_attr_gettime - EINVAL ( NULL clock allowed )" ); |
---|
156 | status = pthread_attr_getcputime( &attr, NULL ); |
---|
157 | fatal_directive_check_status_only( status, EINVAL, "NULL clock allowed" ); |
---|
158 | |
---|
159 | puts( "Init: validate pthread_attr_setcputime - CLOCK_DISABLED" ); |
---|
160 | status = pthread_attr_setcputime( &attr, CLOCK_DISABLED ); |
---|
161 | posix_service_failed( status, "pthread_attr_setcputime"); |
---|
162 | status = pthread_attr_getcputime( &attr, &clock_allowed ); |
---|
163 | posix_service_failed( status, "pthread_attr_getcputime"); |
---|
164 | if (attr.cputime_clock_allowed != CLOCK_DISABLED) |
---|
165 | perror("ERROR==> pthread_attr_setcputime to CLOCK_DISABLED failed"); |
---|
166 | |
---|
167 | puts( "Init: validate pthread_attr_setcputime - CLOCK_ENABLED" ); |
---|
168 | status = pthread_attr_setcputime( &attr, CLOCK_ENABLED ); |
---|
169 | posix_service_failed( status, "pthread_attr_setcputime"); |
---|
170 | status = pthread_attr_getcputime( &attr, &clock_allowed ); |
---|
171 | posix_service_failed( status, "pthread_attr_getcputime"); |
---|
172 | if (attr.cputime_clock_allowed != CLOCK_ENABLED) |
---|
173 | perror("ERROR==> pthread_attr_setcputime to CLOCK_ENABLED failed"); |
---|
174 | |
---|
175 | /* must go around pthread_attr_set routines to set a bad value */ |
---|
176 | attr.contentionscope = PTHREAD_SCOPE_SYSTEM; |
---|
177 | |
---|
178 | puts( "Init: pthread_create - ENOTSUP (unsupported system contention scope)" ); |
---|
179 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
180 | fatal_directive_check_status_only( status, ENOTSUP, |
---|
181 | "unsupported system contention scope" ); |
---|
182 | |
---|
183 | status = pthread_attr_init( &attr ); |
---|
184 | posix_service_failed( status, "pthread_attr_init"); |
---|
185 | |
---|
186 | /* now check out pthread_create for inherit scheduler */ |
---|
187 | |
---|
188 | status = pthread_attr_setinheritsched( &attr, PTHREAD_INHERIT_SCHED ); |
---|
189 | posix_service_failed( status, "pthread_attr_setinheritsched"); |
---|
190 | |
---|
191 | puts( "Init: pthread_create - SUCCESSFUL (inherit scheduler)" ); |
---|
192 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
193 | posix_service_failed( status, "pthread_create"); |
---|
194 | |
---|
195 | status = pthread_join( Task_id, NULL ); |
---|
196 | posix_service_failed( status, " pthread_join"); |
---|
197 | |
---|
198 | /* switch to Task_1 */ |
---|
199 | |
---|
200 | /* exercise get and set scope */ |
---|
201 | |
---|
202 | empty_line(); |
---|
203 | |
---|
204 | status = pthread_attr_init( &attr ); |
---|
205 | posix_service_failed( status, "pthread_attr_init"); |
---|
206 | |
---|
207 | puts( "Init: pthread_attr_setscope - EINVAL (NULL attr)" ); |
---|
208 | status = pthread_attr_setscope( NULL, PTHREAD_SCOPE_PROCESS ); |
---|
209 | fatal_directive_check_status_only( status, EINVAL , "NULL attr" ); |
---|
210 | |
---|
211 | puts( "Init: pthread_attr_setscope - ENOTSUP" ); |
---|
212 | status = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ); |
---|
213 | fatal_directive_check_status_only( status, ENOTSUP, "PTHREAD_SCOPE_SYSTEM" ); |
---|
214 | |
---|
215 | puts( "Init: pthread_attr_setscope - EINVAL (not initialized attr)" ); |
---|
216 | status = pthread_attr_setscope( &destroyed_attr, PTHREAD_SCOPE_PROCESS ); |
---|
217 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
218 | |
---|
219 | puts( "Init: pthread_attr_setscope - EINVAL (invalid scope)" ); |
---|
220 | status = pthread_attr_setscope( &attr, -1 ); |
---|
221 | fatal_directive_check_status_only( status, EINVAL, "invalid scope" ); |
---|
222 | |
---|
223 | puts( "Init: pthread_attr_setscope - SUCCESSFUL" ); |
---|
224 | status = pthread_attr_setscope( &attr, PTHREAD_SCOPE_PROCESS ); |
---|
225 | posix_service_failed( status, "pthread_attr_setscope"); |
---|
226 | |
---|
227 | puts( "Init: pthread_attr_getscope - EINVAL (NULL attr)" ); |
---|
228 | status = pthread_attr_getscope( NULL, &scope ); |
---|
229 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
230 | |
---|
231 | puts( "Init: pthread_attr_getscope - EINVAL (NULL scope)" ); |
---|
232 | status = pthread_attr_getscope( &attr, NULL ); |
---|
233 | fatal_directive_check_status_only( status, EINVAL, "NULL scope" ); |
---|
234 | |
---|
235 | puts( "Init: pthread_attr_getscope - EINVAL (not initialized attr)" ); |
---|
236 | status = pthread_attr_getscope( &destroyed_attr, &scope ); |
---|
237 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
238 | |
---|
239 | puts( "Init: pthread_attr_getscope - SUCCESSFUL" ); |
---|
240 | status = pthread_attr_getscope( &attr, &scope ); |
---|
241 | posix_service_failed( status, "pthread_attr_getscope"); |
---|
242 | printf( "Init: current scope attribute = %d\n", scope ); |
---|
243 | |
---|
244 | /* exercise get and set inherit scheduler */ |
---|
245 | |
---|
246 | empty_line(); |
---|
247 | |
---|
248 | puts( "Init: pthread_attr_setinheritsched - EINVAL (NULL attr)" ); |
---|
249 | status = pthread_attr_setinheritsched( NULL, PTHREAD_INHERIT_SCHED ); |
---|
250 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
251 | |
---|
252 | puts( "Init: pthread_attr_setinheritsched - EINVAL (not initialized attr)" ); |
---|
253 | status = |
---|
254 | pthread_attr_setinheritsched( &destroyed_attr, PTHREAD_INHERIT_SCHED ); |
---|
255 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
256 | |
---|
257 | puts( "Init: pthread_attr_setinheritsched - ENOTSUP (invalid inheritsched)" ); |
---|
258 | status = pthread_attr_setinheritsched( &attr, -1 ); |
---|
259 | fatal_directive_check_status_only( status, ENOTSUP, "invalid inheritsched" ); |
---|
260 | |
---|
261 | puts( "Init: pthread_attr_setinheritsched - SUCCESSFUL" ); |
---|
262 | status = pthread_attr_setinheritsched( &attr, PTHREAD_INHERIT_SCHED ); |
---|
263 | posix_service_failed( status, "pthread_attr_setinheritsched"); |
---|
264 | |
---|
265 | puts( "Init: pthread_attr_getinheritsched - EINVAL (NULL attr)" ); |
---|
266 | status = pthread_attr_getinheritsched( NULL, &inheritsched ); |
---|
267 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
268 | |
---|
269 | puts( "Init: pthread_attr_getinheritsched - EINVAL (NULL inheritsched)" ); |
---|
270 | status = pthread_attr_getinheritsched( &attr, NULL ); |
---|
271 | fatal_directive_check_status_only( status, EINVAL, "NULL inheritsched" ); |
---|
272 | |
---|
273 | puts( "Init: pthread_attr_getinheritsched - EINVAL (not initialized attr)" ); |
---|
274 | status = pthread_attr_getinheritsched( &destroyed_attr, &inheritsched ); |
---|
275 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
276 | |
---|
277 | puts( "Init: pthread_attr_getinheritsched - SUCCESSFUL" ); |
---|
278 | status = pthread_attr_getinheritsched( &attr, &inheritsched ); |
---|
279 | posix_service_failed( status, "pthread_attr_getinheritsched"); |
---|
280 | printf( "Init: current inherit scheduler attribute = %d\n", inheritsched ); |
---|
281 | |
---|
282 | /* exercise get and set inherit scheduler */ |
---|
283 | |
---|
284 | empty_line(); |
---|
285 | |
---|
286 | puts( "Init: pthread_attr_setschedpolicy - EINVAL (NULL attr)" ); |
---|
287 | status = pthread_attr_setschedpolicy( NULL, SCHED_FIFO ); |
---|
288 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
289 | |
---|
290 | puts( "Init: pthread_attr_setschedpolicy - EINVAL (not initialized attr)" ); |
---|
291 | status = |
---|
292 | pthread_attr_setschedpolicy( &destroyed_attr, SCHED_OTHER ); |
---|
293 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
294 | |
---|
295 | puts( "Init: pthread_attr_setschedpolicy - ENOTSUP (invalid schedpolicy)" ); |
---|
296 | status = pthread_attr_setschedpolicy( &attr, -1 ); |
---|
297 | fatal_directive_check_status_only( status, ENOTSUP, "invalid schedpolicy" ); |
---|
298 | |
---|
299 | puts( "Init: pthread_attr_setschedpolicy - SUCCESSFUL" ); |
---|
300 | status = pthread_attr_setschedpolicy( &attr, SCHED_RR ); |
---|
301 | posix_service_failed( status, "pthread_attr_setschedpolicy"); |
---|
302 | |
---|
303 | puts( "Init: pthread_attr_getschedpolicy - EINVAL (NULL attr)" ); |
---|
304 | status = pthread_attr_getschedpolicy( NULL, &schedpolicy ); |
---|
305 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
306 | |
---|
307 | puts( "Init: pthread_attr_getschedpolicy - EINVAL (NULL schedpolicy)" ); |
---|
308 | status = pthread_attr_getschedpolicy( &attr, NULL ); |
---|
309 | fatal_directive_check_status_only( status, EINVAL, "NULL schedpolicy" ); |
---|
310 | |
---|
311 | puts( "Init: pthread_attr_getschedpolicy - EINVAL (not initialized attr)" ); |
---|
312 | status = pthread_attr_getschedpolicy( &destroyed_attr, &schedpolicy ); |
---|
313 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
314 | |
---|
315 | puts( "Init: pthread_attr_getschedpolicy - SUCCESSFUL" ); |
---|
316 | status = pthread_attr_getschedpolicy( &attr, &schedpolicy ); |
---|
317 | posix_service_failed( status, "pthread_attr_getschedpolicy"); |
---|
318 | printf( "Init: current scheduler policy attribute = %d\n", schedpolicy ); |
---|
319 | |
---|
320 | /* exercise get and set stack size */ |
---|
321 | |
---|
322 | empty_line(); |
---|
323 | |
---|
324 | puts( "Init: pthread_attr_setstacksize - EINVAL (NULL attr)" ); |
---|
325 | status = pthread_attr_setstacksize( NULL, 0 ); |
---|
326 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
327 | |
---|
328 | puts( "Init: pthread_attr_setstacksize - EINVAL (not initialized attr)" ); |
---|
329 | status = |
---|
330 | pthread_attr_setstacksize( &destroyed_attr, 0 ); |
---|
331 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
332 | |
---|
333 | puts( "Init: pthread_attr_setstacksize - SUCCESSFUL (low stacksize)" ); |
---|
334 | status = pthread_attr_setstacksize( &attr, 0 ); |
---|
335 | posix_service_failed( status, "pthread_attr_setstacksize"); |
---|
336 | |
---|
337 | puts( "Init: pthread_attr_setstacksize - SUCCESSFUL (high stacksize)" ); |
---|
338 | status = pthread_attr_setstacksize( &attr, STACK_MINIMUM_SIZE * 2 ); |
---|
339 | posix_service_failed( status, ""); |
---|
340 | |
---|
341 | puts( "Init: pthread_attr_getstacksize - EINVAL (NULL attr)" ); |
---|
342 | status = pthread_attr_getstacksize( NULL, &stacksize ); |
---|
343 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
344 | |
---|
345 | puts( "Init: pthread_attr_getstacksize - EINVAL (NULL stacksize)" ); |
---|
346 | status = pthread_attr_getstacksize( &attr, NULL ); |
---|
347 | fatal_directive_check_status_only( status, EINVAL, "NULL stacksize" ); |
---|
348 | |
---|
349 | puts( "Init: pthread_attr_getstacksize - EINVAL (not initialized attr)" ); |
---|
350 | status = pthread_attr_getstacksize( &destroyed_attr, &stacksize ); |
---|
351 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
352 | |
---|
353 | puts( "Init: pthread_attr_getstacksize - SUCCESSFUL" ); |
---|
354 | status = pthread_attr_getstacksize( &attr, &stacksize ); |
---|
355 | posix_service_failed( status, "pthread_attr_getstacksize"); |
---|
356 | if ( stacksize == (STACK_MINIMUM_SIZE * 2) ) |
---|
357 | printf( "Init: current stack size attribute is OK\n" ); |
---|
358 | |
---|
359 | /* exercise get and set stack address */ |
---|
360 | |
---|
361 | empty_line(); |
---|
362 | |
---|
363 | puts( "Init: pthread_attr_setstackaddr - EINVAL (NULL attr)" ); |
---|
364 | status = pthread_attr_setstackaddr( NULL, NULL ); |
---|
365 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
366 | |
---|
367 | puts( "Init: pthread_attr_setstackaddr - EINVAL (not initialized attr)" ); |
---|
368 | status = |
---|
369 | pthread_attr_setstackaddr( &destroyed_attr, NULL ); |
---|
370 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
371 | |
---|
372 | puts( "Init: pthread_attr_setstackaddr - SUCCESSFUL" ); |
---|
373 | status = pthread_attr_setstackaddr( &attr, 0 ); |
---|
374 | posix_service_failed( status, ""); |
---|
375 | |
---|
376 | puts( "Init: pthread_attr_getstackaddr - EINVAL (NULL attr)" ); |
---|
377 | status = pthread_attr_getstackaddr( NULL, &stackaddr ); |
---|
378 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
379 | |
---|
380 | puts( "Init: pthread_attr_getstackaddr - EINVAL (NULL stackaddr)" ); |
---|
381 | status = pthread_attr_getstackaddr( &attr, NULL ); |
---|
382 | fatal_directive_check_status_only( status, EINVAL, "NULL stackaddr" ); |
---|
383 | |
---|
384 | puts( "Init: pthread_attr_getstackaddr - EINVAL (not initialized attr)" ); |
---|
385 | status = pthread_attr_getstackaddr( &destroyed_attr, &stackaddr ); |
---|
386 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
387 | |
---|
388 | puts( "Init: pthread_attr_getstackaddr - SUCCESSFUL" ); |
---|
389 | status = pthread_attr_getstackaddr( &attr, &stackaddr ); |
---|
390 | posix_service_failed( status, "pthread_attr_getstackaddr"); |
---|
391 | printf( "Init: current stack address attribute = %p\n", stackaddr ); |
---|
392 | |
---|
393 | /* exercise get and set detach state */ |
---|
394 | |
---|
395 | empty_line(); |
---|
396 | |
---|
397 | puts( "Init: pthread_attr_setdetachstate - EINVAL (NULL attr)" ); |
---|
398 | status = pthread_attr_setdetachstate( NULL, PTHREAD_CREATE_DETACHED ); |
---|
399 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
400 | |
---|
401 | puts( "Init: pthread_attr_setdetachstate - EINVAL (not initialized attr)" ); |
---|
402 | status = |
---|
403 | pthread_attr_setdetachstate( &destroyed_attr, PTHREAD_CREATE_JOINABLE ); |
---|
404 | fatal_directive_check_status_only( status, EINVAL, "not initialized att" ); |
---|
405 | |
---|
406 | puts( "Init: pthread_attr_setdetachstate - EINVAL (invalid detachstate)" ); |
---|
407 | status = pthread_attr_setdetachstate( &attr, -1 ); |
---|
408 | fatal_directive_check_status_only( status, EINVAL, "invalid detachstate" ); |
---|
409 | |
---|
410 | puts( "Init: pthread_attr_setdetachstate - SUCCESSFUL" ); |
---|
411 | status = pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE ); |
---|
412 | posix_service_failed( status, "pthread_attr_setdetachstate"); |
---|
413 | |
---|
414 | puts( "Init: pthread_attr_getdetachstate - EINVAL (NULL attr)" ); |
---|
415 | status = pthread_attr_getdetachstate( NULL, &detachstate ); |
---|
416 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
417 | |
---|
418 | puts( "Init: pthread_attr_getdetachstate - EINVAL (NULL detatchstate)" ); |
---|
419 | status = pthread_attr_getdetachstate( &attr, NULL ); |
---|
420 | fatal_directive_check_status_only( status, EINVAL, "NULL detatchstate" ); |
---|
421 | |
---|
422 | puts( "Init: pthread_attr_getdetachstate - EINVAL (not initialized attr)" ); |
---|
423 | status = pthread_attr_getdetachstate( &destroyed_attr, &detachstate ); |
---|
424 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
425 | |
---|
426 | puts( "Init: pthread_attr_getdetachstate - SUCCESSFUL" ); |
---|
427 | status = pthread_attr_getdetachstate( &attr, &detachstate ); |
---|
428 | posix_service_failed( status, "pthread_attr_getdetachstate"); |
---|
429 | printf( "Init: current detach state attribute = %d\n", detachstate ); |
---|
430 | |
---|
431 | /* exercise get and set scheduling parameters */ |
---|
432 | |
---|
433 | empty_line(); |
---|
434 | |
---|
435 | puts( "Init: pthread_attr_getschedparam - SUCCESSFUL" ); |
---|
436 | status = pthread_attr_getschedparam( &attr, &schedparam ); |
---|
437 | posix_service_failed( status, "pthread_attr_getschedparam"); |
---|
438 | |
---|
439 | print_schedparam( "Init: ", &schedparam ); |
---|
440 | |
---|
441 | puts( "Init: pthread_attr_setschedparam - EINVAL (NULL attr)" ); |
---|
442 | status = pthread_attr_setschedparam( NULL, &schedparam ); |
---|
443 | fatal_directive_check_status_only( status, EINVAL, "NULL attr" ); |
---|
444 | |
---|
445 | puts( "Init: pthread_attr_setschedparam - EINVAL (not initialized attr)" ); |
---|
446 | status = pthread_attr_setschedparam( &destroyed_attr, &schedparam ); |
---|
447 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
448 | |
---|
449 | puts( "Init: pthread_attr_setschedparam - EINVAL (NULL schedparam)" ); |
---|
450 | status = pthread_attr_setschedparam( &attr, NULL ); |
---|
451 | fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" ); |
---|
452 | |
---|
453 | puts( "Init: pthread_attr_setschedparam - SUCCESSFUL" ); |
---|
454 | status = pthread_attr_setschedparam( &attr, &schedparam ); |
---|
455 | posix_service_failed( status, "pthread_attr_setschedparam"); |
---|
456 | |
---|
457 | puts( "Init: pthread_attr_getschedparam - EINVAL (NULL attr)" ); |
---|
458 | status = pthread_attr_getschedparam( NULL, &schedparam ); |
---|
459 | fatal_directive_check_status_only( status, EINVAL, "pthread_attr_getschedparam" ); |
---|
460 | |
---|
461 | puts( "Init: pthread_attr_getschedparam - EINVAL (not initialized attr)" ); |
---|
462 | status = pthread_attr_getschedparam( &destroyed_attr, &schedparam ); |
---|
463 | fatal_directive_check_status_only( status, EINVAL, "not initialized attr" ); |
---|
464 | |
---|
465 | puts( "Init: pthread_attr_getschedparam - EINVAL (NULL schedparam)" ); |
---|
466 | status = pthread_attr_getschedparam( &attr, NULL ); |
---|
467 | fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" ); |
---|
468 | |
---|
469 | /* exercise pthread_getschedparam */ |
---|
470 | |
---|
471 | empty_line(); |
---|
472 | |
---|
473 | puts( "Init: pthread_getschedparam - EINVAL (NULL policy)" ); |
---|
474 | status = pthread_getschedparam( pthread_self(), NULL, &schedparam ); |
---|
475 | fatal_directive_check_status_only( status, EINVAL, "NULL policy" ); |
---|
476 | |
---|
477 | puts( "Init: pthread_getschedparam - EINVAL (NULL schedparam)" ); |
---|
478 | status = pthread_getschedparam( pthread_self(), &schedpolicy, NULL ); |
---|
479 | fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" ); |
---|
480 | |
---|
481 | puts( "Init: pthread_getschedparam - ESRCH (bad thread)" ); |
---|
482 | status = pthread_getschedparam( (pthread_t) -1, &schedpolicy, &schedparam ); |
---|
483 | fatal_directive_check_status_only( status, ESRCH, "bad thread" ); |
---|
484 | |
---|
485 | puts( "Init: pthread_getschedparam - SUCCESSFUL" ); |
---|
486 | status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); |
---|
487 | posix_service_failed( status, "pthread_getschedparam"); |
---|
488 | |
---|
489 | printf( "Init: policy = %d\n", schedpolicy ); |
---|
490 | |
---|
491 | print_schedparam( "Init: ", &schedparam ); |
---|
492 | |
---|
493 | /* exercise pthread_setschedparam */ |
---|
494 | |
---|
495 | empty_line(); |
---|
496 | |
---|
497 | puts( "Init: pthread_setschedparam - EINVAL (NULL schedparam)" ); |
---|
498 | status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL ); |
---|
499 | fatal_directive_check_status_only( status, EINVAL, "NULL schedparam" ); |
---|
500 | |
---|
501 | schedparam.sched_priority = -1; |
---|
502 | |
---|
503 | puts( "Init: pthread_setschedparam - EINVAL (invalid priority)" ); |
---|
504 | status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL ); |
---|
505 | fatal_directive_check_status_only( status, EINVAL, "invalid priority" ); |
---|
506 | |
---|
507 | schedparam.sched_priority = sched_get_priority_max(SCHED_OTHER); |
---|
508 | |
---|
509 | puts( "Init: pthread_setschedparam - EINVAL (invalid policy)" ); |
---|
510 | status = pthread_setschedparam( pthread_self(), -1, &schedparam ); |
---|
511 | fatal_directive_check_status_only( status, EINVAL, "invalid policy" ); |
---|
512 | |
---|
513 | puts( "Init: pthread_setschedparam - ESRCH (invalid thread)" ); |
---|
514 | status = pthread_setschedparam( (pthread_t) -1, SCHED_OTHER, &schedparam ); |
---|
515 | fatal_directive_check_status_only( status, ESRCH, "invalid thread" ); |
---|
516 | |
---|
517 | /* now get sporadic server errors */ |
---|
518 | |
---|
519 | schedparam.ss_replenish_period.tv_sec = 1; |
---|
520 | schedparam.ss_replenish_period.tv_nsec = 0; |
---|
521 | schedparam.ss_initial_budget.tv_sec = 1; |
---|
522 | schedparam.ss_initial_budget.tv_nsec = 1; |
---|
523 | |
---|
524 | puts( "Init: pthread_setschedparam - EINVAL (replenish < budget)" ); |
---|
525 | status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam ); |
---|
526 | fatal_directive_check_status_only( status, EINVAL, "replenish < budget" ); |
---|
527 | |
---|
528 | schedparam.ss_replenish_period.tv_sec = 2; |
---|
529 | schedparam.ss_replenish_period.tv_nsec = 0; |
---|
530 | schedparam.ss_initial_budget.tv_sec = 1; |
---|
531 | schedparam.ss_initial_budget.tv_nsec = 0; |
---|
532 | schedparam.ss_low_priority = -1; |
---|
533 | |
---|
534 | puts( "Init: pthread_setschedparam - EINVAL (invalid priority)" ); |
---|
535 | status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam ); |
---|
536 | fatal_directive_check_status_only( status, EINVAL, "invalid priority" ); |
---|
537 | |
---|
538 | puts( "*** END OF POSIX TEST 7 ***" ); |
---|
539 | rtems_test_exit( 0 ); |
---|
540 | |
---|
541 | return NULL; /* just so the compiler thinks we returned something */ |
---|
542 | } |
---|