Blame SOURCES/0021-tests-Add-a-better-test-of-real-VDDK.patch

f954f3
From bd181ea739ebfafbf7239b5fa89e98becdb8cb72 Mon Sep 17 00:00:00 2001
f954f3
From: "Richard W.M. Jones" <rjones@redhat.com>
f954f3
Date: Mon, 5 Jul 2021 22:03:10 +0100
f954f3
Subject: [PATCH] tests: Add a better test of real VDDK
f954f3
f954f3
The previous test only tested reading and maybe extents, and used an
f954f3
all-zero disk.  I'm fairly convinced the test only worked accidentally
f954f3
since you must use an absolute path when opening a local file and the
f954f3
test did not do that.
f954f3
f954f3
Add a more comprehensive test that tests writing and flush too.
f954f3
f954f3
(cherry picked from commit a6ca4f24593008bb2d8efb177e7f424cff51dfbf)
f954f3
---
f954f3
 tests/test-vddk-real.sh | 55 ++++++++++++++++++++++++++++-------------
f954f3
 1 file changed, 38 insertions(+), 17 deletions(-)
f954f3
f954f3
diff --git a/tests/test-vddk-real.sh b/tests/test-vddk-real.sh
f954f3
index df486ba1..f848db44 100755
f954f3
--- a/tests/test-vddk-real.sh
f954f3
+++ b/tests/test-vddk-real.sh
f954f3
@@ -37,8 +37,12 @@ set -x
f954f3
 requires test "x$vddkdir" != "x"
f954f3
 requires test -d "$vddkdir"
f954f3
 requires test -f "$vddkdir/lib64/libvixDiskLib.so"
f954f3
+requires test -r /dev/urandom
f954f3
+requires cmp --version
f954f3
+requires dd --version
f954f3
 requires qemu-img --version
f954f3
 requires nbdcopy --version
f954f3
+requires nbdinfo --version
f954f3
 requires stat --version
f954f3
 
f954f3
 # VDDK > 5.1.1 only supports x86_64.
f954f3
@@ -47,31 +51,48 @@ if [ `uname -m` != "x86_64" ]; then
f954f3
     exit 77
f954f3
 fi
f954f3
 
f954f3
-files="test-vddk-real.vmdk test-vddk-real.out test-vddk-real.log"
f954f3
-rm -f $files
f954f3
-cleanup_fn rm -f $files
f954f3
-
f954f3
-qemu-img create -f vmdk test-vddk-real.vmdk 100M
f954f3
-
f954f3
 # Since we are comparing error messages below, let's make sure we're
f954f3
 # not translating errors.
f954f3
 export LANG=C
f954f3
 
f954f3
-fail=0
f954f3
-nbdkit -f -v -U - \
f954f3
-       --filter=readahead \
f954f3
-       vddk libdir="$vddkdir" test-vddk-real.vmdk \
f954f3
-       --run 'nbdcopy "$uri" test-vddk-real.out' \
f954f3
-       > test-vddk-real.log 2>&1 || fail=1
f954f3
+pid=test-vddk-real.pid
f954f3
+sock=$(mktemp -u /tmp/nbdkit-test-sock.XXXXXX)
f954f3
+vmdk=$PWD/test-vddk-real.vmdk ;# note must be an absolute path
f954f3
+raw=test-vddk-real.raw
f954f3
+raw2=test-vddk-real.raw2
f954f3
+log=test-vddk-real.log
f954f3
+files="$pid $sock $vmdk $raw $raw2 $log"
f954f3
+rm -f $files
f954f3
+cleanup_fn rm -f $files
f954f3
+
f954f3
+qemu-img create -f vmdk $vmdk 10M
f954f3
+
f954f3
+# Check first that the VDDK library can be fully loaded.  We have to
f954f3
+# check the log file for missing modules since they may not show up as
f954f3
+# errors.
f954f3
+nbdkit -fv -U - vddk libdir="$vddkdir" $vmdk --run 'nbdinfo "$uri"' >$log 2>&1
f954f3
 
f954f3
 # Check the log for missing modules
f954f3
-cat test-vddk-real.log
f954f3
+cat $log
f954f3
 if grep 'cannot open shared object file' test-vddk-real.log; then
f954f3
    exit 1
f954f3
 fi
f954f3
 
f954f3
-# Check the raw output file has exactly the right size.
f954f3
-size="$(stat -c '%s' test-vddk-real.out)"
f954f3
-test "$size" -eq $((100 * 1024 * 1024))
f954f3
+# Now run nbdkit for the test.
f954f3
+start_nbdkit -P $pid -U $sock vddk libdir="$vddkdir" $vmdk
f954f3
+uri="nbd+unix:///?socket=$sock"
f954f3
 
f954f3
-exit $fail
f954f3
+# VDDK < 6.0 did not support flush, so disable flush test there.  Also
f954f3
+# if nbdinfo doesn't support the --can flush syntax (added in libnbd
f954f3
+# 1.10) then this is disabled.
f954f3
+if nbdinfo --can flush "$uri"; then flush="--flush"; else flush=""; fi
f954f3
+
f954f3
+# Copy in and out some data.  This should exercise read, write,
f954f3
+# extents and flushing.
f954f3
+dd if=/dev/urandom of=$raw count=5 bs=$((1024*1024))
f954f3
+truncate -s 10M $raw
f954f3
+
f954f3
+nbdcopy $flush $raw "$uri"
f954f3
+nbdcopy "$uri" $raw2
f954f3
+
f954f3
+cmp $raw $raw2
f954f3
-- 
f954f3
2.31.1
f954f3