#! /usr/bin/env python3 # # 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/build.sh - Test build and install targets # # Copyright Red Hat # Author: David Gibson import contextlib import os.path import shutil import subprocess import tempfile import exeter def host_run(*cmd, **kwargs): return subprocess.run(cmd, check=True, encoding='UTF-8', **kwargs) def host_out(*cmd, **kwargs): return host_run(*cmd, capture_output=True, **kwargs).stdout @contextlib.contextmanager def clone_source_tree(): with tempfile.TemporaryDirectory(ignore_cleanup_errors=False) as tmpdir: # Make a temporary copy of the sources srcfiles = host_out('git', 'ls-files').splitlines() for src in srcfiles: dst = os.path.join(tmpdir, src) os.makedirs(os.path.dirname(dst), exist_ok=True) shutil.copy(src, dst) os.chdir(tmpdir) yield tmpdir def build_target(target, outputs): with clone_source_tree(): for o in outputs: assert not os.path.exists(o) host_run('make', f'{target}', 'CFLAGS="-Werror"') for o in outputs: assert os.path.exists(o) host_run('make', 'clean') for o in outputs: assert not os.path.exists(o) @exeter.test def test_make_passt(): build_target('passt', ['passt']) @exeter.test def test_make_pasta(): build_target('pasta', ['pasta']) @exeter.test def test_make_qrap(): build_target('qrap', ['qrap']) @exeter.test def test_make_all(): build_target('all', ['passt', 'pasta', 'qrap']) @exeter.test def test_make_install_uninstall(): with clone_source_tree(): with tempfile.TemporaryDirectory(ignore_cleanup_errors=False) \ as prefix: bindir = os.path.join(prefix, 'bin') mandir = os.path.join(prefix, 'share', 'man') exes = ['passt', 'pasta', 'qrap'] # Install host_run('make', 'install', 'CFLAGS="-Werror"', f'prefix={prefix}') for t in exes: assert os.path.isfile(os.path.join(bindir, t)) host_run('man', '-M', f'{mandir}', '-W', 'passt') # Uninstall host_run('make', 'uninstall', f'prefix={prefix}') for t in exes: assert not os.path.exists(os.path.join(bindir, t)) cmd = ['man', '-M', f'{mandir}', '-W', 'passt'] exeter.assert_raises(subprocess.CalledProcessError, host_run, *cmd) if __name__ == '__main__': exeter.main()