[rtems-central commit] specview.py: Improve item enablement

Sebastian Huber sebh at rtems.org
Tue May 9 13:45:27 UTC 2023


Module:    rtems-central
Branch:    master
Commit:    0708b86080e44e487c62f18c9185bbc6b5e771ce
Changeset: http://git.rtems.org/rtems-central/commit/?id=0708b86080e44e487c62f18c9185bbc6b5e771ce

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri May  5 14:41:20 2023 +0200

specview.py: Improve item enablement

---

 rtemsspec/rtems.py            | 30 +++++++++++++++++++++++++--
 rtemsspec/tests/test_rtems.py | 47 ++++++++++++++++++++++++++++++++++++++++++-
 specview.py                   | 14 ++++---------
 3 files changed, 78 insertions(+), 13 deletions(-)

diff --git a/rtemsspec/rtems.py b/rtemsspec/rtems.py
index 79954c8c..c62f8fd3 100644
--- a/rtemsspec/rtems.py
+++ b/rtemsspec/rtems.py
@@ -24,9 +24,9 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
-from typing import Any
+from typing import Any, List
 
-from rtemsspec.items import create_unique_link, Item, ItemCache
+from rtemsspec.items import create_unique_link, Item, ItemCache, Link
 
 _NOT_PRE_QUALIFIED = set([
     "/acfg/constraint/option-not-pre-qualified",
@@ -42,6 +42,32 @@ def is_pre_qualified(item: Item) -> bool:
             _NOT_PRE_QUALIFIED))
 
 
+_ENABLEMENT_ROLES = [
+    "interface-function", "interface-ingroup", "interface-ingroup-hidden",
+    "requirement-refinement", "validation"
+]
+
+
+def _link_is_enabled(_link: Link) -> bool:
+    return True
+
+
+def recursive_is_enabled(enabled: List[str], item: Item) -> bool:
+    """
+    Returns true, if the item is enabled and there exists a path to the root
+    item where each item on the path is enabled, otherwise false.
+    """
+    if not item.is_enabled(enabled):
+        return False
+    result = True
+    for parent in item.parents(_ENABLEMENT_ROLES,
+                               is_link_enabled=_link_is_enabled):
+        if recursive_is_enabled(enabled, parent):
+            return True
+        result = False
+    return result
+
+
 def _add_link(item_cache: ItemCache, child: Item, data: Any) -> None:
     parent = item_cache[child.to_abs_uid(data["uid"])]
     create_unique_link(child, parent, data)
diff --git a/rtemsspec/tests/test_rtems.py b/rtemsspec/tests/test_rtems.py
index f13e63ba..92f41ee1 100644
--- a/rtemsspec/tests/test_rtems.py
+++ b/rtemsspec/tests/test_rtems.py
@@ -27,7 +27,8 @@
 import pytest
 
 from rtemsspec.items import EmptyItemCache, Item
-from rtemsspec.rtems import augment_with_test_links, is_pre_qualified
+from rtemsspec.rtems import augment_with_test_links, is_pre_qualified, \
+    recursive_is_enabled
 
 
 def test_is_pre_qualified():
@@ -72,3 +73,47 @@ def test_augment_with_test_links():
     augment_with_test_links(item_cache)
     assert item.child("validation") == test_case
     assert test_case.parent("validation") == item
+
+
+def test_recursive_is_enabled():
+    item_cache = EmptyItemCache()
+    a = item_cache.add_volatile_item("/a", {"enabled-by": True, "links": []})
+    b = item_cache.add_volatile_item(
+        "/b", {
+            "enabled-by": False,
+            "links": [{
+                "role": "requirement-refinement",
+                "uid": "/a"
+            }]
+        })
+    c = item_cache.add_volatile_item(
+        "/c", {
+            "enabled-by": True,
+            "links": [{
+                "role": "requirement-refinement",
+                "uid": "/a"
+            }]
+        })
+    d = item_cache.add_volatile_item(
+        "/d", {
+            "enabled-by":
+            True,
+            "links": [{
+                "role": "requirement-refinement",
+                "uid": "/b"
+            }, {
+                "role": "requirement-refinement",
+                "uid": "/c"
+            }]
+        })
+    e = item_cache.add_volatile_item(
+        "/e", {
+            "enabled-by": True,
+            "links": [{
+                "role": "requirement-refinement",
+                "uid": "/b"
+            }]
+        })
+    item_cache.set_enabled([], recursive_is_enabled)
+    assert d.enabled
+    assert not e.enabled
diff --git a/specview.py b/specview.py
index 48ba9b8f..f38afc73 100755
--- a/specview.py
+++ b/specview.py
@@ -32,7 +32,8 @@ from typing import Any, Dict, List, Optional, Set, Tuple
 
 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, is_pre_qualified, \
+    recursive_is_enabled
 from rtemsspec.sphinxcontent import SphinxContent
 from rtemsspec.transitionmap import Transition, TransitionMap
 from rtemsspec.util import load_config
@@ -204,13 +205,6 @@ _VALIDATION_LEAF = [
 _VALIDATION_ROLES = _CHILD_ROLES + ["validation"]
 
 
-def _is_enabled(item: Item) -> bool:
-    result = item.enabled
-    for parent in item.parents("interface-placement"):
-        result = result and _is_enabled(parent)
-    return result
-
-
 def _validate_tree(item: Item) -> bool:
     pre_qualified = is_pre_qualified(item)
     item["_pre_qualified"] = pre_qualified
@@ -231,7 +225,7 @@ def _validate_containers(item: Item) -> None:
             item.cache.items_by_type["interface/domain"],
             item.cache.items_by_type["interface/header-file"]):
         for item_3 in item_2.children("interface-placement"):
-            if _is_enabled(item_3) and not item_3["_validated"]:
+            if not item_3["_validated"]:
                 item_2["_validated"] = False
                 break
 
@@ -466,7 +460,7 @@ def main() -> None:
     args = parser.parse_args(sys.argv[1:])
     config = load_config("config.yml")["spec"]
     config["enabled"] = args.enabled.split(",") if args.enabled else []
-    item_cache = ItemCache(config)
+    item_cache = ItemCache(config, is_item_enabled=recursive_is_enabled)
     augment_with_test_links(item_cache)
     augment_with_test_case_links(item_cache)
     root = item_cache["/req/root"]



More information about the vc mailing list