Richard W.M. Jones
2017-Feb-19 12:27 UTC
[Libguestfs] [PATCH [WIP] 0/3] tests: Define common test functions.
There's a lot of common code in the tests, eg: if [ "$(guestfish get-backend)" = "uml" ]; then echo "$0: test skipped because UML backend does not support network" exit 77 fi These commits (work in progress) create a common set of test functions for skipping tests etc. Rich.
Richard W.M. Jones
2017-Feb-19 12:27 UTC
[Libguestfs] [PATCH [WIP] 1/3] tests: Rename test-data/test-utils.sh -> tests/test-functions.sh.
This is pure code motion. --- Makefile.am | 1 + test-data/Makefile.am | 3 --- tests/qemu/qemu-liveness.sh | 2 +- tests/qemu/qemu-snapshot-isolation.sh | 2 +- test-data/test-utils.sh => tests/test-functions.sh | 0 v2v/test-v2v-i-ova-formats.sh | 2 +- v2v/test-v2v-i-ova-gz.sh | 2 +- v2v/test-v2v-i-ova-subfolders.sh | 2 +- v2v/test-v2v-i-ova-tar.sh | 2 +- v2v/test-v2v-i-ova-two-disks.sh | 2 +- v2v/test-v2v-i-ova.sh | 2 +- v2v/test-v2v-in-place.sh | 2 +- 12 files changed, 10 insertions(+), 12 deletions(-) rename test-data/test-utils.sh => tests/test-functions.sh (100%) diff --git a/Makefile.am b/Makefile.am index ac472d7..7250cae 100644 --- a/Makefile.am +++ b/Makefile.am @@ -240,6 +240,7 @@ EXTRA_DIST = \ ocaml-link.sh \ podcheck.pl \ tests/automake2junit.ml \ + tests/test-functions.sh \ tmp/.gitignore \ update-bugs.sh \ utils/README \ diff --git a/test-data/Makefile.am b/test-data/Makefile.am index 9963f58..3c07188 100644 --- a/test-data/Makefile.am +++ b/test-data/Makefile.am @@ -26,9 +26,6 @@ SUBDIRS += fake-virtio-win fake-virt-tools SUBDIRS += files SUBDIRS += . -EXTRA_DIST = \ - test-utils.sh - # Build an ISO containing various files from the subdirectories, which # is used by tests/c-api and a few guestfish tests and regression # tests. diff --git a/tests/qemu/qemu-liveness.sh b/tests/qemu/qemu-liveness.sh index ee22b66..6f59da7 100755 --- a/tests/qemu/qemu-liveness.sh +++ b/tests/qemu/qemu-liveness.sh @@ -22,7 +22,7 @@ set -e -. $srcdir/../../test-data/test-utils.sh +. $srcdir/../../tests/test-functions.sh rm -f liveness1.img diff --git a/tests/qemu/qemu-snapshot-isolation.sh b/tests/qemu/qemu-snapshot-isolation.sh index 78cc69c..e062328 100755 --- a/tests/qemu/qemu-snapshot-isolation.sh +++ b/tests/qemu/qemu-snapshot-isolation.sh @@ -22,7 +22,7 @@ set -e -. $srcdir/../../test-data/test-utils.sh +. $srcdir/../../tests/test-functions.sh # UML backend doesn't support qcow2 format. supports_qcow2=yes diff --git a/test-data/test-utils.sh b/tests/test-functions.sh similarity index 100% rename from test-data/test-utils.sh rename to tests/test-functions.sh diff --git a/v2v/test-v2v-i-ova-formats.sh b/v2v/test-v2v-i-ova-formats.sh index dccf574..4c60de2 100755 --- a/v2v/test-v2v-i-ova-formats.sh +++ b/v2v/test-v2v-i-ova-formats.sh @@ -46,7 +46,7 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -. $srcdir/../test-data/test-utils.sh +. $srcdir/../tests/test-functions.sh d=test-v2v-i-ova-formats.d rm -rf $d diff --git a/v2v/test-v2v-i-ova-gz.sh b/v2v/test-v2v-i-ova-gz.sh index 32ffff8..33a98f3 100755 --- a/v2v/test-v2v-i-ova-gz.sh +++ b/v2v/test-v2v-i-ova-gz.sh @@ -34,7 +34,7 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -. $srcdir/../test-data/test-utils.sh +. $srcdir/../tests/test-functions.sh d=test-v2v-i-ova-gz.d rm -rf $d diff --git a/v2v/test-v2v-i-ova-subfolders.sh b/v2v/test-v2v-i-ova-subfolders.sh index 34dcd99..d1e12f9 100755 --- a/v2v/test-v2v-i-ova-subfolders.sh +++ b/v2v/test-v2v-i-ova-subfolders.sh @@ -34,7 +34,7 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -. $srcdir/../test-data/test-utils.sh +. $srcdir/../tests/test-functions.sh d=test-v2v-i-ova-subfolders.d rm -rf $d diff --git a/v2v/test-v2v-i-ova-tar.sh b/v2v/test-v2v-i-ova-tar.sh index 99988f4..dc3838b 100755 --- a/v2v/test-v2v-i-ova-tar.sh +++ b/v2v/test-v2v-i-ova-tar.sh @@ -34,7 +34,7 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -. $srcdir/../test-data/test-utils.sh +. $srcdir/../tests/test-functions.sh d=test-v2v-i-ova-tar.d rm -rf $d diff --git a/v2v/test-v2v-i-ova-two-disks.sh b/v2v/test-v2v-i-ova-two-disks.sh index f02e8f2..bbc2df0 100755 --- a/v2v/test-v2v-i-ova-two-disks.sh +++ b/v2v/test-v2v-i-ova-two-disks.sh @@ -35,7 +35,7 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" -. $srcdir/../test-data/test-utils.sh +. $srcdir/../tests/test-functions.sh d=test-v2v-i-ova-two-disks.d rm -rf $d diff --git a/v2v/test-v2v-i-ova.sh b/v2v/test-v2v-i-ova.sh index 37c99bc..3f426c4 100755 --- a/v2v/test-v2v-i-ova.sh +++ b/v2v/test-v2v-i-ova.sh @@ -48,7 +48,7 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" -. $srcdir/../test-data/test-utils.sh +. $srcdir/../tests/test-functions.sh d=test-v2v-i-ova.d rm -rf $d diff --git a/v2v/test-v2v-in-place.sh b/v2v/test-v2v-in-place.sh index 9424b7f..c49b9b5 100755 --- a/v2v/test-v2v-in-place.sh +++ b/v2v/test-v2v-in-place.sh @@ -44,7 +44,7 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" -. $srcdir/../test-data/test-utils.sh +. $srcdir/../tests/test-functions.sh d=$PWD/test-v2v-in-place.d rm -rf $d -- 2.10.2
Richard W.M. Jones
2017-Feb-19 12:27 UTC
[Libguestfs] [PATCH [WIP] 2/3] tests: Add $TEST_FUNCTIONS.
This macro(?) expands to some shell script to source the tests/test-functions.sh file from its correct location. The intention is to use this in all tests, but in this commit only the existing tests which already include test-functions.sh are modified. --- subdir-rules.mk | 5 +++++ tests/qemu/qemu-liveness.sh | 2 +- tests/qemu/qemu-snapshot-isolation.sh | 2 +- v2v/test-v2v-i-ova-formats.sh | 4 ++-- v2v/test-v2v-i-ova-gz.sh | 4 ++-- v2v/test-v2v-i-ova-subfolders.sh | 4 ++-- v2v/test-v2v-i-ova-tar.sh | 4 ++-- v2v/test-v2v-i-ova-two-disks.sh | 4 ++-- v2v/test-v2v-i-ova.sh | 4 ++-- v2v/test-v2v-in-place.sh | 4 ++-- 10 files changed, 21 insertions(+), 16 deletions(-) diff --git a/subdir-rules.mk b/subdir-rules.mk index c6b21fd..4926c9c 100644 --- a/subdir-rules.mk +++ b/subdir-rules.mk @@ -87,3 +87,8 @@ if HAVE_OCAMLOPT .ml.cmx: $(guestfs_am_v_ocamlopt)$(OCAMLFIND) ocamlopt $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@ endif + +# Test shell scripts should use '$TEST_FUNCTIONS' to get a predefined +# set of helper functions for running tests (see +# tests/test-functions.sh). +export TEST_FUNCTIONS := source $(abs_top_srcdir)/tests/test-functions.sh diff --git a/tests/qemu/qemu-liveness.sh b/tests/qemu/qemu-liveness.sh index 6f59da7..c9b79f0 100755 --- a/tests/qemu/qemu-liveness.sh +++ b/tests/qemu/qemu-liveness.sh @@ -22,7 +22,7 @@ set -e -. $srcdir/../../tests/test-functions.sh +$TEST_FUNCTIONS rm -f liveness1.img diff --git a/tests/qemu/qemu-snapshot-isolation.sh b/tests/qemu/qemu-snapshot-isolation.sh index e062328..d72ff9f 100755 --- a/tests/qemu/qemu-snapshot-isolation.sh +++ b/tests/qemu/qemu-snapshot-isolation.sh @@ -22,7 +22,7 @@ set -e -. $srcdir/../../tests/test-functions.sh +$TEST_FUNCTIONS # UML backend doesn't support qcow2 format. supports_qcow2=yes diff --git a/v2v/test-v2v-i-ova-formats.sh b/v2v/test-v2v-i-ova-formats.sh index 4c60de2..d49b7be 100755 --- a/v2v/test-v2v-i-ova-formats.sh +++ b/v2v/test-v2v-i-ova-formats.sh @@ -22,6 +22,8 @@ unset CDPATH export LANG=C set -e +$TEST_FUNCTIONS + formats="zip tar-gz tar-xz" if [ -n "$SKIP_TEST_V2V_I_OVA_FORMATS_SH" ]; then @@ -46,8 +48,6 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -. $srcdir/../tests/test-functions.sh - d=test-v2v-i-ova-formats.d rm -rf $d mkdir $d diff --git a/v2v/test-v2v-i-ova-gz.sh b/v2v/test-v2v-i-ova-gz.sh index 33a98f3..e292683 100755 --- a/v2v/test-v2v-i-ova-gz.sh +++ b/v2v/test-v2v-i-ova-gz.sh @@ -22,6 +22,8 @@ unset CDPATH export LANG=C set -e +$TEST_FUNCTIONS + if [ -n "$SKIP_TEST_V2V_I_OVA_GZ_SH" ]; then echo "$0: test skipped because environment variable is set" exit 77 @@ -34,8 +36,6 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -. $srcdir/../tests/test-functions.sh - d=test-v2v-i-ova-gz.d rm -rf $d mkdir $d diff --git a/v2v/test-v2v-i-ova-subfolders.sh b/v2v/test-v2v-i-ova-subfolders.sh index d1e12f9..ea3352c 100755 --- a/v2v/test-v2v-i-ova-subfolders.sh +++ b/v2v/test-v2v-i-ova-subfolders.sh @@ -22,6 +22,8 @@ unset CDPATH export LANG=C set -e +$TEST_FUNCTIONS + if [ -n "$SKIP_TEST_V2V_I_OVA_SUBFOLDERS_SH" ]; then echo "$0: test skipped because environment variable is set" exit 77 @@ -34,8 +36,6 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -. $srcdir/../tests/test-functions.sh - d=test-v2v-i-ova-subfolders.d rm -rf $d mkdir -p $d/subfolder diff --git a/v2v/test-v2v-i-ova-tar.sh b/v2v/test-v2v-i-ova-tar.sh index dc3838b..2d1389d 100755 --- a/v2v/test-v2v-i-ova-tar.sh +++ b/v2v/test-v2v-i-ova-tar.sh @@ -22,6 +22,8 @@ unset CDPATH export LANG=C set -e +$TEST_FUNCTIONS + if [ -n "$SKIP_TEST_V2V_I_OVA_FORMATS_SH" ]; then echo "$0: test skipped because environment variable is set" exit 77 @@ -34,8 +36,6 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -. $srcdir/../tests/test-functions.sh - d=test-v2v-i-ova-tar.d rm -rf $d mkdir $d diff --git a/v2v/test-v2v-i-ova-two-disks.sh b/v2v/test-v2v-i-ova-two-disks.sh index bbc2df0..86584c3 100755 --- a/v2v/test-v2v-i-ova-two-disks.sh +++ b/v2v/test-v2v-i-ova-two-disks.sh @@ -22,6 +22,8 @@ unset CDPATH export LANG=C set -e +$TEST_FUNCTIONS + if [ -n "$SKIP_TEST_V2V_I_OVA_TWO_DISKS_SH" ]; then echo "$0: test skipped because environment variable is set" exit 77 @@ -35,8 +37,6 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" -. $srcdir/../tests/test-functions.sh - d=test-v2v-i-ova-two-disks.d rm -rf $d mkdir $d diff --git a/v2v/test-v2v-i-ova.sh b/v2v/test-v2v-i-ova.sh index 3f426c4..4b97a1a 100755 --- a/v2v/test-v2v-i-ova.sh +++ b/v2v/test-v2v-i-ova.sh @@ -22,6 +22,8 @@ unset CDPATH export LANG=C set -e +$TEST_FUNCTIONS + if [ -n "$SKIP_TEST_V2V_I_OVA_SH" ]; then echo "$0: test skipped because environment variable is set" exit 77 @@ -48,8 +50,6 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" -. $srcdir/../tests/test-functions.sh - d=test-v2v-i-ova.d rm -rf $d mkdir $d diff --git a/v2v/test-v2v-in-place.sh b/v2v/test-v2v-in-place.sh index c49b9b5..c8b2ec4 100755 --- a/v2v/test-v2v-in-place.sh +++ b/v2v/test-v2v-in-place.sh @@ -23,6 +23,8 @@ unset CDPATH export LANG=C set -e +$TEST_FUNCTIONS + if [ -n "$SKIP_TEST_V2V_IN_PLACE_SH" ]; then echo "$0: test skipped because environment variable is set" exit 77 @@ -44,8 +46,6 @@ fi export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" -. $srcdir/../tests/test-functions.sh - d=$PWD/test-v2v-in-place.d rm -rf $d mkdir $d -- 2.10.2
Richard W.M. Jones
2017-Feb-19 12:27 UTC
[Libguestfs] [PATCH [WIP] 3/3] tests: Extend $TEST_FUNCTIONS with predefined functions for skipping tests etc.
Apply this change across all the shell scripts containing tests. Additionally this defines the environment variables $abs_srcdir, $abs_builddir, $top_srcdir, $top_builddir, $abs_top_srcdir and $abs_top_builddir which can now be used throughout test scripts. --- docs/guestfs-hacking.pod | 4 +- subdir-rules.mk | 18 ++++- tests/test-functions.sh | 121 ++++++++++++++++++++++++++++++- v2v/test-v2v-bad-networks-and-bridges.sh | 10 +-- v2v/test-v2v-cdrom.sh | 34 ++------- v2v/test-v2v-conversion-of.sh | 21 +----- v2v/test-v2v-copy-to-local.sh | 16 +--- v2v/test-v2v-floppy.sh | 33 ++------- v2v/test-v2v-i-disk.sh | 25 ++----- v2v/test-v2v-i-ova-formats.sh | 28 ++----- v2v/test-v2v-i-ova-gz.sh | 14 +--- v2v/test-v2v-i-ova-subfolders.sh | 14 +--- v2v/test-v2v-i-ova-tar.sh | 14 +--- v2v/test-v2v-i-ova-two-disks.sh | 16 +--- v2v/test-v2v-i-ova.sh | 33 ++------- v2v/test-v2v-in-place.sh | 23 ++---- 16 files changed, 198 insertions(+), 226 deletions(-) diff --git a/docs/guestfs-hacking.pod b/docs/guestfs-hacking.pod index 43b69e6..8f320cc 100644 --- a/docs/guestfs-hacking.pod +++ b/docs/guestfs-hacking.pod @@ -643,7 +643,9 @@ normal test. =item * Modify the test so it checks if the C<SLOW=1> environment variable is -set, and if I<not> set it skips (ie. returns with exit code 77). +set, and if I<not> set it skips (ie. returns with exit code 77). If +using C<$TEST_FUNCTIONS>, you can call the function C<slow_test> for +this. =item * diff --git a/subdir-rules.mk b/subdir-rules.mk index 4926c9c..61ab0d8 100644 --- a/subdir-rules.mk +++ b/subdir-rules.mk @@ -91,4 +91,20 @@ endif # Test shell scripts should use '$TEST_FUNCTIONS' to get a predefined # set of helper functions for running tests (see # tests/test-functions.sh). -export TEST_FUNCTIONS := source $(abs_top_srcdir)/tests/test-functions.sh +# +# Notes: +# +# (1) This is in fact a single command all on one line. The variables +# are evaluated in test-functions.sh. +# +# (2) We use absolute paths here and in test-functions.sh so that the +# test can change directory freely. But we also include the +# non-absolute values so they can be used by the test script itself. +export TEST_FUNCTIONS := \ + source $(abs_top_srcdir)/tests/test-functions.sh \ + abs_srcdir="$(abs_srcdir)" \ + abs_builddir="$(abs_builddir)" \ + top_srcdir="$(top_srcdir)" \ + top_builddir="$(top_builddir)" \ + abs_top_srcdir="$(abs_top_srcdir)" \ + abs_top_builddir="$(abs_top_builddir)" diff --git a/tests/test-functions.sh b/tests/test-functions.sh index 86a5aaf..f532a93 100755 --- a/tests/test-functions.sh +++ b/tests/test-functions.sh @@ -1,6 +1,6 @@ #!/bin/bash - # libguestfs -# Copyright (C) 2014 Red Hat Inc. +# Copyright (C) 2014-2017 Red Hat Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,6 +16,119 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# Most of the tests written in shell script source this file for +# useful functions. +# +# To include this file, the test must do: +# +# $TEST_FUNCTIONS +# +# (this macro is defined in subdir-rules.mk). + +# Clean up the environment in every test script. +unset CDPATH +export LANG=C + +# When test-functions.sh is invoked, a list of variables is passed as +# parameters, so we eval those to define the variables. +while [ $# -ge 1 ]; do eval "$1"; shift; done + +# Skip if $SKIP_<script_name> environment variable is set. +# Every test should call this function first. +skip_if_skipped () +{ + local v="SKIP_$(echo $0 | sed 's,.*/,,' | tr .- _ | tr a-z A-Z)" + if [ -n "${!v}" ]; then + echo "$(basename $0): test skipped because \$$v is set" + exit 77 + fi +} + +# Skip if the current libguestfs backend is $1. +# eg. skip_if_backend uml +skip_if_backend () +{ + local b="$(guestfish get-backend)" + case "$1" in + # Some magic happens for $1 == libvirt. + libvirt) + if [ "$b" = "libvirt" ] || [[ "$b" =~ ^libvirt: ]]; then + echo "$(basename $0): test skipped because the current backend is $b" + exit 77 + fi + ;; + *) + if [ "$b" = "$1" ]; then + echo "$(basename $0): test skipped because the current backend is $b" + exit 77 + fi + ;; + esac +} + +# Skip if the current libguestfs backend is NOT $1. +skip_unless_backend () +{ + local b="$(guestfish get-backend)" + case "$1" in + # Some magic happens for $1 == libvirt. + libvirt) + if [ "$b" != "libvirt" ] && [[ ! "$b" =~ ^libvirt: ]]; then + echo "$(basename $0): this test only runs if the backend is libvirt, but the current backend is $b" + exit 77 + fi + ;; + *) + if [ "$b" = "$1" ]; then + echo "$(basename $0): this test only runs if the backend is $1, but the current backend is $b" + exit 77 + fi + ;; + esac +} + +# Skip if the named ($1) disk image in test-data/phony-guests was not +# created. +skip_unless_phony_guest () +{ + local f="$abs_top_builddir/test-data/phony-guests/$1" + if ! test -f $f || ! test -s $f; then + echo "$(basename $0): test skipped because disk image '$1' was not created" + echo "$(basename $0): try running: make -C test-data check" + exit 77 + fi +} + +# Skip if the current arch != $1. +skip_unless_arch () +{ + local m="$(uname -m)" + if [ "$m" != "$1" ]; then + echo "$(basename $0): test skipped because the current architecture ($m) is not $1" + exit 77 + fi +} + +# Run an external command and skip if the command fails. This can be +# used to test if a command exists. Normally you should use +# `cmd --help' or `cmd --version' or similar. +skip_unless () +{ + if ! "$@"; then + echo "$(basename $0): test skipped because $1 is not available" + exit 77 + fi +} + +# Slow tests should always call this function. (See guestfs-hacking(1)). +slow_test () +{ + if [ -z "$SLOW" ]; then + echo "$(basename $0): use 'make check-slow' to run this test" + exit 77 + fi +} + do_md5 () { case "$(uname)" in @@ -23,7 +136,7 @@ do_md5 () md5sum "$1" | awk '{print $1}' ;; *) - echo "$0: unknown method to calculate MD5 of file on $(uname)" + echo "$(basename $0): unknown method to calculate MD5 of file on $(uname)" exit 1 ;; esac @@ -36,7 +149,7 @@ do_sha1 () sha1sum "$1" | awk '{print $1}' ;; *) - echo "$0: unknown method to calculate SHA1 of file on $(uname)" + echo "$(basename $0): unknown method to calculate SHA1 of file on $(uname)" exit 1 ;; esac @@ -49,7 +162,7 @@ do_sha256 () sha256sum "$1" | awk '{print $1}' ;; *) - echo "$0: unknown method to calculate SHA256 of file on $(uname)" + echo "$(basename $0): unknown method to calculate SHA256 of file on $(uname)" exit 1 ;; esac diff --git a/v2v/test-v2v-bad-networks-and-bridges.sh b/v2v/test-v2v-bad-networks-and-bridges.sh index f336620..28d457a 100755 --- a/v2v/test-v2v-bad-networks-and-bridges.sh +++ b/v2v/test-v2v-bad-networks-and-bridges.sh @@ -18,17 +18,13 @@ # Test detection of duplicate --network and --bridge parameters. -unset CDPATH -export LANG=C set -e set -x -if [ -n "$SKIP_TEST_V2V_BAD_NETWORKS_AND_BRIDGES_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi +$TEST_FUNCTIONS +skip_if_skipped -# We expect all of these to print an error. NB LANG=C above. +# We expect all of these to print an error. NB: LANG=C is set. virt-v2v -i disk -b b1 -b b1 |& grep "duplicate -b" virt-v2v -i disk -n n1 -n n1 |& grep "duplicate -n" diff --git a/v2v/test-v2v-cdrom.sh b/v2v/test-v2v-cdrom.sh index 0679923..0c8680d 100755 --- a/v2v/test-v2v-cdrom.sh +++ b/v2v/test-v2v-cdrom.sh @@ -19,37 +19,17 @@ # Test cdrom dev assignment. # https://bugzilla.redhat.com/show_bug.cgi?id=1238053 -unset CDPATH -export LANG=C set -e -if [ -n "$SKIP_TEST_V2V_CDROM_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi +$TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml +skip_unless_phony_guest windows.img +skip_unless_phony_guest blank-disk.img -if [ "$(guestfish get-backend)" = "uml" ]; then - echo "$0: test skipped because UML backend does not support network" - exit 77 -fi - -abs_builddir="$(pwd)" libvirt_uri="test://$abs_builddir/test-v2v-cdrom.xml" - -f=../test-data/phony-guests/windows.img -if ! test -f $f || ! test -s $f; then - echo "$0: test skipped because phony Windows image was not created" - exit 77 -fi - -f=../test-data/phony-guests/blank-disk.img -if ! test -f $f || ! test -s $f; then - echo "$0: test skipped because blank-disk.img was not created" - exit 77 -fi - -export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" +export VIRTIO_WIN="$top_srcdir/test-data/fake-virtio-win" d=test-v2v-cdrom.d rm -rf $d diff --git a/v2v/test-v2v-conversion-of.sh b/v2v/test-v2v-conversion-of.sh index a590085..3c98243 100755 --- a/v2v/test-v2v-conversion-of.sh +++ b/v2v/test-v2v-conversion-of.sh @@ -18,19 +18,12 @@ # Test virt-v2v on real guests. -unset CDPATH -export LANG=C set -e -if [ -z "$SLOW" ]; then - echo "$script: use 'make check-slow' to run this test" - exit 77 -fi - -if [ -n "$SKIP_TEST_V2V_CONVERSION_OF_SH" ]; then - echo "$script: test skipped because environment variable is set" - exit 77 -fi +$TEST_FUNCTIONS +slow_test +skip_if_skipped +skip_unless_arch x86_64 guestname="$1" if [ -z "$guestname" ]; then @@ -52,12 +45,6 @@ if ! virt-builder -l "$guestname" >/dev/null 2>&1; then exit 77 fi -# We can only run the tests on x86_64. -if [ "$(uname -m)" != "x86_64" ]; then - echo "$script: test skipped because !x86_64." - exit 77 -fi - # Some guests need special virt-builder parameters. # See virt-builder --notes "$guestname" declare -a extra diff --git a/v2v/test-v2v-copy-to-local.sh b/v2v/test-v2v-copy-to-local.sh index 8629083..3eb384a 100755 --- a/v2v/test-v2v-copy-to-local.sh +++ b/v2v/test-v2v-copy-to-local.sh @@ -18,24 +18,14 @@ # Test virt-v2v-copy-to-local command. -unset CDPATH -export LANG=C set -e -if [ -n "$SKIP_TEST_V2V_COPY_TO_LOCAL_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi +$TEST_FUNCTIONS +skip_if_skipped +skip_unless_phony_guest fedora.img -abs_top_builddir="$(cd ..; pwd)" libvirt_uri="test://$abs_top_builddir/test-data/phony-guests/guests.xml" -f=../test-data/phony-guests/fedora.img -if ! test -f $f || ! test -s $f; then - echo "$0: test skipped because phony Fedora image was not created" - exit 77 -fi - d=test-v2v-copy-to-local.d rm -rf $d mkdir $d diff --git a/v2v/test-v2v-floppy.sh b/v2v/test-v2v-floppy.sh index 1f3f1bc..ac407b4 100755 --- a/v2v/test-v2v-floppy.sh +++ b/v2v/test-v2v-floppy.sh @@ -19,37 +19,18 @@ # Test converting a guest with a floppy disk. # https://bugzilla.redhat.com/show_bug.cgi?id=1309706 -unset CDPATH -export LANG=C set -e -if [ -n "$SKIP_TEST_V2V_FLOPPY_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi +$TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml +skip_unless_phony_guest windows.img +skip_unless_phony_guest blank-disk.img -if [ "$(guestfish get-backend)" = "uml" ]; then - echo "$0: test skipped because UML backend does not support network" - exit 77 -fi - -abs_builddir="$(pwd)" libvirt_uri="test://$abs_builddir/test-v2v-floppy.xml" -f=../test-data/phony-guests/windows.img -if ! test -f $f || ! test -s $f; then - echo "$0: test skipped because phony Windows image was not created" - exit 77 -fi - -f=../test-data/phony-guests/blank-disk.img -if ! test -f $f || ! test -s $f; then - echo "$0: test skipped because blank-disk.img was not created" - exit 77 -fi - -export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" +export VIRTIO_WIN="$top_srcdir/test-data/fake-virtio-win" d=test-v2v-floppy.d rm -rf $d diff --git a/v2v/test-v2v-i-disk.sh b/v2v/test-v2v-i-disk.sh index b806a44..c4b519c 100755 --- a/v2v/test-v2v-i-disk.sh +++ b/v2v/test-v2v-i-disk.sh @@ -18,34 +18,21 @@ # Test -i disk option. -unset CDPATH -export LANG=C set -e -if [ -n "$SKIP_TEST_V2V_I_DISK_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi +$TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml +skip_unless_phony_guest windows.img -if [ "$(guestfish get-backend)" = "uml" ]; then - echo "$0: test skipped because UML backend does not support network" - exit 77 -fi - -f=../test-data/phony-guests/windows.img -if ! test -f $f || ! test -s $f; then - echo "$0: test skipped because phony Windows image was not created" - exit 77 -fi - -export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" d=test-v2v-i-disk.d rm -rf $d mkdir $d $VG virt-v2v --debug-gc \ - -i disk $f \ + -i disk $top_builddir/test-data/phony-guests/windows.img \ -o local -os $d # Test the libvirt XML metadata and a disk was created. diff --git a/v2v/test-v2v-i-ova-formats.sh b/v2v/test-v2v-i-ova-formats.sh index d49b7be..d357287 100755 --- a/v2v/test-v2v-i-ova-formats.sh +++ b/v2v/test-v2v-i-ova-formats.sh @@ -18,35 +18,17 @@ # Test -i ova option with ova file compressed in different ways -unset CDPATH -export LANG=C set -e $TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml +skip_unless zip --version +skip_unless unzip --help formats="zip tar-gz tar-xz" -if [ -n "$SKIP_TEST_V2V_I_OVA_FORMATS_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi - -if ! zip --version >/dev/null 2>&1; then - echo "$0: test skipped because 'zip' utility is not available" - exit 77 -fi - -if ! unzip --help >/dev/null 2>&1; then - echo "$0: test skipped because 'unzip' utility is not available" - exit 77 -fi - -if [ "$(guestfish get-backend)" = "uml" ]; then - echo "$0: test skipped because UML backend does not support network" - exit 77 -fi - -export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" d=test-v2v-i-ova-formats.d rm -rf $d diff --git a/v2v/test-v2v-i-ova-gz.sh b/v2v/test-v2v-i-ova-gz.sh index e292683..2bf2f5e 100755 --- a/v2v/test-v2v-i-ova-gz.sh +++ b/v2v/test-v2v-i-ova-gz.sh @@ -23,18 +23,10 @@ export LANG=C set -e $TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml -if [ -n "$SKIP_TEST_V2V_I_OVA_GZ_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi - -if [ "$(guestfish get-backend)" = "uml" ]; then - echo "$0: test skipped because UML backend does not support network" - exit 77 -fi - -export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" d=test-v2v-i-ova-gz.d rm -rf $d diff --git a/v2v/test-v2v-i-ova-subfolders.sh b/v2v/test-v2v-i-ova-subfolders.sh index ea3352c..12e0e87 100755 --- a/v2v/test-v2v-i-ova-subfolders.sh +++ b/v2v/test-v2v-i-ova-subfolders.sh @@ -23,18 +23,10 @@ export LANG=C set -e $TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml -if [ -n "$SKIP_TEST_V2V_I_OVA_SUBFOLDERS_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi - -if [ "$(guestfish get-backend)" = "uml" ]; then - echo "$0: test skipped because UML backend does not support network" - exit 77 -fi - -export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" d=test-v2v-i-ova-subfolders.d rm -rf $d diff --git a/v2v/test-v2v-i-ova-tar.sh b/v2v/test-v2v-i-ova-tar.sh index 2d1389d..003d5e6 100755 --- a/v2v/test-v2v-i-ova-tar.sh +++ b/v2v/test-v2v-i-ova-tar.sh @@ -23,18 +23,10 @@ export LANG=C set -e $TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml -if [ -n "$SKIP_TEST_V2V_I_OVA_FORMATS_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi - -if [ "$(guestfish get-backend)" = "uml" ]; then - echo "$0: test skipped because UML backend does not support network" - exit 77 -fi - -export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" d=test-v2v-i-ova-tar.d rm -rf $d diff --git a/v2v/test-v2v-i-ova-two-disks.sh b/v2v/test-v2v-i-ova-two-disks.sh index 86584c3..9ecc380 100755 --- a/v2v/test-v2v-i-ova-two-disks.sh +++ b/v2v/test-v2v-i-ova-two-disks.sh @@ -23,19 +23,11 @@ export LANG=C set -e $TEST_FUNCTIONS +skip_if_skipped +skip_if_backend uml -if [ -n "$SKIP_TEST_V2V_I_OVA_TWO_DISKS_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi - -if [ "$(guestfish get-backend)" = "uml" ]; then - echo "$0: test skipped because UML backend does not support network" - exit 77 -fi - -export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" +export VIRTIO_WIN="$top_srcdir/test-data/fake-virtio-win" d=test-v2v-i-ova-two-disks.d rm -rf $d diff --git a/v2v/test-v2v-i-ova.sh b/v2v/test-v2v-i-ova.sh index 4b97a1a..7a33b6c 100755 --- a/v2v/test-v2v-i-ova.sh +++ b/v2v/test-v2v-i-ova.sh @@ -18,37 +18,19 @@ # Test -i ova option. -unset CDPATH -export LANG=C set -e $TEST_FUNCTIONS - -if [ -n "$SKIP_TEST_V2V_I_OVA_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi - -if [ "$(guestfish get-backend)" = "uml" ]; then - echo "$0: test skipped because UML backend does not support network" - exit 77 -fi +skip_if_skipped +skip_if_backend uml +skip_unless_phony_guest windows.img # XXX Remove when we fix this. See: # https://www.redhat.com/archives/libguestfs/2017-February/msg00101.html -if [[ "$(guestfish get-backend)" =~ ^libvirt ]]; then - echo "$0: test skipped because of bug with virt-v2v -i ova and libvirt" - exit 77 -fi +skip_if_backend libvirt -f=../test-data/phony-guests/windows.img -if ! test -f $f || ! test -s $f; then - echo "$0: test skipped because phony Windows image was not created" - exit 77 -fi - -export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" +export VIRTIO_WIN="$top_srcdir/test-data/fake-virtio-win" d=test-v2v-i-ova.d rm -rf $d @@ -60,7 +42,8 @@ mf=test-ova.mf ova=test-ova.ova raw=TestOva-sda -qemu-img convert $f -O vmdk $d/$vmdk +qemu-img convert $top_builddir/test-data/phony-guests/windows.img \ + -O vmdk $d/$vmdk cp $ovf $d/$ovf sha1=`do_sha1 $d/$ovf` echo "SHA1($ovf)= $sha1" > $d/$mf diff --git a/v2v/test-v2v-in-place.sh b/v2v/test-v2v-in-place.sh index c8b2ec4..6f7d78f 100755 --- a/v2v/test-v2v-in-place.sh +++ b/v2v/test-v2v-in-place.sh @@ -24,27 +24,14 @@ export LANG=C set -e $TEST_FUNCTIONS - -if [ -n "$SKIP_TEST_V2V_IN_PLACE_SH" ]; then - echo "$0: test skipped because environment variable is set" - exit 77 -fi - -if [ "$(guestfish get-backend)" = "uml" ]; then - echo "$0: test skipped because UML backend does not support network" - exit 77 -fi - -abs_top_builddir="$(cd ..; pwd)" +skip_if_skipped +skip_if_backend uml +skip_unless_phony_guest windows.img img_base="$abs_top_builddir/test-data/phony-guests/windows.img" -if ! test -f $img_base || ! test -s $img_base; then - echo "$0: test skipped because phony Windows image was not created" - exit 77 -fi -export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools" -export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win" +export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" +export VIRTIO_WIN="$top_srcdir/test-data/fake-virtio-win" d=$PWD/test-v2v-in-place.d rm -rf $d -- 2.10.2