[rtems-central commit] specview: Add option to show action req tables
Sebastian Huber
sebh at rtems.org
Wed Mar 17 17:37:29 UTC 2021
Module: rtems-central
Branch: master
Commit: 8012787bc72a3fc1208a9b07b5a7ca318dd3e24d
Changeset: http://git.rtems.org/rtems-central/commit/?id=8012787bc72a3fc1208a9b07b5a7ca318dd3e24d
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Wed Mar 17 15:56:27 2021 +0100
specview: Add option to show action req tables
---
rtemsspec/tests/test_validation.py | 9 +++++--
rtemsspec/validation.py | 7 +++++
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 5a0f165..032b531 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 05bb2bc..a36aa19 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 0189155..7c55182 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)
More information about the vc
mailing list