Move the build and make install tests from the old hand-rolled test harness to avocado. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- Makefile | 1 + avocado/.gitignore | 1 + avocado/build.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++ avocado/common.py | 31 +++++++++++++++++ oldtest/run | 2 +- test/build/all | 61 ---------------------------------- test/lib/setup | 7 ---- test/run | 4 --- 8 files changed, 117 insertions(+), 73 deletions(-) create mode 100644 avocado/.gitignore create mode 100644 avocado/build.py create mode 100644 avocado/common.py delete mode 100644 test/build/all diff --git a/Makefile b/Makefile index 0fd9fe9..b860a85 100644 --- a/Makefile +++ b/Makefile @@ -135,6 +135,7 @@ clean: $(RM) $(BIN) *~ *.o seccomp.h pasta.1 \ passt.tar passt.tar.gz *.deb *.rpm \ passt.pid README.plain.md + $(RM) -r avocado/__pycache__ install: $(BIN) $(MANPAGES) docs mkdir -p $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir) diff --git a/avocado/.gitignore b/avocado/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/avocado/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/avocado/build.py b/avocado/build.py new file mode 100644 index 0000000..c3cb596 --- /dev/null +++ b/avocado/build.py @@ -0,0 +1,83 @@ +#! /usr/bin/python3 + +# SPDX-License-Identifier: GPL-2.0-or-later +# +# avocado/build.py - Tests for various make targets +# +# Copyright Red Hat +# Author: David Gibson <david(a)gibson.dropbear.id.au> + +import os +import os.path +import shutil +import sys + +import avocado + +import common + + +class BuildTest(common.BaseTest): + # Some of these can take a little while + timeout = 30.0 + + def setUp(self): + super().setUp() + + # Make a temporary copy of the sources + srcfiles = self.hostx('git ls-files').splitlines() + for src in srcfiles: + dst = os.path.join(bytes(self.workdir, 'utf-8'), src) + os.makedirs(os.path.dirname(dst), exist_ok=True) + shutil.copy(src, dst) + os.chdir(self.workdir) + + def build_target(self, target, outputs=None): + if outputs is None: + outputs = [target] + for o in outputs: + self.assertFalse(os.path.exists(o)) + self.hostx('make {} CFLAGS="-Werror"'.format(target)) + for o in outputs: + self.assertTrue(os.path.isfile(o)) + self.hostx('make clean') + for o in outputs: + self.assertFalse(os.path.exists(o)) + + def test_make_passt(self): + self.build_target('passt') + + def test_make_pasta(self): + self.build_target('pasta') + + def test_make_qrap(self): + self.build_target('qrap') + + def test_make_all(self): + self.build_target('all', ['passt', 'pasta', 'qrap']) + + def test_make_install_uninstall(self): + prefix = os.path.join(self.workdir, "prefix") + os.makedirs(prefix) + + # Install + self.hostx('make install CFLAGS="-Werror" prefix={}'.format(prefix)) + self.assertTrue(os.path.isfile(os.path.join(prefix, 'bin/passt'))) + self.assertTrue(os.path.isfile(os.path.join(prefix, 'bin/pasta'))) + self.assertTrue(os.path.isfile(os.path.join(prefix, 'bin/qrap'))) + mandir = os.path.join(prefix, 'share/man') + self.hostx('man -M {} -W passt'.format(mandir)) + self.hostx('man -M {} -W pasta'.format(mandir)) + self.hostx('man -M {} -W qrap'.format(mandir)) + + # Uninstall + self.hostx('make uninstall prefix={}'.format(prefix)) + self.assertFalse(os.path.exists(os.path.join(prefix, 'bin/passt'))) + self.assertFalse(os.path.exists(os.path.join(prefix, 'bin/pasta'))) + self.assertFalse(os.path.exists(os.path.join(prefix, 'bin/qrap'))) + self.assertRaises(avocado.utils.process.CmdError, + self.hostx, 'man -M {} -W passt'.format(mandir)) + self.assertRaises(avocado.utils.process.CmdError, + self.hostx, 'man -M {} -W pasta'.format(mandir)) + self.assertRaises(avocado.utils.process.CmdError, + self.hostx, 'man -M {} -W qrap'.format(mandir)) diff --git a/avocado/common.py b/avocado/common.py new file mode 100644 index 0000000..036ef3d --- /dev/null +++ b/avocado/common.py @@ -0,0 +1,31 @@ +#! /usr/bin/python3 + +# SPDX-License-Identifier: GPL-2.0-or-later +# +# avocado/common.py - Avocado test helper routines +# +# Copyright Red Hat +# Author: David Gibson <david(a)gibson.dropbear.id.au> + +import avocado +from avocado.utils.process import system_output, CmdError + + +class BaseTest(avocado.Test): + # Fairly short timeout by default + timeout = 5.0 + + def hostx(self, cmd, **kwargs): + return system_output(cmd, **kwargs) + + +# +# Tests for the test infrastructure itself +# + +class HostExecTests(BaseTest): + def test_true(self): + self.hostx('true') + + def test_false(self): + self.assertRaises(CmdError, self.hostx, 'false') diff --git a/oldtest/run b/oldtest/run index 56fcd1b..a16bc49 100755 --- a/oldtest/run +++ b/oldtest/run @@ -65,7 +65,7 @@ run() { [ ${CI} -eq 1 ] && video_start ci setup build -# test build/all + test build/all test build/cppcheck test build/clang_tidy teardown build diff --git a/test/build/all b/test/build/all deleted file mode 100644 index 1f79e0d..0000000 --- a/test/build/all +++ /dev/null @@ -1,61 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# -# PASST - Plug A Simple Socket Transport -# for qemu/UNIX domain socket mode -# -# PASTA - Pack A Subtle Tap Abstraction -# for network namespace/tap device mode -# -# test/build/all - Build targets, one by one, then all together, check output -# -# Copyright (c) 2021 Red Hat GmbH -# Author: Stefano Brivio <sbrivio(a)redhat.com> - -htools make cc rm uname getconf mkdir cp rm man - -test Build passt -host make clean -check ! [ -e passt ] -host CFLAGS="-Werror" make passt -check [ -f passt ] - -test Build pasta -host make clean -check ! [ -e pasta ] -host CFLAGS="-Werror" make pasta -check [ -h pasta ] - -test Build qrap -host make clean -check ! [ -e qrap ] -host CFLAGS="-Werror" make qrap -check [ -f qrap ] - -test Build all -host make clean -check ! [ -e passt ] -check ! [ -e pasta ] -check ! [ -e qrap ] -host CFLAGS="-Werror" make -check [ -f passt ] -check [ -h pasta ] -check [ -f qrap ] - -test Install -host mkdir __STATEDIR__/prefix -host prefix=__STATEDIR__/prefix make install -check [ -f __STATEDIR__/prefix/bin/passt ] -check [ -h __STATEDIR__/prefix/bin/pasta ] -check [ -f __STATEDIR__/prefix/bin/qrap ] -check man -M __STATEDIR__/prefix/share/man -W passt -check man -M __STATEDIR__/prefix/share/man -W pasta -check man -M __STATEDIR__/prefix/share/man -W qrap - -test Uninstall -host prefix=__STATEDIR__/prefix make uninstall -check ! [ -f __STATEDIR__/prefix/bin/passt ] -check ! [ -h __STATEDIR__/prefix/bin/pasta ] -check ! [ -f __STATEDIR__/prefix/bin/qrap ] -check ! man -M __STATEDIR__/prefix/share/man -W passt 2>/dev/null -check ! man -M __STATEDIR__/prefix/share/man -W pasta 2>/dev/null -check ! man -M __STATEDIR__/prefix/share/man -W qrap 2>/dev/null diff --git a/test/lib/setup b/test/lib/setup index 9b39b9f..5386805 100755 --- a/test/lib/setup +++ b/test/lib/setup @@ -18,13 +18,6 @@ VCPUS="$( [ $(nproc) -ge 8 ] && echo 6 || echo $(( $(nproc) / 2 + 1 )) )" __mem_kib="$(sed -n 's/MemTotal:[ ]*\([0-9]*\) kB/\1/p' /proc/meminfo)" VMEM="$((${__mem_kib} / 1024 / 4))" -# setup_build() - Set up pane layout for build tests -setup_build() { - context_setup_host host - - layout_host -} - # setup_passt() - Start qemu and passt setup_passt() { context_setup_host host diff --git a/test/run b/test/run index ce24f44..b800022 100755 --- a/test/run +++ b/test/run @@ -64,10 +64,6 @@ run() { perf_init [ ${CI} -eq 1 ] && video_start ci - setup build - test build/all - teardown build - setup pasta test pasta/ndp test pasta/dhcp -- 2.40.0