#! /usr/bin/python3 # SPDX-License-Identifier: GPL-2.0-or-later # # avocado/build.py - Test various make targets # # Copyright Red Hat # Author: David Gibson import contextlib import os import os.path import shutil import sys import tempfile import tasst from tasst.site import CmdError, REAL_HOST @contextlib.contextmanager def clone_source_tree(where): REAL_HOST.require_cmds('git', 'make') with tempfile.TemporaryDirectory(dir=where, ignore_cleanup_errors=False) as tmpdir: # Make a temporary copy of the sources srcfiles = REAL_HOST.output('git ls-files').decode('utf-8').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 class BuildTasst(tasst.Tasst): # Some of these can take a little while timeout = 60.0 def build_target(self, target, outputs): with clone_source_tree(self.workdir): self.assertFalse(any(os.path.exists(o) for o in outputs)) REAL_HOST.fg('make {} CFLAGS="-Werror"'.format(target)) self.assertTrue(all(os.path.exists(o) for o in outputs)) REAL_HOST.fg('make clean') self.assertFalse(any(os.path.exists(o) for o in outputs)) def test_make_passt(self): self.build_target('passt', ['passt']) def test_make_pasta(self): self.build_target('pasta', ['pasta']) def test_make_qrap(self): self.build_target('qrap', ['qrap']) def test_make_all(self): self.build_target('all', ['passt', 'pasta', 'qrap']) def test_make_install_uninstall(self): with clone_source_tree(self.workdir): with tempfile.TemporaryDirectory(dir=self.workdir, ignore_cleanup_errors=False) as prefix: bindir = os.path.join(prefix, 'bin') mandir = os.path.join(prefix, 'share', 'man') exes = ['passt', 'pasta', 'qrap'] # Install REAL_HOST.fg('make install CFLAGS="-Werror" prefix={}'.format(prefix)) for t in exes: self.assertTrue(os.path.isfile(os.path.join(bindir, t))) REAL_HOST.fg('man -M {} -W passt'.format(mandir)) # Uninstall REAL_HOST.fg('make uninstall prefix={}'.format(prefix)) for t in exes: self.assertFalse(os.path.exists(os.path.join(bindir, t))) self.assertRaises(CmdError, REAL_HOST.fg, 'man -M {} -W passt'.format(mandir))