[Libguestfs] [libnbd PATCH 1/5] Fix test requirements

Martin Kletzander mkletzan at redhat.com
Thu May 6 11:30:06 UTC 2021


Some tests have extra dependencies that may be missing in minimal
deployments (e.g. hexdump), some require kernel modules or support (nbd, fuse)
and others need qemu, but were written to only work with qemu-kvm binary.

All these were fixed to my best knowledge, but of course they are still not
perfect.

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 tests/functions.sh.in                 | 21 +++++++++++++++++++++
 interop/dirty-bitmap.sh               |  4 ++--
 copy/copy-block-to-nbd.sh             |  1 +
 copy/copy-nbd-to-block.sh             |  1 +
 copy/copy-nbd-to-nbd.sh               |  1 +
 copy/copy-nbd-to-small-block-error.sh |  1 +
 copy/copy-tls.sh                      |  1 +
 fuse/test-file-mode.sh                |  1 +
 fuse/test-nbdkit.sh                   |  1 +
 fuse/test-qcow2.sh                    |  1 +
 info/info-map-qemu-dirty-bitmap.sh    |  4 ++--
 11 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/tests/functions.sh.in b/tests/functions.sh.in
index 2f5206fd4e14..345b2a290a19 100644
--- a/tests/functions.sh.in
+++ b/tests/functions.sh.in
@@ -76,6 +76,27 @@ requires ()
     }
 }
 
