[rtems-central commit] validation: Fix N/A pre-condition handling

Sebastian Huber sebh at rtems.org
Fri May 7 06:00:30 UTC 2021


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu May  6 11:35:09 2021 +0200

validation: Fix N/A pre-condition handling

---

 rtemsspec/tests/test_validation.py | 68 ++++++++------------------------------
 rtemsspec/validation.py            | 45 +++++++++++++++----------
 2 files changed, 42 insertions(+), 71 deletions(-)

diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py
index a08e1c6..ccce1d5 100644
--- a/rtemsspec/tests/test_validation.py
+++ b/rtemsspec/tests/test_validation.py
@@ -689,7 +689,6 @@ static inline Directive_Entry Directive_GetEntry( size_t index )
 T_TEST_CASE_FIXTURE( Directive, &Directive_Fixture )
 {
   Directive_Context *ctx;
-  Directive_Entry entry;
   size_t index;
 
   ctx = T_fixture_context();
@@ -701,44 +700,20 @@ T_TEST_CASE_FIXTURE( Directive, &Directive_Fixture )
     ctx->pcs[ 0 ] < Directive_Pre_Name_NA;
     ++ctx->pcs[ 0 ]
   ) {
-    entry = Directive_GetEntry( index );
-
-    if ( entry.Pre_Name_NA ) {
-      ctx->pcs[ 0 ] = Directive_Pre_Name_NA;
-      index += ( Directive_Pre_Name_NA - 1 )
-        * Directive_Pre_Node_NA
-        * Directive_Pre_Id_NA;
-    }
-
     for (
       ctx->pcs[ 1 ] = Directive_Pre_Node_Local;
       ctx->pcs[ 1 ] < Directive_Pre_Node_NA;
       ++ctx->pcs[ 1 ]
     ) {
-      entry = Directive_GetEntry( index );
-
-      if ( entry.Pre_Node_NA ) {
-        ctx->pcs[ 1 ] = Directive_Pre_Node_NA;
-        index += ( Directive_Pre_Node_NA - 1 )
-          * Directive_Pre_Id_NA;
-      }
-
       for (
         ctx->pcs[ 2 ] = Directive_Pre_Id_NullPtr;
         ctx->pcs[ 2 ] < Directive_Pre_Id_NA;
         ++ctx->pcs[ 2 ]
       ) {
-        entry = Directive_GetEntry( index );
+        Directive_Entry entry;
 
-        if ( entry.Pre_Id_NA ) {
-          ctx->pcs[ 2 ] = Directive_Pre_Id_NA;
-          index += ( Directive_Pre_Id_NA - 1 );
-        }
-
-        if ( entry.Skip ) {
-          ++index;
-          continue;
-        }
+        entry = Directive_GetEntry( index );
+        ++index;
 
         Directive_Pre_Name_Prepare( ctx, ctx->pcs[ 0 ] );
         Directive_Pre_Node_Prepare( ctx, ctx->pcs[ 1 ] );
@@ -746,7 +721,6 @@ T_TEST_CASE_FIXTURE( Directive, &Directive_Fixture )
         Directive_Action( ctx );
         Directive_Post_Status_Check( ctx, entry.Post_Status );
         Directive_Post_Id_Check( ctx, entry.Post_Id );
-        ++index;
       }
     }
   }
