]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: introduce test_require_bin() and use it
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 2 Jun 2023 19:10:08 +0000 (21:10 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 5 Jun 2023 14:50:13 +0000 (16:50 +0200)
No functional change.

test/TEST-21-DFUZZER/test.sh
test/TEST-43-PRIVATEUSER-UNPRIV/test.sh
test/TEST-46-HOMED/test.sh
test/TEST-50-DISSECT/test.sh
test/TEST-70-TPM2/test.sh
test/TEST-75-RESOLVED/test.sh
test/test-functions

index eb0a6549e0ce228515e20bebb9833df392b6dbf8..4b1919b86ed4fe7002a861c3a9cc392bb20fb3fb 100755 (executable)
@@ -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..."
index 844c08ab1f2b78846cda6307ec99ebe340ea0644..1d1dab43c30604b50dd1183450d22ce3479b913d 100755 (executable)
@@ -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
index 0daf211103cbff952b02d8eb7c972772d8e905f7..3bf3891380ca28c61a7898747da4109d8d09c67a 100755 (executable)
@@ -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() {
index 2d44ca2b6ee21ccc91fe3446ac6b8bf7db05c89d..bcc81749afca6768644e541018b4870451afee2c 100755 (executable)
@@ -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
index db92d21c4aa323f88679afb8ca1452c98f2a1890..f3ac1399fce2a0d66142e8f35fb6cd54fae7a0fe 100755 (executable)
@@ -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:?}"
index 6c63db65fb371d213fe3c6f2fc806a4a0e01e3b4..cbb9e3dbbf7aa7b0edee504c726617d5a00e714b 100755 (executable)
@@ -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
index f374e8ade0ac5f8760bfed6dba0a7c38c6ad2d6a..09e5e0d38efd7b0d11cdb2f0477f072aa7ed489e 100644 (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'"
 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.