Changeset 5f66ac86 in rtems


Ignore:
Timestamp:
Jul 20, 2020, 12:00:31 PM (3 weeks ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
a231276
Parents:
28313958
git-author:
Sebastian Huber <sebastian.huber@…> (07/20/20 12:00:31)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/23/20 07:27:47)
Message:

spintrcritical08: Use T_interrupt_test()

Location:
testsuites/sptests
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • testsuites/sptests/Makefile.am

    r28313958 r5f66ac86  
    12411241sp_screens += spintrcritical08/spintrcritical08.scn
    12421242sp_docs += spintrcritical08/spintrcritical08.doc
    1243 spintrcritical08_SOURCES = spintrcritical08/init.c \
    1244         spintrcritical_support/intrcritical.c \
    1245         spintrcritical_support/intrcritical.h
     1243spintrcritical08_SOURCES = spintrcritical08/init.c
    12461244spintrcritical08_CPPFLAGS = $(AM_CPPFLAGS) \
    12471245        $(TEST_FLAGS_spintrcritical08) $(support_includes) \
  • testsuites/sptests/spintrcritical08/init.c

    r28313958 r5f66ac86  
    11/*
     2 *  Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
     3 *
    24 *  COPYRIGHT (c) 1989-2012.
    35 *  On-Line Applications Research Corporation (OAR).
     
    1214#endif
    1315
    14 #include <tmacros.h>
    15 #include <intrcritical.h>
     16#include <string.h>
     17
     18#include <rtems/test.h>
     19#include <rtems/test-info.h>
     20
    1621#include <rtems/score/watchdogimpl.h>
    1722#include <rtems/rtems/ratemonimpl.h>
     
    1924const char rtems_test_name[] = "SPINTRCRITICAL 8";
    2025
    21 /* forward declarations to avoid warnings */
    22 rtems_task Init(rtems_task_argument argument);
     26typedef struct {
     27  rtems_id        period;
     28  Thread_Control *thread;
     29} test_context;
    2330
    24 static rtems_id Period;
    25 
    26 static volatile bool case_hit = false;
    27 
    28 static Thread_Control *thread;
    29 
    30 static rtems_rate_monotonic_period_states getState(void)
     31static rtems_rate_monotonic_period_states getState(test_context *ctx)
    3132{
    3233  Rate_monotonic_Control *the_period;
    3334  ISR_lock_Context        lock_context;
    3435
    35   the_period = _Rate_monotonic_Get( Period, &lock_context );
    36   rtems_test_assert( the_period != NULL );
     36  the_period = _Rate_monotonic_Get( ctx->period, &lock_context );
     37  T_quiet_assert_not_null( the_period );
    3738  _ISR_lock_ISR_enable( &lock_context );
    3839
     
    4041}
    4142
    42 static rtems_timer_service_routine test_release_from_isr(
    43   rtems_id  timer,
    44   void     *arg
    45 )
     43static T_interrupt_test_state interrupt( void *arg )
    4644{
    47   Per_CPU_Control *cpu = _Per_CPU_Get();
    48   Watchdog_Header *header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ];
    49   Watchdog_Control *watchdog = (Watchdog_Control *) header->first;
     45  test_context                       *ctx;
     46  Per_CPU_Control                    *cpu_self;
     47  Watchdog_Header                    *header;
     48  Watchdog_Control                   *watchdog;
     49  T_interrupt_test_state              state;
     50  Thread_Wait_flags                   flags;
     51  ISR_Level                           level;
     52  rtems_rate_monotonic_period_states  previous_period_state;
    5053
    51   if (
    52     watchdog != NULL
    53       && watchdog->expire == cpu->Watchdog.ticks
    54       && watchdog->routine == _Rate_monotonic_Timeout
    55   ) {
    56     Thread_Wait_flags flags = _Thread_Wait_flags_get( thread );
     54  state = T_interrupt_test_get_state();
    5755
    58     _Watchdog_Per_CPU_remove_ticks( watchdog );
     56  if ( state != T_INTERRUPT_TEST_ACTION ) {
     57    return T_INTERRUPT_TEST_CONTINUE;
     58  }
    5959
    60     rtems_test_assert( getState() == RATE_MONOTONIC_ACTIVE );
     60  ctx = arg;
     61  cpu_self = _Per_CPU_Get();
     62  header = &cpu_self->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ];
     63  watchdog = (Watchdog_Control *) header->first;
     64  T_quiet_assert_not_null( watchdog );
     65  T_quiet_eq_u64( watchdog->expire, cpu_self->Watchdog.ticks );
     66  T_quiet_eq_ptr( watchdog->routine, _Rate_monotonic_Timeout );
    6167
    62     (*watchdog->routine)( watchdog );
     68  flags = _Thread_Wait_flags_get( ctx->thread );
    6369
    64     if ( flags == RATE_MONOTONIC_INTEND_TO_BLOCK ) {
    65       rtems_test_assert(
    66         _Thread_Wait_flags_get( thread ) == RATE_MONOTONIC_READY_AGAIN
    67       );
    68       rtems_test_assert( getState() == RATE_MONOTONIC_ACTIVE );
    69       case_hit = true;
    70     }
     70  _ISR_Local_disable( level );
     71  _Watchdog_Per_CPU_remove( watchdog, cpu_self, header );
     72  _ISR_Local_enable( level );
     73
     74  previous_period_state = getState( ctx );
     75  ( *watchdog->routine )( watchdog );
     76
     77  if ( flags == RATE_MONOTONIC_INTEND_TO_BLOCK ) {
     78    T_quiet_eq_int( previous_period_state, RATE_MONOTONIC_ACTIVE );
     79    T_quiet_eq_int( getState( ctx ), RATE_MONOTONIC_ACTIVE );
     80    state = T_INTERRUPT_TEST_DONE;
     81  } else if ( flags == THREAD_WAIT_FLAGS_INITIAL ) {
     82    T_quiet_true(
     83      previous_period_state == RATE_MONOTONIC_ACTIVE
     84        || previous_period_state == RATE_MONOTONIC_EXPIRED
     85    );
     86    state = T_INTERRUPT_TEST_EARLY;
     87  } else {
     88    T_quiet_eq_int( flags, RATE_MONOTONIC_BLOCKED );
     89    T_quiet_true(
     90      previous_period_state == RATE_MONOTONIC_ACTIVE
     91        || previous_period_state == RATE_MONOTONIC_EXPIRED
     92    );
     93    state = T_INTERRUPT_TEST_LATE;
    7194  }
     95
     96  return state;
    7297}
    7398
    74 static bool test_body( void *arg )
     99static void prepare( void *arg )
    75100{
    76   rtems_status_code sc;
     101  test_context      *ctx;
     102  rtems_status_code  sc;
     103  ISR_Level          level;
     104  bool               success;
    77105
    78   (void) arg;
     106  ctx = arg;
    79107
    80   sc = rtems_rate_monotonic_cancel( Period );
    81   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     108  do {
     109    sc = rtems_rate_monotonic_cancel( ctx->period );
     110    T_quiet_rsc_success( sc );
    82111
    83   sc = rtems_rate_monotonic_period( Period, 1 );
    84   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     112    sc = rtems_rate_monotonic_period( ctx->period, 1 );
     113    T_quiet_rsc_success( sc );
    85114
    86   sc = rtems_rate_monotonic_period( Period, 1 );
    87   rtems_test_assert( sc == RTEMS_SUCCESSFUL || sc == RTEMS_TIMEOUT );
     115    /*
     116     * Depending on the time to the next clock tick and the CPU time available
     117     * to a simulator, we may get sporadic RTEMS_TIMEOUT here.  In the next
     118     * round we are synchronized with the clock tick.
     119     */
     120    sc = rtems_rate_monotonic_period( ctx->period, 1 );
     121  } while ( sc != RTEMS_SUCCESSFUL );
    88122
    89   return case_hit;
     123  _ISR_Local_disable( level );
     124  success = _Thread_Wait_flags_try_change_release(
     125    ctx->thread,
     126    RATE_MONOTONIC_READY_AGAIN,
     127    THREAD_WAIT_FLAGS_INITIAL
     128  );
     129  _ISR_Local_enable( level );
     130  T_quiet_true( success );
    90131}
    91132
    92 rtems_task Init(
    93   rtems_task_argument ignored
    94 )
     133static void action( void *arg )
    95134{
    96   rtems_status_code     sc;
     135  test_context      *ctx;
     136  rtems_status_code  sc;
    97137
    98   TEST_BEGIN();
     138  ctx = arg;
    99139
    100   puts( "Init - Trying to generate period ending while blocking" );
     140  sc = rtems_rate_monotonic_period( ctx->period, 1 );
     141  T_quiet_true( sc == RTEMS_SUCCESSFUL || sc == RTEMS_TIMEOUT );
    101142
    102   thread = _Thread_Get_executing();
     143  T_interrupt_test_busy_wait_for_interrupt();
     144}
    103145
    104   puts( "Init - rtems_rate_monotonic_create - OK" );
     146static const T_interrupt_test_config config = {
     147  .prepare = prepare,
     148  .action = action,
     149  .interrupt = interrupt,
     150  .max_iteration_count = 10000
     151};
     152
     153T_TEST_CASE( RateMonotonicPeriodInterrupt )
     154{
     155  test_context ctx;
     156  rtems_status_code sc;
     157  T_interrupt_test_state state;
     158
     159  memset( &ctx, 0 , sizeof( ctx ) );
     160  ctx.thread = _Thread_Get_executing();
     161
    105162  sc = rtems_rate_monotonic_create(
    106163    rtems_build_name( 'P', 'E', 'R', '1' ),
    107     &Period
     164    &ctx.period
    108165  );
    109   directive_failed( sc, "rtems_rate_monotonic_create" );
     166  T_rsc_success( sc );
    110167
    111   interrupt_critical_section_test( test_body, NULL, test_release_from_isr );
     168  state = T_interrupt_test( &config, &ctx );
     169  T_eq_int( state, T_INTERRUPT_TEST_DONE );
    112170
    113   if ( case_hit ) {
    114     puts( "Init - It appears the case has been hit" );
    115     TEST_END();
    116   } else
    117     puts( "Init - Case not hit - ran too long" );
    118   rtems_test_exit(0);
     171  sc = rtems_rate_monotonic_delete( ctx.period );
     172  T_rsc_success( sc );
     173}
     174
     175static rtems_task Init( rtems_task_argument argument )
     176{
     177  rtems_test_run( argument, TEST_STATE );
    119178}
    120179
     
    124183#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
    125184
    126 #define CONFIGURE_MAXIMUM_TASKS       2
    127 #define CONFIGURE_MAXIMUM_TIMERS      1
     185#define CONFIGURE_MAXIMUM_TASKS       1
    128186#define CONFIGURE_MAXIMUM_PERIODS     1
    129 #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
     187
    130188#define CONFIGURE_MICROSECONDS_PER_TICK  1000
    131189#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
  • testsuites/sptests/spintrcritical08/spintrcritical08.scn

    r28313958 r5f66ac86  
    1 *** TEST INTERRUPT CRITICAL SECTION 08 ***
    2 Init - Trying to generate period ending while blocking
    3 Init - rtems_rate_monotonic_create - OK
    4 Support - rtems_timer_create - creating timer 1
    5 Init - It appears the case has been hit
    6 *** END OF TEST INTERRUPT CRITICAL SECTION 08 ***
     1*** BEGIN OF TEST SPINTRCRITICAL 8 ***
     2*** TEST VERSION: 6.0.0.929e49a54ab4d2d18c9fb8d03610614f63e25b8d
     3*** TEST STATE: EXPECTED_PASS
     4*** TEST BUILD: RTEMS_DEBUG RTEMS_POSIX_API RTEMS_SMP
     5*** TEST TOOLS: 10.0.1 20200406 (RTEMS 6, RSB bec88a6dd856892c3e66e4598252ea07d7a0d762, Newlib ece49e4)
     6A:SPINTRCRITICAL 8
     7S:Platform:RTEMS
     8S:Compiler:10.0.1 20200406 (RTEMS 6, RSB bec88a6dd856892c3e66e4598252ea07d7a0d762, Newlib ece49e4)
     9S:Version:6.0.0.929e49a54ab4d2d18c9fb8d03610614f63e25b8d
     10S:BSP:realview_pbx_a9_qemu
     11S:RTEMS_DEBUG:1
     12S:RTEMS_MULTIPROCESSING:0
     13S:RTEMS_POSIX_API:1
     14S:RTEMS_PROFILING:0
     15S:RTEMS_SMP:1
     16B:RateMonotonicPeriodInterrupt
     17P:0:0:UI1:init.c:156
     18P:1:0:UI1:init.c:159
     19P:2:0:UI1:init.c:162
     20E:RateMonotonicPeriodInterrupt:N:3:F:0:D:0.057652
     21Z:SPINTRCRITICAL 8:C:1:N:3:F:0:D:0.058758
     22Y:ReportHash:SHA256:381af5dc18c561d18b7b3ead593defa1aef4835f918df9edee7fe1ded0e089da
     23
     24*** END OF TEST SPINTRCRITICAL 8 ***
Note: See TracChangeset for help on using the changeset viewer.