[Libguestfs] [PATCH v2 3/3] tests: Introduce test harness for running tests.

Richard W.M. Jones rjones at redhat.com
Sat Sep 20 14:37:22 UTC 2014


We would like to have a more flexible way to run tests, including
running them on an installed copy of libguestfs, running them in
parallel, and being able to express dependencies and ordering between
tests and test files properly.

Therefore introduce a test harness (generator/test-harness) program
which can run tests either from the locally built copy, or from an
installed copy of the tests (in @libdir@/guestfs/tests).

The test harness is backwards compatible on the command line, ie.
'make check', 'make -C inspector check-valgrind' etc. will still work.
But in addition, you can now run the tests on an installed copy of
libguestfs by doing:

  cd /usr/lib/guestfs/tests
  ./test-harness

The test-harness script supports various options, see 'test-harness --help'
for full details.

Other notable features:

 - Checking SKIP_* environment variables in tests is no longer
   necessary.  The test harness deals with these.

 - Every test runs in its own temporary directory.  There is no need
   to clean up output files.  On the other hand, tests must use
   $srcdir to refer to test data.

This is only implemented for a single directory at the moment
(ie. inspector/)
---
 .gitignore                                       |   5 +-
 Makefile.am                                      |   5 +
 common-rules.mk                                  |   3 +
 configure.ac                                     |   2 +
 generator/Makefile.am                            |   2 +
 generator/main.ml                                |   9 +
 generator/tests.ml                               | 725 +++++++++++++++++++++++
 generator/types.ml                               |   9 +
 inspector/Makefile.am                            |  17 +-
 inspector/test-virt-inspector-local-guests.sh.in |  26 +
 inspector/test-virt-inspector.sh                 |  13 +-
 inspector/test-xmllint.sh.in                     |   5 +
 inspector/tests.mk                               |  83 +++
 tests/data/Makefile.am                           |  10 +-
 tests/guests/Makefile.am                         |  84 +--
 tests/guests/guest-aux/make-debian-img.sh        |   6 +-
 tests/guests/guest-aux/make-fedora-img.pl        |  21 +-
 tests/guests/guest-aux/make-ubuntu-img.sh        |   4 +-
 tests/guests/guest-aux/make-windows-img.sh       |   6 +-
 19 files changed, 928 insertions(+), 107 deletions(-)
 create mode 100644 generator/tests.ml
 create mode 100755 inspector/test-virt-inspector-local-guests.sh.in
 create mode 100644 inspector/tests.mk

diff --git a/.gitignore b/.gitignore
index 86158eb..5edcbdd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -262,8 +262,8 @@ Makefile.in
 /html/virt-tar-out.1.html
 /html/virt-v2v.1.html
 /html/virt-win-reg.1.html
-/inspector/actual-*.xml
 /inspector/stamp-virt-inspector.pod
+/inspector/test-virt-inspector-local-guests.sh
 /inspector/test-xmllint.sh
 /inspector/virt-inspector
 /inspector/virt-inspector.1
@@ -474,6 +474,7 @@ Makefile.in
 /sysprep/virt-sysprep.1
 /test.err
 /test.out
+/test-harness
 /tests/c-api/test-add-drive-opts
 /tests/c-api/test-add-libvirt-dom
 /tests/c-api/test-backend-settings
@@ -523,7 +524,7 @@ Makefile.in
 /tests/guests/guest-aux/fedora-packages.db
 /tests/guests/guest-aux/windows-software
 /tests/guests/guest-aux/windows-system
-/tests/guests/stamp-fedora-md.img
+/tests/guests/stamp-guests
 /tests/guests/ubuntu.img
 /tests/guests/windows.img
 /tests/mount-local/test-parallel-mount-local
diff --git a/Makefile.am b/Makefile.am
index 097ba80..a6df034 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -201,6 +201,7 @@ EXTRA_DIST = \
 	logo/fish-5yrs.svg logo/fish-5yrs.png \
 	logo/virt-builder.svg \
 	m4/.gitignore \
+	test-harness \
 	tests/run-xml-to-junit.sh \
 	tests/run-xml-to-junit.xsl \
 	tmp/.gitignore \
@@ -406,6 +407,10 @@ clean-local:
 quickcheck:
 	$(top_builddir)/run test-tool/libguestfs-test-tool $(QUICKCHECK_TEST_TOOL_ARGS)
 
+# Install the test harness.
+localtestsdir = $(alltestsdir)
+localtests_SCRIPTS = test-harness
+
 # Non-standard tests.
 
 check-all:
diff --git a/common-rules.mk b/common-rules.mk
index 312107e..5a239ab 100644
--- a/common-rules.mk
+++ b/common-rules.mk
@@ -27,3 +27,6 @@ builddir     ?= @builddir@
 abs_builddir ?= @abs_builddir@
 srcdir       ?= @srcdir@
 abs_srcdir   ?= @abs_srcdir@
+
+# Tests directory.
+alltestsdir   = $(libdir)/guestfs/tests
diff --git a/configure.ac b/configure.ac
index 0b2c0e0..d01844b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1612,6 +1612,8 @@ mkdir -p \
 dnl http://www.mail-archive.com/automake@gnu.org/msg10204.html
 AC_CONFIG_FILES([appliance/libguestfs-make-fixed-appliance],
                 [chmod +x,-w appliance/libguestfs-make-fixed-appliance])
