public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob 9c7d9c237962d87343ef62c10a487664d27a6175 3264 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
106
107
108
109
 
#! /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.py - 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 subprocess
import tempfile
from typing import Iterable, Iterator

import exeter

def sh(cmd):
    """Run given command in a shell"""
    subprocess.run(cmd, shell=True)


@contextlib.contextmanager
def clone_sources() -> Iterator[str]:
    """Create a temporary copy of the passt sources.

    When the context enters create a temporary directory and copy the
    passt sources into it.  Clean it up when the context exits.
    """

    os.chdir('..')  # Move from test/ to repo base
    with tempfile.TemporaryDirectory(ignore_cleanup_errors=False) as tmpdir:
        sh(f"cp --parents -d $(git ls-files) {tmpdir}")
        os.chdir(tmpdir)
        yield tmpdir


def test_make(target: str, expected_files: list[str]) -> None:
    """Check a make target works as expected.

    Arguments:
    target -- make target to invoke
    expected_files -- files make is expected to create

    Verifies that
      1) `make target` completes successfully
      2) expected_files care created by `make target`
      3) expected_files are removed by `make clean`
    """

    ex_paths = [Path(f) for f in expected_files]
    with clone_sources():
        for p in ex_paths:
            assert not p.exists(), f"{p} existed before make"
        sh(f'make {target} CFLAGS="-Werror"')
        for p in ex_paths:
            assert p.exists(), f"{p} wasn't made"
        sh('make clean')
        for p in ex_paths:
            assert not p.exists(), f"{p} 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:
    """Test `make install` and `make uninstall work as expected

    Tests that `make install` installs the expected files to the
    install prefix, and that `make uninstall` removes them again.
    """

    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()

debug log:

solving 9c7d9c23 ...
found 9c7d9c23 in https://archives.passt.top/passt-dev/20250820105456.1281906-4-david@gibson.dropbear.id.au/

applying [1/1] https://archives.passt.top/passt-dev/20250820105456.1281906-4-david@gibson.dropbear.id.au/
diff --git a/test/build/build.py b/test/build/build.py
new file mode 100755
index 00000000..9c7d9c23

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

index at:
100755 9c7d9c237962d87343ef62c10a487664d27a6175	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).