diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2022-07-27 15:52:12 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2022-07-27 17:21:50 +0200 |
commit | b2bc5dd3ecb14c48a973df59e28b6097a4823f2b (patch) | |
tree | f5a2d69a7978c82a7f09597553215cd6da68b9b8 | |
parent | spec: Clarify priority boosting (diff) | |
download | rtems-central-b2bc5dd3ecb14c48a973df59e28b6097a4823f2b.tar.bz2 |
rtemsspec: Module for RTEMS specification details
-rw-r--r-- | rtemsspec/items.py | 13 | ||||
-rw-r--r-- | rtemsspec/rtems.py | 40 | ||||
-rw-r--r-- | rtemsspec/tests/test_items_itemcache.py | 4 | ||||
-rw-r--r-- | rtemsspec/tests/test_rtems.py | 43 | ||||
-rwxr-xr-x | specview.py | 19 |
5 files changed, 99 insertions, 20 deletions
diff --git a/rtemsspec/items.py b/rtemsspec/items.py index cd6846d1..d9cee00b 100644 --- a/rtemsspec/items.py +++ b/rtemsspec/items.py @@ -673,19 +673,26 @@ class ItemCache: """ Returns the types of the items. """ return self._types - def add_volatile_item(self, path: str, uid: str) -> Item: + def add_volatile_item(self, uid: str, data: Any) -> Item: """ - Adds an item stored in the specified file to the cache and returns it. + Adds an item with the specified data to the cache and returns it. The item is not added to the persistent cache storage. """ - data = _load_item(path, uid) item = self._add_item(uid, data) item.init_parents(self) item.init_children() self._set_type(item) return item + def add_volatile_item_from_file(self, uid: str, path: str) -> Item: + """ + Adds an item stored in the specified file to the cache and returns it. + + The item is not added to the persistent cache storage. + """ + return self.add_volatile_item(uid, _load_item(path, uid)) + def _add_item(self, uid: str, data: Any) -> Item: item = Item(self, uid, data) self._items[uid] = item diff --git a/rtemsspec/rtems.py b/rtemsspec/rtems.py new file mode 100644 index 00000000..910b3aa1 --- /dev/null +++ b/rtemsspec/rtems.py @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: BSD-2-Clause +""" This module provides details of the RTEMS specification. """ + +# Copyright (C) 2021, 2022 embedded brains GmbH (http://www.embedded-brains.de) +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +from rtemsspec.items import Item + +_NOT_PRE_QUALIFIED = set([ + "/acfg/constraint/option-not-pre-qualified", + "/constraint/constant-not-pre-qualified", + "/constraint/directive-not-pre-qualified", +]) + + +def is_pre_qualified(item: Item) -> bool: + """ Returns true, if the item is pre-qualified, otherwise false. """ + return not bool( + set(parent.uid for parent in item.parents("constraint")).intersection( + _NOT_PRE_QUALIFIED)) diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py index 2636286d..1b8e8f14 100644 --- a/rtemsspec/tests/test_items_itemcache.py +++ b/rtemsspec/tests/test_items_itemcache.py @@ -71,8 +71,8 @@ def test_load(tmpdir): item_cache_3 = ItemCache(config) assert item_cache_3.updates assert item_cache_3["/d/c"]["v"] == "x" - item = item_cache_3.add_volatile_item( - os.path.join(os.path.dirname(__file__), "spec/root.yml"), "/foo/bar") + item = item_cache_3.add_volatile_item_from_file( + "/foo/bar", os.path.join(os.path.dirname(__file__), "spec/root.yml")) assert item.uid == "/foo/bar" assert item.type == "" assert item["type"] == "spec" diff --git a/rtemsspec/tests/test_rtems.py b/rtemsspec/tests/test_rtems.py new file mode 100644 index 00000000..ee16fc67 --- /dev/null +++ b/rtemsspec/tests/test_rtems.py @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: BSD-2-Clause +""" Unit tests for the rtemsspec.rtems module. """ + +# Copyright (C) 2022 embedded brains GmbH (http://www.embedded-brains.de) +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +import pytest + +from rtemsspec.items import EmptyItemCache, Item +from rtemsspec.rtems import is_pre_qualified + + +def test_is_pre_qualified(): + item_cache = EmptyItemCache() + uid = "/constraint/constant-not-pre-qualified" + constraint = item_cache.add_volatile_item(uid, {"links": []}) + assert is_pre_qualified(constraint) + item = item_cache.add_volatile_item( + "/i", {"links": [{ + "role": "constraint", + "uid": uid + }]}) + assert not is_pre_qualified(item) diff --git a/specview.py b/specview.py index 2f4560e9..c3217100 100755 --- a/specview.py +++ b/specview.py @@ -32,9 +32,10 @@ from typing import Any, Dict, List, Optional, Set, Tuple from rtemsspec.items import EmptyItem, Item, ItemCache, ItemMapper, \ ItemGetValueContext, Link +from rtemsspec.rtems import is_pre_qualified from rtemsspec.sphinxcontent import SphinxContent -from rtemsspec.util import load_config from rtemsspec.transitionmap import Transition, TransitionMap +from rtemsspec.util import load_config _CHILD_ROLES = [ "requirement-refinement", "interface-ingroup", "interface-ingroup-hidden", @@ -171,18 +172,6 @@ _VALIDATION_LEAF = [ "validation", ] -_NOT_PRE_QUALIFIED = set([ - "/acfg/constraint/option-not-pre-qualified", - "/constraint/constant-not-pre-qualified", - "/constraint/directive-not-pre-qualified", -]) - - -def _is_pre_qualified(item: Item) -> bool: - return not bool( - set(parent.uid for parent in item.parents("constraint")).intersection( - _NOT_PRE_QUALIFIED)) - def _validation_count(item: Item, enabled: List[str]) -> int: return len( @@ -201,7 +190,7 @@ def _validate(item: Item, enabled: List[str]) -> bool: if parent.is_enabled(enabled): validated = _validate(parent, enabled) and validated count += 1 - pre_qualified = _is_pre_qualified(item) + pre_qualified = is_pre_qualified(item) item["_pre_qualified"] = pre_qualified if count == 0: if not pre_qualified: @@ -400,7 +389,7 @@ _API_ROLES = [ def _gather_api_names(item: Item, names: Dict[str, List[str]]) -> None: - if item.type in _API_INTERFACES and _is_pre_qualified(item): + if item.type in _API_INTERFACES and is_pre_qualified(item): group = names.setdefault(item.parent(_API_ROLES)["name"], []) group.append(item["name"]) for child in item.children(_API_ROLES): |