test: introduce test_require_bin() and use it

No functional change.
This commit is contained in:
Frantisek Sumsal 2023-06-02 21:10:08 +02:00
parent 97d7af86b5
commit 70bdf6e661
7 changed files with 17 additions and 15 deletions

View file

@ -18,7 +18,7 @@ if ! get_bool "${TEST_PREFER_NSPAWN:=}"; then
TEST_NO_NSPAWN=1 TEST_NO_NSPAWN=1
fi fi
command -v dfuzzer >/dev/null || exit 0 test_require_bin dfuzzer
if ! get_bool "$IS_BUILT_WITH_ASAN"; then if ! get_bool "$IS_BUILT_WITH_ASAN"; then
echo "systemd is built without ASan, skipping..." echo "systemd is built without ASan, skipping..."

View file

@ -9,7 +9,7 @@ IMAGE_NAME="private-users"
. "${TEST_BASE_DIR:?}/test-functions" . "${TEST_BASE_DIR:?}/test-functions"
has_user_dbus_socket || exit 0 has_user_dbus_socket || exit 0
command -v mksquashfs >/dev/null 2>&1 || exit 0 test_require_bin mksquashfs
test_append_files() { test_append_files() {
inst_binary unsquashfs inst_binary unsquashfs

View file

@ -11,10 +11,7 @@ TEST_DESCRIPTION="testing homed"
. "${TEST_BASE_DIR:?}/test-functions" . "${TEST_BASE_DIR:?}/test-functions"
get_bool "${NO_BUILD:-}" && HOMECTL_BIN="homectl" || HOMECTL_BIN="${BUILD_DIR:?}/homectl" get_bool "${NO_BUILD:-}" && HOMECTL_BIN="homectl" || HOMECTL_BIN="${BUILD_DIR:?}/homectl"
if ! command -v "$HOMECTL_BIN" >/dev/null; then test_require_bin "$HOMECTL_BIN"
echo "Built without systemd-homed, skipping the test"
exit 0
fi
# Need loop devices for mounting images # Need loop devices for mounting images
test_append_files() { test_append_files() {

View file

@ -12,9 +12,7 @@ TEST_INSTALL_VERITY_MINIMAL=1
# shellcheck source=test/test-functions # shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions" . "${TEST_BASE_DIR:?}/test-functions"
command -v mksquashfs >/dev/null 2>&1 || exit 0 test_require_bin mksquashfs veritysetup sfdisk
command -v veritysetup >/dev/null 2>&1 || exit 0
command -v sfdisk >/dev/null 2>&1 || exit 0
test_append_files() { test_append_files() {
instmods squashfs =squashfs instmods squashfs =squashfs

View file

@ -11,8 +11,7 @@ TEST_REQUIRE_INSTALL_TESTS=0
# shellcheck source=test/test-functions # shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions" . "${TEST_BASE_DIR:?}/test-functions"
command -v swtpm >/dev/null 2>&1 || exit 0 test_require_bin swtpm tpm2_pcrextend
command -v tpm2_pcrextend >/dev/null 2>&1 || exit 0
test_append_files() { test_append_files() {
local workspace="${1:?}" local workspace="${1:?}"

View file

@ -9,10 +9,7 @@ NSPAWN_ARGUMENTS="--private-network"
# shellcheck source=test/test-functions # shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions" . "${TEST_BASE_DIR:?}/test-functions"
if ! command -v knotd >/dev/null; then test_require_bin knotd
echo "This test requires Knot DNS server, skipping..."
exit 0
fi
# We need at least Knot 3.0 which support (among others) the ds-push directive # We need at least Knot 3.0 which support (among others) the ds-push directive
if ! knotc -c "${TEST_BASE_DIR:?}/knot-data/knot.conf" conf-check; then if ! knotc -c "${TEST_BASE_DIR:?}/knot-data/knot.conf" conf-check; then

View file

@ -326,6 +326,17 @@ if get_bool "$IS_BUILT_WITH_ASAN"; then
echo "Detected ASan RT '$ASAN_RT_NAME' located at '$ASAN_RT_PATH'" echo "Detected ASan RT '$ASAN_RT_NAME' located at '$ASAN_RT_PATH'"
fi fi
test_require_bin() {
local bin
for bin in "$@"; do
if ! command -v "$bin" >/dev/null; then
echo "Required binary $bin not available, skipping the test"
exit 0
fi
done
}
find_qemu_bin() { find_qemu_bin() {
QEMU_BIN="${QEMU_BIN:-""}" QEMU_BIN="${QEMU_BIN:-""}"
# SUSE and Red Hat call the binary qemu-kvm. Debian and Gentoo call it kvm. # SUSE and Red Hat call the binary qemu-kvm. Debian and Gentoo call it kvm.