source: rtems/testsuites/psxtests/psx07/init.c @ 2cc30e90

4.104.115
Last change on this file since 2cc30e90 was 2cc30e90, checked in by Joel Sherrill <joel.sherrill@…>, on 04/25/10 at 19:40:12

2010-04-25 Joel Sherrill <joel.sherrill@…>

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