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

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


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Mar 22 14:48:50 2021 +0100

validation: Add TransitionMap.get_variants()

---

 rtemsspec/tests/test_validation.py |  9 +++++++--
 rtemsspec/validation.py            | 29 ++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py
index a487374..dba67b8 100644
--- a/rtemsspec/tests/test_validation.py
+++ b/rtemsspec/tests/test_validation.py
@@ -42,8 +42,13 @@ def test_validation(tmpdir):
         tmpdir, "spec-validation", with_spec_types=True)
     item_cache = ItemCache(item_cache_config)
 
-    transition_map = TransitionMap(item_cache["/action2"])
-    assert transition_map.post_co_idx_st_idx_to_st_name(0, 0) == "A0"
+    transition_map = TransitionMap(item_cache["/directive"])
+    assert transition_map.pre_co_idx_to_co_name(0) == "Name"
+    assert transition_map.post_co_idx_st_idx_to_st_name(0, 0) == "Ok"
+    assert transition_map.post_co_idx_to_co_name(0) == "Status"
+    assert len(list(transition_map.get_variants([]))) == 36
+    assert len(list(transition_map.get_variants(["RTEMS_MULTIPROCESSING"
+                                                 ]))) == 36
 
     generate(validation_config, item_cache)
 
diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py
index aedfd45..0f44179 100644
--- a/rtemsspec/validation.py
+++ b/rtemsspec/validation.py
@@ -36,7 +36,8 @@ from typing import Any, Dict, Iterator, List, NamedTuple, Optional, Tuple
 from rtemsspec.content import CContent, CInclude, enabled_by_to_exp, \
     ExpressionMapper, GenericContent, get_value_params, \
     get_value_doxygen_group, get_value_doxygen_function, to_camel_case
-from rtemsspec.items import Item, ItemCache, ItemGetValueContext, ItemMapper
+from rtemsspec.items import is_enabled, Item, ItemCache, \
+    ItemGetValueContext, ItemMapper
 
 ItemMap = Dict[str, Item]
 
@@ -656,6 +657,20 @@ class TransitionMap:
         """ Yields the transition map entry variants sorted by frequency. """
         yield from sorted(self._entries.values(), key=lambda x: x[1])
 
+    def get_variants(self,
+                     enabled: List[str]) -> Iterator[Tuple[int, Transition]]:
+        """
+        Yields the map index and the transition variants enabled by the enabled
+        list.
+        """
+        for map_idx, transitions in enumerate(self._map):
+            for variant in transitions[1:]:
+                if is_enabled(enabled, variant.enabled_by):
+                    break
+            else:
+                variant = transitions[0]
+            yield map_idx, variant
+
     def _post_process(self) -> None:
         for map_idx, transitions in enumerate(self):
             if not transitions or not isinstance(
@@ -703,12 +718,24 @@ class TransitionMap:
         """
         return self._pre_co_name_to_co_idx[co_name]
 
+    def pre_co_idx_to_co_name(self, co_idx: int) -> str:
+        """
+        Maps the pre-condition index to the associated pre-condition name.
+        """
+        return self._pre_co_idx_to_cond[co_idx]["name"]
+
     def post_co_name_to_co_idx(self, co_name: str) -> int:
         """
         Maps the post-condition name to the associated post-condition index.
         """
         return self._post_co_name_to_co_idx[co_name]
 
+    def post_co_idx_to_co_name(self, co_idx: int) -> str:
+        """
+        Maps the post-condition index to the associated post-condition name.
+        """
+        return self._post_co_idx_to_co_name[co_idx]
+
     def pre_co_idx_st_idx_to_st_name(self, co_idx: int, st_idx: int) -> str:
         """
         Maps the pre-condition name and state index to the associated state



More information about the vc mailing list