source: rtems/testsuites/psxtests/psx07/init.c @ 8c3c4822

4.104.115
Last change on this file since 8c3c4822 was 8c3c4822, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/27/09 at 05:01:14

Use HAVE_DECL_PTHREAD_ATTR_GETCPUTIME, HAVE_DECL_PTHREAD_ATTR_SETCPUTIME.

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