summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2022-08-09 17:14:31 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2022-09-02 14:52:26 +0200
commit4c35033ea46bfe3dc200bc3d2b9ff9882e76d590 (patch)
treec28b1bff1ca0660ca2b5e2361b85c90e12e0cc4c
parentmodules: Update rtems (diff)
downloadrtems-central-4c35033ea46bfe3dc200bc3d2b9ff9882e76d590.tar.bz2
validation: Add augment_with_test_case_links()
-rw-r--r--rtemsspec/tests/test_validation.py4
-rw-r--r--rtemsspec/validation.py65
2 files changed, 46 insertions, 23 deletions
diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py
index 34aeafea..b123c4af 100644
--- a/rtemsspec/tests/test_validation.py
+++ b/rtemsspec/tests/test_validation.py
@@ -27,7 +27,8 @@
import os
import pytest
-from rtemsspec.validation import generate, TransitionMap
+from rtemsspec.validation import augment_with_test_case_links, generate, \
+ TransitionMap
from rtemsspec.items import EmptyItemCache, Item, ItemCache
from rtemsspec.tests.util import create_item_cache_config_and_copy_spec
@@ -41,6 +42,7 @@ def test_validation(tmpdir):
item_cache_config = create_item_cache_config_and_copy_spec(
tmpdir, "spec-validation", with_spec_types=True)
item_cache = ItemCache(item_cache_config)
+ augment_with_test_case_links(item_cache)
transition_map = TransitionMap(item_cache["/directive"])
assert transition_map.pre_co_idx_to_co_name(0) == "Name"
diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py
index d4c9cfd5..fce22ad1 100644
--- a/rtemsspec/validation.py
+++ b/rtemsspec/validation.py
@@ -37,10 +37,10 @@ from rtemsspec.content import CContent, CInclude, enabled_by_to_exp, \
get_value_plural, get_value_doxygen_group, get_value_doxygen_function, \
to_camel_case
from rtemsspec.items import Item, ItemCache, \
- ItemGetValueContext, ItemMapper
+ ItemGetValueContext, ItemMapper, Link
from rtemsspec.transitionmap import TransitionMap
-ItemMap = Dict[str, Item]
+_CaseToSuite = Dict[str, List["_TestItem"]]
_STEPS = re.compile(r"^steps/([0-9]+)$")
@@ -193,9 +193,8 @@ class _TestItem:
"""
return self._mapper.substitute(text, prefix=prefix)
- def add_test_case_description(
- self, content: CContent,
- test_case_to_suites: Dict[str, List["_TestItem"]]) -> None:
+ def add_test_case_description(self, content: CContent,
+ test_case_to_suites: _CaseToSuite) -> None:
""" Adds the test case description. """
with content.defgroup_block(self.group_identifier, self.name):
try:
@@ -444,7 +443,7 @@ class _TestItem:
epilogue.add("T_pop_fixture();")
def generate(self, content: CContent, base_directory: str,
- test_case_to_suites: Dict[str, List["_TestItem"]]) -> None:
+ test_case_to_suites: _CaseToSuite) -> None:
""" Generates the content. """
self.add_test_case_description(content, test_case_to_suites)
instance = self.add_context(content)
@@ -499,7 +498,7 @@ class _TestSuiteItem(_TestItem):
return f"RTEMSTestSuite{self.ident}"
def generate(self, content: CContent, _base_directory: str,
- _test_case_to_suites: Dict[str, List[_TestItem]]) -> None:
+ _test_case_to_suites: _CaseToSuite) -> None:
with content.defgroup_block(self.group_identifier, self.name):
content.add("@ingroup RTEMSTestSuites")
content.add_brief_description(self.brief)
@@ -822,7 +821,7 @@ class _ActionRequirementTestItem(_TestItem):
super().add_header_body(content, header)
def generate(self, content: CContent, base_directory: str,
- test_case_to_suites: Dict[str, List[_TestItem]]) -> None:
+ test_case_to_suites: _CaseToSuite) -> None:
self.add_test_case_description(content, test_case_to_suites)
header = self["test-header"]
if header:
@@ -970,7 +969,7 @@ class _RuntimeMeasurementTestItem(_TestItem):
return requests
def generate(self, content: CContent, base_directory: str,
- test_case_to_suites: Dict[str, List[_TestItem]]) -> None:
+ test_case_to_suites: _CaseToSuite) -> None:
self.add_test_case_description(content, test_case_to_suites)
instance = self.add_context(content)
content.add(self.substitute_code(self["test-support"]))
@@ -1051,7 +1050,7 @@ class _SourceFile:
self._test_cases.append(_RuntimeMeasurementTestItem(item))
def generate(self, base_directory: str,
- test_case_to_suites: Dict[str, List[_TestItem]]) -> None:
+ test_case_to_suites: _CaseToSuite) -> None:
"""
Generates the source file and the corresponding build specification.
"""
@@ -1160,24 +1159,15 @@ _GATHER = {
}
-def generate(config: dict,
- item_cache: ItemCache,
- targets: Optional[List[str]] = None) -> None:
- """
- Generates source files and build specification items for validation test
- suites and test cases according to the configuration.
-
- :param config: A dictionary with configuration entries.
- :param item_cache: The specification item cache containing the validation
- test suites and test cases.
- """
+def _gather(
+ item_cache: ItemCache) -> Tuple[Dict[str, _SourceFile], _CaseToSuite]:
source_files = {} # type: Dict[str, _SourceFile]
test_programs = [] # type: List[_TestProgram]
for item in item_cache.all.values():
_GATHER.get(item.type, _gather_default)(item, source_files,
test_programs)
- test_case_to_suites = {} # type: Dict[str, List[_TestItem]]
+ test_case_to_suites = {} # type: _CaseToSuite
for test_program in test_programs:
test_program.add_source_files(source_files)
test_suites = [] # type: List[_TestItem]
@@ -1188,6 +1178,22 @@ def generate(config: dict,
test_case_to_suites.setdefault(test_case.uid,
[]).extend(test_suites)
+ return source_files, test_case_to_suites
+
+
+def generate(config: dict,
+ item_cache: ItemCache,
+ targets: Optional[List[str]] = None) -> None:
+ """
+ Generates source files and build specification items for validation test
+ suites and test cases according to the configuration.
+
+ :param config: A dictionary with configuration entries.
+ :param item_cache: The specification item cache containing the validation
+ test suites and test cases.
+ """
+ source_files, test_case_to_suites = _gather(item_cache)
+
if not targets:
for src in source_files.values():
src.generate(config["base-directory"], test_case_to_suites)
@@ -1195,3 +1201,18 @@ def generate(config: dict,
for target in targets:
source_files[target].generate(config["base-directory"],
test_case_to_suites)
+
+
+def augment_with_test_case_links(item_cache: ItemCache) -> None:
+ """
+ Augments the test case items with links to the associated test suites and
+ vice versa.
+ """
+ _, test_case_to_suites = _gather(item_cache)
+ for test_case_uid, test_suites in test_case_to_suites.items():
+ child = item_cache[test_case_uid]
+ for test_suite in test_suites:
+ parent = item_cache[test_suite.item.uid]
+ link = {"role": "test-case", "uid": parent.uid}
+ parent.add_link_to_child(Link(child, link))
+ child.add_link_to_parent(Link(parent, link))