From b0e8c33fe224459a6925cc27b35f0e843dd3fb78 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 21 Nov 2023 11:13:16 +0100 Subject: rtems: Add gather_api_items() --- rtemsspec/rtems.py | 40 ++++++++++++++++++++++- rtemsspec/tests/spec-rtems/if/group-general.yml | 2 +- rtemsspec/tests/spec-rtems/if/group.yml | 2 +- rtemsspec/tests/spec-rtems/req/api.yml | 14 ++++++++ rtemsspec/tests/spec/non-functional-more.yml | 4 +++ rtemsspec/tests/test_rtems.py | 10 ++++-- specview.py | 43 ++++--------------------- 7 files changed, 73 insertions(+), 42 deletions(-) create mode 100644 rtemsspec/tests/spec-rtems/req/api.yml diff --git a/rtemsspec/rtems.py b/rtemsspec/rtems.py index df0af3f5..cd68f036 100644 --- a/rtemsspec/rtems.py +++ b/rtemsspec/rtems.py @@ -27,7 +27,7 @@ import base64 import hashlib import itertools -from typing import Any, List, Tuple, Union +from typing import Any, Dict, List, Tuple, Union from rtemsspec.items import create_unique_link, Item, ItemCache, Link from rtemsspec.glossary import augment_glossary_terms @@ -240,6 +240,44 @@ def validate(item: Item) -> None: "interface-placement") +_API_INTERFACES = [ + "interface/appl-config-option/feature", + "interface/appl-config-option/feature-enable", + "interface/appl-config-option/initializer", + "interface/appl-config-option/integer", + "interface/function", + "interface/macro", + "interface/unspecified-function", + "interface/unspecified-macro", +] + +_API_ROLES = [ + "requirement-refinement", + "interface-ingroup", +] + + +def _gather_api_items(item: Item, items: Dict[str, List[Item]]) -> None: + if item.type in _API_INTERFACES and item["_pre_qualified"]: + parent = item.parent(_API_ROLES) + group = items.setdefault(parent.get("name", parent.spec), []) + group.append(item) + for child in item.children(_API_ROLES): + _gather_api_items(child, items) + + +def gather_api_items(item_cache: ItemCache, items: Dict[str, + List[Item]]) -> None: + """ + Gathers all API related items and groups them by the associated interface + group name. + + If a group has no name, then the UID is used instead. + """ + for group in item_cache["/req/api"].children("requirement-refinement"): + _gather_api_items(group, items) + + def _is_proxy_link_enabled(link: Link) -> bool: return link.item.is_enabled(link.item.cache.enabled) diff --git a/rtemsspec/tests/spec-rtems/if/group-general.yml b/rtemsspec/tests/spec-rtems/if/group-general.yml index 0e9bb163..8908a167 100644 --- a/rtemsspec/tests/spec-rtems/if/group-general.yml +++ b/rtemsspec/tests/spec-rtems/if/group-general.yml @@ -10,7 +10,7 @@ links: - role: interface-placement uid: domain - role: requirement-refinement - uid: ../req/root + uid: ../req/api name: General System Configuration text: '' type: interface diff --git a/rtemsspec/tests/spec-rtems/if/group.yml b/rtemsspec/tests/spec-rtems/if/group.yml index 1f43773c..a1b2fc9c 100644 --- a/rtemsspec/tests/spec-rtems/if/group.yml +++ b/rtemsspec/tests/spec-rtems/if/group.yml @@ -7,7 +7,7 @@ index-entries: [] interface-type: group links: - role: requirement-refinement - uid: ../req/root + uid: ../req/api - role: interface-placement uid: domain name: Application Configuration diff --git a/rtemsspec/tests/spec-rtems/req/api.yml b/rtemsspec/tests/spec-rtems/req/api.yml new file mode 100644 index 00000000..3c3d4626 --- /dev/null +++ b/rtemsspec/tests/spec-rtems/req/api.yml @@ -0,0 +1,14 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +copyrights: +- Copyright (C) 2020 embedded brains GmbH & Co. KG +enabled-by: true +links: +- role: requirement-refinement + uid: root +non-functional-type: interface-requirement +rationale: null +references: [] +requirement-type: non-functional +text: | + The software product shall provide an API. +type: requirement diff --git a/rtemsspec/tests/spec/non-functional-more.yml b/rtemsspec/tests/spec/non-functional-more.yml index aa64a2b2..144e75c0 100644 --- a/rtemsspec/tests/spec/non-functional-more.yml +++ b/rtemsspec/tests/spec/non-functional-more.yml @@ -13,6 +13,10 @@ links: spec-key: non-functional-type spec-value: design-group uid: non-functional +- role: spec-refinement + spec-key: non-functional-type + spec-value: interface-requirement + uid: non-functional - role: spec-refinement spec-key: non-functional-type spec-value: performance-runtime diff --git a/rtemsspec/tests/test_rtems.py b/rtemsspec/tests/test_rtems.py index 2d0a4980..ae399f8a 100644 --- a/rtemsspec/tests/test_rtems.py +++ b/rtemsspec/tests/test_rtems.py @@ -27,8 +27,8 @@ import pytest from rtemsspec.items import EmptyItemCache, Item, ItemCache -from rtemsspec.rtems import augment_with_test_links, is_pre_qualified, \ - recursive_is_enabled, validate +from rtemsspec.rtems import augment_with_test_links, gather_api_items, \ + is_pre_qualified, recursive_is_enabled, validate from rtemsspec.tests.util import create_item_cache_config_and_copy_spec @@ -125,3 +125,9 @@ def test_validate(tmpdir): tmpdir, "spec-rtems", with_spec_types=True) item_cache = ItemCache(item_cache_config) assert not validate(item_cache["/req/root"]) + api_items = {} + gather_api_items(item_cache, api_items) + assert [ + (group, [item.uid for item in group_items]) + for group, group_items in sorted(api_items.items()) + ] == [("General System Configuration", ["/if/disable-newlib-reentrancy"])] diff --git a/specview.py b/specview.py index a60abb97..5ebdd320 100755 --- a/specview.py +++ b/specview.py @@ -33,7 +33,7 @@ from typing import Any, Dict, List, Optional, Set, Tuple from rtemsspec.build import gather_files from rtemsspec.items import EmptyItem, Item, ItemCache, ItemMapper, \ ItemGetValueContext -from rtemsspec.rtems import augment_with_test_links, is_pre_qualified, \ +from rtemsspec.rtems import augment_with_test_links, gather_api_items, \ recursive_is_enabled, validate from rtemsspec.sphinxcontent import SphinxContent from rtemsspec.transitionmap import Transition, TransitionMap @@ -326,44 +326,13 @@ def _action_list(item: Item) -> None: print(" * " + ", ".join(entries)) -_API_INTERFACES = [ - "interface/appl-config-option/feature", - "interface/appl-config-option/feature-enable", - "interface/appl-config-option/initializer", - "interface/appl-config-option/integer", - "interface/function", - "interface/macro", - "interface/unspecified-function", -] - -_API_ROLES = [ - "requirement-refinement", - "interface-ingroup", -] - - -def _gather_api_names(item: Item, names: Dict[str, List[str]]) -> None: - if item.type in _API_INTERFACES and is_pre_qualified(item): - try: - name = item.parent(_API_ROLES)["name"] - except KeyError: - name = item.parent(_API_ROLES).spec - group = names.setdefault(name, []) - group.append(item["name"]) - for child in item.children(_API_ROLES): - _gather_api_names(child, names) - - def _list_api(item_cache: ItemCache) -> None: - names: Dict[str, List[str]] = {} - _gather_api_names(item_cache["/req/applconfig"], names) - _gather_api_names(item_cache["/if/group"], names) - _gather_api_names(item_cache["/c/if/group"], names) - _gather_api_names(item_cache["/newlib/if/group"], names) - for group in sorted(names.keys()): + items: Dict[str, List[Item]] = {} + gather_api_items(item_cache, items) + for group, group_items in sorted(items.items()): print(group) - for name in sorted(names[group]): - print(f"\t{name}") + for item in group_items: + print(f"\t{item['name']}") def main() -> None: -- cgit v1.2.3