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