summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-03-22 14:48:50 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-03-22 14:53:16 +0100
commita1254b0546585834f6aa0d70dc2b969b2b519e79 (patch)
treecd6187001a895f7bb00e8658373fd64650c7e7ae
parent800935a199ecdabcc689a347ca8094825a22f49e (diff)
downloadrtems-central-a1254b0546585834f6aa0d70dc2b969b2b519e79.tar.bz2
validation: Add TransitionMap.get_variants()
-rw-r--r--rtemsspec/tests/test_validation.py9
-rw-r--r--rtemsspec/validation.py29
2 files changed, 35 insertions, 3 deletions
diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py
index a4873746..dba67b87 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 aedfd459..0f44179a 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