Changeset 59ee3020 in rtems


Ignore:
Timestamp:
Jul 20, 2020, 10:51:49 AM (3 weeks ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
1414e71
Parents:
38636e23
git-author:
Sebastian Huber <sebastian.huber@…> (07/20/20 10:51:49)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/23/20 07:27:47)
Message:

spintrcritical21: Use T_interrupt_test()

Location:
testsuites/sptests
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • testsuites/sptests/Makefile.am

    r38636e23 r59ee3020  
    13511351sp_screens += spintrcritical21/spintrcritical21.scn
    13521352sp_docs += spintrcritical21/spintrcritical21.doc
    1353 spintrcritical21_SOURCES = spintrcritical21/init.c \
    1354         spintrcritical_support/intrcritical.c
     1353spintrcritical21_SOURCES = spintrcritical21/init.c
    13551354spintrcritical21_CPPFLAGS = $(AM_CPPFLAGS) \
    13561355        $(TEST_FLAGS_spintrcritical21) $(support_includes) \
  • testsuites/sptests/spintrcritical21/init.c

    r38636e23 r59ee3020  
    11/*
    22 *  Classic API Signal to Task from ISR
     3 *
     4 *  Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
    35 *
    46 *  COPYRIGHT (c) 1989-2011.
     
    1416#endif
    1517
    16 #define CONFIGURE_INIT
    17 #include "system.h"
    18 
    19 #include <intrcritical.h>
     18#include <rtems/test.h>
     19#include <rtems/test-info.h>
    2020
    2121#include <rtems/score/threadimpl.h>
     
    2424const char rtems_test_name[] = "SPINTRCRITICAL 21";
    2525
    26 /*
    27  *  ERROR CHECKING NOTE:
    28  *
    29  *  We are either at dispatch disable level 1 or 2.  Either way, it is
    30  *  safer not to check the dispatch level explicitly so we are using
    31  *  fatal_directive_check_status_only() not directive_failed().
    32  */
    33 
    34 static volatile bool case_hit;
    35 
    36 static rtems_id main_task;
    37 
    38 static Thread_Control *main_thread;
    39 
    40 static rtems_id other_task;
    41 
    42 static bool is_case_hit( void )
    43 {
    44   return _Thread_Wait_flags_get( main_thread)
     26#define MAX_ITERATION_COUNT 10000
     27
     28typedef struct {
     29  rtems_id        main_task;
     30  Thread_Control *main_thread;
     31  rtems_id        other_task;
     32} test_context;
     33
     34static bool is_blocked( Thread_Wait_flags flags )
     35{
     36  return flags == ( THREAD_WAIT_CLASS_EVENT | THREAD_WAIT_STATE_BLOCKED );
     37}
     38
     39static bool interrupts_blocking_op( Thread_Wait_flags flags )
     40{
     41  return flags
    4542    == ( THREAD_WAIT_CLASS_EVENT | THREAD_WAIT_STATE_INTEND_TO_BLOCK );
    4643}
    4744
    48 static rtems_timer_service_routine test_event_from_isr(
    49   rtems_id  timer,
    50   void     *arg
     45static T_interrupt_test_state event_from_isr_interrupt(
     46  void *arg
    5147)
    5248{
    53   rtems_status_code     status;
    54 
    55   if ( is_case_hit() ) {
     49  test_context           *ctx;
     50  T_interrupt_test_state state;
     51  Thread_Wait_flags      flags;
     52  rtems_status_code      status;
     53
     54  ctx = arg;
     55  flags = _Thread_Wait_flags_get( ctx->main_thread );
     56
     57  if ( interrupts_blocking_op( flags ) ) {
    5658    /*
    5759     *  This event send hits the critical section but sends to
    5860     *  another task so doesn't impact this critical section.
    5961     */
    60     status = rtems_event_send( other_task, 0x02 );
    61     fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" );
     62    status = rtems_event_send( ctx->other_task, 0x02 );
     63    T_quiet_rsc_success( status );
    6264
    6365    /*
     
    6567     *  it's blocking condition so it will still block
    6668     */
    67     status = rtems_event_send( main_task, 0x02 );
    68     fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" );
    69 
    70     case_hit = true;
     69    status = rtems_event_send( ctx->main_task, 0x02 );
     70    T_quiet_rsc_success( status );
     71
     72    state = T_INTERRUPT_TEST_DONE;
     73  } else if ( is_blocked( flags ) ) {
     74    state = T_INTERRUPT_TEST_LATE;
     75  } else {
     76    state = T_INTERRUPT_TEST_EARLY;
    7177  }
    72   status = rtems_event_send( main_task, 0x01 );
    73   fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" );
    74 }
    75 
    76 static bool test_body_event_from_isr( void *arg )
     78
     79  status = rtems_event_send( ctx->main_task, 0x01 );
     80  T_quiet_rsc_success( status );
     81
     82  return state;
     83}
     84
     85static void event_from_isr_action( void *arg )
    7786{
    7887  rtems_status_code status;
     
    8291
    8392  status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 0, &out );
    84   rtems_test_assert( status == RTEMS_SUCCESSFUL );
    85 
    86   return case_hit;
    87 }
    88 
    89 static rtems_timer_service_routine test_event_with_timeout_from_isr(
    90   rtems_id  timer,
    91   void     *arg
    92 )
    93 {
    94   rtems_status_code     status;
    95 
    96   if ( is_case_hit() ) {
    97     /*
    98      *  We want to catch the task while it is blocking.  Otherwise
    99      *  just send and make it happy.
    100      */
    101     case_hit = true;
    102   }
    103   status = rtems_event_send( main_task, 0x01 );
    104   fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" );
    105 }
    106 
    107 static bool test_body_event_with_timeout_from_isr( void *arg )
    108 {
    109   rtems_status_code status;
    110   rtems_event_set   out;
    111 
    112   (void) arg;
    113 
    114   status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 1, &out );
    115   rtems_test_assert( status == RTEMS_SUCCESSFUL || status == RTEMS_TIMEOUT );
    116 
    117   return case_hit;
    118 }
    119 
    120 rtems_task Init(
    121   rtems_task_argument argument
    122 )
    123 {
    124   rtems_status_code     status;
    125 
    126   TEST_BEGIN();
    127 
    128   main_task = rtems_task_self();
    129   main_thread = _Thread_Get_executing();
     93  T_quiet_rsc_success( status );
     94}
     95
     96static const T_interrupt_test_config event_from_isr_config = {
     97  .action = event_from_isr_action,
     98  .interrupt = event_from_isr_interrupt,
     99  .max_iteration_count = MAX_ITERATION_COUNT
     100};
     101
     102T_TEST_CASE(EventFromISR)
     103{
     104  test_context           ctx;
     105  T_interrupt_test_state state;
     106  rtems_status_code      status;
     107
     108  ctx.main_task = rtems_task_self();
     109  ctx.main_thread = _Thread_Get_executing();
    130110
    131111  status = rtems_task_create(
     
    135115    RTEMS_DEFAULT_MODES,
    136116    RTEMS_DEFAULT_ATTRIBUTES,
    137     &other_task
     117    &ctx.other_task
    138118  );
    139   directive_failed( status, "rtems_task_create" );
    140 
    141   /*
    142    * Test Event send successful from ISR -- receive is forever
    143    */
    144 
    145   case_hit = false;
    146   interrupt_critical_section_test(
    147     test_body_event_from_isr,
    148     NULL,
    149     test_event_from_isr
    150   );
    151 
    152   printf(
    153     "Event sent from ISR hitting synchronization point has %soccurred\n",
    154     case_hit ? "" : "NOT "
    155   );
    156 
    157   rtems_test_assert( case_hit );
    158 
    159   /*
    160    * Test Event send successful from ISR -- receive has timeout
    161    */
    162 
    163   case_hit = false;
    164   interrupt_critical_section_test(
    165     test_body_event_with_timeout_from_isr,
    166     NULL,
    167     test_event_with_timeout_from_isr
    168   );
    169 
    170   printf(
    171     "Event sent from ISR (with timeout) hitting synchronization "
    172       "point has %soccurred\n",
    173     case_hit ? "" : "NOT "
    174   );
    175 
    176   rtems_test_assert( case_hit );
    177 
    178   TEST_END();
    179   rtems_test_exit( 0 );
    180 }
     119  T_assert_rsc_success( status );
     120
     121  state = T_interrupt_test( &event_from_isr_config, &ctx );
     122  T_eq_int( state, T_INTERRUPT_TEST_DONE );
     123
     124  status = rtems_task_delete( ctx.other_task );
     125  T_rsc_success( status );
     126}
     127
     128static T_interrupt_test_state event_with_timeout_from_isr_interrupt(
     129  void *arg
     130)
     131{
     132  test_context           *ctx;
     133  T_interrupt_test_state  state;
     134  Thread_Wait_flags       flags;
     135  rtems_status_code       status;
     136
     137  ctx = arg;
     138  flags = _Thread_Wait_flags_get( ctx->main_thread );
     139
     140  if ( interrupts_blocking_op( flags ) ) {
     141    /*
     142     *  We want to catch the task while it is blocking.  Otherwise
     143     *  just send and make it happy.
     144     */
     145    state = T_INTERRUPT_TEST_DONE;
     146  } else if ( is_blocked( flags ) ) {
     147    state = T_INTERRUPT_TEST_LATE;
     148  } else {
     149    state = T_INTERRUPT_TEST_EARLY;
     150  }
     151
     152  status = rtems_event_send( ctx->main_task, 0x01 );
     153  T_quiet_rsc_success( status );
     154
     155  return state;
     156}
     157
     158static void event_with_timeout_from_isr_action( void *arg )
     159{
     160  rtems_status_code status;
     161  rtems_event_set   out;
     162
     163  (void) arg;
     164
     165  status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 1, &out );
     166  T_quiet_true( status == RTEMS_SUCCESSFUL || status == RTEMS_TIMEOUT );
     167}
     168
     169static const T_interrupt_test_config event_with_timeout_from_isr_config = {
     170  .action = event_with_timeout_from_isr_action,
     171  .interrupt = event_with_timeout_from_isr_interrupt,
     172  .max_iteration_count = MAX_ITERATION_COUNT
     173};
     174
     175T_TEST_CASE( EventWithTimeoutFromISR )
     176{
     177  test_context           ctx;
     178  T_interrupt_test_state state;
     179
     180  ctx.main_task = rtems_task_self();
     181  ctx.main_thread = _Thread_Get_executing();
     182  ctx.other_task = 0xdeadbeef;
     183
     184  state = T_interrupt_test( &event_with_timeout_from_isr_config, &ctx );
     185  T_eq_int( state, T_INTERRUPT_TEST_DONE );
     186}
     187
     188static rtems_task Init( rtems_task_argument argument )
     189{
     190  rtems_test_run( argument, TEST_STATE );
     191}
     192
     193#define CONFIGURE_INIT
     194
     195#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
     196#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
     197
     198#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
     199
     200#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
     201
     202#define CONFIGURE_MICROSECONDS_PER_TICK   1000
     203
     204#define CONFIGURE_MAXIMUM_TASKS             2
     205
     206#include <rtems/confdefs.h>
  • testsuites/sptests/spintrcritical21/spintrcritical21.scn

    r38636e23 r59ee3020  
    11*** BEGIN OF TEST SPINTRCRITICAL 21 ***
    2 Event sent from ISR hitting synchronization point has occurred
    3 Event sent from ISR (with timeout) hitting synchronization point has occurred
     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 21
     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:EventWithTimeoutFromISR
     17P:0:0:UI1:init.c:185
     18E:EventWithTimeoutFromISR:N:1:F:0:D:0.990057
     19B:EventFromISR
     20P:0:0:UI1:init.c:119
     21P:1:0:UI1:init.c:122
     22P:2:0:UI1:init.c:125
     23E:EventFromISR:N:3:F:0:D:0.042543
     24Z:SPINTRCRITICAL 21:C:2:N:4:F:0:D:1.034216
     25Y:ReportHash:SHA256:64aa73f53f6e67b5eb349f0dcf4e2246ce87d7e3e8c201f9ee26ec4e3bfc30f6
     26
    427*** END OF TEST SPINTRCRITICAL 21 ***
Note: See TracChangeset for help on using the changeset viewer.