Changeset c123a084 in rtems


Ignore:
Timestamp:
Aug 7, 1996, 3:52:30 PM (25 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
cc757fe
Parents:
4bab8e2d
Message:

added complete test cases for pthread_attr_getschedparam,
pthread_attr_setschedparam, and pthread_getschedparam.

added test cases for error paths for pthread_setschedparam.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/tests/psxtests/psx07/init.c

    r4bab8e2d rc123a084  
    1515#include <errno.h>
    1616
     17void print_schedparam(
     18  char               *prefix,
     19  struct sched_param *schedparam
     20)
     21{
     22  printf( "%ssched priority      = %d\n", prefix, schedparam->sched_priority );
     23#if defined(_POSIX_SPORADIC_SERVER)
     24  printf( "%sss_low_priority     = %d\n", prefix, schedparam->ss_low_priority );
     25  printf( "%sss_replenish_period = (%ld, %ld)\n", prefix,
     26     schedparam->ss_replenish_period.tv_sec,
     27     schedparam->ss_replenish_period.tv_nsec );
     28  printf( "%sss_initial_budget = (%ld, %ld)\n", prefix,
     29     schedparam->ss_initial_budget.tv_sec,
     30     schedparam->ss_initial_budget.tv_nsec );
     31#else
     32  printf( "%s_POSIX_SPORADIC_SERVER is not defined\n" );
     33#endif
     34}
     35
    1736void *POSIX_Init(
    1837  void *argument
    1938)
    2039{
    21   int             status;
    22   int             scope;
    23   int             inheritsched;
    24   int             schedpolicy;
    25   size_t          stacksize;
    26   void           *stackaddr;
    27   int             detachstate;
    28   pthread_attr_t  attr;
    29   pthread_attr_t  destroyed_attr;
     40  int                 status;
     41  int                 scope;
     42  int                 inheritsched;
     43  int                 schedpolicy;
     44  size_t              stacksize;
     45  void               *stackaddr;
     46  int                 detachstate;
     47  struct sched_param  schedparam;
     48  pthread_attr_t      attr;
     49  pthread_attr_t      destroyed_attr;
    3050
    3151  puts( "\n\n*** POSIX TEST 7 ***" );
     
    268288  printf( "Init: current detach state attribute = %d\n", detachstate );
    269289
     290  /* exercise get and set scheduling parameters */
     291
     292  empty_line();
     293
     294  puts( "Init: pthread_attr_getschedparam - SUCCESSFUL" );
     295  status = pthread_attr_getschedparam( &attr, &schedparam );
     296  assert( !status );
     297
     298  print_schedparam( "Init: ", &schedparam );
     299
     300  puts( "Init: pthread_attr_setschedparam - EINVAL (NULL attr)" );
     301  status = pthread_attr_setschedparam( NULL, &schedparam );
     302  assert( status == EINVAL );
     303 
     304  puts( "Init: pthread_attr_setschedparam - EINVAL (not initialized attr)" );
     305  status = pthread_attr_setschedparam( &destroyed_attr, &schedparam );
     306  assert( status == EINVAL );
     307 
     308  puts( "Init: pthread_attr_setschedparam - EINVAL (NULL schedparam)" );
     309  status = pthread_attr_setschedparam( &attr, NULL );
     310  assert( status == EINVAL );
     311 
     312  puts( "Init: pthread_attr_setschedparam - SUCCESSFUL" );
     313  status = pthread_attr_setschedparam( &attr, &schedparam );
     314  assert( !status );
     315 
     316  puts( "Init: pthread_attr_getschedparam - EINVAL (NULL attr)" );
     317  status = pthread_attr_getschedparam( NULL, &schedparam );
     318  assert( status == EINVAL );
     319 
     320  puts( "Init: pthread_attr_getschedparam - EINVAL (not initialized attr)" );
     321  status = pthread_attr_getschedparam( &destroyed_attr, &schedparam );
     322  assert( status == EINVAL );
     323 
     324  puts( "Init: pthread_attr_getschedparam - EINVAL (NULL schedparam)" );
     325  status = pthread_attr_getschedparam( &attr, NULL );
     326  assert( status == EINVAL );
     327 
     328  /* exercise pthread_getschedparam */
     329
     330  empty_line();
     331
     332  puts( "Init: pthread_getschedparam - EINVAL (NULL policy)" );
     333  status = pthread_getschedparam( pthread_self(), NULL, &schedparam );
     334  assert( status == EINVAL );
     335 
     336  puts( "Init: pthread_getschedparam - EINVAL (NULL schedparam)" );
     337  status = pthread_getschedparam( pthread_self(), &schedpolicy, NULL );
     338  assert( status == EINVAL );
     339 
     340  puts( "Init: pthread_getschedparam - ESRCH (bad thread)" );
     341  status = pthread_getschedparam( -1, &schedpolicy, &schedparam );
     342  assert( status == ESRCH );
     343 
     344  puts( "Init: pthread_getschedparam - SUCCESSFUL" );
     345  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
     346  assert( !status );
     347 
     348  printf( "Init: policy = %d\n", schedpolicy );
     349
     350  print_schedparam( "Init: ", &schedparam );
     351
     352  /* exercise pthread_setschedparam */
     353
     354  empty_line();
     355
     356  puts( "Init: pthread_setschedparam - EINVAL (NULL schedparam)" );
     357  status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL );
     358  assert( status == EINVAL );
     359
     360  schedparam.sched_priority = -1;
     361
     362  puts( "Init: pthread_setschedparam - EINVAL (invalid priority)" );
     363  status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL );
     364  assert( status == EINVAL );
     365
     366  schedparam.sched_priority = 128;
     367
     368  puts( "Init: pthread_setschedparam - EINVAL (invalid policy)" );
     369  status = pthread_setschedparam( pthread_self(), -1, &schedparam );
     370  assert( status == EINVAL );
     371
     372  puts( "Init: pthread_setschedparam - ESRCH (invalid thread)" );
     373  status = pthread_setschedparam( -1, SCHED_OTHER, &schedparam );
     374  assert( status == ESRCH );
     375
     376  /* now get sporadic server errors */
     377
     378  schedparam.ss_replenish_period.tv_sec = 1;
     379  schedparam.ss_replenish_period.tv_nsec = 0;
     380  schedparam.ss_initial_budget.tv_sec = 1;
     381  schedparam.ss_initial_budget.tv_nsec = 1;
     382
     383  puts( "Init: pthread_setschedparam - EINVAL (replenish < budget)" );
     384  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
     385  assert( status == EINVAL );
     386
     387  schedparam.ss_replenish_period.tv_sec = 2;
     388  schedparam.ss_replenish_period.tv_nsec = 0;
     389  schedparam.ss_initial_budget.tv_sec = 1;
     390  schedparam.ss_initial_budget.tv_nsec = 0;
     391  schedparam.ss_low_priority = -1;
     392
     393  puts( "Init: pthread_setschedparam - EINVAL (invalid priority)" );
     394  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
     395  assert( status == EINVAL );
     396
     397
    270398  puts( "*** END OF POSIX TEST 7 ***" );
    271399  exit( 0 );
  • testsuites/psxtests/psx07/init.c

    r4bab8e2d rc123a084  
    1515#include <errno.h>
    1616
     17void print_schedparam(
     18  char               *prefix,
     19  struct sched_param *schedparam
     20)
     21{
     22  printf( "%ssched priority      = %d\n", prefix, schedparam->sched_priority );
     23#if defined(_POSIX_SPORADIC_SERVER)
     24  printf( "%sss_low_priority     = %d\n", prefix, schedparam->ss_low_priority );
     25  printf( "%sss_replenish_period = (%ld, %ld)\n", prefix,
     26     schedparam->ss_replenish_period.tv_sec,
     27     schedparam->ss_replenish_period.tv_nsec );
     28  printf( "%sss_initial_budget = (%ld, %ld)\n", prefix,
     29     schedparam->ss_initial_budget.tv_sec,
     30     schedparam->ss_initial_budget.tv_nsec );
     31#else
     32  printf( "%s_POSIX_SPORADIC_SERVER is not defined\n" );
     33#endif
     34}
     35
    1736void *POSIX_Init(
    1837  void *argument
    1938)
    2039{
    21   int             status;
    22   int             scope;
    23   int             inheritsched;
    24   int             schedpolicy;
    25   size_t          stacksize;
    26   void           *stackaddr;
    27   int             detachstate;
    28   pthread_attr_t  attr;
    29   pthread_attr_t  destroyed_attr;
     40  int                 status;
     41  int                 scope;
     42  int                 inheritsched;
     43  int                 schedpolicy;
     44  size_t              stacksize;
     45  void               *stackaddr;
     46  int                 detachstate;
     47  struct sched_param  schedparam;
     48  pthread_attr_t      attr;
     49  pthread_attr_t      destroyed_attr;
    3050
    3151  puts( "\n\n*** POSIX TEST 7 ***" );
     
    268288  printf( "Init: current detach state attribute = %d\n", detachstate );
    269289
     290  /* exercise get and set scheduling parameters */
     291
     292  empty_line();
     293
     294  puts( "Init: pthread_attr_getschedparam - SUCCESSFUL" );
     295  status = pthread_attr_getschedparam( &attr, &schedparam );
     296  assert( !status );
     297
     298  print_schedparam( "Init: ", &schedparam );
     299
     300  puts( "Init: pthread_attr_setschedparam - EINVAL (NULL attr)" );
     301  status = pthread_attr_setschedparam( NULL, &schedparam );
     302  assert( status == EINVAL );
     303 
     304  puts( "Init: pthread_attr_setschedparam - EINVAL (not initialized attr)" );
     305  status = pthread_attr_setschedparam( &destroyed_attr, &schedparam );
     306  assert( status == EINVAL );
     307 
     308  puts( "Init: pthread_attr_setschedparam - EINVAL (NULL schedparam)" );
     309  status = pthread_attr_setschedparam( &attr, NULL );
     310  assert( status == EINVAL );
     311 
     312  puts( "Init: pthread_attr_setschedparam - SUCCESSFUL" );
     313  status = pthread_attr_setschedparam( &attr, &schedparam );
     314  assert( !status );
     315 
     316  puts( "Init: pthread_attr_getschedparam - EINVAL (NULL attr)" );
     317  status = pthread_attr_getschedparam( NULL, &schedparam );
     318  assert( status == EINVAL );
     319 
     320  puts( "Init: pthread_attr_getschedparam - EINVAL (not initialized attr)" );
     321  status = pthread_attr_getschedparam( &destroyed_attr, &schedparam );
     322  assert( status == EINVAL );
     323 
     324  puts( "Init: pthread_attr_getschedparam - EINVAL (NULL schedparam)" );
     325  status = pthread_attr_getschedparam( &attr, NULL );
     326  assert( status == EINVAL );
     327 
     328  /* exercise pthread_getschedparam */
     329
     330  empty_line();
     331
     332  puts( "Init: pthread_getschedparam - EINVAL (NULL policy)" );
     333  status = pthread_getschedparam( pthread_self(), NULL, &schedparam );
     334  assert( status == EINVAL );
     335 
     336  puts( "Init: pthread_getschedparam - EINVAL (NULL schedparam)" );
     337  status = pthread_getschedparam( pthread_self(), &schedpolicy, NULL );
     338  assert( status == EINVAL );
     339 
     340  puts( "Init: pthread_getschedparam - ESRCH (bad thread)" );
     341  status = pthread_getschedparam( -1, &schedpolicy, &schedparam );
     342  assert( status == ESRCH );
     343 
     344  puts( "Init: pthread_getschedparam - SUCCESSFUL" );
     345  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
     346  assert( !status );
     347 
     348  printf( "Init: policy = %d\n", schedpolicy );
     349
     350  print_schedparam( "Init: ", &schedparam );
     351
     352  /* exercise pthread_setschedparam */
     353
     354  empty_line();
     355
     356  puts( "Init: pthread_setschedparam - EINVAL (NULL schedparam)" );
     357  status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL );
     358  assert( status == EINVAL );
     359
     360  schedparam.sched_priority = -1;
     361
     362  puts( "Init: pthread_setschedparam - EINVAL (invalid priority)" );
     363  status = pthread_setschedparam( pthread_self(), SCHED_OTHER, NULL );
     364  assert( status == EINVAL );
     365
     366  schedparam.sched_priority = 128;
     367
     368  puts( "Init: pthread_setschedparam - EINVAL (invalid policy)" );
     369  status = pthread_setschedparam( pthread_self(), -1, &schedparam );
     370  assert( status == EINVAL );
     371
     372  puts( "Init: pthread_setschedparam - ESRCH (invalid thread)" );
     373  status = pthread_setschedparam( -1, SCHED_OTHER, &schedparam );
     374  assert( status == ESRCH );
     375
     376  /* now get sporadic server errors */
     377
     378  schedparam.ss_replenish_period.tv_sec = 1;
     379  schedparam.ss_replenish_period.tv_nsec = 0;
     380  schedparam.ss_initial_budget.tv_sec = 1;
     381  schedparam.ss_initial_budget.tv_nsec = 1;
     382
     383  puts( "Init: pthread_setschedparam - EINVAL (replenish < budget)" );
     384  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
     385  assert( status == EINVAL );
     386
     387  schedparam.ss_replenish_period.tv_sec = 2;
     388  schedparam.ss_replenish_period.tv_nsec = 0;
     389  schedparam.ss_initial_budget.tv_sec = 1;
     390  schedparam.ss_initial_budget.tv_nsec = 0;
     391  schedparam.ss_low_priority = -1;
     392
     393  puts( "Init: pthread_setschedparam - EINVAL (invalid priority)" );
     394  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
     395  assert( status == EINVAL );
     396
     397
    270398  puts( "*** END OF POSIX TEST 7 ***" );
    271399  exit( 0 );
Note: See TracChangeset for help on using the changeset viewer.