Skip to content

Instantly share code, notes, and snippets.

@haakov
Last active February 1, 2021 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haakov/ad0bedfa68229dc7ea1479861850b72e to your computer and use it in GitHub Desktop.
Save haakov/ad0bedfa68229dc7ea1479861850b72e to your computer and use it in GitHub Desktop.
Test all in-tree GNU Radio examples
# Copyright 2016 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
import pytest
import os
from os import path
import tempfile
from grc.core.platform import Platform
# Gather blocks
block_paths = []
root = path.join(path.dirname(__file__), '../..')
block_paths = [path.join(path.dirname(__file__), '../../grc/blocks')]
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():
root = path.join(path.dirname(__file__), '../..')
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)
except FileNotFoundError:
continue
return example_paths
def print_proper(element):
if element.is_block:
return element.name
else:
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'))
generator.write()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment