[Libguestfs] [nbdkit PATCH 3/3] tests: Add regression test for NBDKIT_EMULATE_CACHE fix
Eric Blake
eblake at redhat.com
Fri Jun 10 16:12:32 UTC 2022
On Fri, Jun 10, 2022 at 10:55:27AM -0500, Eric Blake wrote:
> Add testsuite coverage for the bug fixed in the previous patch (done
> separately, to make it easier to prove the test fails without the
> patch).
> ---
> tests/Makefile.am | 2 +
> tests/test-eval-cache.sh | 85 ++++++++++++++++++++++++++++++++++++++++
> +# This plugin requests nbdkit to emulate caching with pread. When the witness
> +# file exists, cache reads; when absent, reads fail if not already cached.
> +export witness="$PWD/eval-cache.witness"
> +export cache="$PWD/eval-cache.cache"
> +export script='
> +import os
> +import errno
> +
> +witness = os.getenv("witness")
> +
> +def touch(path):
> + open(path, "a").close()
> +
> +# Test that uncached read fails
> +try:
> + h.pread(1024 * 1024, 0)
> +except nbd.Error as ex:
> + assert ex.errnum == errno.EIO
> +
> +# Cache the entire image; nbdkit should break it into 64k preads
64M preads
> +touch(witness)
> +h.cache(h.get_size(), 0)
> +os.unlink(witness)
> +
> +# Now read should succeed
> +buf = h.pread(64 * 1024 * 1024, 64 * 1024 * 1024)
> +if hasattr(buf, "is_zero"):
> + assert buf.is_zero()
> +'
> +nbdkit -U - -v eval \
> + get_size='echo 128M' can_cache='echo emulate' open='touch "$cache"' \
> + pread='
> + if test -f "$witness"; then
> + echo "$3 $4" >> "$cache"
> + elif ! grep -q "^$3 $4$" "$cache"; then
> + echo EIO >&2; exit 1
> + fi
> + dd if=/dev/zero count=$3 iflag=count_bytes
> + ' --run 'nbdsh -u "$uri" -c "$script"'
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
More information about the Libguestfs
mailing list