[rtems commit] validation: Properly teardown test cases

Sebastian Huber sebh at rtems.org
Wed Nov 9 15:55:46 UTC 2022


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Nov  9 14:41:26 2022 +0100

validation: Properly teardown test cases

Make sure that the state of the testable interrupt vector is restored to the
state at the test case begin.

---

 testsuites/validation/tc-intr-entry-install.c   | 31 +++++++++++++++++++-
 testsuites/validation/tc-intr-entry-remove.c    | 31 +++++++++++++++++++-
 testsuites/validation/tc-intr-handler-iterate.c | 39 ++++++++++++++++++++++++-
 3 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/testsuites/validation/tc-intr-entry-install.c b/testsuites/validation/tc-intr-entry-install.c
index 714486772a..152963828c 100644
--- a/testsuites/validation/tc-intr-entry-install.c
+++ b/testsuites/validation/tc-intr-entry-install.c
@@ -189,6 +189,12 @@ typedef struct {
    */
   rtems_vector_number test_vector;
 
+  /**
+   * @brief If this member is true, then the testable interrupt vector was
+   *   enabled at the test case begin.
+   */
+  bool test_vector_was_enabled;
+
   /**
    * @brief This member provides the attributes of the testable interrupt
    *   vector.
@@ -1120,6 +1126,11 @@ static void RtemsIntrReqEntryInstall_Setup(
 
   ctx->initialized_during_setup = bsp_interrupt_is_initialized();
   ctx->test_vector = GetTestableInterruptVector( &required );
+  ctx->test_vector_was_enabled = false;
+  (void) rtems_interrupt_vector_is_enabled(
+    ctx->test_vector,
+    &ctx->test_vector_was_enabled
+  );
   sc = rtems_interrupt_get_attributes( ctx->test_vector, &ctx->attributes );
   T_rsc_success( sc );
 }
@@ -1133,6 +1144,24 @@ static void RtemsIntrReqEntryInstall_Setup_Wrap( void *arg )
   RtemsIntrReqEntryInstall_Setup( ctx );
 }
 
+static void RtemsIntrReqEntryInstall_Teardown(
+  RtemsIntrReqEntryInstall_Context *ctx
+)
+{
+  if ( ctx->test_vector_was_enabled ) {
+    (void) rtems_interrupt_vector_enable( ctx->test_vector );
+  }
+}
+
+static void RtemsIntrReqEntryInstall_Teardown_Wrap( void *arg )
+{
+  RtemsIntrReqEntryInstall_Context *ctx;
+
+  ctx = arg;
+  ctx->Map.in_action_loop = false;
+  RtemsIntrReqEntryInstall_Teardown( ctx );
+}
+
 static void RtemsIntrReqEntryInstall_Prepare(
   RtemsIntrReqEntryInstall_Context *ctx
 )
@@ -1320,7 +1349,7 @@ static size_t RtemsIntrReqEntryInstall_Scope( void *arg, char *buf, size_t n )
 static T_fixture RtemsIntrReqEntryInstall_Fixture = {
   .setup = RtemsIntrReqEntryInstall_Setup_Wrap,
   .stop = NULL,
-  .teardown = NULL,
+  .teardown = RtemsIntrReqEntryInstall_Teardown_Wrap,
   .scope = RtemsIntrReqEntryInstall_Scope,
   .initial_context = &RtemsIntrReqEntryInstall_Instance
 };
diff --git a/testsuites/validation/tc-intr-entry-remove.c b/testsuites/validation/tc-intr-entry-remove.c
index c73bcbb3fc..9807251dc6 100644
--- a/testsuites/validation/tc-intr-entry-remove.c
+++ b/testsuites/validation/tc-intr-entry-remove.c
@@ -233,6 +233,12 @@ typedef struct {
    */
   rtems_vector_number test_vector;
 
+  /**
+   * @brief If this member is true, then the testable interrupt vector was
+   *   enabled at the test case begin.
+   */
+  bool test_vector_was_enabled;
+
   /**
    * @brief This member provides the attributes of the testable interrupt
    *   vector.
@@ -1088,6 +1094,11 @@ static void RtemsIntrReqEntryRemove_Setup(
 
   ctx->initialized_during_setup = bsp_interrupt_is_initialized();
   ctx->test_vector = GetTestableInterruptVector( NULL );
+  ctx->test_vector_was_enabled = false;
+  (void) rtems_interrupt_vector_is_enabled(
+    ctx->test_vector,
+    &ctx->test_vector_was_enabled
+  );
   sc = rtems_interrupt_get_attributes( ctx->test_vector, &ctx->attributes );
   T_rsc_success( sc );
 }
@@ -1101,6 +1112,24 @@ static void RtemsIntrReqEntryRemove_Setup_Wrap( void *arg )
   RtemsIntrReqEntryRemove_Setup( ctx );
 }
 
+static void RtemsIntrReqEntryRemove_Teardown(
+  RtemsIntrReqEntryRemove_Context *ctx
+)
+{
+  if ( ctx->test_vector_was_enabled ) {
+    (void) rtems_interrupt_vector_enable( ctx->test_vector );
+  }
+}
+
+static void RtemsIntrReqEntryRemove_Teardown_Wrap( void *arg )
+{
+  RtemsIntrReqEntryRemove_Context *ctx;
+
+  ctx = arg;
+  ctx->Map.in_action_loop = false;
+  RtemsIntrReqEntryRemove_Teardown( ctx );
+}
+
 static void RtemsIntrReqEntryRemove_Prepare(
   RtemsIntrReqEntryRemove_Context *ctx
 )
@@ -1292,7 +1321,7 @@ static size_t RtemsIntrReqEntryRemove_Scope( void *arg, char *buf, size_t n )
 static T_fixture RtemsIntrReqEntryRemove_Fixture = {
   .setup = RtemsIntrReqEntryRemove_Setup_Wrap,
   .stop = NULL,
-  .teardown = NULL,
+  .teardown = RtemsIntrReqEntryRemove_Teardown_Wrap,
   .scope = RtemsIntrReqEntryRemove_Scope,
   .initial_context = &RtemsIntrReqEntryRemove_Instance
 };
diff --git a/testsuites/validation/tc-intr-handler-iterate.c b/testsuites/validation/tc-intr-handler-iterate.c
index 77b9b2b7d7..66259318c8 100644
--- a/testsuites/validation/tc-intr-handler-iterate.c
+++ b/testsuites/validation/tc-intr-handler-iterate.c
@@ -133,6 +133,12 @@ typedef struct {
    */
   rtems_vector_number test_vector;
 
+  /**
+   * @brief If this member is true, then the testable interrupt vector was
+   *   enabled at the test case begin.
+   */
+  bool test_vector_was_enabled;
+
   /**
    * @brief If this member is true, then the service shall be initialized.
    */
@@ -506,6 +512,11 @@ static void RtemsIntrReqHandlerIterate_Setup(
 
   ctx->initialized_during_setup = bsp_interrupt_is_initialized();
   ctx->test_vector = GetTestableInterruptVector( NULL );
+  ctx->test_vector_was_enabled = false;
+  (void) rtems_interrupt_vector_is_enabled(
+    ctx->test_vector,
+    &ctx->test_vector_was_enabled
+  );
   rtems_interrupt_entry_initialize(
     &ctx->entry,
     EntryRoutine,
@@ -529,6 +540,32 @@ static void RtemsIntrReqHandlerIterate_Setup_Wrap( void *arg )
   RtemsIntrReqHandlerIterate_Setup( ctx );
 }
 
+static void RtemsIntrReqHandlerIterate_Teardown(
+  RtemsIntrReqHandlerIterate_Context *ctx
+)
+{
+  rtems_status_code sc;
+
+  sc = rtems_interrupt_entry_remove(
+    ctx->test_vector,
+    &ctx->entry
+  );
+  T_rsc_success( sc );
+
+  if ( ctx->test_vector_was_enabled ) {
+    (void) rtems_interrupt_vector_enable( ctx->test_vector );
+  }
+}
+
+static void RtemsIntrReqHandlerIterate_Teardown_Wrap( void *arg )
+{
+  RtemsIntrReqHandlerIterate_Context *ctx;
+
+  ctx = arg;
+  ctx->Map.in_action_loop = false;
+  RtemsIntrReqHandlerIterate_Teardown( ctx );
+}
+
 static void RtemsIntrReqHandlerIterate_Action(
   RtemsIntrReqHandlerIterate_Context *ctx
 )
@@ -586,7 +623,7 @@ static size_t RtemsIntrReqHandlerIterate_Scope(
 static T_fixture RtemsIntrReqHandlerIterate_Fixture = {
   .setup = RtemsIntrReqHandlerIterate_Setup_Wrap,
   .stop = NULL,
-  .teardown = NULL,
+  .teardown = RtemsIntrReqHandlerIterate_Teardown_Wrap,
   .scope = RtemsIntrReqHandlerIterate_Scope,
   .initial_context = &RtemsIntrReqHandlerIterate_Instance
 };



More information about the vc mailing list