+AC_CONFIG_FILES([inspector/test-virt-inspector-local-guests.sh],
+                [chmod +x,-w inspector/test-virt-inspector-local-guests.sh])
 AC_CONFIG_FILES([inspector/test-xmllint.sh],
                 [chmod +x,-w inspector/test-xmllint.sh])
 AC_CONFIG_FILES([p2v/virt-p2v-make-disk],
diff --git a/generator/Makefile.am b/generator/Makefile.am
index 3716c77..610b078 100644
--- a/generator/Makefile.am
+++ b/generator/Makefile.am
@@ -52,6 +52,7 @@ sources = \
 	ruby.ml \
 	structs.ml \
 	structs.mli \
+	tests.ml \
 	tests_c_api.ml \
 	types.ml \
 	utils.ml \
@@ -71,6 +72,7 @@ objects = \
 	pr.cmo \
 	docstrings.cmo \
 	checks.cmo \
+	tests.cmo \
 	c.cmo \
 	xdr.cmo \
 	daemon.cmo \
diff --git a/generator/main.ml b/generator/main.ml
index c0ad146..3aef124 100644
--- a/generator/main.ml
+++ b/generator/main.ml
@@ -30,6 +30,7 @@ open Types
 open C
 open Xdr
 open Daemon
+open Tests
 open Tests_c_api
 open Fish
 open Ocaml
@@ -48,6 +49,8 @@ open Bindtests
 open Errnostring
 open Customize
 
+let (//) = Filename.concat
+
 let perror msg = function
   | Unix_error (err, _, _) ->
       eprintf "%s: %s\n" msg (error_message err)
@@ -214,6 +217,12 @@ Run it from the top source directory using the command
   output_to "customize/customize-synopsis.pod" generate_customize_synopsis_pod;
   output_to "customize/customize-options.pod" generate_customize_options_pod;
 
+  List.iter (
+    fun (dir, tests) ->
+      output_to (dir // "tests.mk") (generate_tests_mk dir tests)
+  ) tests;
+  output_to ~perm:0o555 "test-harness" generate_test_harness;
+
   (* Generate the list of files generated -- last. *)
   printf "generated %d lines of code\n" (get_lines_generated ());
   let files = List.sort compare (get_files_generated ()) in
diff --git a/generator/tests.ml b/generator/tests.ml
new file mode 100644
index 0000000..41d64a9
--- /dev/null
+++ b/generator/tests.ml
@@ -0,0 +1,725 @@
+(* libguestfs
+ * Copyright (C) 2014 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *)
+
+(* Please read generator/README first. *)
+
+open Printf
+
+open Types
+open Utils
+open Pr
+open Docstrings
+
+(* Tests and their dependencies. *)
+let tests = [
+  "inspector", {
+    check = [
+      "test-virt-inspector.sh";
+    ];
+    check_fast = [
+      "test-xmllint.sh";
+    ];
+    check_slow = [];
+    check_local_guests = [
+      "test-virt-inspector-local-guests.sh";
+    ];
+    check_data = [
+      "example-debian-netinst-cd.xml";
+      "example-debian.xml";
+      "example-fedora-dvd.xml";
+      "example-fedora-netinst-cd.xml";
+      "example-fedora.xml";
+      "example-rhel-6-dvd.xml";
+      "example-rhel-6-netinst-cd.xml";
+      "example-rhel-6.xml";
+      "example-ubuntu-live-cd.xml";
+      "example-ubuntu.xml";
+      "example-windows-2003-x64-cd.xml";
+      "example-windows-2003-x86-cd.xml";
+      "example-windows.xml";
+      "example-windows-xp-cd.xml";
+      "expected-debian.img.xml";
+      "expected-fedora.img.xml";
+      "expected-ubuntu.img.xml";
+      "expected-windows.img.xml";
+      "virt-inspector.rng";
+    ]
+  };
+
+]
+
+(* Generate the tests.mk files in each subdirectory. *)
+let generate_tests_mk dir tests () =
+  generate_header HashStyle GPLv2plus;
+
+  let all_test_files =
+    tests.check @ tests.check_fast @ tests.check_slow @ tests.check_local_guests
+  in
+
+  pr "localtestsdir = $(alltestsdir)/%s\n" dir;
+
+  if tests.check_data <> [] then (
+    pr "\n";
+    pr "localtests_DATA =";
+    List.iter (fun n -> pr " \\\n\t%s" n) tests.check_data;
+    pr "\n";
+  );
+
+  pr "\n";
+  pr "localtests_SCRIPTS =";
+  List.iter (fun n -> pr " \\\n\t%s" n) all_test_files;
+  pr "\n";
+
+  (* Create rules so that 'make -C dir check' etc will do something. *)
+  if tests.check <> [] then (
+    pr "\n";
+    (* Note that we cannot create a simple 'check' target since
+     * automake will (silently) overrule it.
+     *)
+    pr "TESTS_ENVIRONMENT = $(top_builddir)/run\n";
+    pr "TESTS = $(top_builddir)/test-harness\n";
+    pr "\n";
+    pr "check-valgrind:\n";
+    pr "\t$(top_builddir)/run $(top_builddir)/test-harness --valgrind\n";
+    pr "\n";
+    pr "check-direct:\n";
+    pr "\t$(top_builddir)/run $(top_builddir)/test-harness --direct\n";
+    pr "\n";
+    pr "check-valgrind-direct:\n";
+    pr "\t$(top_builddir)/run $(top_builddir)/test-harness --valgrind --direct\n";
+    pr "\n";
+    pr "check-uml:\n";
+    pr "\t$(top_builddir)/run $(top_builddir)/test-harness --uml\n";
+    pr "\n";
+    pr "check-valgrind-uml:\n";
+    pr "\t$(top_builddir)/run $(top_builddir)/test-harness --valgrind --uml\n";
+    pr "\n";
+    pr "check-with-upstream-qemu:\n";
+    pr "\t$(top_builddir)/run $(top_builddir)/test-harness --with-upstream-qemu\n";
+    pr "\n";
+    pr "check-with-upstream-libvirt:\n";
+    pr "\t$(top_builddir)/run $(top_builddir)/test-harness --with-upstream-libvirt\n";
+  );
+
+  if tests.check_fast <> [] then (
+    pr "\n";
+    pr "check-fast:\n";
+    pr "\t$(top_builddir)/run $(top_builddir)/test-harness --fast\n"
+  );
+
+  if tests.check_slow <> [] then (
+    pr "\n";
+    pr "check-slow:\n";
+    pr "\t$(top_builddir)/run $(top_builddir)/test-harness --slow\n"
+  );
+
+  if tests.check_local_guests <> [] then (
+    pr "\n";
+    pr "check-local-guests:\n";
+    pr "\t$(top_builddir)/run $(top_builddir)/test-harness --local-guests\n";
+    pr "\n";
+    pr "check-valgrind-local-guests:\n";
+    pr "\t$(top_builddir)/run $(top_builddir)/test-harness --valgrind --local-guests\n"
+  );
+
+  pr "\n";
+  pr "EXTRA_DIST += tests.mk\n"
+
+let generate_test_harness () =
+  pr "#!/bin/bash -\n";
+  generate_header HashStyle GPLv2plus;
+
+  pr "\
+unset CDPATH
+
+usage ()
+{
+    echo \"test-harness: Run the libguestfs test suite, or parts of it.\"
+    echo
+    echo \"Usage:\"
+    echo \"  $0 [--options] [directory]\"
+    echo
+    echo \"Normally tests in the current directory are run.  If the current\"
+    echo \"directory is the top level of the test suite then the whole test\"
+    echo \"suite is run.  If the current directory is a leaf directory, then\"
+    echo \"only tests in that directory are run.  If you specify a directory\"
+    echo \"name on the command line, then we 'cd' into that directory first.\"
+    echo
+    echo \"Options to select which tests to run:\"
+    echo \"  --fast       Run only test which don't need the appliance\"
+    echo \"  --slow       Run only very long-running tests\"
+    echo \"(if neither --fast or --slow, then --fast + normal tests are run)\"
+    echo \"  --local-guests\"
+    echo \"               Run tests that use locally installed guests r/o\"
+    echo
+    echo \"Options to run the selected tests under different conditions:\"
+    echo \"  --debug      Run tests with debugging enabled (recommended)\"
+    echo \"  --valgrind   Run tests under valgrind\"
+    echo \"  --direct     Run tests using the direct backend\"
+    echo \"  --uml[=UML]  Run tests using the UML backend [default ~/d/linux-um/vmlinux]\"
+    echo \"  --with-upstream-qemu[=QEMU]\"
+    echo \"               Run tests using upstream qemu\"
+    echo \"                 [default ~/d/qemu/x86_64-softmmu/qemu-system-x86_64]\"
+    echo \"  --with-upstream-libvirt[=LIBVIRTDIR]\"
+    echo \"               Run tests using upstream libvirt [default ~/d/libvirt]\"
+    echo
+    echo \"Options used internally:\"
+    echo \"  --make-phony-guests-only\"
+    echo \"               Generate the phony guests used for testing.\"
+    exit 0
+}
+
+TEMP=`getopt \\
+        -o '?' \\
+        -l 'help,debug,direct,fast,local-guests,make-phony-guests-only,slow,uml::,valgrind,with-upstream-libvirt::,with-upstream-qemu::' \\
+        -- \"$@\"`
+if [ $? != 0 ]; then
+    echo \"$0: problem parsing the command line arguments\"
+    exit 1
+fi
+eval set -- \"$TEMP\"
+
+fast=0
+normal=0
+slow=0
+local_guests=0
+
+while true ; do
+    case \"$1\" in
+        --debug)
+            debug=1
+            shift
+            ;;
+        --direct)
+            direct=1
+            shift
+            ;;
+        --fast)
+            fast=1
+            shift
+            ;;
+        --local-guests)
+            local_guests=1
+            shift
+            ;;
+        --make-phony-guests-only)
+            make_phony_guests_only=1
+            shift
+            ;;
+        --slow)
+            slow=1
+            shift
+            ;;
+        --uml)
+            if [ \"x$1\" != \"x\" ]; then
+                uml=$HOME/d/linux-um/vmlinux
+            else
+                uml=\"$1\"
+            fi
+            shift 2
+            ;;
+        --valgrind)
+            valgrind=1
+            shift
+            ;;
+        --with-upstream-libvirt)
+            if [ \"x$1\" != \"x\" ]; then
+                libvirt=$HOME/d/libvirt
+            else
+                libvirt=\"$1\"
+            fi
+            shift 2
+            ;;
+        --with-upstream-qemu)
+            if [ \"x$1\" != \"x\" ]; then
+                qemu=$HOME/d/qemu/x86_64-softmmu/qemu-system-x86_64
+            else
+                qemu=\"$1\"
+            fi
+            shift 2
+            ;;
+        --help)
+            usage
+            ;;
+        --)
+            shift
+            break
+            ;;
+        *)
+            echo \"$0: internal error ($1)\"
+            exit 1
+            ;;
+    esac
+done
+
+# Some combinations are not permitted.
+if [ $(( fast + slow + local_guests )) -gt 1 ]; then
+    echo \"$0: cannot use --fast, --slow and --local-guests options together\"
+    exit 1
+fi
+
+# If none of the selection options are used, select fast + normal.
+if [ $(( fast + slow + local_guests )) -eq 0 ]; then
+    fast=1
+    normal=1
+fi
+
+# --direct and --uml cannot be combined.
+if [ -n \"$direct\" -a -n \"$uml\" ]; then
+    echo \"$0: cannot use --direct and --uml options together\"
+    exit 1
+fi
+
+# A single parameter on the command line means start the tests in
+# that directory.
+if [ \"$#\" -eq 1 ]; then
+    cd \"$1\"
+elif [ \"$#\" -gt 1 ]; then
+    echo \"$0: too many command line arguments\"
+    exit 1
+fi
+
+# Find out whether we are running in the top-level directory (and
+# hence running all the tests) or in a subdirectory.
+b=\"$(basename $(pwd))\"
+if [ -x test-harness -a -d inspector ]; then
+    run_func=run_all_tests
+    top_builddir=\"$(pwd)\"
+elif [ \"$b\" = \"guests\" -a -d \"guest-aux\" ]; then
+    run_func=
+    top_builddir=\"$(cd ../..; pwd)\"
+";
+
+  List.iter (
+    fun (dir, tests) ->
+      let dir_safe = replace_char dir '/' '_' in
+
+      (* Calculate a ../.. path to take us to the top build directory. *)
+      let path_to_top = ref ".." in
+      for i = 0 to String.length dir-1 do
+        if dir.[i] = '/' then path_to_top := !path_to_top ^ "/.."
+      done;
+      let path_to_top = !path_to_top in
+
+      (* Match just the last element of the path with the basename ... *)
+      let dir_base =
+        try
+          let i = String.rindex dir '/' in
+          String.sub dir (i+1) (String.length dir - (i+1))
+        with Not_found -> dir in
+      (* ... and any file in the directory. *)
+      let any_file =
+        if tests.check <> [] then List.hd tests.check
+        else if tests.check_fast <> [] then List.hd tests.check_fast
+        else if tests.check_slow <> [] then List.hd tests.check_slow
+        else if tests.check_local_guests <> [] then
+          List.hd tests.check_local_guests
+        else (
+          assert (tests.check_data <> []);
+          List.hd tests.check_data
+        ) in
+
+      pr "elif [ \"$b\" = \"%s\" -a -f \"%s\" ]; then\n" dir_base any_file;
+      pr "    run_func=run_%s\n" dir_safe;
+      pr "    top_builddir=\"$(cd %s; pwd)\"\n" path_to_top;
+  ) tests;
+
+pr "\
+else
+    echo \"$0: current directory ($b) is not a libguestfs test directory.\"
+    exit 1
+fi
+
+# Now we can set the top_* environment variables, as with automake.
+# Was srcdir passed by automake?
+if [ -n \"$srcdir\" -a \"$srcdir\" != \".\" ]; then
+    top_srcdir=\"(cd $top_builddir; cd $srcdir; pwd)\"
+else
+    top_srcdir=\"$top_builddir\"
+fi
+abs_top_srcdir=\"$top_srcdir\"
+abs_top_builddir=\"$top_builddir\"
+export top_srcdir top_builddir abs_top_srcdir abs_top_builddir
+
+# Are we running from the build directory or from installed tests?
+# If installed, then we cannot write to the phony guests directory.
+if [ -f \"$top_builddir/Makefile.am\" ]; then
+    phonydir=\"$top_builddir/tests/guests\"
+else
+    mkdir -p \"$HOME/.cache/libguestfs-tests\"
+    phonydir=\"$HOME/.cache/libguestfs-tests/phony-guests\"
+fi
+export phonydir
+
+# Debugging.
+if [ -n \"$debug\" ]; then
+    export LIBGUESTFS_DEBUG=1
+    export LIBGUESTFS_TRACE=1
+fi
+
+# Direct.
+if [ -n \"$direct\" ]; then
+    export LIBGUESTFS_BACKEND=direct
+fi
+
+# UML
+if [ -n \"$uml\" ]; then
+    export LIBGUESTFS_BACKEND=uml
+    export LIBGUESTFS_HV=\"$uml\"
+fi
+
+# Valgrind - just check it exists here.
+if [ -n \"$valgrind\" ]; then
+    if ! valgrind --help >/dev/null 2>&1; then
+        echo \"$0: valgrind is not installed\"
+        exit 1
+    fi
+fi
+
+# Timeouts.
+timeout_period=4h
+timeout_kill=30s
+
+# Do we have Padraig's timeout utility (from coreutils)?
+if timeout --help >/dev/null 2>&1; then
+    # Must use the --foreground option (RHBZ#1025269).
+    if timeout --foreground 2 sleep 0 >/dev/null 2>&1; then
+        # Does this version of timeout have the -k option?  (Not on RHEL 6)
+        if timeout -k 10s 10s true >/dev/null 2>&1; then
+            timeout=\"timeout --foreground -k $timeout_kill $timeout_period\"
+        fi
+    fi
+fi
+
+# QEMU.
+if [ -n \"$qemu\" ]; then
+    export LIBGUESTFS_HV=\"$qemu\"
+fi
+
+# libvirt.
+if [ -n \"$libvirt\" ]; then
+    libvirt=\"$libvirt/run\"
+    if [ ! -x \"$libvirt\" ]; then
+        echo \"$0: --with-libvirt: script '$libvirt' not found\"
+        exit 1
+    fi
+fi
+
+# Make phony guests.
+make_phony_guests ()
+{
+    mkdir -p \"$phonydir\"
+    if [ ! -d \"$phonydir\" ]; then
+        echo \"$0: $phonydir could not be created or is not a directory\"
+        exit 1
+    fi
+
+    builddir=\"$top_builddir/tests/guests\"
+    srcdir=\"$top_srcdir/tests/guests\"
+    abs_srcdir=\"$srcdir\"
+    abs_builddir=\"$builddir\"
+    export srcdir builddir abs_srcdir abs_builddir
+
+    datadir=\"$top_builddir/tests/data\"
+    export datadir
+
+    # Because we distribute all the intermediate files, they are always(?)
+    # in srcdir, not builddir.
+    ga=\"$top_srcdir/tests/guests/guest-aux\"
+
+    pushd \"$phonydir\" >/dev/null
+
+    # Make several different blank images.  These are not guests, but we
+    # include them in the libvirt fake XML to make sure that virt-df and
+    # virt-alignment-scan don't break when they encounter them.
+    for f in disk part fs bootroot bootrootlv; do
+        o=\"blank-$f.img\"
+        if [ ! -f \"$o\" ]; then
+            echo \"test-harness: building $o\"
+            if guestfish -N \"$o-t=$f\" exit; then
+                mv \"$o-t\" \"$o\"
+            else
+                echo \"$0: could not create $o\"
+                exit 1
+            fi
+        fi
+    done
+
+    # Make a (phony) Fedora image.
+    o=\"fedora.img\"
+    if [ ! -f \"$o\" -o \\
+        \"$o\" -ot \"$ga/make-fedora-img.pl\" -o \\
+        \"$o\" -ot \"$ga/fedora-journal.tar.xz\" -o \\
+        \"$o\" -ot \"$ga/fedora-name.db\" -o \\
+        \"$o\" -ot \"$ga/fedora-packages.db\" ]; then
+        echo \"test-harness: building $o\"
+        if ! \"$ga/make-fedora-img.pl\" --layout=partitions; then
+            echo \"$0: could not create $o\"
+            exit 1
+        fi
+    fi
+
+    # Make a (phony) Fedora image using md devices.
+    o=\"fedora-md1.img\"
+    if [ ! -f \"$o\" -o \\
+        \"$o\" -ot \"$ga/make-fedora-img.pl\" -o \\
+        \"$o\" -ot \"$ga/fedora-journal.tar.xz\" -o \\
+        \"$o\" -ot \"$ga/fedora-name.db\" -o \\
+        \"$o\" -ot \"$ga/fedora-packages.db\" ]; then
+        echo \"test-harness: building $o\"
+        if ! \"$ga/make-fedora-img.pl\" --layout=partitions-md; then
+            echo \"$0: could not create $o\"
+            exit 1
+        fi
+    fi
+
+    # Make a (phony) Fedora image using btrfs.
+    o=\"fedora-btrfs.img\"
+    if [ ! -f \"$o\" -o \\
+        \"$o\" -ot \"$ga/make-fedora-img.pl\" -o \\
+        \"$o\" -ot \"$ga/fedora-journal.tar.xz\" -o \\
+        \"$o\" -ot \"$ga/fedora-name.db\" -o \\
+        \"$o\" -ot \"$ga/fedora-packages.db\" ]; then
+        echo \"test-harness: building $o\"
+        if ! \"$ga/make-fedora-img.pl\" --layout=btrfs; then
+            echo \"$0: could not create $o\"
+            exit 1
+        fi
+    fi
+
+    # Make a (phony) Debian image.
+    o=\"debian.img\"
+    if [ ! -f \"$o\" -o \\
+        \"$o\" -ot \"$ga/make-debian-img.sh\" ]; then
+        echo \"test-harness: building $o\"
+        if ! \"$ga/make-debian-img.sh\"; then
+            echo \"$0: could not create $o\"
+            exit 1
+        fi
+    fi
+
+    # Make a (phony) Ubuntu image.
+    o=\"ubuntu.img\"
+    if [ ! -f \"$o\" -o \\
+        \"$o\" -ot \"$ga/make-ubuntu-img.sh\" ]; then
+        echo \"test-harness: building $o\"
+        if ! \"$ga/make-ubuntu-img.sh\"; then
+            echo \"$0: could not create $o\"
+            exit 1
+        fi
+    fi
+
+    # Make a (phony) Windows image.
+    o=\"windows.img\"
+    if [ ! -f \"$o\" -o \\
+        \"$o\" -ot \"$ga/make-windows-img.sh\" -o \\
+        \"$o\" -ot \"$ga/windows-software\" -o \\
+        \"$o\" -ot \"$ga/windows-system\" ]; then
+        echo \"test-harness: building $o\"
+        if ! \"$ga/make-windows-img.sh\"; then
+            echo \"$0: could not create $o\"
+            exit 1
+        fi
+    fi
+
+    # Make XML describing all guests we managed to create above.
+    \"$ga/make-guests-all-good.pl\" > guests-all-good.xml \
+        blank-disk.img \
+        blank-part.img \
+        blank-fs.img \
+        blank-bootroot.img \
+        blank-bootrootlv.img \
+        debian.img \
+        fedora.img \
+        fedora-md1.img \
+        fedora-md2.img \
+        fedora-btrfs.img \
+        ubuntu.img \
+        windows.img
+
+    rm -f *.tmp.*
+
+    popd >/dev/null
+}
+
+# Count total tests, skipped, timed out, errors.
+total=0
+skipped=0
+timedout=0
+errors=0
+
+# Wrapper function to run one ordinary test.
+run_one_test ()
+{
+    if [ -n \"$valgrind\" ]; then
+        export VG=\"valgrind --vgdb=no --log-file=/tmp/valgrind-%%q{T}-%%p.log --leak-check=full --error-exitcode=119 --suppressions=$abs_top_srcdir/valgrind-suppressions\"
+    else
+        unset VG
+    fi
+
+    # The test runs inside a temporary directory which is deleted
+    # as soon as the test finishes, UNLESS it fails in which case we
+    # leave it around for you to examine.
+    tmpdir=\"$(mktemp -d)\"
+
+    echo \"test-harness:\" \"$@\"
+    pushd \"$tmpdir\" >/dev/null
+    start_t=\"$(date +'%%s')\"
+    $timeout $libvirt \"$@\" >output 2>&1
+    r=$?
+    end_t=\"$(date +'%%s')\"
+    popd >/dev/null
+
+    ((total++))
+
+    case $r in
+        0)
+            echo \"test-harness:\" \"$@\" \"took $(( $end_t - $start_t )) second(s)\"
+            rm -r \"$tmpdir\"
+            ;;
+        77)
+            ((skipped++))
+            cat $tmpdir/output
+            rm -r \"$tmpdir\"
+            ;;
+        124)
+            ((timedout++))
+            cat $tmpdir/output
+            echo \"$0: command timed out after $timeout_period\"
+            rm -r \"$tmpdir\"
+            ;;
+        *)
+            ((errors++))
+            cat $tmpdir/output
+            echo \"$0: command failed with exit code $r\"
+            echo \"$0: test results left in $tmpdir\"
+            ;;
+    esac
+}
+
+# Wrapper function to run one 'local guests' test.
+run_local_guests_test ()
+{
+    run_one_test \"$1\" $( $top_builddir/pick-guests.pl 5 )
+}
+
+";
+
+  (* Define shell functions to run the tests in one subdirectory. *)
+  List.iter (
+    fun (dir, tests) ->
+      let dir_safe = replace_char dir '/' '_' in
+
+      pr "\
+run_%s ()
+{
+    echo \"test-harness: entering directory %s\"
+
+    builddir=\"$top_builddir/%s\"
+    srcdir=\"$top_srcdir/%s\"
+    abs_srcdir=\"$srcdir\"
+    abs_builddir=\"$builddir\"
+    export srcdir builddir abs_srcdir abs_builddir
+
+    datadir=\"$top_builddir/tests/data\"
+    export datadir
+
+    #echo srcdir=$srcdir
+    #echo top_srcdir=$top_srcdir
+    #echo datadir=$datadir
+
+" dir_safe dir dir dir;
+
+      let emit_tests run_wrapper =
+        List.iter (
+          fun name ->
+            let skip_name = replace_char name '-' '_' in
+            let skip_name = replace_char skip_name '.' '_' in
+            let skip_name = "SKIP_" ^ String.uppercase skip_name in
+            pr "        if [ -n \"$%s\" ]; then\n" skip_name;
+            pr "            ((skipped++))\n";
+            pr "            echo \"test-harness: %s skipped\"\n" name;
+            pr "        else\n";
+            pr "            %s \"$(pwd)/%s\"\n" run_wrapper name;
+            pr "        fi\n";
+        )
+      in
+
+      if tests.check_fast <> [] then (
+        pr "    if [ \"$fast\" -eq 1 ]; then\n";
+        emit_tests "run_one_test" tests.check_fast;
+        pr "    fi\n"
+      );
+      if tests.check <> [] then (
+        pr "    if [ \"$normal\" -eq 1 ]; then\n";
+        emit_tests "run_one_test" tests.check;
+        pr "    fi\n"
+      );
+      if tests.check_slow <> [] then (
+        pr "    if [ \"$slow\" -eq 1 ]; then\n";
+        emit_tests "run_one_test" tests.check_slow;
+        pr "    fi\n"
+      );
+      if tests.check_local_guests <> [] then (
+        pr "    if [ \"$local_guests\" -eq 1 ]; then\n";
+        emit_tests "run_local_guests_test" tests.check_local_guests;
+        pr "    fi\n"
+      );
+      pr "\n";
+      pr "    echo \"test-harness: leaving directory %s\"\n" dir;
+      pr "}\n";
+      pr "\n"
+  ) tests;
+
+  (* Define a shell function 'run_all_tests' which runs all of the
+   * above tests.
+   *)
+  pr "run_all_tests ()\n";
+  pr "{\n";
+  List.iter (
+    fun (dir, _) ->
+      let dir_safe = replace_char dir '/' '_' in
+      pr "    pushd %s >/dev/null\n" dir;
+      pr "    run_%s\n" dir_safe;
+      pr "    popd >/dev/null\n";
+  ) tests;
+  pr "}\n";
+  pr "\n";
+
+  pr "\
+# Before running the tests, we may need to generate the phony guests.
+if [ -n \"$make_phony_guests_only\" -o \"$normal\" -eq 1 -o \"$slow\" -eq 1 ]; then
+    make_phony_guests
+    if [ -n \"$make_phony_guests_only\" ]; then exit 0; fi
+fi
+
+# Run the tests.
+$run_func
+
+echo \"--------------------------------------------------\"
+echo \"Test summary\"
+echo \"--------------------------------------------------\"
+echo \"Total tests run . . . . . . . . . . . .  $total\"
+echo \"Errors  . . . . . . . . . . . . . . . .  $errors\"
+echo \"Timed out . . . . . . . . . . . . . . .  $timedout\"
+echo \"Skipped . . . . . . . . . . . . . . . .  $skipped\"
+echo \"--------------------------------------------------\"
+if [ $errors -gt 0 -o $timedout -gt 0 ]; then
+    exit 1
+fi
+"
diff --git a/generator/types.ml b/generator/types.ml
index 63aa235..3f1f682 100644
--- a/generator/types.ml
+++ b/generator/types.ml
@@ -207,6 +207,15 @@ type fish_output_t =
   | FishOutputOctal       (* for int return, print in octal *)
   | FishOutputHexadecimal (* for int return, print in hex *)
 
+type test = {
+  check : string list;
+  (* "fast" here means the appliance is not needed *)
+  check_fast : string list;
+  check_slow : string list;
+  check_local_guests : string list;
+  check_data : string list;
+}
+
 (* See guestfs(3)/EXTENDING LIBGUESTFS. *)
 type c_api_tests = (c_api_test_init * c_api_test_prereq * c_api_test * c_api_test_cleanup) list
 and c_api_test =
diff --git a/inspector/Makefile.am b/inspector/Makefile.am
index 86e0cd7..2bf78e9 100644
--- a/inspector/Makefile.am
+++ b/inspector/Makefile.am
@@ -17,6 +17,8 @@
 
 include $(top_srcdir)/subdir-rules.mk
 
+generator_built = tests.mk
+
 example_xml = \
 	example-debian.xml \
 	example-fedora.xml \
@@ -38,6 +40,7 @@ EXTRA_DIST = \
 	expected-fedora.img.xml \
 	expected-ubuntu.img.xml \
 	expected-windows.img.xml \
+	test-virt-inspector-local-guests.sh \
 	test-virt-inspector.sh \
 	test-xmllint.sh.in \
 	virt-inspector.pod
@@ -100,16 +103,4 @@ stamp-virt-inspector.pod: virt-inspector.pod
 	  $<
 	touch $@
 
-TESTS_ENVIRONMENT = $(top_builddir)/run --test
-TESTS = test-virt-inspector.sh
-if HAVE_XMLLINT
-TESTS += test-xmllint.sh
-endif
-
-check-valgrind:
-	$(MAKE) TESTS="test-virt-inspector.sh" VG="$(top_builddir)/run @VG@" check
-
-check-valgrind-local-guests:
-	for g in $(GUESTS); do \
-	  $(top_builddir)/run --test @VG@ ./virt-inspector -c "$(libvirt_ro_uri)" -d "$$g" || exit $$?; \
-	done
+include $(srcdir)/tests.mk
diff --git a/inspector/test-virt-inspector-local-guests.sh.in b/inspector/test-virt-inspector-local-guests.sh.in
new file mode 100755
index 0000000..7eade26
--- /dev/null
+++ b/inspector/test-virt-inspector-local-guests.sh.in
@@ -0,0 +1,26 @@
+#!/bin/bash -
+# libguestfs virt-inspector test script
+# @configure_input@
+# Copyright (C) 2012-2014 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+export LANG=C
+set -e
+set -x
+
+for g in "$@"; do
+    virt-inspector -c "@libvirt_ro_uri@" -d "$g" || exit 1
+done
diff --git a/inspector/test-virt-inspector.sh b/inspector/test-virt-inspector.sh
index 6fab253..d666e7b 100755
--- a/inspector/test-virt-inspector.sh
+++ b/inspector/test-virt-inspector.sh
@@ -20,23 +20,16 @@ export LANG=C
 set -e
 set -x
 
-# Allow this test to be skipped.
-if [ -n "$SKIP_TEST_VIRT_INSPECTOR_SH" ]; then
-    echo "$0: skipping test because SKIP_TEST_VIRT_INSPECTOR_SH is set."
-    exit 77
-fi
-
 # ntfs-3g can't set UUIDs right now, so ignore just that <uuid>.
 diff_ignore="-I <uuid>[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]</uuid>"
 
-for f in ../tests/guests/{debian,fedora,ubuntu,windows}.img; do
-    # Ignore zero-sized windows.img if ntfs-3g is not installed.
+for f in $phonydir/{debian,fedora,ubuntu,windows}.img; do
     if [ -s "$f" ]; then
         b=$(basename "$f" .xml)
-	$VG virt-inspector -a "$f" > "actual-$b.xml"
+	$VG virt-inspector -a "$f" > actual-$b.xml
         # This 'diff' command will fail (because of -e option) if there
         # are any differences.
-        diff -ur $diff_ignore "expected-$b.xml" "actual-$b.xml"
+        diff -ur $diff_ignore $srcdir/expected-$b.xml actual-$b.xml
     fi
 done
 
diff --git a/inspector/test-xmllint.sh.in b/inspector/test-xmllint.sh.in
index aef5ebc..f1195fd 100755
--- a/inspector/test-xmllint.sh.in
+++ b/inspector/test-xmllint.sh.in
@@ -19,6 +19,11 @@
 export LANG=C
 set -e
 
+if ! "@XMLLINT@" --version >/dev/null 2>&1; then
+    echo "$0: test skipped before xmllint is not installed"
+    exit 77
+fi
+
 for f in $srcdir/example-*.xml; do
     @XMLLINT@ --noout --relaxng $srcdir/virt-inspector.rng $f
 done
diff --git a/inspector/tests.mk b/inspector/tests.mk
new file mode 100644
index 0000000..ecbbdac
--- /dev/null
+++ b/inspector/tests.mk
@@ -0,0 +1,83 @@
+# libguestfs generated file
+# WARNING: THIS FILE IS GENERATED FROM:
+#   generator/ *.ml
+# ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
+#
+# Copyright (C) 2009-2014 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+localtestsdir = $(alltestsdir)/inspector
+
+localtests_DATA = \
+	example-debian-netinst-cd.xml \
+	example-debian.xml \
+	example-fedora-dvd.xml \
+	example-fedora-netinst-cd.xml \
+	example-fedora.xml \
+	example-rhel-6-dvd.xml \
+	example-rhel-6-netinst-cd.xml \
+	example-rhel-6.xml \
+	example-ubuntu-live-cd.xml \
+	example-ubuntu.xml \
+	example-windows-2003-x64-cd.xml \
+	example-windows-2003-x86-cd.xml \
+	example-windows.xml \
+	example-windows-xp-cd.xml \
+	expected-debian.img.xml \
+	expected-fedora.img.xml \
+	expected-ubuntu.img.xml \
+	expected-windows.img.xml \
+	virt-inspector.rng
+
+localtests_SCRIPTS = \
+	test-virt-inspector.sh \
+	test-xmllint.sh \
+	test-virt-inspector-local-guests.sh
+
+TESTS_ENVIRONMENT = $(top_builddir)/run
+TESTS = $(top_builddir)/test-harness
+
+check-valgrind:
+	$(top_builddir)/run $(top_builddir)/test-harness --valgrind
+
+check-direct:
+	$(top_builddir)/run $(top_builddir)/test-harness --direct
+
+check-valgrind-direct:
+	$(top_builddir)/run $(top_builddir)/test-harness --valgrind --direct
+
+check-uml:
+	$(top_builddir)/run $(top_builddir)/test-harness --uml
+
+check-valgrind-uml:
+	$(top_builddir)/run $(top_builddir)/test-harness --valgrind --uml
+
+check-with-upstream-qemu:
+	$(top_builddir)/run $(top_builddir)/test-harness --with-upstream-qemu
+
+check-with-upstream-libvirt:
+	$(top_builddir)/run $(top_builddir)/test-harness --with-upstream-libvirt
+
+check-fast:
+	$(top_builddir)/run $(top_builddir)/test-harness --fast
+
+check-local-guests:
+	$(top_builddir)/run $(top_builddir)/test-harness --local-guests
+
+check-valgrind-local-guests:
+	$(top_builddir)/run $(top_builddir)/test-harness --valgrind --local-guests
+
+EXTRA_DIST += tests.mk
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index a020f04..7cb3ab8 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -85,12 +85,14 @@ images_files_build = \
 	initrd-x86_64.img.gz \
 	test-grep.txt.gz
 
-check_DATA = $(images_files_build) test.iso
-
-CLEANFILES = $(images_files_build) test.iso
-
 images_files = $(images_files_src) $(images_files_build)
 
+localtestsdir = $(alltestsdir)/tests/data
+
+localtests_DATA = $(images_files) test.iso
+
+CLEANFILES = $(images_files_build) test.iso
+
 test.iso: $(images_files)
 	rm -f $@ $@-t
 	mkdir -p directory
diff --git a/tests/guests/Makefile.am b/tests/guests/Makefile.am
index 62f5d14..7cfdbd3 100644
--- a/tests/guests/Makefile.am
+++ b/tests/guests/Makefile.am
@@ -55,62 +55,34 @@ disk_images = \
 # time and we need the tools we have built in order to make it.
 check_DATA = $(disk_images) guests-all-good.xml
 
-CLEANFILES = $(check_DATA) \
-	guests-all-good.xml \
-	stamp-fedora-md.img \
-	*.tmp.*
+$(disk_images) guests-all-good.xml: stamp-guests
 
-# Make several different blank images.  These are not guests, but we
-# include them in the libvirt fake XML to make sure that virt-df and
-# virt-alignment-scan don't break when they encounter them.
-blank-%.img:
-	rm -f $@ $@-t
-	$(top_builddir)/run \
-	  ../../fish/guestfish \
-	    -N $@-t="$$(echo $@ | sed -e 's/blank-//' -e 's/.img//')" exit
-	mv $@-t $@
-
-# Make a (dummy) Fedora image.
-fedora.img: guest-aux/make-fedora-img.pl \
-		guest-aux/fedora-journal.tar.xz \
-		guest-aux/fedora-name.db \
-		guest-aux/fedora-packages.db
-	SRCDIR=$(srcdir) LAYOUT=partitions $(top_builddir)/run --test $<
-
-# Make a (dummy) Fedora image using md devices
-fedora-md1.img fedora-md2.img: stamp-fedora-md.img
-
-stamp-fedora-md.img: guest-aux/make-fedora-img.pl \
-		guest-aux/fedora-journal.tar.xz \
-		guest-aux/fedora-name.db \
-		guest-aux/fedora-packages.db
-	rm -f $@
-	SRCDIR=$(srcdir) LAYOUT=partitions-md $(top_builddir)/run --test $<
+stamp-guests: $(top_builddir)/test-harness
+	$(top_builddir)/run $< --make-phony-guests-only
 	touch $@
 
-fedora-btrfs.img: guest-aux/make-fedora-img.pl \
-		guest-aux/fedora-journal.tar.xz \
-		guest-aux/fedora-name.db \
-		guest-aux/fedora-packages.db
-	SRCDIR=$(srcdir) LAYOUT=btrfs $(top_builddir)/run --test $<
+CLEANFILES = \
+	$(check_DATA) \
+	stamp-guests \
+	*.tmp.*
 
-# Make a (dummy) Debian image.
-debian.img: guest-aux/make-debian-img.sh
-	SRCDIR=$(srcdir) $(top_builddir)/run --test $<
-
-# Make a (dummy) Ubuntu image.
-ubuntu.img: guest-aux/make-ubuntu-img.sh
-	SRCDIR=$(srcdir) $(top_builddir)/run --test $<
-
-# Make a (dummy) Windows image.
-windows.img: guest-aux/make-windows-img.sh \
-	     guest-aux/windows-software guest-aux/windows-system
-	SRCDIR=$(srcdir) $(top_builddir)/run --test $<
-
-guests-all-good.xml: guest-aux/make-guests-all-good.pl $(disk_images)
-	rm -f $@ $@-t
-	$^ > $@-t
-	mv $@-t $@
+# For installed tests.
+localtestsdir = $(alltestsdir)/tests/guests/guest-aux
+localtests_DATA = \
+	guest-aux/debian-packages \
+	guest-aux/debian-syslog \
+	guest-aux/fedora-journal.tar.xz \
+	guest-aux/fedora-name.db \
+	guest-aux/fedora-packages.db \
+	guest-aux/minimal-hive \
+	guest-aux/windows-software \
+	guest-aux/windows-system
+localtests_SCRIPTS = \
+	guest-aux/make-debian-img.sh \
+	guest-aux/make-fedora-img.pl \
+	guest-aux/make-guests-all-good.pl \
+	guest-aux/make-ubuntu-img.sh \
+	guest-aux/make-windows-img.sh
 
 # Since users might not have the tools needed to create this, we also
 # distribute these files and they are only cleaned by 'make distclean'
@@ -142,11 +114,3 @@ DISTCLEANFILES = \
 	guest-aux/fedora-packages.db \
 	guest-aux/windows-software \
 	guest-aux/windows-system
-
-# Don't construct the guests in parallel.  In automake 1.13, check_DATA
-# was changed so it can now run in parallel, but this causes everything
-# to fall over on machines with limited memory.
-#
-# ALSO: the guestfish rules above for making the blank-*.img files are
-# NOT safe to run in parallel.
-.NOTPARALLEL:
diff --git a/tests/guests/guest-aux/make-debian-img.sh b/tests/guests/guest-aux/make-debian-img.sh
index 95228ab..af251b4 100755
--- a/tests/guests/guest-aux/make-debian-img.sh
+++ b/tests/guests/guest-aux/make-debian-img.sh
@@ -82,11 +82,11 @@ upload fstab.tmp.$$ /etc/fstab
 write /etc/debian_version "5.0.1"
 write /etc/hostname "debian.invalid"
 
-upload $SRCDIR/guest-aux/debian-packages /var/lib/dpkg/status
+upload $srcdir/guest-aux/debian-packages /var/lib/dpkg/status
 
-upload $SRCDIR/../data/bin-x86_64-dynamic /bin/ls
+upload $datadir/../data/bin-x86_64-dynamic /bin/ls
 
-upload $SRCDIR/guest-aux/debian-syslog /var/log/syslog
+upload $srcdir/guest-aux/debian-syslog /var/log/syslog
 
 mkdir /boot/grub
 touch /boot/grub/grub.conf
diff --git a/tests/guests/guest-aux/make-fedora-img.pl b/tests/guests/guest-aux/make-fedora-img.pl
index 1c23b6d..95bd6e4 100755
--- a/tests/guests/guest-aux/make-fedora-img.pl
+++ b/tests/guests/guest-aux/make-fedora-img.pl
@@ -44,11 +44,12 @@ my $g = Sys::Guestfs->new ();
 
 my $bootdev;
 
-foreach ('LAYOUT', 'SRCDIR') {
-  defined ($ENV{$_}) or die "Missing environment variable: $_";
+if (@ARGV < 1 || $ARGV[0] !~ /^--layout=(.*)/) {
+    die "usage: $0 --layout=(partitions|partitions-md|btrfs)\n"
 }
+my $layout = $1;
 
-if ($ENV{LAYOUT} eq 'partitions') {
+if ($layout eq 'partitions') {
   push (@images, "fedora.img.tmp.$$");
 
   open (my $fstab, '>', "fstab.tmp.$$") or die;
@@ -73,7 +74,7 @@ EOF
   init_lvm_root ('/dev/sda2');
 }
 
-elsif ($ENV{LAYOUT} eq 'partitions-md') {
+elsif ($layout eq 'partitions-md') {
   push (@images, "fedora-md1.img.tmp.$$", "fedora-md2.img.tmp.$$");
 
   open (my $fstab, '>', "fstab.tmp.$$") or die;
@@ -122,7 +123,7 @@ EOF
   init_lvm_root ('/dev/md/root');
 }
 
-elsif ($ENV{LAYOUT} eq 'btrfs') {
+elsif ($layout eq 'btrfs') {
   push (@images, "fedora-btrfs.img.tmp.$$");
 
   open (my $fstab, '>', "fstab.tmp.$$") or die;
@@ -154,7 +155,7 @@ EOF
 }
 
 else {
-  print STDERR "$0: Unknown LAYOUT: ",$ENV{LAYOUT},"\n";
+  print STDERR "$0: Unknown layout: ",$layout,"\n";
   exit 1;
 }
 
@@ -217,12 +218,12 @@ if (-f "mdadm.tmp.$$") {
   unlink ("mdadm.tmp.$$") or die;
 }
 
-$g->upload ($ENV{SRCDIR}.'/guest-aux/fedora-name.db', '/var/lib/rpm/Name');
-$g->upload ($ENV{SRCDIR}.'/guest-aux/fedora-packages.db', '/var/lib/rpm/Packages');
+$g->upload ($ENV{srcdir}.'/guest-aux/fedora-name.db', '/var/lib/rpm/Name');
+$g->upload ($ENV{srcdir}.'/guest-aux/fedora-packages.db', '/var/lib/rpm/Packages');
 
-$g->upload ($ENV{SRCDIR}.'/../data/bin-x86_64-dynamic', '/bin/ls');
+$g->upload ($ENV{datadir}.'/../data/bin-x86_64-dynamic', '/bin/ls');
 
-$g->txz_in ($ENV{SRCDIR}.'/guest-aux/fedora-journal.tar.xz', '/var/log/journal');
+$g->txz_in ($ENV{srcdir}.'/guest-aux/fedora-journal.tar.xz', '/var/log/journal');
 
 $g->mkdir ('/boot/grub');
 $g->touch ('/boot/grub/grub.conf');
diff --git a/tests/guests/guest-aux/make-ubuntu-img.sh b/tests/guests/guest-aux/make-ubuntu-img.sh
index 183985b..36abe55 100755
--- a/tests/guests/guest-aux/make-ubuntu-img.sh
+++ b/tests/guests/guest-aux/make-ubuntu-img.sh
@@ -73,9 +73,9 @@ write /etc/debian_version "5.0.1"
 upload release.tmp.$$ /etc/lsb-release
 write /etc/hostname "ubuntu.invalid"
 
-upload $SRCDIR/guest-aux/debian-packages /var/lib/dpkg/status
+upload $srcdir/guest-aux/debian-packages /var/lib/dpkg/status
 
-upload $SRCDIR/../data/bin-x86_64-dynamic /bin/ls
+upload $datadir/../data/bin-x86_64-dynamic /bin/ls
 
 mkdir /boot/grub
 touch /boot/grub/grub.conf
diff --git a/tests/guests/guest-aux/make-windows-img.sh b/tests/guests/guest-aux/make-windows-img.sh
index 9d477fa..c553d69 100755
--- a/tests/guests/guest-aux/make-windows-img.sh
+++ b/tests/guests/guest-aux/make-windows-img.sh
@@ -58,10 +58,10 @@ mkfs ntfs /dev/sda2
 mount /dev/sda2 /
 mkdir-p /Windows/System32/Config
 
-upload $SRCDIR/guest-aux/windows-software /Windows/System32/Config/SOFTWARE
-upload $SRCDIR/guest-aux/windows-system /Windows/System32/Config/SYSTEM
+upload $srcdir/guest-aux/windows-software /Windows/System32/Config/SOFTWARE
+upload $srcdir/guest-aux/windows-system /Windows/System32/Config/SYSTEM
 
-upload $SRCDIR/../data/bin-win32.exe /Windows/System32/cmd.exe
+upload $datadir/../data/bin-win32.exe /Windows/System32/cmd.exe
 
 mkdir "/Program Files"
 touch /autoexec.bat
-- 
2.0.4




More information about the Libguestfs mailing list