[rtems-central commit] specview.py: New script
Sebastian Huber
sebh at rtems.org
Thu Jan 21 06:54:55 UTC 2021
Module: rtems-central
Branch: master
Commit: 8b6d19e721b9432c6ec2e26746cb9f2c3f3c8743
Changeset: http://git.rtems.org/rtems-central/commit/?id=8b6d19e721b9432c6ec2e26746cb9f2c3f3c8743
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Thu Jan 21 07:54:02 2021 +0100
specview.py: New script
---
specview.py | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 118 insertions(+)
diff --git a/specview.py b/specview.py
new file mode 100755
index 0000000..0189155
--- /dev/null
+++ b/specview.py
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: BSD-2-Clause
+""" Views the specification. """
+
+# Copyright (C) 2021 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 argparse
+import sys
+from typing import List, Set
+
+from rtemsspec.items import Item, ItemCache, Link
+from rtemsspec.util import load_config
+
+_CHILD_ROLES = [
+ "requirement-refinement", "interface-ingroup", "interface-function",
+ "validation", "appl-config-group-member"
+]
+
+_PARENT_ROLES = ["interface-enumerator", "interface-placement"]
+
+
+def _view(item: Item, level: int) -> None:
+ print(f"{' ' * level}{item.uid}")
+ for child in item.children(_CHILD_ROLES):
+ _view(child, level + 1)
+
+
+def _no_validation(item: Item, path: List[str]) -> List[str]:
+ leaf = True
+ path_2 = path + [item.uid]
+ for child in item.children(_CHILD_ROLES):
+ path_2 = _no_validation(child, path_2)
+ leaf = False
+ if leaf and item.type not in [
+ "requirement/functional/action", "test-case", "test-suite"
+ ]:
+ for index, component in enumerate(path_2):
+ if component:
+ print(f"{' ' * index}{component}")
+ path_2[index] = ""
+ return path_2[:-1]
+
+
+def _gather(item: Item, spec: Set) -> None:
+ spec.add(item)
+ for child in item.children(_CHILD_ROLES):
+ _gather(child, spec)
+ for parent in item.parents(_PARENT_ROLES):
+ _gather(parent, spec)
+
+
+def _add_link(item_cache: ItemCache, child: Item, link: Link) -> None:
+ parent = item_cache[child.to_abs_uid(link["uid"])]
+ parent.add_link_to_child(Link(child, link))
+
+
+def _process_test_cases(item_cache: ItemCache) -> None:
+ for item in item_cache.all.values():
+ if item.type == "test-case":
+ for actions in item["test-actions"]:
+ for checks in actions["checks"]:
+ for link in checks["links"]:
+ _add_link(item_cache, item, link)
+ for link in actions["links"]:
+ _add_link(item_cache, item, link)
+
+
+def main() -> None:
+ """ Views the specification. """
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--filter',
+ choices=["none", "orphan", "no-validation"],
+ type=str.lower,
+ default="none",
+ help="filter the items")
+ args = parser.parse_args(sys.argv[1:])
+ config = load_config("config.yml")
+ item_cache = ItemCache(config["spec"])
+ _process_test_cases(item_cache)
+ root = item_cache["/req/root"]
+
+ if args.filter == "none":
+ _view(root, 0)
+ elif args.filter == "orphan":
+ spec = set() # type: Set[Item]
+ _gather(root, spec)
+ for item in item_cache.all.values():
+ if item["type"] in ["build", "glossary", "spec"]:
+ continue
+ if item not in spec:
+ print(item.uid)
+ elif args.filter == "no-validation":
+ _no_validation(root, [])
+
+
+if __name__ == "__main__":
+ main()
More information about the vc
mailing list