[rtems-central commit] validation: Add test early preparation

Sebastian Huber sebh at rtems.org
Thu Aug 20 14:13:13 UTC 2020


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Aug  4 07:08:38 2020 +0200

validation: Add test early preparation

---

 rtemsspec/tests/spec-validation/action2.yml   |  2 ++
 rtemsspec/tests/spec-validation/directive.yml |  1 +
 rtemsspec/tests/test_validation.py            |  6 ++++++
 rtemsspec/validation.py                       | 19 +++++++++++++------
 spec/req/rtems/ident-local.yml                |  1 +
 spec/req/rtems/ident.yml                      |  1 +
 spec/req/rtems/tasks/ident.yml                |  1 +
 spec/spec/requirement-action.yml              |  7 +++++++
 8 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/rtemsspec/tests/spec-validation/action2.yml b/rtemsspec/tests/spec-validation/action2.yml
index 8f7f690..9a56d81 100644
--- a/rtemsspec/tests/spec-validation/action2.yml
+++ b/rtemsspec/tests/spec-validation/action2.yml
@@ -124,6 +124,8 @@ test-includes:
 test-local-includes:
 - b.h
 test-name: Action 2
+test-prepare: |
+  /* Prepare */
 test-setup:
   brief: |
     Setup brief.
diff --git a/rtemsspec/tests/spec-validation/directive.yml b/rtemsspec/tests/spec-validation/directive.yml
index 71e583f..47eef2e 100644
--- a/rtemsspec/tests/spec-validation/directive.yml
+++ b/rtemsspec/tests/spec-validation/directive.yml
@@ -196,6 +196,7 @@ test-includes:
 test-local-includes:
 - x.h
 test-name: Classic Task Identification
+test-prepare: null
 test-setup:
   brief: |
     Setup brief description.
diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py
index b0a7a3e..76b9c63 100644
--- a/rtemsspec/tests/test_validation.py
+++ b/rtemsspec/tests/test_validation.py
@@ -1416,6 +1416,11 @@ static const struct {
   }
 };
 
+static void Action2_Prepare( Action2_Context *ctx )
+{
+  /* Prepare */
+}
+
 static void Action2_Action( Action2_Context *ctx )
 {
   /* Action */
@@ -1462,6 +1467,7 @@ void Action2_Run( int *a, int b, int *c )
         continue;
       }
 
+      Action2_Prepare( ctx );
       Action2_Pre_A_Prepare( ctx, ctx->pcs[ 0 ] );
       Action2_Pre_B_Prepare( ctx, ctx->pcs[ 1 ] );
       Action2_Action( ctx );
diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py
index a6e6172..20c6911 100644
--- a/rtemsspec/validation.py
+++ b/rtemsspec/validation.py
@@ -471,18 +471,24 @@ class _TestDirectiveItem(_TestItem):
         content.add([f"}} {self.ident}_TransitionInfo[] = {{", "  {"])
         content.append(["\n  }, {\n".join(info_elements), "  }", "};"])
 
-    def _add_action(self, content: CContent) -> None:
-        with content.function("static void", f"{self.ident}_Action",
-                              [f"{self.context} *ctx"]):
-            content.append(self.substitute_code(self["test-action"]))
+    def _add_function(self, content: CContent, key: str, name: str) -> None:
+        if self[key] is not None:
+            with content.function("static void", f"{self.ident}_{name}",
+                                  [f"{self.context} *ctx"]):
+                content.append(self.substitute_code(self[key]))
+
+    def _add_call(self, content: CContent, key: str, name: str) -> None:
+        if self[key] is not None:
+            content.append(f"{self.ident}_{name}( ctx );")
 
     def _add_loop_body(self, content: CContent) -> None:
         with content.condition(f"{self.ident}_TransitionInfo[ index ].Skip"):
             content.append(["++index;", "continue;"])
         content.add_blank_line()
+        self._add_call(content, "test-prepare", "Prepare")
         for index, enum in enumerate(self._pre_index_to_enum):
             content.append(f"{enum[0]}_Prepare( ctx, ctx->pcs[ {index} ] );")
-        content.append(f"{self.ident}_Action( ctx );")
+        self._add_call(content, "test-action", "Action")
         transition_map = f"{self.ident}_TransitionMap"
         for index, enum in enumerate(self._post_index_to_enum):
             content.append([
@@ -642,7 +648,8 @@ class _TestDirectiveItem(_TestItem):
             f"  .initial_context = &{self.ident}_Instance", "};"
         ])
         self._add_transition_map(content)
-        self._add_action(content)
+        self._add_function(content, "test-prepare", "Prepare")
+        self._add_function(content, "test-action", "Action")
         self._add_test_case(content, header)
         content.add("/** @} */")
 
diff --git a/spec/req/rtems/ident-local.yml b/spec/req/rtems/ident-local.yml
index 3dff42a..5df8819 100644
--- a/spec/req/rtems/ident-local.yml
+++ b/spec/req/rtems/ident-local.yml
@@ -127,6 +127,7 @@ test-includes: []
 test-local-includes:
 - support-object-ident-local.h
 test-name: Classic Object Local Ident
+test-prepare: null
 test-setup: null
 test-stop: null
 test-support: null
diff --git a/spec/req/rtems/ident.yml b/spec/req/rtems/ident.yml
index 38ad2f7..b95fcef 100644
--- a/spec/req/rtems/ident.yml
+++ b/spec/req/rtems/ident.yml
@@ -188,6 +188,7 @@ test-includes: []
 test-local-includes:
 - support-object-ident.h
 test-name: Classic Object Ident
+test-prepare: null
 test-setup: null
 test-stop: null
 test-support: null
diff --git a/spec/req/rtems/tasks/ident.yml b/spec/req/rtems/tasks/ident.yml
index 8875f72..61e26aa 100644
--- a/spec/req/rtems/tasks/ident.yml
+++ b/spec/req/rtems/tasks/ident.yml
@@ -75,6 +75,7 @@ test-includes: []
 test-local-includes:
 - support-object-ident.h
 test-name: Classic Task Ident
+test-prepare: null
 test-setup:
   brief: null
   code: |
diff --git a/spec/spec/requirement-action.yml b/spec/spec/requirement-action.yml
index 6afa787..aacef50 100644
--- a/spec/spec/requirement-action.yml
+++ b/spec/spec/requirement-action.yml
@@ -97,6 +97,7 @@ spec-example: |
   test-includes: []
   test-local-includes: []
   test-name: RedGreenData
+  test-prepare: null
   test-setup: null
   test-stop: null
   test-support: null
@@ -171,6 +172,12 @@ spec-info:
       test-name:
         description: null
         spec-type: test-name
+      test-prepare:
+        description: |
+          If the value is present, then it shall be the early test preparation
+          code.  The code is placed in the test action loop body before the
+          test pre-condition preparations.
+        spec-type: optional-str
       test-setup:
         description: null
         spec-type: requirement-action-test-fixture



More information about the vc mailing list