[rtems commit] psxintrcritical01: Use T_interrupt_test()

Sebastian Huber sebh at rtems.org
Thu Jul 23 08:57:41 UTC 2020


Module:    rtems
Branch:    master
Commit:    857a65dc7ed8987f5fc72f23ebcf7eba65070362
Changeset: http://git.rtems.org/rtems/commit/?id=857a65dc7ed8987f5fc72f23ebcf7eba65070362

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Jul 20 11:50:53 2020 +0200

psxintrcritical01: Use T_interrupt_test()

---

 testsuites/psxtests/Makefile.am                    |   3 +-
 testsuites/psxtests/psxintrcritical01/init.c       | 135 ++++++++++++++-------
 .../psxintrcritical01/psxintrcritical01.scn        |  33 ++++-
 3 files changed, 121 insertions(+), 50 deletions(-)

diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index 1f9e423..d89bcd8 100755
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -525,8 +525,7 @@ if TEST_psxintrcritical01
 psx_tests += psxintrcritical01
 psx_screens += psxintrcritical01/psxintrcritical01.scn
 psx_docs += psxintrcritical01/psxintrcritical01.doc
-psxintrcritical01_SOURCES = psxintrcritical01/init.c \
-	../sptests/spintrcritical_support/intrcritical.c
+psxintrcritical01_SOURCES = psxintrcritical01/init.c
 psxintrcritical01_CPPFLAGS = $(AM_CPPFLAGS) \
 	$(TEST_FLAGS_psxintrcritical01) $(support_includes) \
 	-I$(top_srcdir)/../sptests/spintrcritical_support
diff --git a/testsuites/psxtests/psxintrcritical01/init.c b/testsuites/psxtests/psxintrcritical01/init.c
index 9830c41..dd46c03 100644
--- a/testsuites/psxtests/psxintrcritical01/init.c
+++ b/testsuites/psxtests/psxintrcritical01/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,73 +13,122 @@
 #include "config.h"
 #endif
 
-#include <tmacros.h>
-#include <intrcritical.h>
+#include <string.h>
 #include <time.h>
 
+#include <rtems/test.h>
+#include <rtems/simple-test.h>
+
 const char rtems_test_name[] = "PSXINTRCRITICAL 1";
 
-/* forward declarations to avoid warnings */
-rtems_task Init(rtems_task_argument ignored);
+typedef struct {
+  timer_t           timer;
+  struct itimerspec spec;
+  volatile bool early;
+  volatile bool late;
+  long early_count;
+  long late_count;
+  long potential_hits;
+} test_context;
 
-#define TEST_NAME          "01"
-#define TEST_STRING        "POSIX Timer"
+#define POSIX_TIMER_RELATIVE 0
 
-static timer_t           Timer;
-static struct itimerspec TimerParams;
+static void prepare(void *arg)
+{
+  test_context *ctx;
 
-#define POSIX_TIMER_RELATIVE 0
+  ctx = arg;
+  ctx->early = false;
+  ctx->late = false;
+}
 
-static bool test_body( void *arg )
+static void action(void *arg)
 {
+  test_context *ctx;
   int rv;
 
-  (void) arg;
+  ctx = arg;
+  ctx->early = true;
+  rv = timer_settime(ctx->timer, POSIX_TIMER_RELATIVE, &ctx->spec, NULL);
+  ctx->late = true;
+  T_quiet_psx_success(rv);
 
-  rv = timer_settime(Timer, POSIX_TIMER_RELATIVE, &TimerParams, NULL);
-  rtems_test_assert( rv == 0 );
-
-  return false;
+  while (T_interrupt_test_get_state() == T_INTERRUPT_TEST_ACTION) {
+    /* Wait */
+  }
 }
 
-static rtems_timer_service_routine test_release_from_isr(
-  rtems_id  timer,
-  void     *arg
-)
+static T_interrupt_test_state interrupt(void *arg)
 {
-  test_body( NULL );
+  test_context *ctx;
+  T_interrupt_test_state state;
+  int rv;
+
+  state = T_interrupt_test_get_state();
+
+  if (state != T_INTERRUPT_TEST_ACTION) {
+    return T_INTERRUPT_TEST_EARLY;
+  }
+
+  ctx = arg;
+  rv = timer_settime(ctx->timer, POSIX_TIMER_RELATIVE, &ctx->spec, NULL);
+  T_quiet_psx_success(rv);
+
+  if (ctx->late) {
+    ++ctx->late_count;
+    return T_INTERRUPT_TEST_LATE;
+  } else if (ctx->early) {
+    ++ctx->early_count;
+    return T_INTERRUPT_TEST_EARLY;
+  } else {
+    ++ctx->potential_hits;
+
+    if (ctx->potential_hits > 13) {
+      return T_INTERRUPT_TEST_DONE;
+    } else {
+      return T_INTERRUPT_TEST_CONTINUE;
+    }
+  }
 }
 
