[rtems-central commit] validation: Add TransitionMap.skip_idx_to_name()

Sebastian Huber sebh at rtems.org
Mon Mar 22 14:43:48 UTC 2021


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Mar 22 15:29:06 2021 +0100

validation: Add TransitionMap.skip_idx_to_name()

---

 rtemsspec/tests/test_validation.py |  2 ++
 rtemsspec/validation.py            | 19 ++++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py
index dba67b8..938762c 100644
--- a/rtemsspec/tests/test_validation.py
+++ b/rtemsspec/tests/test_validation.py
@@ -49,6 +49,8 @@ def test_validation(tmpdir):
     assert len(list(transition_map.get_variants([]))) == 36
     assert len(list(transition_map.get_variants(["RTEMS_MULTIPROCESSING"
                                                  ]))) == 36
+    transition_map = TransitionMap(item_cache["/action2"])
+    assert transition_map.skip_idx_to_name(1) == "SkipReason"
 
     generate(validation_config, item_cache)
 
diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py
index 0f44179..aabdd7b 100644
--- a/rtemsspec/validation.py
+++ b/rtemsspec/validation.py
@@ -643,6 +643,12 @@ class TransitionMap:
         self._post_co_idx_to_co_name = dict(
             (co_idx, condition["name"])
             for co_idx, condition in enumerate(item["post-conditions"]))
+        self._skip_idx_to_name = dict(
+            (skip_idx + 1, key)
+            for skip_idx, key in enumerate(item["skip-reasons"].keys()))
+        self._skip_name_to_idx = dict(
+            (key, skip_idx + 1)
+            for skip_idx, key in enumerate(item["skip-reasons"].keys()))
         self._entries = {}  # type: Dict[str, List[Any]]
         self._map = self._build_map()
         self._post_process()
@@ -764,6 +770,12 @@ class TransitionMap:
         """
         return self._post_co_idx_st_name_to_st_idx[co_idx][st_name]
 
+    def skip_idx_to_name(self, skip_idx: int) -> str:
+        """
+        Maps the skip index the associated skip name index.
+        """
+        return self._skip_idx_to_name[skip_idx]
+
     def _map_post_cond(self, desc_idx: int, map_idx: int, co_idx: int,
                        post_cond: Tuple[Any, ...]) -> Tuple[Any, ...]:
         if isinstance(post_cond[co_idx], int):
@@ -884,9 +896,10 @@ class TransitionMap:
                            f"post-condition state {err}")
                     raise ValueError(msg) from err
             else:
-                skip_post_cond = (1, ) + tuple(
-                    self._post_co_idx_st_name_to_st_idx[co_idx]["N/A"]
-                    for co_idx in range(self._post_co_count))
+                skip_post_cond = (
+                    self._skip_name_to_idx[desc["post-conditions"]], ) + tuple(
+                        self._post_co_idx_st_name_to_st_idx[co_idx]["N/A"]
+                        for co_idx in range(self._post_co_count))
             if isinstance(desc["pre-conditions"], dict):
                 self._add_transitions(transition_map, desc, desc_idx,
                                       skip_post_cond, 0, 0, ())



More information about the vc mailing list