diff options
Diffstat (limited to 'rtemsspec')
-rw-r--r-- | rtemsspec/items.py | 18 | ||||
-rw-r--r-- | rtemsspec/tests/spec-validation/ts.yml | 2 | ||||
-rw-r--r-- | rtemsspec/tests/test_validation.py | 84 | ||||
-rw-r--r-- | rtemsspec/validation.py | 42 |
4 files changed, 78 insertions, 68 deletions
diff --git a/rtemsspec/items.py b/rtemsspec/items.py index 7e116075..fb4a1d0b 100644 --- a/rtemsspec/items.py +++ b/rtemsspec/items.py @@ -29,10 +29,11 @@ import base64 import hashlib import os import pickle +import re import string import stat -from typing import Any, Callable, Dict, Iterable, Iterator, List, NamedTuple, \ - Optional, Set, TextIO, Tuple, Union +from typing import Any, Callable, Dict, Iterable, Iterator, List, Match, \ + NamedTuple, Optional, Set, TextIO, Tuple, Union import json import yaml @@ -180,12 +181,20 @@ def data_digest(data: Any) -> str: return base64.urlsafe_b64encode(state.digest()).decode("ascii") +_UID_TO_UPPER = re.compile(r"[/_-]+(.)") + + +def _match_to_upper(match: Match) -> str: + return match.group(1).upper() + + class Item: """ Objects of this class represent a specification item. """ # pylint: disable=too-many-public-methods def __init__(self, item_cache: "ItemCache", uid: str, data: Any): self._cache = item_cache + self._ident = _UID_TO_UPPER.sub(_match_to_upper, uid) self._uid = uid self._data = data self._links_to_parents: List[Link] = [] @@ -265,6 +274,11 @@ class Item: return self._uid @property + def ident(self) -> str: + """ Returns the identifier of the item. """ + return self._ident + + @property def spec(self) -> str: """ Returns the UID of the item with an URL-like format. """ return f"spec:{self._uid}" diff --git a/rtemsspec/tests/spec-validation/ts.yml b/rtemsspec/tests/spec-validation/ts.yml index 83fbc05a..cbea16f2 100644 --- a/rtemsspec/tests/spec-validation/ts.yml +++ b/rtemsspec/tests/spec-validation/ts.yml @@ -8,7 +8,7 @@ enabled-by: true links: [] test-brief: The Blue Green brief description. test-code: | - /* Blue green code */ + /* Blue green code for ${.:test-suite-name} */ test-description: The Blue Green description. test-includes: - blue.h diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py index b123c4af..51c209a4 100644 --- a/rtemsspec/tests/test_validation.py +++ b/rtemsspec/tests/test_validation.py @@ -70,7 +70,7 @@ def test_validation(tmpdir): /** * @file * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts */ /* @@ -126,7 +126,7 @@ def test_validation(tmpdir): #include <rtems/test.h> /** - * @defgroup RTEMSTestSuiteTs spec:/ts + * @defgroup Ts spec:/ts * * @ingroup RTEMSTestSuites * @@ -137,7 +137,7 @@ def test_validation(tmpdir): * @{ */ -/* Blue green code */ +/* Blue green code for Ts */ /** @} */ """ @@ -148,9 +148,9 @@ def test_validation(tmpdir): /** * @file * - * @ingroup RTEMSTestCaseDirective - * @ingroup RTEMSTestCaseTc - * @ingroup RTEMSTestCaseTc2 + * @ingroup Directive + * @ingroup Tc + * @ingroup Tc2 */ /* @@ -209,9 +209,9 @@ def test_validation(tmpdir): #include <rtems/test.h> /** - * @defgroup RTEMSTestCaseDirective spec:/directive + * @defgroup Directive spec:/directive * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts * * @brief Test rtems_task_ident() brief description. * @@ -753,9 +753,9 @@ T_TEST_CASE_FIXTURE( Directive, &Directive_Fixture ) /** @} */ /** - * @defgroup RTEMSTestCaseTc spec:/tc + * @defgroup Tc spec:/tc * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts * * @brief Test case brief description. * @@ -830,9 +830,9 @@ T_TEST_CASE( Tc ) /** @} */ /** - * @defgroup RTEMSTestCaseTc2 spec:/tc2 + * @defgroup Tc2 spec:/tc2 * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts * * @brief Test case 2 brief description. * @@ -940,13 +940,13 @@ T_TEST_CASE_FIXTURE( Tc2, &Tc2_Fixture ) /** * @file * - * @ingroup RTEMSTestCaseRtm - * @ingroup RTEMSTestCaseTc3 - * @ingroup RTEMSTestCaseTc4 - * @ingroup RTEMSTestCaseTc5 - * @ingroup RTEMSTestCaseTc6 - * @ingroup RTEMSTestCaseTc7 - * @ingroup RTEMSTestCaseTc8 + * @ingroup Rtm + * @ingroup Tc3 + * @ingroup Tc4 + * @ingroup Tc5 + * @ingroup Tc6 + * @ingroup Tc7 + * @ingroup Tc8 */ /* @@ -1004,9 +1004,9 @@ T_TEST_CASE_FIXTURE( Tc2, &Tc2_Fixture ) #include <rtems/test.h> /** - * @defgroup RTEMSTestCaseRtm spec:/rtm + * @defgroup Rtm spec:/rtm * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts * * @brief Test brief. * @@ -1236,9 +1236,9 @@ T_TEST_CASE_FIXTURE( Rtm, &Rtm_Fixture ) /** @} */ /** - * @defgroup RTEMSTestCaseTc3 spec:/tc3 + * @defgroup Tc3 spec:/tc3 * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts * * @brief Test case 3 brief description. * @@ -1279,9 +1279,9 @@ T_TEST_CASE( Tc3 ) /** @} */ /** - * @defgroup RTEMSTestCaseTc4 spec:/tc4 + * @defgroup Tc4 spec:/tc4 * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts * * @brief Test case 4 brief description. * @@ -1300,9 +1300,9 @@ T_TEST_CASE( Tc4 ) /** @} */ /** - * @defgroup RTEMSTestCaseTc5 spec:/tc5 + * @defgroup Tc5 spec:/tc5 * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts * * @brief Test case 5 brief description. * @@ -1417,9 +1417,9 @@ void Tc5_Run( int *a, int b, int *c ) /** @} */ /** - * @defgroup RTEMSTestCaseTc6 spec:/tc6 + * @defgroup Tc6 spec:/tc6 * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts * * @{ */ @@ -1431,9 +1431,9 @@ void Tc6_Run( void ) /** @} */ /** - * @defgroup RTEMSTestCaseTc7 spec:/tc7 + * @defgroup Tc7 spec:/tc7 * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts * * This test case performs the following actions: * @@ -1466,9 +1466,9 @@ void Tc7_Run( void ) /** @} */ /** - * @defgroup RTEMSTestCaseTc8 spec:/tc8 + * @defgroup Tc8 spec:/tc8 * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts * * This test case performs the following actions: * @@ -1527,7 +1527,7 @@ void Tc8_Run( void ) /** * @file * - * @ingroup RTEMSTestCaseTc5 + * @ingroup Tc5 */ /* @@ -1584,7 +1584,7 @@ extern "C" { #endif /** - * @addtogroup RTEMSTestCaseTc5 + * @addtogroup Tc5 * * @{ */ @@ -1617,7 +1617,7 @@ void Tc5_Run( int *a, int b, int *c ); /** * @file * - * @ingroup RTEMSTestCaseTc6 + * @ingroup Tc6 */ /* @@ -1670,7 +1670,7 @@ extern "C" { #endif /** - * @addtogroup RTEMSTestCaseTc6 + * @addtogroup Tc6 * * @{ */ @@ -1695,7 +1695,7 @@ void Tc6_Run( void ); /** * @file * - * @ingroup RTEMSTestCaseAction2 + * @ingroup Action2 */ /* @@ -1752,7 +1752,7 @@ extern "C" { #endif /** - * @addtogroup RTEMSTestCaseAction2 + * @addtogroup Action2 * * @{ */ @@ -1820,7 +1820,7 @@ void Action2_Run( int *a, int b, int *c ); /** * @file * - * @ingroup RTEMSTestCaseAction2 + * @ingroup Action2 */ /* @@ -1876,9 +1876,9 @@ void Action2_Run( int *a, int b, int *c ); #include <rtems/test.h> /** - * @defgroup RTEMSTestCaseAction2 spec:/action2 + * @defgroup Action2 spec:/action2 * - * @ingroup RTEMSTestSuiteTs + * @ingroup Ts * * @brief Test brief. * diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py index 2bf5384b..aa96e79f 100644 --- a/rtemsspec/validation.py +++ b/rtemsspec/validation.py @@ -34,8 +34,7 @@ from typing import Any, Dict, List, Optional, Tuple from rtemsspec.content import CContent, CInclude, enabled_by_to_exp, \ ExpressionMapper, GenericContent, get_integer_type, get_value_params, \ - get_value_plural, get_value_doxygen_group, get_value_doxygen_function, \ - to_camel_case + get_value_plural, get_value_doxygen_group, get_value_doxygen_function from rtemsspec.items import create_unique_link, Item, ItemCache, \ ItemGetValueContext, ItemMapper from rtemsspec.transitionmap import TransitionMap @@ -46,15 +45,19 @@ _STEPS = re.compile(r"^steps/([0-9]+)$") def _get_test_context_instance(ctx: ItemGetValueContext) -> Any: - return f"{to_camel_case(ctx.item.uid[1:])}_Instance" + return f"{ctx.item.ident}_Instance" def _get_test_context_type(ctx: ItemGetValueContext) -> Any: - return f"{to_camel_case(ctx.item.uid[1:])}_Context" + return f"{ctx.item.ident}_Context" def _get_test_run(ctx: ItemGetValueContext) -> Any: - return f"{to_camel_case(ctx.item.uid[1:])}_Run" + return f"{ctx.item.ident}_Run" + + +def _get_test_suite_name(ctx: ItemGetValueContext) -> Any: + return ctx.item.ident class _Mapper(ItemMapper): @@ -71,6 +74,8 @@ class _Mapper(ItemMapper): self.add_get_value("interface/macro:/params/name", get_value_params) self.add_get_value("interface/unspecified-function:/name", get_value_doxygen_function) + self.add_get_value("memory-benchmark:/test-suite-name", + _get_test_suite_name) self.add_get_value( "requirement/functional/action:/test-context-instance", _get_test_context_instance) @@ -85,6 +90,7 @@ class _Mapper(ItemMapper): self.add_get_value("test-case:/test-context-type", _get_test_context_type) self.add_get_value("test-case:/test-run", _get_test_run) + self.add_get_value("test-suite:/test-suite-name", _get_test_suite_name) @property def steps(self): @@ -112,7 +118,7 @@ class _Mapper(ItemMapper): def _add_ingroup(content: CContent, items: List["_TestItem"]) -> None: - content.add_ingroup([item.group_identifier for item in items]) + content.add_ingroup([item.ident for item in items]) class _TestItem: @@ -121,8 +127,7 @@ class _TestItem: # pylint: disable=too-many-public-methods def __init__(self, item: Item): self._item = item - self._ident = to_camel_case(item.uid[1:]) - self._context = f"{self._ident}_Context" + self._context = f"{self.ident}_Context" self._mapper = _Mapper(item) def __getitem__(self, key: str): @@ -141,7 +146,7 @@ class _TestItem: @property def ident(self) -> str: """ Returns the test identifier. """ - return self._ident + return self._item.ident @property def context(self) -> str: @@ -173,11 +178,6 @@ class _TestItem: """ Returns the substituted description. """ return self.substitute_text(self["test-description"]) - @property - def group_identifier(self) -> str: - """ Returns the group identifier. """ - return f"RTEMSTestCase{self.ident}" - def substitute_code(self, text: Optional[str], prefix: Optional[str] = None) -> str: @@ -197,7 +197,7 @@ class _TestItem: 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): + with content.defgroup_block(self.ident, self.name): try: test_suites = test_case_to_suites[self.uid] except KeyError as err: @@ -227,7 +227,7 @@ class _TestItem: def _add_test_case_actions(self, content: CContent) -> CContent: actions = CContent() for index, action in enumerate(self["test-actions"]): - method = f"{self._ident}_Action_{index}" + method = f"{self.ident}_Action_{index}" if self.context == "void": args = [] params = [] @@ -373,7 +373,7 @@ class _TestItem: content.register_license_and_copyrights_of_item(self._item) content.prepend_spdx_license_identifier() with content.file_block(): - content.add_ingroup([self.group_identifier]) + content.add_ingroup([self.ident]) content.add_copyrights_and_licenses() content.add_automatically_generated_warning() with content.header_guard(os.path.basename(header["target"])): @@ -381,7 +381,7 @@ class _TestItem: content.add_includes(list(map(CInclude, header["local-includes"])), local=True) with content.extern_c(): - with content.add_to_group(self.group_identifier): + with content.add_to_group(self.ident): self.add_header_body(content, header) content.write(os.path.join(base_directory, header["target"])) @@ -495,13 +495,9 @@ class _TestItem: class _TestSuiteItem(_TestItem): """ A test suite item. """ - @property - def group_identifier(self) -> str: - return f"RTEMSTestSuite{self.ident}" - def generate(self, content: CContent, _base_directory: str, _test_case_to_suites: _CaseToSuite) -> None: - with content.defgroup_block(self.group_identifier, self.name): + with content.defgroup_block(self.ident, self.name): content.add("@ingroup RTEMSTestSuites") content.add_brief_description(self.brief) content.wrap(self.description) |