summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHåkon Vågsether <hauk142@gmail.com>2021-02-11 13:18:22 +0100
committermormj <34754695+mormj@users.noreply.github.com>2021-05-20 07:14:29 -0400
commitb930b98f7c3847305f7fcae43785a2c6a27fe6d4 (patch)
treeef37fdd003d2e80c5055c768dba19d16ef913ab1
parent91ccd28abae6727509e88ff60032057483ac1b90 (diff)
grc: Test all in-tree examples
Signed-off-by: Håkon Vågsether <hauk142@gmail.com>
-rw-r--r--grc/tests/test_examples.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/grc/tests/test_examples.py b/grc/tests/test_examples.py
new file mode 100644
index 0000000000..ac45adcd55
--- /dev/null
+++ b/grc/tests/test_examples.py
@@ -0,0 +1,67 @@
+import os
+
+from os import path
+
+import pytest
+
+from grc.core.platform import Platform
+
+try:
+ os.mkdir(path.join(path.dirname(__file__), 'resources/tests'))
+except FileExistsError:
+ pass
+
+# Gather blocks
+BLOCK_PATHS = []
+ROOT = path.join(path.dirname(__file__), '../..')
+BLOCK_PATHS = [path.join(path.dirname(__file__), '../../grc/blocks'), '../../build/gr-uhd/grc']
+for file_dir in os.scandir(ROOT):
+ # If it is a module
+ if path.isdir(file_dir) and file_dir.name.startswith("gr-"):
+ BLOCK_PATHS.append(path.join(file_dir, "grc"))
+
+def gather_examples():
+ global ROOT
+ example_paths = []
+ for file_dir in os.scandir(ROOT):
+ # If it is a module
+ if path.isdir(file_dir) and file_dir.name.startswith("gr-"):
+ try:
+ for pos_ex in os.scandir(path.join(file_dir, "examples")):
+ if path.isfile(pos_ex) and pos_ex.name.endswith(".grc"):
+ example_paths.append(pos_ex)
+
+ # Some modules have their .grc files in a subdirectory called "grc"
+ for pos_ex in os.scandir(path.join(file_dir, "examples/grc")):
+ if path.isfile(pos_ex) and pos_ex.name.endswith(".grc"):
+ example_paths.append(pos_ex)
+ except FileNotFoundError:
+ continue
+ return example_paths
+
+def print_proper(element):
+ if element.is_block:
+ return element.name
+ return f"{element.parent.name} - {element}"
+
+@pytest.mark.parametrize("example", gather_examples())
+def test_all_examples(example):
+ global BLOCK_PATHS
+
+ print(example.path)
+
+ platform = Platform(
+ name='GNU Radio Companion Compiler',
+ prefs=None,
+ version='0.0.0',
+ )
+ platform.build_library(BLOCK_PATHS)
+
+ flow_graph = platform.make_flow_graph(example.path)
+ flow_graph.rewrite()
+ flow_graph.validate()
+
+ assert flow_graph.is_valid(), (example.name, [f"{print_proper(elem)}: {msg}" for elem, msg in flow_graph.iter_error_messages()])
+
+ generator = platform.Generator(flow_graph, path.join(path.dirname(__file__), 'resources/tests'))
+ generator.write()