@@ -2226,7 +2200,6 @@ static T_fixture_node Action2_Node;
 void Action2_Run( int *a, int b, int *c )
 {
   Action2_Context *ctx;
-  Action2_Entry entry;
   size_t index;
 
   ctx = &Action2_Instance;
@@ -2243,45 +2216,32 @@ void Action2_Run( int *a, int b, int *c )
     ctx->pcs[ 0 ] < Action2_Pre_A_NA;
     ++ctx->pcs[ 0 ]
   ) {
-    entry = Action2_GetEntry( index );
-
-    if ( entry.Pre_A_NA ) {
-      ctx->pcs[ 0 ] = Action2_Pre_A_NA;
-      index += ( Action2_Pre_A_NA - 1 )
-        * Action2_Pre_B_NA
-        * Action2_Pre_C_NA;
-    }
-
     for (
       ctx->pcs[ 1 ] = Action2_Pre_B_B0;
       ctx->pcs[ 1 ] < Action2_Pre_B_NA;
       ++ctx->pcs[ 1 ]
     ) {
-      entry = Action2_GetEntry( index );
-
-      if ( entry.Pre_B_NA ) {
-        ctx->pcs[ 1 ] = Action2_Pre_B_NA;
-        index += ( Action2_Pre_B_NA - 1 )
-          * Action2_Pre_C_NA;
-      }
-
       for (
         ctx->pcs[ 2 ] = Action2_Pre_C_C0;
         ctx->pcs[ 2 ] < Action2_Pre_C_NA;
         ++ctx->pcs[ 2 ]
       ) {
-        entry = Action2_GetEntry( index );
+        Action2_Entry entry;
+        size_t pcs[ 3 ];
 
-        if ( entry.Pre_C_NA ) {
-          ctx->pcs[ 2 ] = Action2_Pre_C_NA;
-          index += ( Action2_Pre_C_NA - 1 );
-        }
+        entry = Action2_GetEntry( index );
+        ++index;
 
         if ( entry.Skip ) {
-          ++index;
           continue;
         }
 
+        memcpy( pcs, ctx->pcs, sizeof( pcs ) );
+
+        if ( entry.Pre_A_NA ) {
+          ctx->pcs[ 0 ] = Action2_Pre_A_NA;
+        }
+
         Action2_Prepare( ctx );
         Action2_Pre_A_Prepare( ctx, ctx->pcs[ 0 ] );
         Action2_Pre_B_Prepare( ctx, ctx->pcs[ 1 ] );
@@ -2290,7 +2250,7 @@ void Action2_Run( int *a, int b, int *c )
         Action2_Post_A_Check( ctx, entry.Post_A );
         Action2_Post_B_Check( ctx, entry.Post_B );
         Action2_Cleanup( ctx );
-        ++index;
+        memcpy( ctx->pcs, pcs, sizeof( ctx->pcs ) );
       }
     }
   }
diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py
index ea7dbe2..628b520 100644
--- a/rtemsspec/validation.py
+++ b/rtemsspec/validation.py
@@ -681,6 +681,7 @@ class TransitionMap:
         self._item = item
         self._pre_co_count = len(item["pre-conditions"])
         self._post_co_count = len(item["post-conditions"])
+        self.pre_co_summary = tuple(0 for _ in range(self._pre_co_count + 1))
         self._pre_co_idx_st_idx_to_st_name = _to_st_name(
             item["pre-conditions"])
         self._post_co_idx_st_idx_to_st_name = _to_st_name(
@@ -947,6 +948,9 @@ class TransitionMap:
                     f"{self._item.spec} is the first variant for "
                     f"{{{self._map_index_to_pre_conditions(map_idx)}}} "
                     "and it is not enabled by default")
