source: rtems/testsuites/psxtests/psx07/init.c @ 6c2434a8

4.104.11
Last change on this file since 6c2434a8 was 6c2434a8, checked in by Ralf Corsepius <ralf.corsepius@…>, on Oct 25, 2009 at 5:49:38 PM

2009-10-25 Ralf Corsépius <ralf.corsepius@…>

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