From 82d2dbe09683c898e1999e2314de6fac4ccad740 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 21 Nov 2023 11:13:16 +0100 Subject: rtems: Add RTEMSItemCache --- rtemsspec/packagebuildfactory.py | 2 + rtemsspec/rtems.py | 59 ++++++++++++++++++++++ .../tests/spec-packagebuild/glossary-general.yml | 12 +++++ .../tests/spec-packagebuild/qdp/package-build.yml | 2 + rtemsspec/tests/spec-packagebuild/qdp/steps/a.yml | 4 ++ .../qdp/steps/rtems-item-cache.yml | 11 ++++ rtemsspec/tests/spec-packagebuild/req/glossary.yml | 12 +++++ rtemsspec/tests/spec-packagebuild/req/root.yml | 12 +++++ rtemsspec/tests/spec-packagebuild/rtems/domain.yml | 13 +++++ .../tests/spec-packagebuild/rtems/group-acfg.yml | 16 ++++++ rtemsspec/tests/spec-packagebuild/rtems/group.yml | 19 +++++++ rtemsspec/tests/spec-packagebuild/rtems/header.yml | 16 ++++++ rtemsspec/tests/spec-packagebuild/rtems/if.yml | 36 +++++++++++++ rtemsspec/tests/spec-packagebuild/rtems/proxy.yml | 6 +++ rtemsspec/tests/spec-packagebuild/rtems/req.yml | 14 +++++ .../tests/spec-packagebuild/rtems/test-case.yml | 34 +++++++++++++ spec-qdp/spec/qdp-rtems-item-cache.yml | 27 ++++++++++ 17 files changed, 295 insertions(+) create mode 100644 rtemsspec/tests/spec-packagebuild/glossary-general.yml create mode 100644 rtemsspec/tests/spec-packagebuild/qdp/steps/rtems-item-cache.yml create mode 100644 rtemsspec/tests/spec-packagebuild/req/glossary.yml create mode 100644 rtemsspec/tests/spec-packagebuild/req/root.yml create mode 100644 rtemsspec/tests/spec-packagebuild/rtems/domain.yml create mode 100644 rtemsspec/tests/spec-packagebuild/rtems/group-acfg.yml create mode 100644 rtemsspec/tests/spec-packagebuild/rtems/group.yml create mode 100644 rtemsspec/tests/spec-packagebuild/rtems/header.yml create mode 100644 rtemsspec/tests/spec-packagebuild/rtems/if.yml create mode 100644 rtemsspec/tests/spec-packagebuild/rtems/proxy.yml create mode 100644 rtemsspec/tests/spec-packagebuild/rtems/req.yml create mode 100644 rtemsspec/tests/spec-packagebuild/rtems/test-case.yml create mode 100644 spec-qdp/spec/qdp-rtems-item-cache.yml diff --git a/rtemsspec/packagebuildfactory.py b/rtemsspec/packagebuildfactory.py index 9b3e7944..28e52fa3 100644 --- a/rtemsspec/packagebuildfactory.py +++ b/rtemsspec/packagebuildfactory.py @@ -28,6 +28,7 @@ from rtemsspec.archiver import Archiver from rtemsspec.directorystate import DirectoryState from rtemsspec.packagebuild import BuildItemFactory, PackageVariant from rtemsspec.reposubset import RepositorySubset +from rtemsspec.rtems import RTEMSItemCache from rtemsspec.runactions import RunActions from rtemsspec.runtests import RunTests, TestLog from rtemsspec.testrunner import DummyTestRunner, GRMONManualTestRunner, \ @@ -40,6 +41,7 @@ def create_build_item_factory() -> BuildItemFactory: factory.add_constructor("qdp/build-step/archive", Archiver) factory.add_constructor("qdp/build-step/repository-subset", RepositorySubset) + factory.add_constructor("qdp/build-step/rtems-item-cache", RTEMSItemCache) factory.add_constructor("qdp/build-step/run-actions", RunActions) factory.add_constructor("qdp/build-step/run-tests", RunTests) factory.add_constructor("qdp/directory-state/generic", DirectoryState) diff --git a/rtemsspec/rtems.py b/rtemsspec/rtems.py index 6407de19..df0af3f5 100644 --- a/rtemsspec/rtems.py +++ b/rtemsspec/rtems.py @@ -24,10 +24,15 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +import base64 +import hashlib import itertools from typing import Any, List, Tuple, Union from rtemsspec.items import create_unique_link, Item, ItemCache, Link +from rtemsspec.glossary import augment_glossary_terms +from rtemsspec.packagebuild import BuildItem, PackageBuildDirector +from rtemsspec.validation import augment_with_test_case_links _NOT_PRE_QUALIFIED = set([ "/acfg/constraint/option-not-pre-qualified", @@ -85,6 +90,19 @@ def augment_with_test_links(item_cache: ItemCache) -> None: _add_link(item_cache, item, link) +def _visit_domain(item: Item, domain: Item) -> None: + for item_2 in itertools.chain(item.children("interface-placement"), + item.parents("interface-enumerator")): + item_2["_interface_domain"] = domain + _visit_domain(item_2, domain) + + +def _augment_with_interface_domains(item_cache: ItemCache) -> None: + """ Augments the interface items with their interface domain. """ + for item in item_cache.items_by_type["interface/domain"]: + _visit_domain(item, item) + + _SELF_VALIDATION = { "memory-benchmark": "memory benchmark", "requirement/functional/action": "validation by test", @@ -220,3 +238,44 @@ def validate(item: Item) -> None: ["interface-ingroup", "interface-ingroup-hidden"]) _fixup_pre_qualified(item, ["interface/header-file"], "interface-placement") + + +def _is_proxy_link_enabled(link: Link) -> bool: + return link.item.is_enabled(link.item.cache.enabled) + + +class RTEMSItemCache(BuildItem): + """ + This build step augments the items with RTEMS-specific attributes and + links. + """ + + def __init__(self, director: PackageBuildDirector, item: Item): + super().__init__(director, item) + self.item_cache = self.item.cache + + # It is crucial to resolve the proxies before we use the recursive + # enabled below since unresolved proxy items have no links. + self.item_cache.resolve_proxies(_is_proxy_link_enabled) + self.item_cache.set_enabled(self.enabled_set, recursive_is_enabled) + + augment_with_test_links(self.item_cache) + augment_with_test_case_links(self.item_cache) + _augment_with_interface_domains(self.item_cache) + for glossary in ["/glossary-general", "/req/glossary"]: + augment_glossary_terms(self.item_cache[glossary], []) + validate(self.item_cache[self["spec-root-uid"]]) + + # Calculate the overall item cache hash. Ignore QDP configuration + # items and specification type changes. + state = hashlib.sha512() + for item_2 in sorted(self.item_cache.values()): + if not item_2.type.startswith(("qdp", "spec")): + state.update(item_2.digest.encode("ascii")) + self._hash = base64.urlsafe_b64encode(state.digest()).decode("ascii") + + def has_changed(self, link: Link) -> bool: + return link["hash"] is None or self._hash != link["hash"] + + def refresh_link(self, link: Link) -> None: + link["hash"] = self._hash diff --git a/rtemsspec/tests/spec-packagebuild/glossary-general.yml b/rtemsspec/tests/spec-packagebuild/glossary-general.yml new file mode 100644 index 00000000..df7d6499 --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/glossary-general.yml @@ -0,0 +1,12 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 +copyrights: +- Copyright (C) 2020 embedded brains GmbH & Co. KG +enabled-by: true +glossary-type: group +links: +- role: requirement-refinement + uid: /req/root +name: General +text: | + The system shall have a general glossary of terms. +type: glossary diff --git a/rtemsspec/tests/spec-packagebuild/qdp/package-build.yml b/rtemsspec/tests/spec-packagebuild/qdp/package-build.yml index 2af718ef..b97ccd14 100644 --- a/rtemsspec/tests/spec-packagebuild/qdp/package-build.yml +++ b/rtemsspec/tests/spec-packagebuild/qdp/package-build.yml @@ -3,6 +3,8 @@ copyrights: - Copyright (C) 2020 embedded brains GmbH & Co. KG enabled-by: true links: +- role: build-step + uid: steps/rtems-item-cache - role: build-step uid: steps/a - role: build-step diff --git a/rtemsspec/tests/spec-packagebuild/qdp/steps/a.yml b/rtemsspec/tests/spec-packagebuild/qdp/steps/a.yml index bf480a60..27ffb675 100644 --- a/rtemsspec/tests/spec-packagebuild/qdp/steps/a.yml +++ b/rtemsspec/tests/spec-packagebuild/qdp/steps/a.yml @@ -10,6 +10,10 @@ links: name: variant role: input uid: ../variant +- hash: null + name: spec + role: input + uid: rtems-item-cache - hash: null name: bar role: input-to diff --git a/rtemsspec/tests/spec-packagebuild/qdp/steps/rtems-item-cache.yml b/rtemsspec/tests/spec-packagebuild/qdp/steps/rtems-item-cache.yml new file mode 100644 index 00000000..6d042940 --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/qdp/steps/rtems-item-cache.yml @@ -0,0 +1,11 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-step-type: rtems-item-cache +copyrights: +- Copyright (C) 2023 embedded brains GmbH & Co. KG +description: | + Augment items. +enabled-by: true +links: [] +qdp-type: build-step +spec-root-uid: /req/root +type: qdp diff --git a/rtemsspec/tests/spec-packagebuild/req/glossary.yml b/rtemsspec/tests/spec-packagebuild/req/glossary.yml new file mode 100644 index 00000000..b9881ec6 --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/req/glossary.yml @@ -0,0 +1,12 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 +copyrights: +- Copyright (C) 2023 embedded brains GmbH & Co. KG +enabled-by: true +glossary-type: group +links: +- role: requirement-refinement + uid: root +name: Specification +text: | + The system shall have a glossary of specification-specific terms. +type: glossary diff --git a/rtemsspec/tests/spec-packagebuild/req/root.yml b/rtemsspec/tests/spec-packagebuild/req/root.yml new file mode 100644 index 00000000..0cb3ba69 --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/req/root.yml @@ -0,0 +1,12 @@ +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: [] +non-functional-type: design +rationale: null +references: [] +requirement-type: non-functional +text: | + The software product shall be a real-time operating system. +type: requirement diff --git a/rtemsspec/tests/spec-packagebuild/rtems/domain.yml b/rtemsspec/tests/spec-packagebuild/rtems/domain.yml new file mode 100644 index 00000000..908b51a0 --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/rtems/domain.yml @@ -0,0 +1,13 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +copyrights: +- Copyright (C) 2023 embedded brains GmbH & Co. KG +description: | + Description. +enabled-by: true +index-entries: [] +interface-type: domain +links: +- role: requirement-refinement + uid: ../req/root +name: Domain +type: interface diff --git a/rtemsspec/tests/spec-packagebuild/rtems/group-acfg.yml b/rtemsspec/tests/spec-packagebuild/rtems/group-acfg.yml new file mode 100644 index 00000000..80f2477f --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/rtems/group-acfg.yml @@ -0,0 +1,16 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +copyrights: +- Copyright (C) 2023 embedded brains GmbH & Co. KG +description: | + Description. +enabled-by: true +index-entries: [] +interface-type: appl-config-group +links: +- role: interface-placement + uid: domain +- role: requirement-refinement + uid: ../req/root +name: Name +text: '' +type: interface diff --git a/rtemsspec/tests/spec-packagebuild/rtems/group.yml b/rtemsspec/tests/spec-packagebuild/rtems/group.yml new file mode 100644 index 00000000..7f7864b7 --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/rtems/group.yml @@ -0,0 +1,19 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +brief: | + Brief. +copyrights: +- Copyright (C) 2023 embedded brains GmbH & Co. KG +description: null +enabled-by: true +identifier: Group +index-entries: [] +interface-type: group +links: +- role: interface-placement + uid: header +- role: requirement-refinement + uid: ../req/root +name: Name +text: | + Text. +type: interface diff --git a/rtemsspec/tests/spec-packagebuild/rtems/header.yml b/rtemsspec/tests/spec-packagebuild/rtems/header.yml new file mode 100644 index 00000000..503fdc03 --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/rtems/header.yml @@ -0,0 +1,16 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +brief: | + Brief. +copyrights: +- Copyright (C) 2023 embedded brains GmbH & Co. KG +enabled-by: true +index-entries: [] +interface-type: header-file +links: +- role: interface-placement + uid: domain +- role: interface-ingroup + uid: group +path: header.h +prefix: dir +type: interface diff --git a/rtemsspec/tests/spec-packagebuild/rtems/if.yml b/rtemsspec/tests/spec-packagebuild/rtems/if.yml new file mode 100644 index 00000000..0e1d67fe --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/rtems/if.yml @@ -0,0 +1,36 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +brief: | + Brief. +copyrights: +- Copyright (C) 2023 embedded brains GmbH & Co. KG +definition: + default: + attributes: null + body: | + return ${.:/params[0]/name}; + params: + - int ${.:/params[0]/name} + return: int + variants: [] +description: null +enabled-by: true +index-entries: [] +interface-type: function +links: +- role: proxy-member + uid: proxy +- role: interface-placement + uid: header +- role: interface-ingroup + uid: group +name: identity +notes: null +params: +- description: Parameter. + dir: null + name: param +return: + return: | + Returns. + return-values: [] +type: interface diff --git a/rtemsspec/tests/spec-packagebuild/rtems/proxy.yml b/rtemsspec/tests/spec-packagebuild/rtems/proxy.yml new file mode 100644 index 00000000..27c48bfb --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/rtems/proxy.yml @@ -0,0 +1,6 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +copyrights: +- Copyright (C) 2023 embedded brains GmbH & Co. KG +enabled-by: true +links: [] +type: proxy diff --git a/rtemsspec/tests/spec-packagebuild/rtems/req.yml b/rtemsspec/tests/spec-packagebuild/rtems/req.yml new file mode 100644 index 00000000..c27a4fb9 --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/rtems/req.yml @@ -0,0 +1,14 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 +copyrights: +- Copyright (C) 2023 embedded brains GmbH & Co. KG +enabled-by: true +links: +- role: interface-function + uid: proxy +functional-type: function +rationale: null +references: [] +requirement-type: functional +text: | + Text. +type: requirement diff --git a/rtemsspec/tests/spec-packagebuild/rtems/test-case.yml b/rtemsspec/tests/spec-packagebuild/rtems/test-case.yml new file mode 100644 index 00000000..910a28a4 --- /dev/null +++ b/rtemsspec/tests/spec-packagebuild/rtems/test-case.yml @@ -0,0 +1,34 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +copyrights: +- Copyright (C) 2023 embedded brains GmbH & Co. KG +enabled-by: true +links: [] +test-actions: +- action-brief: | + Brief. + action-code: | + int i; + checks: + - brief: | + Check. + code: | + T_eq_int( identity( i ), i ); + links: + - role: validation + uid: req + links: [] +test-brief: | + Brief. +test-context: [] +test-context-support: null +test-description: null +test-header: null +test-includes: +- header.h +test-local-includes: [] +test-setup: null +test-stop: null +test-support: null +test-target: testsuites/validation/tc-identity.c +test-teardown: null +type: test-case diff --git a/spec-qdp/spec/qdp-rtems-item-cache.yml b/spec-qdp/spec/qdp-rtems-item-cache.yml new file mode 100644 index 00000000..78f2ae2e --- /dev/null +++ b/spec-qdp/spec/qdp-rtems-item-cache.yml @@ -0,0 +1,27 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +copyrights: +- Copyright (C) 2023 embedded brains GmbH & Co. KG +enabled-by: true +links: +- role: spec-member + uid: root +- role: spec-refinement + spec-key: build-step-type + spec-value: rtems-item-cache + uid: qdp-build-step +spec-description: null +spec-example: null +spec-info: + dict: + attributes: + spec-root-uid: + description: | + It shall be the UID of the root specification item. + spec-type: str + description: | + This set of attributes specifies a build step to augment the items with + RTEMS-specific attributes and links. + mandatory-attributes: all +spec-name: RTEMS Item Cache Item Type +spec-type: qdp-rtems-item-cache +type: spec -- cgit v1.2.3