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

Richard W.M. Jones rjones at redhat.com
Tue Sep 16 14:05:58 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                                    |   3 +-
 Makefile.am                                   |   1 +
 common-rules.mk                               |   3 +
 generator/Makefile.am                         |   2 +
 generator/main.ml                             |   9 +
 generator/tests.ml                            | 560 ++++++++++++++++++++++++++
 generator/types.ml                            |   9 +
 inspector/Makefile.am                         |  17 +-
 inspector/test-virt-inspector-local-guests.sh |  25 ++
 inspector/test-virt-inspector.sh              |  12 +-
 inspector/test-xmllint.sh.in                  |   5 +
 11 files changed, 623 insertions(+), 23 deletions(-)
 create mode 100644 generator/tests.ml
 create mode 100755 inspector/test-virt-inspector-local-guests.sh

diff --git a/.gitignore b/.gitignore
index 86158eb..342b06a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@ cscope.out
 .libs
 Makefile
 Makefile.in
+tests.mk
 
 /.sc-*
 /ABOUT-NLS
@@ -262,7 +263,6 @@ 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-xmllint.sh
 /inspector/virt-inspector
@@ -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
diff --git a/Makefile.am b/Makefile.am
index 097ba80..11b7a2d 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 \
diff --git a/common-rules.mk b/common-rules.mk
index 312107e..e9fc7c6 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.
+testsdir      = $(libdir)/guestfs/tests
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..838f282
--- /dev/null
+++ b/generator/tests.ml
@@ -0,0 +1,560 @@
+(* 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";
+    ]
+  };
+
+]
+
+(* 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]\"
+    exit 0
+}
+
+TEMP=`getopt \\
+        -o '?' \\
+        -l 'help,debug,direct,fast,local-guests,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
+            ;;
+        --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
+
+# 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
+
+# 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
+
+      (* Calculate a ../.. path to take us to the top build directory. *)
+      let dot_dot = ref ".." in
+      for i = 0 to String.length dir-1 do
+        if dir.[i] = '/' then dot_dot := !dot_dot ^ "/.."
+      done;
+      let dot_dot = !dot_dot in
+
+      pr "\
+run_%s ()
+{
+    echo \"test-harness: entering directory %s\"
+
+    top_builddir=\"$(cd %s; pwd)\"
+    # 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
+    builddir=\"$top_builddir/%s\"
+    srcdir=\"$top_srcdir/%s\"
+    abs_top_srcdir=\"$top_srcdir\"
+    abs_top_builddir=\"$top_builddir\"
+    abs_srcdir=\"$srcdir\"
+    abs_builddir=\"$builddir\"
+    export srcdir builddir top_srcdir top_builddir
+    export abs_srcdir abs_builddir abs_top_srcdir abs_top_builddir
+
+    # XXX Not set correctly yet.
+    datadir=\"$top_builddir/tests/guests\"
+    export datadir
+
+" dir dir_safe dot_dot 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 \"%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";
+
+  (* Define a shell function 'run_subdirectory_tests' which has to
+   * work out which subdir it is in, then run only the tests from that
+   * subdirectory.
+   *)
+  pr "run_subdirectory_tests ()\n";
+  pr "{\n";
+  pr "    b=\"$(basename $(pwd))\"\n";
+  pr "    if false; then : ;\n";
+  List.iter (
+    fun (dir, tests) ->
+      let dir_safe = replace_char dir '/' '_' 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_%s\n" dir_safe;
+  ) tests;
+  pr "    else\n";
+  pr "        echo \"$0: current directory ($b) is not a libguestfs test directory.\"\n";
+  pr "        exit 1\n";
+  pr "    fi\n";
+  pr "}\n";
+  pr "\n";
+
+  pr "\
+# Are we in the top-level directory of the test suite, or
+# in a subdirectory?  Top-level means run the whole suite.
+if [ -x test-harness -a -d inspector ]; then
+    run_all_tests
+else
+    run_subdirectory_tests
+fi
+
+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..2f51d79 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 tests.mk
diff --git a/inspector/test-virt-inspector-local-guests.sh b/inspector/test-virt-inspector-local-guests.sh
new file mode 100755
index 0000000..9af378a
--- /dev/null
+++ b/inspector/test-virt-inspector-local-guests.sh
@@ -0,0 +1,25 @@
+#!/bin/bash -
+# libguestfs virt-inspector test script
+# 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..58f8d47 100755
--- a/inspector/test-virt-inspector.sh
+++ b/inspector/test-virt-inspector.sh
@@ -20,23 +20,17 @@ 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
+for f in $datadir/{debian,fedora,ubuntu,windows}.img; do
     # Ignore zero-sized windows.img if ntfs-3g is not installed.
     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
-- 
2.0.4




More information about the Libguestfs mailing list