From 70bdf6e661f67dfbfd6a198f7d1ebc6fdf0dce62 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 2 Jun 2023 21:10:08 +0200 Subject: [PATCH] test: introduce test_require_bin() and use it No functional change. --- test/TEST-21-DFUZZER/test.sh | 2 +- test/TEST-43-PRIVATEUSER-UNPRIV/test.sh | 2 +- test/TEST-46-HOMED/test.sh | 5 +---- test/TEST-50-DISSECT/test.sh | 4 +--- test/TEST-70-TPM2/test.sh | 3 +-- test/TEST-75-RESOLVED/test.sh | 5 +---- test/test-functions | 11 +++++++++++ 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/test/TEST-21-DFUZZER/test.sh b/test/TEST-21-DFUZZER/test.sh index eb0a6549e0c..4b1919b86ed 100755 --- a/test/TEST-21-DFUZZER/test.sh +++ b/test/TEST-21-DFUZZER/test.sh @@ -18,7 +18,7 @@ if ! get_bool "${TEST_PREFER_NSPAWN:=}"; then TEST_NO_NSPAWN=1 fi -command -v dfuzzer >/dev/null || exit 0 +test_require_bin dfuzzer if ! get_bool "$IS_BUILT_WITH_ASAN"; then echo "systemd is built without ASan, skipping..." diff --git a/test/TEST-43-PRIVATEUSER-UNPRIV/test.sh b/test/TEST-43-PRIVATEUSER-UNPRIV/test.sh index 844c08ab1f2..1d1dab43c30 100755 --- a/test/TEST-43-PRIVATEUSER-UNPRIV/test.sh +++ b/test/TEST-43-PRIVATEUSER-UNPRIV/test.sh @@ -9,7 +9,7 @@ IMAGE_NAME="private-users" . "${TEST_BASE_DIR:?}/test-functions" has_user_dbus_socket || exit 0 -command -v mksquashfs >/dev/null 2>&1 || exit 0 +test_require_bin mksquashfs test_append_files() { inst_binary unsquashfs diff --git a/test/TEST-46-HOMED/test.sh b/test/TEST-46-HOMED/test.sh index 0daf211103c..3bf3891380c 100755 --- a/test/TEST-46-HOMED/test.sh +++ b/test/TEST-46-HOMED/test.sh @@ -11,10 +11,7 @@ TEST_DESCRIPTION="testing homed" . "${TEST_BASE_DIR:?}/test-functions" get_bool "${NO_BUILD:-}" && HOMECTL_BIN="homectl" || HOMECTL_BIN="${BUILD_DIR:?}/homectl" -if ! command -v "$HOMECTL_BIN" >/dev/null; then - echo "Built without systemd-homed, skipping the test" - exit 0 -fi +test_require_bin "$HOMECTL_BIN" # Need loop devices for mounting images test_append_files() { diff --git a/test/TEST-50-DISSECT/test.sh b/test/TEST-50-DISSECT/test.sh index 2d44ca2b6ee..bcc81749afc 100755 --- a/test/TEST-50-DISSECT/test.sh +++ b/test/TEST-50-DISSECT/test.sh @@ -12,9 +12,7 @@ TEST_INSTALL_VERITY_MINIMAL=1 # shellcheck source=test/test-functions . "${TEST_BASE_DIR:?}/test-functions" -command -v mksquashfs >/dev/null 2>&1 || exit 0 -command -v veritysetup >/dev/null 2>&1 || exit 0 -command -v sfdisk >/dev/null 2>&1 || exit 0 +test_require_bin mksquashfs veritysetup sfdisk test_append_files() { instmods squashfs =squashfs diff --git a/test/TEST-70-TPM2/test.sh b/test/TEST-70-TPM2/test.sh index db92d21c4aa..f3ac1399fce 100755 --- a/test/TEST-70-TPM2/test.sh +++ b/test/TEST-70-TPM2/test.sh @@ -11,8 +11,7 @@ TEST_REQUIRE_INSTALL_TESTS=0 # shellcheck source=test/test-functions . "${TEST_BASE_DIR:?}/test-functions" -command -v swtpm >/dev/null 2>&1 || exit 0 -command -v tpm2_pcrextend >/dev/null 2>&1 || exit 0 +test_require_bin swtpm tpm2_pcrextend test_append_files() { local workspace="${1:?}" diff --git a/test/TEST-75-RESOLVED/test.sh b/test/TEST-75-RESOLVED/test.sh index 6c63db65fb3..cbb9e3dbbf7 100755 --- a/test/TEST-75-RESOLVED/test.sh +++ b/test/TEST-75-RESOLVED/test.sh @@ -9,10 +9,7 @@ NSPAWN_ARGUMENTS="--private-network" # shellcheck source=test/test-functions . "${TEST_BASE_DIR:?}/test-functions" -if ! command -v knotd >/dev/null; then - echo "This test requires Knot DNS server, skipping..." - exit 0 -fi +test_require_bin knotd # 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 diff --git a/test/test-functions b/test/test-functions index f374e8ade0a..09e5e0d38ef 100644 --- a/test/test-functions +++ b/test/test-functions @@ -326,6 +326,17 @@ if get_bool "$IS_BUILT_WITH_ASAN"; then echo "Detected ASan RT '$ASAN_RT_NAME' located at '$ASAN_RT_PATH'" 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() { QEMU_BIN="${QEMU_BIN:-""}" # SUSE and Red Hat call the binary qemu-kvm. Debian and Gentoo call it kvm.