source: rtems/testsuites/psxtests/psx07/init.c @ af43554

5
Last change on this file since af43554 was af43554, checked in by Sebastian Huber <sebastian.huber@…>, on 10/26/17 at 11:59:11

tests: Remove TEST_INIT

The TEST_EXTERN is a used only by the system.h style tests and they use
CONFIGURE_INIT appropriately.

Update #3170.
Update #3199.

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