[PATCH 21/33] spintrcritical09: Use T_interrupt_test()

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Jul 21 15:04:38 UTC 2020


---
 testsuites/sptests/Makefile.am                |   4 +-
 testsuites/sptests/spintrcritical09/init.c    | 121 +++++++++++-------
 .../spintrcritical09/spintrcritical09.scn     |  28 +++-
 3 files changed, 103 insertions(+), 50 deletions(-)

diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index 4e3a3f0009..9f66b66371 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -1250,9 +1250,7 @@ if TEST_spintrcritical09
 sp_tests += spintrcritical09
 sp_screens += spintrcritical09/spintrcritical09.scn
 sp_docs += spintrcritical09/spintrcritical09.doc
-spintrcritical09_SOURCES = spintrcritical09/init.c \
-	spintrcritical_support/intrcritical.c \
-	spintrcritical_support/intrcritical.h
+spintrcritical09_SOURCES = spintrcritical09/init.c
 spintrcritical09_CPPFLAGS = $(AM_CPPFLAGS) \
 	$(TEST_FLAGS_spintrcritical09) $(support_includes) \
 	-I$(top_srcdir)/spintrcritical_support
diff --git a/testsuites/sptests/spintrcritical09/init.c b/testsuites/sptests/spintrcritical09/init.c
index 63cfa2b5fb..890d90b4a8 100644
--- a/testsuites/sptests/spintrcritical09/init.c
+++ b/testsuites/sptests/spintrcritical09/init.c
@@ -1,4 +1,6 @@
 /*
+ *  Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ *
  *  COPYRIGHT (c) 1989-2012.
  *  On-Line Applications Research Corporation (OAR).
  *
@@ -11,8 +13,8 @@
 #include "config.h"
 #endif
 
-#include <tmacros.h>
-#include <intrcritical.h>
+#include <rtems/test.h>
+#include <rtems/simple-test.h>
 
 #include <rtems/score/threadimpl.h>
 #include <rtems/score/threadimpl.h>
@@ -20,82 +22,117 @@
 
 const char rtems_test_name[] = "SPINTRCRITICAL 9";
 
-static Thread_Control *thread;
-
-static rtems_id Semaphore;
+typedef struct {
+  Thread_Control *thread;
+  rtems_id        semaphore;
+  volatile bool   early;
+} test_context;
 
-static bool case_hit;
-
-static bool is_interrupt_timeout(void)
+static bool is_interrupt_timeout( test_context *ctx )
 {
-  Thread_Wait_flags flags = _Thread_Wait_flags_get( thread );
+  Thread_Wait_flags flags = _Thread_Wait_flags_get( ctx->thread );
 
   return flags == ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_READY_AGAIN );
 }
 
-static rtems_timer_service_routine test_release_from_isr(
-  rtems_id  timer,
-  void     *arg
-)
+static T_interrupt_test_state interrupt( void *arg )
 {
-  Per_CPU_Control *cpu_self = _Per_CPU_Get();
-  Watchdog_Header *header = &cpu_self->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ];
-  Watchdog_Control *watchdog = (Watchdog_Control *) header->first;
+  test_context           *ctx;
+  Per_CPU_Control        *cpu_self;
+  Watchdog_Header        *header;
+  Watchdog_Control       *watchdog;
+  T_interrupt_test_state  state;
+
+  ctx = arg;
+  cpu_self = _Per_CPU_Get();
+  header = &cpu_self->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ];
+  watchdog = (Watchdog_Control *) header->first;
 
   if (
     watchdog != NULL
       && watchdog->expire == cpu_self->Watchdog.ticks
       && watchdog->routine == _Thread_Timeout
   ) {
+    ISR_Level level;
+
+    _ISR_Local_disable( level );
     _Watchdog_Per_CPU_remove( watchdog, cpu_self, header );
+    _ISR_Local_enable( level );
 
-    (*watchdog->routine)( watchdog );
+    ( *watchdog->routine )( watchdog );
 
-    if ( is_interrupt_timeout() ) {
-      case_hit = true;
+    if ( is_interrupt_timeout( ctx ) ) {
+      state = T_INTERRUPT_TEST_DONE;
+    } else {
+      state = T_INTERRUPT_TEST_LATE;
+    }
+  } else {
+    if ( ctx->early ) {
+      state = T_INTERRUPT_TEST_EARLY;
+    } else {
+      state = T_INTERRUPT_TEST_LATE;
     }
   }
+
+  return state;
 }
 
-static bool test_body( void *arg )
+static void prepare( void *arg )
 {
-  (void) arg;
+  test_context      *ctx;
+  rtems_status_code  sc;
 
-  rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 1 );
-
-  return case_hit;
+  ctx = arg;
+  ctx->early = true;
+  sc = rtems_semaphore_obtain( ctx->semaphore, RTEMS_NO_WAIT, 0 );
+  T_quiet_true( sc == RTEMS_SUCCESSFUL || sc == RTEMS_UNSATISFIED );
 }
 
-static rtems_task Init(
-  rtems_task_argument ignored
-)
+static void action( void *arg )
 {
-  rtems_status_code     sc;
+  test_context      *ctx;
+  rtems_status_code  sc;
+
+  ctx = arg;
+  ctx->early = false;
+  sc = rtems_semaphore_obtain( ctx->semaphore, RTEMS_DEFAULT_OPTIONS, 1 );
+  T_quiet_rsc( sc, RTEMS_TIMEOUT );
+}
 
-  TEST_BEGIN();
+static const T_interrupt_test_config config = {
+  .prepare = prepare,
+  .action = action,
+  .interrupt = interrupt,
+  .max_iteration_count = 10000
+};
 
-  thread = _Thread_Get_executing();
+T_TEST_CASE( SemaphoreObtainInterrupt )
+{
+  test_context           ctx;
+  rtems_status_code      sc;
+  T_interrupt_test_state state;
+
+  ctx.thread = _Thread_Get_executing();
 
-  puts( "Init - Test may not be able to detect case is hit reliably" );
-  puts( "Init - Trying to generate timeout from ISR while blocking" );
   sc = rtems_semaphore_create(
     rtems_build_name( 'S', 'M', '1', ' ' ),
     0,
     RTEMS_DEFAULT_ATTRIBUTES,
     RTEMS_NO_PRIORITY,
-    &Semaphore
+    &ctx.semaphore
   );
-  directive_failed( sc, "rtems_semaphore_create of SM1" );
+  T_assert_rsc_success( sc );
 
-  interrupt_critical_section_test( test_body, NULL, test_release_from_isr );
+  state = T_interrupt_test( &config, &ctx );
+  T_eq_int( state, T_INTERRUPT_TEST_DONE );
 
-  if ( case_hit ) {
-    puts( "Init - It appears the case has been hit" );
-    TEST_END();
-  } else
-    puts( "Init - Case not hit - ran too long" );
+  sc = rtems_semaphore_delete( ctx.semaphore );
+  T_rsc_success( sc );
+}
 
-  rtems_test_exit(0);
+static rtems_task Init( rtems_task_argument argument )
+{
+  rtems_test_run( argument, TEST_STATE );
 }
 
 /* configuration information */