+            self.pre_co_summary = tuple(
+                a + b for a, b in zip(self.pre_co_summary, (variant.skip, ) +
+                                      variant.pre_cond_na))
             transition_map[map_idx].add(variant)
 
     def _add_default(self, transition_map: _TransitionMap, desc: Dict[str,
@@ -1148,8 +1152,24 @@ class _ActionRequirementTestItem(_TestItem):
 
     def _add_loop_body(self, content: CContent,
                        transition_map: TransitionMap) -> None:
-        with content.condition("entry.Skip"):
-            content.append(["++index;", "continue;"])
+        has_pre_co_na = max(transition_map.pre_co_summary[1:])
+        content.add(f"{self.ident}_Entry entry;")
+        if has_pre_co_na:
+            content.append(f"size_t pcs[ {self._pre_co_count} ];")
+        content.call_function("entry =", f"{self.ident}_GetEntry", ["index"])
+        content.append("++index;")
+        if transition_map.pre_co_summary[0]:
+            with content.condition("entry.Skip"):
+                content.append("continue;")
+        if has_pre_co_na:
+            content.call_function(None, "memcpy",
+                                  ["pcs", "ctx->pcs", "sizeof( pcs )"])
+            for index, pre_co in enumerate(self._item["pre-conditions"]):
+                if transition_map.pre_co_summary[index + 1]:
+                    name = pre_co["name"]
+                    with content.condition(f"entry.Pre_{name}_NA"):
+                        enum_na = self._pre_co_idx_to_enum[index][-1]
+                        content.append(f"ctx->pcs[ {index} ] = {enum_na};")
         content.add_blank_line()
         self._add_call(content, "test-prepare", "Prepare")
         for index, enum in enumerate(self._pre_co_idx_to_enum):
@@ -1163,7 +1183,10 @@ class _ActionRequirementTestItem(_TestItem):
                 "ctx", f"entry.{transition_map.get_post_entry_member(index)}"
             ])
         self._add_call(content, "test-cleanup", "Cleanup")
-        content.append("++index;")
+        if has_pre_co_na:
+            content.gap = False
+            content.call_function(None, "memcpy",
+                                  ["ctx->pcs", "pcs", "sizeof( ctx->pcs )"])
 
     def _add_for_loops(self, content: CContent, transition_map: TransitionMap,
                        index: int) -> None:
@@ -1173,17 +1196,6 @@ class _ActionRequirementTestItem(_TestItem):
             end = self._pre_co_idx_to_enum[index][-1]
             with content.for_loop(f"{var} = {begin}", f"{var} < {end}",
                                   f"++{var}"):
-                name = self._item['pre-conditions'][index]["name"]
-                content.call_function("entry =", f"{self.ident}_GetEntry",
-                                      ["index"])
-                with content.condition(f"entry.Pre_{name}_NA"):
-                    content.append(f"{var} = {end};")
-                    content.append(f"index += ( {end} - 1 )")
-                    for index_2 in range(index + 1, self._pre_co_count):
-                        with content.indent():
-                            content.append(
-                                f"* {self._pre_co_idx_to_enum[index_2][-1]}")
-                    content.lines[-1] += ";"
                 self._add_for_loops(content, transition_map, index + 1)
         else:
             self._add_loop_body(content, transition_map)
@@ -1198,7 +1210,6 @@ class _ActionRequirementTestItem(_TestItem):
                 f"return {self.ident}_Entries[",
                 f"  {self.ident}_Map[ index ]", "];"
             ])
-        entry = f"{self.ident}_Entry entry;"
         fixture = f"{self.ident}_Fixture"
         prologue = CContent()
         epilogue = CContent()
@@ -1207,7 +1218,7 @@ class _ActionRequirementTestItem(_TestItem):
             ret = "void"
             name = f"{self.ident}_Run"
             params = self._get_run_params(header)
-            prologue.add([f"{self.context} *ctx;", entry, "size_t index;"])
+            prologue.add([f"{self.context} *ctx;", "size_t index;"])
             self.assign_run_params(prologue, header)
             prologue.call_function("ctx =", "T_push_fixture",
                                    [f"&{self.ident}_Node", f"&{fixture}"])
@@ -1223,7 +1234,7 @@ class _ActionRequirementTestItem(_TestItem):
             name = "T_TEST_CASE_FIXTURE"
             params = [f"{self.ident}", f"&{fixture}"]
             prologue.add([
-                f"{self.context} *ctx;", entry, "size_t index;", "",
+                f"{self.context} *ctx;", "size_t index;", "",
                 "ctx = T_fixture_context();", "ctx->in_action_loop = true;",
                 "index = 0;"
             ])



More information about the vc mailing list