Commit 47e43a72 authored by Richard W.M. Jones's avatar Richard W.M. Jones
Browse files

build: Check for qemu-img and disable some tests if not present

qemu-img might not be present.  If it is not present then we fail to
create tests/disk, but we should skip creation instead.

At configure time, test for qemu-img.  Disable creation of tests/disk
if not present.  Also update the other test functions so they now test
for $QEMU_IMG instead of directly for qemu-img, so that
'./configure QEMU_IMG=...' will work.

Fixes: #30
Fixes: commit 7adcf1bd
Reported-by: Daniel P. Berrangé
(cherry picked from commit 47202a32)
parent eb2dc228
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -881,6 +881,12 @@ AC_CHECK_PROGS([CUT],[gnucut cut],[cut])
AC_CHECK_PROGS([STAT],[gstat stat],[stat])
AC_CHECK_PROGS([TRUNCATE],[gtruncate truncate],[truncate])

dnl qemu-img is used by the tests to create the disk.  This might not
dnl be present everywhere (eg. on i386), so check for it.  Individual
dnl tests also need to check that qemu-img is present.
AC_CHECK_PROGS([QEMU_IMG], [qemu-img], [no])
AM_CONDITIONAL([HAVE_QEMU_IMG], [test "x$QEMU_IMG" != "xno"])

HEADING([Checking for bash completion])

dnl Bash completion.
+5 −1
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ endif
# skip if not present.
if !IS_WINDOWS
if HAVE_MKE2FS_WITH_D
if HAVE_QEMU_IMG

check_DATA += disk disk.tar
CLEANFILES += disk disk.tar
@@ -117,7 +118,7 @@ disk:
	mkdir disk.tmp
	echo -n "hello,world" > disk.tmp/hello.txt
	$(top_builddir)/nbdkit$(EXEEXT) -fv linuxdisk disk.tmp size=100M \
	    --run 'qemu-img convert "$$uri" $@-t'
	    --run '@QEMU_IMG@ convert "$$uri" $@-t'
	rm -rf disk.tmp
	mv $@-t $@

@@ -172,6 +173,7 @@ disk.tar.lz: disk.tar chunked-lzip.sh
endif HAVE_LZIP
EXTRA_DIST += chunked-lzip.sh

endif HAVE_QEMU_IMG
endif HAVE_MKE2FS_WITH_D
endif !IS_WINDOWS

@@ -1836,6 +1838,7 @@ TESTS += test-exportname.sh
EXTRA_DIST += test-exportname.sh

# ext2 filter test.
if HAVE_QEMU_IMG
if HAVE_MKE2FS_WITH_D
if HAVE_EXT2

@@ -1865,6 +1868,7 @@ ext2.img: disk test-ext2-exportname.sh

endif HAVE_EXT2
endif HAVE_MKE2FS_WITH_D
endif HAVE_QEMU_IMG

# extentlist filter test.
TESTS += test-extentlist.sh
+5 −4
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ SOEXT="@SOEXT@"
EXEEXT="@EXEEXT@"

CUT="@CUT@"
QEMU_IMG="@QEMU_IMG@"
SED="@SED@"
STAT="@STAT@"
TRUNCATE="@TRUNCATE@"
@@ -226,9 +227,9 @@ define()
# requires program [args]
#
# Check that ‘program [args]’ works.  If not, skip the test.
# For example to check that qemu-img is available, do:
# For example to check that 'jq' is available, do:
#
# requires qemu-img --version
#   requires jq --version
requires ()
{
    ( "$@" ) </dev/null >/dev/null 2>&1 || {
@@ -256,12 +257,12 @@ requires_not ()
# https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/SXDLSZ3GKXL6NDAKP4MPJ25IMHKN67X3/
requires_ipv6_loopback ()
{
    requires qemu-img --version
    requires "$QEMU_IMG" --version

    # This should fail with "Connection refused".  If IPv6 is broken
    # then it fails with "Address family for hostname not supported"
    # instead.  It's very unlikely that port 1 is open.
    if LANG=C qemu-img info "nbd:[::1]:1" |& \
    if LANG=C "$QEMU_IMG" info "nbd:[::1]:1" |& \
       grep -sq "Address family for hostname not supported"; then
        echo "$0: IPv6 loopback is not available, skipping this test"
        exit 77
+5 −5
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ requires_run
requires_plugin linuxdisk
requires guestfish --version
requires_nbdcopy
requires qemu-img --version
requires "$QEMU_IMG" --version
requires $STAT --version

sock=$(mktemp -u /tmp/nbdkit-test-sock.XXXXXX)
@@ -74,10 +74,10 @@ fi

# If we have qemu-img, try the hairy rebase operation documented
# in the nbdkit-cow-filter manual.
if qemu-img --version >/dev/null 2>&1; then
    qemu-img create -F raw -b nbd:unix:$sock -f qcow2 cow-diff.qcow2
    time qemu-img rebase -F raw -b cow-base.img -f qcow2 cow-diff.qcow2
    qemu-img info cow-diff.qcow2
if "$QEMU_IMG" --version >/dev/null 2>&1; then
    "$QEMU_IMG" create -F raw -b nbd:unix:$sock -f qcow2 cow-diff.qcow2
    time "$QEMU_IMG" rebase -F raw -b cow-base.img -f qcow2 cow-diff.qcow2
    "$QEMU_IMG" info cow-diff.qcow2

    # This checks the file we created exists.
    guestfish --ro -a cow-diff.qcow2 -m /dev/sda1 cat /hello
+5 −3
Original line number Diff line number Diff line
@@ -37,8 +37,8 @@ set -u

requires_run
requires jq --version
requires qemu-img --version
requires qemu-img map --help
requires "$QEMU_IMG" --version
requires "$QEMU_IMG" map --help
error_if_sparse_page_not_32768

out="test-data-extents.out"
@@ -47,11 +47,13 @@ files="$out $expected"
rm -f $files
cleanup_fn rm -f $files

export QEMU_IMG

do_test ()
{
    # We use jq to normalize the output and convert it to plain text.
    nbdkit data "$1" size="$2" \
           --run 'qemu-img map -f raw --output=json "$uri"' |
           --run '"$QEMU_IMG" map -f raw --output=json "$uri"' |
        jq -c '.[] | {start:.start, length:.length, data:.data, zero:.zero}' \
           > $out
    if ! cmp $out $expected; then
Loading