@@ -104,9 +141,7 @@ static rtems_task Init(
 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
 
 #define CONFIGURE_MAXIMUM_TASKS       1
-#define CONFIGURE_MAXIMUM_TIMERS      1
 #define CONFIGURE_MAXIMUM_SEMAPHORES  1
-#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
diff --git a/testsuites/sptests/spintrcritical09/spintrcritical09.scn b/testsuites/sptests/spintrcritical09/spintrcritical09.scn
index 19f11b127b..ef203c0700 100644
--- a/testsuites/sptests/spintrcritical09/spintrcritical09.scn
+++ b/testsuites/sptests/spintrcritical09/spintrcritical09.scn
@@ -1,4 +1,24 @@
-*** TEST INTERRUPT CRITICAL SECTION 09 ***
-Init - Test may not be able to detect case is hit reliably
-Init - Trying to generate timeout from ISR while blocking
-Support - rtems_timer_create - creating timer 1
+*** BEGIN OF TEST SPINTRCRITICAL 9 ***
+*** TEST VERSION: 6.0.0.929e49a54ab4d2d18c9fb8d03610614f63e25b8d
+*** TEST STATE: EXPECTED_PASS
+*** TEST BUILD: RTEMS_DEBUG RTEMS_POSIX_API RTEMS_SMP
+*** TEST TOOLS: 10.0.1 20200406 (RTEMS 6, RSB bec88a6dd856892c3e66e4598252ea07d7a0d762, Newlib ece49e4)
+A:SPINTRCRITICAL 9
+S:Platform:RTEMS
+S:Compiler:10.0.1 20200406 (RTEMS 6, RSB bec88a6dd856892c3e66e4598252ea07d7a0d762, Newlib ece49e4)
+S:Version:6.0.0.929e49a54ab4d2d18c9fb8d03610614f63e25b8d
+S:BSP:realview_pbx_a9_qemu
+S:RTEMS_DEBUG:1
+S:RTEMS_MULTIPROCESSING:0
+S:RTEMS_POSIX_API:1
+S:RTEMS_PROFILING:0
+S:RTEMS_SMP:1
+B:SemaphoreObtainInterrupt
+P:0:0:UI1:init.c:124
+P:1:0:UI1:init.c:127
+P:2:0:UI1:init.c:130
+E:SemaphoreObtainInterrupt:N:3:F:0:D:0.060862
+Z:SPINTRCRITICAL 9:C:1:N:3:F:0:D:0.061985
+Y:ReportHash:SHA256:432e69ffa61dcb2eaef5b67504104b7da761a56e2c1943cf64973c4a89885008
+
+*** END OF TEST SPINTRCRITICAL 9 ***
-- 
2.26.2



More information about the devel mailing list