summaryrefslogtreecommitdiff
path: root/rtemsspec
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2023-11-21 11:13:16 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2023-11-21 11:15:25 +0100
commitb0e8c33fe224459a6925cc27b35f0e843dd3fb78 (patch)
treecf4f6dd2442729aadaed95308fcb98965bb7c5c7 /rtemsspec
parent82d2dbe09683c898e1999e2314de6fac4ccad740 (diff)
rtems: Add gather_api_items()
Diffstat (limited to 'rtemsspec')
-rw-r--r--rtemsspec/rtems.py40
-rw-r--r--rtemsspec/tests/spec-rtems/if/group-general.yml2
-rw-r--r--rtemsspec/tests/spec-rtems/if/group.yml2
-rw-r--r--rtemsspec/tests/spec-rtems/req/api.yml14
-rw-r--r--rtemsspec/tests/spec/non-functional-more.yml4
-rw-r--r--rtemsspec/tests/test_rtems.py10
6 files changed, 67 insertions, 5 deletions
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
@@ -15,6 +15,10 @@ links:
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
uid: non-functional
- role: spec-refinement
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"])]