Changeset 5d1fc66 in rtems


Ignore:
Timestamp:
Aug 12, 2016, 1:54:46 PM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
fea392a
Parents:
9c42752
git-author:
Sebastian Huber <sebastian.huber@…> (08/12/16 13:54:46)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/18/16 05:28:00)
Message:

psxtests: Adjust sporadic server tests

According to POSIX priority value returned from pthread_getschedparam()
shall be the value specified by the most recent pthread_setschedparam(),
pthread_setschedprio(), or pthread_create() call affecting the target
thread. Read this as though a temporary lower priority due to the
sporadic server policy shall not be visible through
pthread_getschedparam(). Thus, use rtems_task_set_priority() to get the
current priority of the threads.

Use a priority ceiling mutex to prevent sporadic server priority
adjustments.

Location:
testsuites/psxtests
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • testsuites/psxtests/psx09/init.c

    r9c42752 r5d1fc66  
    2121const char rtems_test_name[] = "PSX 9";
    2222
    23 void print_schedparam(
    24   char               *prefix,
    25   struct sched_param *schedparam
    26 );
    27 
    28 int HIGH_PRIORITY;
    29 int MEDIUM_PRIORITY;
    30 int LOW_PRIORITY;
    31 
    32 void print_schedparam(
    33   char               *prefix,
    34   struct sched_param *schedparam
    35 )
    36 {
    37   printf( "%ssched priority      = %d\n", prefix, schedparam->sched_priority );
    38 #if defined(_POSIX_SPORADIC_SERVER)
    39   printf( "%ssched_ss_low_priority     = %d\n",
    40       prefix, schedparam->sched_ss_low_priority );
    41   printf( "%ssched_ss_repl_period = (%" PRIdtime_t ", %ld)\n", prefix,
    42      schedparam->sched_ss_repl_period.tv_sec,
    43      schedparam->sched_ss_repl_period.tv_nsec );
    44   printf( "%ssched_ss_init_budget = (%" PRIdtime_t ", %ld)\n", prefix,
    45      schedparam->sched_ss_init_budget.tv_sec,
    46      schedparam->sched_ss_init_budget.tv_nsec );
    47 #else
    48   printf( "%s_POSIX_SPORADIC_SERVER is not defined\n", prefix );
    49 #endif
     23static int CEILING_PRIORITY;
     24static int HIGH_PRIORITY;
     25static int LOW_PRIORITY;
     26
     27static int get_current_prio( pthread_t thread )
     28{
     29  rtems_status_code sc;
     30  rtems_task_priority prio;
     31  int max;
     32
     33  sc = rtems_task_set_priority( thread, RTEMS_CURRENT_PRIORITY, &prio );
     34  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     35
     36  max = sched_get_priority_max( SCHED_FIFO );
     37
     38  return max + 1 - (int) prio;
    5039}
    5140
     
    11099  TEST_BEGIN();
    111100
     101  CEILING_PRIORITY = sched_get_priority_max( SCHED_SPORADIC );
     102  HIGH_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 1;
     103  LOW_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 2;
     104
    112105  test_destroy_locked_mutex();
    113106
     
    136129  schedparam.sched_ss_init_budget.tv_nsec = 250000000;    /* 1/4 second */
    137130
    138   schedparam.sched_priority = sched_get_priority_max(SCHED_SPORADIC);
    139   schedparam.sched_ss_low_priority = sched_get_priority_max(SCHED_SPORADIC) - 2;
     131  schedparam.sched_priority = HIGH_PRIORITY;
     132  schedparam.sched_ss_low_priority = LOW_PRIORITY;
    140133
    141134  puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" );
     
    143136  rtems_test_assert( !status );
    144137
    145   status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
    146   rtems_test_assert( !status );
    147 
    148   priority = schedparam.sched_priority;
    149   sprintf( buffer, " - new priority = %d", priority );
     138  sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
    150139  print_current_time( "Init: ", buffer );
    151140
     
    153142
    154143  for ( passes=0 ; passes <= 3 ; ) {
    155     status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
    156     rtems_test_assert( !status );
    157 
    158     if ( priority != schedparam.sched_priority ) {
    159       priority = schedparam.sched_priority;
     144    int current_priority;
     145
     146    current_priority = get_current_prio( pthread_self() );
     147
     148    if ( priority != current_priority ) {
     149      priority = current_priority;
    160150      sprintf( buffer, " - new priority = %d", priority );
    161151      print_current_time( "Init: ", buffer );
     
    176166  schedparam.sched_ss_init_budget.tv_nsec = 250000000;    /* 1/4 second */
    177167
    178   HIGH_PRIORITY = sched_get_priority_max( SCHED_SPORADIC );
    179   MEDIUM_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 2;
    180   LOW_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 4;
    181 
    182168  schedparam.sched_priority = HIGH_PRIORITY;
    183169  schedparam.sched_ss_low_priority = LOW_PRIORITY;
     
    191177  rtems_test_assert( !status );
    192178
    193   status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
     179  status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_PROTECT );
     180  rtems_test_assert( !status );
     181
     182  status = pthread_mutexattr_setprioceiling( &attr, CEILING_PRIORITY );
    194183  rtems_test_assert( !status );
    195184
     
    200189  rtems_test_assert( !status );
    201190
    202   status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
    203   rtems_test_assert( !status );
    204 
    205   priority = schedparam.sched_priority;
    206   sprintf( buffer, " - new priority = %d", priority );
     191  sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
    207192  print_current_time( "Init: ", buffer );
    208193
     
    217202  rtems_test_assert( !status );
    218203
    219   for ( ; ; ) {
    220     status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
    221     rtems_test_assert( !status );
    222 
    223     if ( schedparam.sched_priority == LOW_PRIORITY ) {
     204  do {
     205    priority = get_current_prio( pthread_self() );
     206
     207    if ( priority != CEILING_PRIORITY ) {
    224208      puts( "ERROR - Init's priority lowered while holding mutex" );
    225209      rtems_test_exit(0);
     
    227211
    228212    now = time( &now );
    229     if ( now - start > 3 )
    230       break;
    231 
    232     priority = schedparam.sched_priority;
    233     sprintf( buffer, " - new priority = %d", priority );
    234     print_current_time( "Init: ", buffer );
    235 
    236     status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
    237     rtems_test_assert( !status );
    238 
    239     priority = schedparam.sched_priority;
    240     sprintf( buffer, " - new priority = %d", priority );
    241     print_current_time( "Init: ", buffer );
    242 
    243     break;
    244   }
     213  } while ( now - start < 3 );
    245214
    246215  /* with this unlock we should be able to go to low priority */
     
    252221  rtems_test_assert( !status );
    253222
    254   status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
    255   rtems_test_assert( !status );
    256 
    257   priority = schedparam.sched_priority;
    258   sprintf( buffer, " - new priority = %d", priority );
     223  sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
    259224  print_current_time( "Init: ", buffer );
    260225
    261226  for ( ; ; ) {
    262     status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
    263     rtems_test_assert( !status );
    264 
    265     if ( schedparam.sched_priority == LOW_PRIORITY )
     227    if ( get_current_prio( pthread_self() ) == LOW_PRIORITY )
    266228      break;
    267229  }
    268230
    269   status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
    270   rtems_test_assert( !status );
    271 
    272   priority = schedparam.sched_priority;
    273   sprintf( buffer, " - new priority = %d", priority );
     231  sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
    274232  print_current_time( "Init: ", buffer );
    275233
  • testsuites/psxtests/psx09/psx09.scn

    r9c42752 r5d1fc66  
    1 *** POSIX TEST 9 ***
     1*** BEGIN OF TEST PSX 9 ***
    22Init's ID is 0x0b010001
    33Init: pthread_getschedparam - SUCCESSFUL
    44Init: Fri May 24 11:05:00 1996 - current priority = 2
    55Init: pthread_setschedparam - SUCCESSFUL (sporadic server)
    6 Init: Fri May 24 11:05:00 1996 - new priority = 254
    76Init: Fri May 24 11:05:00 1996 - new priority = 252
    8 Init: Fri May 24 11:05:00 1996 - new priority = 254
    97Init: Fri May 24 11:05:00 1996 - new priority = 252
    10 Init: Fri May 24 11:05:01 1996 - new priority = 254
     8Init: Fri May 24 11:05:00 1996 - new priority = 253
     9Init: Fri May 24 11:05:00 1996 - new priority = 252
     10Init: Fri May 24 11:05:00 1996 - new priority = 253
    1111
    1212Init: pthread_setschedparam - SUCCESSFUL (sporadic server)
    1313Init: Initializing mutex attributes for priority ceiling
    1414Init: Creating a mutex
    15 Init: Fri May 24 11:05:01 1996 - new priority = 254
     15Init: Fri May 24 11:05:00 1996 - new priority = 252
    1616Init: pthread_mutex_lock acquire the lock
    17 Init: Fri May 24 11:05:01 1996 - new priority = 254
    18 Init: Fri May 24 11:05:01 1996 - new priority = 254
    1917Init: unlock mutex
    20 Init: Fri May 24 11:05:01 1996 - new priority = 254
    21 Init: Fri May 24 11:05:01 1996 - new priority = 250
    22 *** END OF POSIX TEST 9 ***
     18Init: Fri May 24 11:05:03 1996 - new priority = 253
     19Init: Fri May 24 11:05:03 1996 - new priority = 252
     20*** END OF TEST PSX 9 **
  • testsuites/psxtests/psx12/init.c

    r9c42752 r5d1fc66  
    4545static test_context test_instance;
    4646
     47static int get_current_prio( pthread_t thread )
     48{
     49  rtems_status_code sc;
     50  rtems_task_priority prio;
     51  int max;
     52
     53  sc = rtems_task_set_priority( thread, RTEMS_CURRENT_PRIORITY, &prio );
     54  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     55
     56  max = sched_get_priority_max( SCHED_FIFO );
     57
     58  return max + 1 - (int) prio;
     59}
     60
    4761static void wait_for_prio( int prio )
    4862{
    49   int                status;
    50   int                policy;
    51   struct sched_param param;
    52 
    53   do {
    54     status = pthread_getschedparam( pthread_self(), &policy, &param );
    55     rtems_test_assert( status == 0 );
    56   } while ( prio != param.sched_priority );
     63  while ( prio != get_current_prio( pthread_self() ) ) {
     64    /* Wait */
     65  }
    5766}
    5867
Note: See TracChangeset for help on using the changeset viewer.