public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob 796686726714893cc9612922621f0a3c34d8eb38 2781 bytes (raw)

  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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
 
#! /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.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()

debug log:

solving 79668672 ...
found 79668672 in https://archives.passt.top/passt-dev/20240805123701.1720730-7-david@gibson.dropbear.id.au/

applying [1/1] https://archives.passt.top/passt-dev/20240805123701.1720730-7-david@gibson.dropbear.id.au/
diff --git a/test/build/build.py b/test/build/build.py
new file mode 100644
index 00000000..79668672

Checking patch test/build/build.py...
Applied patch test/build/build.py cleanly.

index at:
100644 796686726714893cc9612922621f0a3c34d8eb38	test/build/build.py

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).