1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
| | #! /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 <david@gibson.dropbear.id.au>
import contextlib
import os
from pathlib import Path
import tempfile
from typing import Iterable, Iterator
import exeter
import tasst.cmdsite
# For convenience
sh = tasst.cmdsite.BUILD_HOST.sh
@contextlib.contextmanager
def clone_sources() -> Iterator[str]:
os.chdir('..') # Move from test/ to repo base
with tempfile.TemporaryDirectory(ignore_cleanup_errors=False) as tmpdir:
sh(f"cp --parents $(git ls-files) {tmpdir}")
os.chdir(tmpdir)
yield tmpdir
def test_make(target: str, outputs: Iterable[str]) -> None:
outpaths = [Path(o) for o in outputs]
with clone_sources():
for o in outpaths:
assert not o.exists(), f"{o} existed before make"
sh(f'make {target} CFLAGS="-Werror"')
for o in outpaths:
assert o.exists(), f"{o} wasn't made"
sh('make clean')
for o in outpaths:
assert not o.exists(), f"{o} existed after make clean"
exeter.register('make_passt', test_make, 'passt', ['passt'])
exeter.register('make_pasta', test_make, 'pasta', ['pasta'])
exeter.register('make_qrap', test_make, 'qrap', ['qrap'])
exeter.register('make_all', test_make, 'all', ['passt', 'pasta', 'qrap'])
@exeter.test
def test_install_uninstall() -> None:
with clone_sources():
with tempfile.TemporaryDirectory(ignore_cleanup_errors=False) \
as prefix:
bindir = Path(prefix) / 'bin'
mandir = Path(prefix) / 'share/man'
progs = ['passt', 'pasta', 'qrap']
# Install
sh(f'make install CFLAGS="-Werror" prefix={prefix}')
for prog in progs:
exe = bindir / prog
assert exe.is_file(), f"{exe} does not exist as a regular file"
sh(f'man -M {mandir} -W {prog}')
# Uninstall
sh(f'make uninstall prefix={prefix}')
for prog in progs:
exe = bindir / prog
assert not exe.exists(), f"{exe} exists after uninstall"
sh(f'! man -M {mandir} -W {prog}')
if __name__ == '__main__':
exeter.main()
|