-rtems_task Init(
-  rtems_task_argument ignored
-)
+static const T_interrupt_test_config config = {
+  .prepare = prepare,
+  .action = action,
+  .interrupt = interrupt,
+  .max_iteration_count = 10000
+};
+
+T_TEST_CASE(PSXSetTimerInterrupt)
 {
+  test_context ctx;
   int sc;
+  T_interrupt_test_state state;
 
-  TEST_BEGIN();
-
-  puts( "Init - Trying to generate timer fire from ISR while firing" );
-  puts( "Init - Variation is: " TEST_STRING );
-
-  puts( "Init - There is no way for the test to know if it hits the case" );
+  memset(&ctx, 0, sizeof(ctx));
 
   /* create POSIX Timer */
-  sc = timer_create (CLOCK_REALTIME, NULL, &Timer);
-  if ( sc == -1 ) {
-    perror ("Error in timer creation\n");
-    rtems_test_exit(0);
-  }
+  sc = timer_create (CLOCK_REALTIME, NULL, &ctx.timer);
+  T_psx_success(sc);
 
   /* we don't care if it ever fires */
-  TimerParams.it_interval.tv_sec  = 10;
-  TimerParams.it_interval.tv_nsec = 0;
-  TimerParams.it_value.tv_sec     = 10;
-  TimerParams.it_value.tv_nsec    = 0;
+  ctx.spec.it_interval.tv_sec  = 10;
+  ctx.spec.it_value.tv_sec     = 10;
+
+  state = T_interrupt_test(&config, &ctx);
+  T_eq_int(state, T_INTERRUPT_TEST_DONE);
 
-  interrupt_critical_section_test( test_body, NULL, test_release_from_isr );
+  T_log(T_NORMAL, "early count = %ld", ctx.early_count);
+  T_log(T_NORMAL, "late count = %ld", ctx.late_count);
+  T_log(T_NORMAL, "potential hits = %ld", ctx.potential_hits);
+  T_gt_int(ctx.potential_hits, 0);
 
-  TEST_END();
-  rtems_test_exit(0);
+  sc = timer_delete(ctx.timer);
+  T_psx_success(sc);
+}
+
+static rtems_task Init(rtems_task_argument arg)
+{
+  rtems_test_run(arg, TEST_STATE);
 }
 
 /* configuration information */
@@ -86,9 +137,7 @@ rtems_task Init(
 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
 
 #define CONFIGURE_MAXIMUM_TASKS          1
-#define CONFIGURE_MAXIMUM_TIMERS         1
 #define CONFIGURE_MAXIMUM_POSIX_TIMERS   1
-#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
 #define CONFIGURE_MICROSECONDS_PER_TICK  1000
 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
 
diff --git a/testsuites/psxtests/psxintrcritical01/psxintrcritical01.scn b/testsuites/psxtests/psxintrcritical01/psxintrcritical01.scn
index d9f9036..b1fbe46 100644
--- a/testsuites/psxtests/psxintrcritical01/psxintrcritical01.scn
+++ b/testsuites/psxtests/psxintrcritical01/psxintrcritical01.scn
@@ -1,5 +1,28 @@
-*** TEST POSIX INTERRUPT CRITICAL SECTION 01 ***
-Init - Trying to generate timer fire from ISR while firing
-Init - Variation is: POSIX Timer
-Init - There is no way for the test to know if it hits the case
-Support - rtems_timer_create - creating timer 1
+*** BEGIN OF TEST PSXINTRCRITICAL 1 ***
+*** TEST VERSION: 6.0.0.2f9fa5f36a632a7acbab8ac3e6fc40ad36115ca0
+*** 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:PSXINTRCRITICAL 1
+S:Platform:RTEMS
+S:Compiler:10.0.1 20200406 (RTEMS 6, RSB bec88a6dd856892c3e66e4598252ea07d7a0d762, Newlib ece49e4)
+S:Version:6.0.0.2f9fa5f36a632a7acbab8ac3e6fc40ad36115ca0
+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:PSXSetTimerInterrupt
+P:0:0:UI1:init.c:111
+P:1:0:UI1:init.c:118
+L:early count = 13
+L:late count = 46
+L:potential hits = 14
+P:2:0:UI1:init.c:123
+P:3:0:UI1:init.c:126
+E:PSXSetTimerInterrupt:N:4:F:0:D:0.117464
+Z:PSXINTRCRITICAL 1:C:1:N:4:F:0:D:0.118703
+Y:ReportHash:SHA256:ab4ae616216edb337cbe6b3adb8d62d1a98ff4f7422966689c6967cce78f9d69
+
+*** END OF TEST PSXINTRCRITICAL 1 ***



More information about the vc mailing list