+# requires_qemu
+#
+# Check that qemu-kvm or qemu-system-$(uname -m) works.  If not, skip the test.
+# If it does, then export the appropriate binary name in $QEMU_BINARY.
+requires_qemu ()
+{
+    local qemu_bin
+    for qemu_bin in "qemu-kvm" "qemu-system-$(uname -m)"; do
+        ( "$qemu_bin" --version ) </dev/null >/dev/null 2>&1 || continue
+
+        export QEMU_BINARY="$qemu_bin"
+        break
+    done
+
+    if test -z "$QEMU_BINARY"; then
+        echo "$0: ‘$*’ failed with error code $?"
+        echo "$0: test prerequisite is missing or not working"
+        exit 77
+    fi
+}
+
 # Tests that run under check-root should use this.
 requires_root ()
 {
diff --git a/interop/dirty-bitmap.sh b/interop/dirty-bitmap.sh
index 6db44f2b41b4..5ba0e69a06af 100755
--- a/interop/dirty-bitmap.sh
+++ b/interop/dirty-bitmap.sh
@@ -25,7 +25,7 @@ set -x
 requires qemu-img --version
 requires qemu-io --version
 requires qemu-nbd --version
-requires qemu-kvm --version
+requires_qemu
 
 # This test uses the qemu-nbd -B option.
 if ! qemu-nbd --help | grep -sq -- -B; then
@@ -46,7 +46,7 @@ cat <<'EOF' |
 {'execute':'block-dirty-bitmap-add','arguments':{'node':'n','name':'bitmap0','persistent':true}}
 {'execute':'quit'}
 EOF
-    qemu-kvm -nodefaults -nographic -qmp stdio -machine none,accel=tcg
+    $QEMU_BINARY -nodefaults -nographic -qmp stdio -machine none,accel=tcg
 qemu-io -f qcow2 -c 'w 64k 64k' -c 'w -z 512k 64k' dirty-bitmap.qcow2
 
 # Run the test.
diff --git a/copy/copy-block-to-nbd.sh b/copy/copy-block-to-nbd.sh
index 0d84cb304e8b..a81a4ba44823 100755
--- a/copy/copy-block-to-nbd.sh
+++ b/copy/copy-block-to-nbd.sh
@@ -23,6 +23,7 @@ set -x
 
 requires_root
 requires nbdkit --exit-with-parent --version
+requires test -e /sys/module/nbd
 requires nbd-client --version
 # /dev/nbd0 must not be in use.
 requires_not nbd-client -c /dev/nbd0
diff --git a/copy/copy-nbd-to-block.sh b/copy/copy-nbd-to-block.sh
index 6fcb18d99ca1..38cc7ac2a34e 100755
--- a/copy/copy-nbd-to-block.sh
+++ b/copy/copy-nbd-to-block.sh
@@ -23,6 +23,7 @@ set -x
 
 requires_root
 requires nbdkit --exit-with-parent --version
+requires test -e /sys/module/nbd
 requires nbd-client --version
 # /dev/nbd0 must not be in use.
 requires_not nbd-client -c /dev/nbd0
diff --git a/copy/copy-nbd-to-nbd.sh b/copy/copy-nbd-to-nbd.sh
index 44134ab795f6..a7526cdb549f 100755
--- a/copy/copy-nbd-to-nbd.sh
+++ b/copy/copy-nbd-to-nbd.sh
@@ -23,6 +23,7 @@ set -x
 
 requires nbdkit --exit-with-parent --version
 requires cmp --version
+requires hexdump --version
 
 pidfile1=copy-nbd-to-nbd.pid1
 pidfile2=copy-nbd-to-nbd.pid2
diff --git a/copy/copy-nbd-to-small-block-error.sh b/copy/copy-nbd-to-small-block-error.sh
index 669f77a0a338..eb78b9456a3f 100755
--- a/copy/copy-nbd-to-small-block-error.sh
+++ b/copy/copy-nbd-to-small-block-error.sh
@@ -23,6 +23,7 @@ set -x
 
 requires_root
 requires nbdkit --exit-with-parent --version
+requires test -e /sys/module/nbd
 requires nbd-client --version
 # /dev/nbd0 must not be in use.
 requires_not nbd-client -c /dev/nbd0
diff --git a/copy/copy-tls.sh b/copy/copy-tls.sh
index 6a15202d5fa8..b4b3c71db02f 100755
--- a/copy/copy-tls.sh
+++ b/copy/copy-tls.sh
@@ -29,6 +29,7 @@ requires test "x$PSKTOOL" != "x"
 requires nbdkit --exit-with-parent --version
 requires bash -c "nbdkit --dump-config | grep tls=yes"
 requires cmp --version
+requires hexdump --version
 
 pskfile=copy-tls.psk
 pidfile1=copy-tls.pid1
diff --git a/fuse/test-file-mode.sh b/fuse/test-file-mode.sh
index ebd74ff7c397..c6d407f197b5 100755
--- a/fuse/test-file-mode.sh
+++ b/fuse/test-file-mode.sh
@@ -27,6 +27,7 @@ requires fusermount3 --version
 requires nbdkit --exit-with-parent --version
 requires cmp --version
 requires dd --version
+requires test -e /dev/fuse
 
 if ! test -r /dev/urandom; then
     echo "$0: test skipped: /dev/urandom not readable"
diff --git a/fuse/test-nbdkit.sh b/fuse/test-nbdkit.sh
index a9c3eff51f8b..c66060aa2cf2 100755
--- a/fuse/test-nbdkit.sh
+++ b/fuse/test-nbdkit.sh
@@ -27,6 +27,7 @@ requires fusermount3 --version
 requires nbdkit --exit-with-parent --version
 requires cmp --version
 requires dd --version
+requires test -e /dev/fuse
 
 if ! test -r /dev/urandom; then
     echo "$0: test skipped: /dev/urandom not readable"
diff --git a/fuse/test-qcow2.sh b/fuse/test-qcow2.sh
index 0c862b92897f..9361ec72bb13 100755
--- a/fuse/test-qcow2.sh
+++ b/fuse/test-qcow2.sh
@@ -29,6 +29,7 @@ requires qemu-nbd --version
 requires qemu-img --version
 requires cmp --version
 requires dd --version
+requires test -e /dev/fuse
 
 if ! test -r /dev/urandom; then
     echo "$0: test skipped: /dev/urandom not readable"
diff --git a/info/info-map-qemu-dirty-bitmap.sh b/info/info-map-qemu-dirty-bitmap.sh
index 90bbe1820c7c..7df3ff5e4895 100755
--- a/info/info-map-qemu-dirty-bitmap.sh
+++ b/info/info-map-qemu-dirty-bitmap.sh
@@ -27,7 +27,7 @@ set -x
 requires qemu-img --version
 requires qemu-io --version
 requires qemu-nbd --version
-requires qemu-kvm --version
+requires_qemu
 requires tr --version
 
 # This test uses the qemu-nbd -B option.
@@ -50,7 +50,7 @@ cat <<'EOF' |
 {'execute':'block-dirty-bitmap-add','arguments':{'node':'n','name':'bitmap0','persistent':true}}
 {'execute':'quit'}
 EOF
-    qemu-kvm -nodefaults -nographic -qmp stdio -machine none,accel=tcg
+    $QEMU_BINARY -nodefaults -nographic -qmp stdio -machine none,accel=tcg
 qemu-io -f qcow2 -c 'w 64k 64k' -c 'w -z 512k 64k' $f
 
 # We have to run qemu-nbd and attempt to clean it up afterwards.
-- 
2.31.1




More information about the Libguestfs mailing list