diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-03-17 15:56:27 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-03-17 18:35:11 +0100 |
commit | 8012787bc72a3fc1208a9b07b5a7ca318dd3e24d (patch) | |
tree | 9bcabca30a0f28ddd13063f88993f49f2f73045c | |
parent | content: Add support for CPU port options (diff) | |
download | rtems-central-8012787bc72a3fc1208a9b07b5a7ca318dd3e24d.tar.bz2 |
specview: Add option to show action req tables
-rw-r--r-- | rtemsspec/tests/test_validation.py | 9 | ||||
-rw-r--r-- | rtemsspec/validation.py | 7 | ||||
-rwxr-xr-x | specview.py | 55 |
3 files changed, 66 insertions, 5 deletions
diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py index 5a0f165b..032b531f 100644 --- a/rtemsspec/tests/test_validation.py +++ b/rtemsspec/tests/test_validation.py @@ -27,7 +27,7 @@ import os import pytest -from rtemsspec.validation import generate +from rtemsspec.validation import generate, TransitionMap from rtemsspec.items import EmptyItemCache, Item, ItemCache from rtemsspec.tests.util import create_item_cache_config_and_copy_spec @@ -40,7 +40,12 @@ def test_validation(tmpdir): item_cache_config = create_item_cache_config_and_copy_spec( tmpdir, "spec-validation", with_spec_types=True) - generate(validation_config, ItemCache(item_cache_config)) + 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" + + generate(validation_config, item_cache) with open(os.path.join(base_directory, "ts.c"), "r") as src: content = """/* SPDX-License-Identifier: BSD-2-Clause */ diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py index 05bb2bcd..a36aa19b 100644 --- a/rtemsspec/validation.py +++ b/rtemsspec/validation.py @@ -679,6 +679,13 @@ class TransitionMap: """ return self._pre_co_idx_st_idx_to_st_name[co_idx][st_idx] + def post_co_idx_st_idx_to_st_name(self, co_idx: int, st_idx: int) -> str: + """ + Maps the post-condition name and state index to the associated state + name. + """ + return self._post_co_idx_st_idx_to_st_name[co_idx][st_idx] + def pre_co_idx_st_name_to_st_idx(self, co_idx: int, st_name: str) -> int: """ Maps the pre-condition index and state name to the associated state diff --git a/specview.py b/specview.py index 01891555..7c551824 100755 --- a/specview.py +++ b/specview.py @@ -26,11 +26,14 @@ # POSSIBILITY OF SUCH DAMAGE. import argparse +import itertools import sys -from typing import List, Set +from typing import List, Set, Tuple -from rtemsspec.items import Item, ItemCache, Link +from rtemsspec.items import is_enabled, Item, ItemCache, Link +from rtemsspec.sphinxcontent import SphinxContent from rtemsspec.util import load_config +from rtemsspec.validation import Transition, TransitionMap _CHILD_ROLES = [ "requirement-refinement", "interface-ingroup", "interface-function", @@ -86,14 +89,34 @@ def _process_test_cases(item_cache: ItemCache) -> None: _add_link(item_cache, item, link) +def _make_row(transition_map: TransitionMap, map_idx: int, + variant: Transition) -> Tuple[str, ...]: + return tuple( + itertools.chain( + [str(map_idx), str(variant.desc_idx)], + (transition_map.pre_co_idx_st_idx_to_st_name(co_idx, st_idx) + for co_idx, st_idx in enumerate( + transition_map.map_idx_to_pre_co_states(map_idx))), + (transition_map.post_co_idx_st_idx_to_st_name(co_idx, st_idx) + for co_idx, st_idx in enumerate(variant.post_cond)))) + + def main() -> None: """ Views the specification. """ parser = argparse.ArgumentParser() parser.add_argument('--filter', - choices=["none", "orphan", "no-validation"], + choices=["none", "orphan", "no-validation", "action"], type=str.lower, default="none", help="filter the items") + parser.add_argument( + "--enabled", + help=("a comma separated list of enabled options used to evaluate " + "enabled-by expressions")) + parser.add_argument("UIDs", + metavar="UID", + nargs="*", + help="an UID of a specification item") args = parser.parse_args(sys.argv[1:]) config = load_config("config.yml") item_cache = ItemCache(config["spec"]) @@ -102,6 +125,32 @@ def main() -> None: if args.filter == "none": _view(root, 0) + elif args.filter == "action": + enabled = args.enabled.split(",") if args.enabled else [] + for uid in args.UIDs: + item = item_cache[uid] + rows = [ + tuple( + itertools.chain( + ["Entry", "Descriptor"], + (condition["name"] + for condition in item["pre-conditions"]), + (condition["name"] + for condition in item["post-conditions"]))) + ] + transition_map = TransitionMap(item) + for map_idx, transitions in enumerate(transition_map): + for variant in transitions[1:]: + if is_enabled(enabled, variant.enabled_by): + rows.append(_make_row(transition_map, map_idx, + variant)) + break + else: + rows.append( + _make_row(transition_map, map_idx, transitions[0])) + content = SphinxContent() + content.add_simple_table(rows) + print(str(content)) elif args.filter == "orphan": spec = set() # type: Set[Item] _gather(root, spec) |