support/testing/tests/package/test_gnuradio.py: new runtime test

Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Julien Olivain 2023-07-22 18:17:08 +02:00 committed by Thomas Petazzoni
parent e22b450692
commit ca3c4d0007
3 changed files with 112 additions and 0 deletions

View File

@ -1742,6 +1742,8 @@ F: support/testing/tests/package/test_ddrescue/
F: support/testing/tests/package/test_dos2unix.py
F: support/testing/tests/package/test_gawk.py
F: support/testing/tests/package/test_gnupg2.py
F: support/testing/tests/package/test_gnuradio.py
F: support/testing/tests/package/test_gnuradio/
F: support/testing/tests/package/test_gzip.py
F: support/testing/tests/package/test_highway.py
F: support/testing/tests/package/test_hwloc.py

View File

@ -0,0 +1,42 @@
import os
import infra.basetest
class TestGnuradio(infra.basetest.BRTest):
# infra.basetest.BASIC_TOOLCHAIN_CONFIG cannot be used as it does
# not include: BR2_TOOLCHAIN_SUPPORTS_ALWAYS_LOCKFREE_ATOMIC_INTS
# needed by gnuradio
config = \
"""
BR2_aarch64=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.39"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
BR2_PACKAGE_GNURADIO=y
BR2_PACKAGE_GNURADIO_BLOCKS=y
BR2_PACKAGE_GNURADIO_PYTHON=y
BR2_PACKAGE_PYTHON3=y
BR2_ROOTFS_OVERLAY="{}"
BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ROOTFS_CPIO_GZIP=y
# BR2_TARGET_ROOTFS_TAR is not set
""".format(
# overlay to add a gnuradio python test script
infra.filepath("tests/package/test_gnuradio/rootfs-overlay"))
def test_run(self):
img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
kern = os.path.join(self.builddir, "images", "Image")
self.emulator.boot(arch="aarch64",
kernel=kern,
kernel_cmdline=["console=ttyAMA0"],
options=["-M", "virt", "-cpu", "cortex-a57", "-m", "256M", "-initrd", img])
self.emulator.login()
self.assertRunOk("/root/test_gnuradio.py", timeout=30)

View File

@ -0,0 +1,68 @@
#! /usr/bin/env python3
from gnuradio import blocks
from gnuradio import gr
INPUT_LENGTH = 100
MUL_CONST = 3
ADD_CONST = 5
def compute_expected_data(input_data):
# demux input
even = input_data[::2]
odd = input_data[1::2]
# multiply "even" list by MUL_CONST
even = [x * MUL_CONST for x in even]
# add 5 to all "odd" elements
odd = [y + ADD_CONST for y in odd]
# mux the two lists
mux = [v for t in zip(even, odd) for v in t]
return mux
def main():
gr.log.info("Starting Buildroot Test for GNU Radio " + gr.version())
input_data = list(range(INPUT_LENGTH))
tb = gr.top_block()
# Create Gnuradio Blocks
src = blocks.vector_source_i(input_data)
demux = blocks.deinterleave(gr.sizeof_int)
mul = blocks.multiply_const_ii(MUL_CONST)
add = blocks.add_const_ii(ADD_CONST)
mux = blocks.interleave(gr.sizeof_int)
sink = blocks.vector_sink_i()
# Create connection in top block
tb.connect(src, demux)
tb.connect((demux, 0), mul)
tb.connect((demux, 1), add)
tb.connect(mul, (mux, 0))
tb.connect(add, (mux, 1))
tb.connect(mux, sink)
tb.run()
gnuradio_data = sink.data()
expected_data = compute_expected_data(input_data)
# For easy debugging
if gnuradio_data != expected_data:
print("Gnuradio output:", gnuradio_data)
print("Expected output:", expected_data)
assert gnuradio_data == expected_data
gr.log.info("Test PASSED")
if __name__ == "__main__":
main()