[Libguestfs] [PATCH v5 4/7] tests/regressions: Convert the regression tests to use the test harness.

Richard W.M. Jones rjones at redhat.com
Sun Oct 5 13:08:38 UTC 2014


---
 generator/tests.ml                     | 38 +++++++++++++++
 tests/regressions/Makefile.am          | 46 ++----------------
 tests/regressions/rhbz1001875.sh       |  7 +--
 tests/regressions/rhbz1044014.sh       |  9 +---
 tests/regressions/rhbz1054761.sh       |  5 --
 tests/regressions/rhbz1091803.sh       |  5 --
 tests/regressions/rhbz563450.sh        |  8 +--
 tests/regressions/rhbz563450b.sh       |  6 +--
 tests/regressions/rhbz690819.sh        |  7 +--
 tests/regressions/rhbz789960.sh        |  2 +-
 tests/regressions/rhbz914931.c         | 11 +----
 tests/regressions/test-noexec-stack.pl | 48 ++++++++----------
 tests/regressions/tests.mk             | 89 ++++++++++++++++++++++++++++++++++
 13 files changed, 166 insertions(+), 115 deletions(-)
 create mode 100644 tests/regressions/tests.mk

diff --git a/generator/tests.ml b/generator/tests.ml
index 9fe63ec..4ffbec4 100644
--- a/generator/tests.ml
+++ b/generator/tests.ml
@@ -324,6 +324,44 @@ let tests = [
       ];
   };
 
+  "tests/regressions", {
+    defaults with
+      check_fast = [
+	"rhbz501893";
+	"rhbz1055452";
+      ];
+      check = [
+	"rhbz503169c13.sh";
+	"rhbz557655.sh";
+	"rhbz563450.sh";
+	"rhbz563450b.sh";
+	"rhbz576879.sh";
+	"rhbz578407.sh";
+	"rhbz580246.sh";
+	"rhbz602997.sh";
+	"rhbz690819.sh";
+	"rhbz789960.sh";
+	"rhbz790721";
+	"rhbz811649.sh";
+	"rhbz895904.sh";
+	"rhbz914931";
+	"rhbz957772.sh";
+	"rhbz975797.sh";
+	"rhbz1001875.sh";
+        "rhbz1044014.sh";
+        "rhbz1054761.sh";
+	"rhbz1091803.sh";
+	"test-noexec-stack.pl";
+      ];
+      check_slow = [
+        "rhbz909624.sh"
+      ];
+      check_data = [
+        "rhbz557655-expected.stderr";
+        "rhbz557655-expected.stdout";
+      ];
+  };
+
   "inspector", {
     defaults with
       check = [
diff --git a/tests/regressions/Makefile.am b/tests/regressions/Makefile.am
index a5e7cfc..8d477ee 100644
--- a/tests/regressions/Makefile.am
+++ b/tests/regressions/Makefile.am
@@ -17,6 +17,8 @@
 
 include $(top_srcdir)/subdir-rules.mk
 
+generator_built = tests.mk
+
 EXTRA_DIST = \
 	rhbz503169c13.sh \
 	rhbz557655.sh \
@@ -44,47 +46,12 @@ EXTRA_DIST = \
 	rhbz1091803.sh \
 	test-noexec-stack.pl
 
-TESTS = \
-	rhbz501893 \
-	rhbz503169c13.sh \
-	rhbz557655.sh \
-	rhbz563450.sh \
-	rhbz563450b.sh \
-	rhbz576879.sh \
-	rhbz578407.sh \
-	rhbz580246.sh \
-	rhbz602997.sh \
-	rhbz690819.sh \
-	rhbz789960.sh \
-	rhbz790721 \
-	rhbz811649.sh \
-	rhbz895904.sh \
-	rhbz914931 \
-	rhbz957772.sh \
-	rhbz975797.sh \
-	rhbz1001875.sh \
-	rhbz1054761.sh \
-	rhbz1055452 \
-	rhbz1091803.sh \
-	test-noexec-stack.pl
-
-if HAVE_LIBVIRT
-TESTS += rhbz1044014.sh
-endif
-
-tests_not_run = \
+# There are a couple of tests that we don't run:
+EXTRA_DIST += \
 	rhbz727178.sh \
 	rhbz909624.sh
 
-TESTS_ENVIRONMENT = \
-	NOEXEC_CHECK="$(top_builddir)/src/.libs/libguestfs.so $(top_builddir)/daemon/guestfsd" \
-	$(top_builddir)/run --test
-
-check_PROGRAMS = \
-	rhbz501893 \
-	rhbz790721 \
-	rhbz914931 \
-	rhbz1055452
+include $(srcdir)/tests.mk
 
 rhbz501893_SOURCES = rhbz501893.c
 rhbz501893_CPPFLAGS = \
@@ -122,6 +89,3 @@ rhbz1055452_CFLAGS = \
 	$(WARN_CFLAGS) $(WERROR_CFLAGS)
 rhbz1055452_LDADD = \
 	$(top_builddir)/src/libguestfs.la
-
-check-slow:
-	$(MAKE) TESTS="rhbz909624.sh" check
diff --git a/tests/regressions/rhbz1001875.sh b/tests/regressions/rhbz1001875.sh
index 885fd8c..6812333 100755
--- a/tests/regressions/rhbz1001875.sh
+++ b/tests/regressions/rhbz1001875.sh
@@ -1,6 +1,6 @@
 #!/bin/bash -
 # libguestfs
-# Copyright (C) 2013 Red Hat Inc.
+# Copyright (C) 2013-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
@@ -23,11 +23,6 @@
 set -e
 export LANG=C
 
-if [ -n "$SKIP_TEST_RHBZ1001875_SH" ]; then
-    echo "$0: test skipped because environment variable is set."
-    exit 77
-fi
-
 rm -f rhbz1001875.img rhbz1001875-[123].tar
 
 guestfish -N rhbz1001875.img=fs -m /dev/sda1 <<EOF
diff --git a/tests/regressions/rhbz1044014.sh b/tests/regressions/rhbz1044014.sh
index 8e0df2a..7296eba 100755
--- a/tests/regressions/rhbz1044014.sh
+++ b/tests/regressions/rhbz1044014.sh
@@ -22,11 +22,6 @@
 set -e
 export LANG=C
 
-if [ -n "$SKIP_TEST_RHBZ1044014_SH" ]; then
-    echo "$0: test skipped because environment variable is set."
-    exit 77
-fi
-
 # Check we are running against the libvirt backend.
 backend="$(guestfish get-backend)"
 if [[ ! ( "$backend" =~ ^libvirt ) ]]; then
@@ -34,12 +29,12 @@ if [[ ! ( "$backend" =~ ^libvirt ) ]]; then
     exit 77
 fi
 
-if [ ! -x ../../src/libvirt-is-version ]; then
+if [ ! -x $top_builddir/src/libvirt-is-version ]; then
     echo "$0: test skipped because libvirt-is-version is not built yet"
     exit 77
 fi
 
-if ! ../../src/libvirt-is-version 1 2 1; then
+if ! $top_builddir/src/libvirt-is-version 1 2 1; then
     echo "$0: test skipped because libvirt is too old (< 1.2.1)"
     exit 77
 fi
diff --git a/tests/regressions/rhbz1054761.sh b/tests/regressions/rhbz1054761.sh
index 344479d..c37e237 100755
--- a/tests/regressions/rhbz1054761.sh
+++ b/tests/regressions/rhbz1054761.sh
@@ -23,11 +23,6 @@
 set -e
 export LANG=C
 
-if [ -n "$SKIP_TEST_RHBZ1054761_SH" ]; then
-    echo "$0: test skipped because environment variable is set."
-    exit 77
-fi
-
 rm -f rhbz1054761-[ab].img
 
 guestfish -N rhbz1054761-a.img=disk -N rhbz1054761-b.img=disk <<EOF
diff --git a/tests/regressions/rhbz1091803.sh b/tests/regressions/rhbz1091803.sh
index 6851a1c..2e4d373 100755
--- a/tests/regressions/rhbz1091803.sh
+++ b/tests/regressions/rhbz1091803.sh
@@ -23,11 +23,6 @@
 set -e
 export LANG=C
 
-if [ -n "$SKIP_TEST_RHBZ1091803_SH" ]; then
-    echo "$0: test skipped because environment variable is set."
-    exit 77
-fi
-
 guestfish <<EOF
 scratch 100M
 run
diff --git a/tests/regressions/rhbz563450.sh b/tests/regressions/rhbz563450.sh
index d7cf751..adf1df4 100755
--- a/tests/regressions/rhbz563450.sh
+++ b/tests/regressions/rhbz563450.sh
@@ -22,7 +22,7 @@
 set -e
 export LANG=C
 
-if [ ! -s ../guests/fedora.img -o ! -s ../data/test.iso -o ! -s ../guests/debian.img ]; then
+if [ ! -s $phonydir/fedora.img -o ! -s $datadir/test.iso -o ! -s $phonydir/debian.img ]; then
     echo "$0: test skipped because there is no fedora.img nor test.iso nor debian.img"
     exit 77
 fi
@@ -30,9 +30,9 @@ fi
 rm -f test.out
 
 guestfish --ro > test.out <<EOF
-add-drive-ro ../guests/fedora.img
-add-cdrom ../data/test.iso
-add-drive-ro ../guests/debian.img
+add-drive-ro $phonydir/fedora.img
+add-cdrom $datadir/test.iso
+add-drive-ro $phonydir/debian.img
 
 run
 
diff --git a/tests/regressions/rhbz563450b.sh b/tests/regressions/rhbz563450b.sh
index 26aaf6f..eb91a38 100755
--- a/tests/regressions/rhbz563450b.sh
+++ b/tests/regressions/rhbz563450b.sh
@@ -1,6 +1,6 @@
 #!/bin/bash -
 # libguestfs
-# Copyright (C) 2013 Red Hat Inc.
+# Copyright (C) 2013-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
@@ -22,7 +22,7 @@
 set -e
 export LANG=C
 
-if [ ! -s ../data/test.iso ]; then
+if [ ! -s $datadir/test.iso ]; then
     echo "$0: test skipped because there is no test.iso"
     exit 77
 fi
@@ -30,7 +30,7 @@ fi
 rm -f test.out
 
 guestfish --ro > test.out <<EOF
-add-cdrom ../data/test.iso
+add-cdrom $datadir/test.iso
 
 run
 
diff --git a/tests/regressions/rhbz690819.sh b/tests/regressions/rhbz690819.sh
index 0af0b64..5b785d7 100755
--- a/tests/regressions/rhbz690819.sh
+++ b/tests/regressions/rhbz690819.sh
@@ -1,6 +1,6 @@
 #!/bin/bash -
 # libguestfs
-# Copyright (C) 2011 Red Hat Inc.
+# Copyright (C) 2011-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
@@ -23,11 +23,6 @@
 set -e
 export LANG=C
 
-if [ -n "$SKIP_TEST_RHBZ690819_SH" ]; then
-    echo "$0: test skipped because environment variable is set."
-    exit 77
-fi
-
 arch="$(uname -m)"
 if [[ "$arch" =~ ^arm || "$arch" = "aarch64" ]]; then
     echo "$0: test skipped because ARM does not support 'ide' interface."
diff --git a/tests/regressions/rhbz789960.sh b/tests/regressions/rhbz789960.sh
index 056b7ed..9888a17 100755
--- a/tests/regressions/rhbz789960.sh
+++ b/tests/regressions/rhbz789960.sh
@@ -24,7 +24,7 @@ export LANG=C
 
 rm -f test.out
 
-guestfish -a ../guests/fedora.img --ro > test.out <<EOF
+guestfish -a $phonydir/fedora.img --ro > test.out <<EOF
 run
 
 # Not a device at all, should fail.
diff --git a/tests/regressions/rhbz914931.c b/tests/regressions/rhbz914931.c
index faa3dd2..bd1812b 100644
--- a/tests/regressions/rhbz914931.c
+++ b/tests/regressions/rhbz914931.c
@@ -1,5 +1,5 @@
 /* libguestfs
- * Copyright (C) 2013 Red Hat Inc.
+ * Copyright (C) 2013-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
@@ -37,15 +37,6 @@ main (int argc, char *argv[])
 {
   guestfs_h *g;
   int r;
-  char *str;
-
-  /* Allow this test to be skipped. */
-  str = getenv ("SKIP_TEST_RHBZ914931");
-  if (str && STREQ (str, "1")) {
-    printf ("%s: test skipped because environment variable is set.\n",
-            program_name);
-    exit (77);
-  }
 
   g = guestfs_create ();
   if (!g) {
diff --git a/tests/regressions/test-noexec-stack.pl b/tests/regressions/test-noexec-stack.pl
index 68bbb0b..e54b1df 100755
--- a/tests/regressions/test-noexec-stack.pl
+++ b/tests/regressions/test-noexec-stack.pl
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# Copyright (C) 2009 Red Hat Inc.
+# 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
@@ -18,67 +18,61 @@
 use strict;
 use warnings;
 
-if ($ENV{SKIP_TEST_NOEXEC_STACK_PL}) {
-    print "$0: skipped test because environment variable is set\n";
-    exit 77;
-}
-
-die("NOEXEC_CHECK not set") unless(exists($ENV{NOEXEC_CHECK}));
-
-my @files = split(/ /, $ENV{NOEXEC_CHECK});
+my @files = ( "$ENV{top_builddir}/src/.libs/libguestfs.so",
+              "$ENV{top_builddir}/daemon/guestfsd" );
 
 FILES: foreach my $file (@files) {
     my $output;
     my @cmd = ('readelf', '-l', $file);
-    open($output, '-|', @cmd)
-        or die("$0: failed to run: '".join(' ', @cmd)."': $!\n");
+    open ($output, '-|', @cmd)
+        or die ("$0: failed to run: '".join(' ', @cmd)."': $!\n");
 
     my $offset;
     my $line = 1;
 
     # Find the offset of the Flags field
-    while(<$output>) {
-        next unless(/^\s*Type\b/);
+    while (<$output>) {
+        next unless /^\s*Type\b/;
 
         my @lines;
-        push(@lines, $_);
+        push (@lines, $_);
 
         # Look for a Flg field on this line (32 bit)
-        $offset = index($_, 'Flg ');
+        $offset = index ($_, 'Flg ');
 
-        if(-1 == $offset) {
+        if (-1 == $offset) {
             # 64 bit is split over 2 lines. Look for a Flags field on the next
             # line
             $_ = <$output>;
-            $offset = index($_, 'Flags ');
+            $offset = index ($_, 'Flags ');
             $line = 2;
-            push(@lines, $_);
+            push (@lines, $_);
         }
 
-        die("Unrecognised header: ".join("\n", @lines)) if(-1 == $offset);
+        die "Unrecognised header: ".join("\n", @lines) if -1 == $offset;
         last;
     }
 
     # Find the GNU_STACK entry
-    while(<$output>) {
-        next unless(/^\s*GNU_STACK\b/);
+    while (<$output>) {
+        next unless /^\s*GNU_STACK\b/;
 
         # Skip over input lines according to the header
-        for(my $i = 1; $i < $line; $i++) {
+        for (my $i = 1; $i < $line; $i++) {
             $_ = <$output>;
         }
 
-        my $flags = substr($_, $offset, 3);
+        my $flags = substr ($_, $offset, 3);
 
-        $flags =~ /^[ R][ W]([ E])$/ or die("Unrecognised flags: $flags");
+        $flags =~ /^[ R][ W]([ E])$/ or die "Unrecognised flags: $flags";
 
-        if('E' eq $1) {
+        if ('E' eq $1) {
             print "***** $file has an executable stack *****\n";
-            exit(1);
+            exit 1;
         }
 
         next FILES;
     }
 
-    die("Didn't find GNU_STACK entry");
+    die "Didn't find GNU_STACK entry";
 }
diff --git a/tests/regressions/tests.mk b/tests/regressions/tests.mk
new file mode 100644
index 0000000..4fa0414
--- /dev/null
+++ b/tests/regressions/tests.mk
@@ -0,0 +1,89 @@
+# 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)/tests/regressions
+
+localtests_DATA = \
+	rhbz557655-expected.stderr \
+	rhbz557655-expected.stdout
+
+localtests_SCRIPTS = \
+	rhbz1001875.sh \
+	rhbz1044014.sh \
+	rhbz1054761.sh \
+	rhbz1091803.sh \
+	rhbz503169c13.sh \
+	rhbz557655.sh \
+	rhbz563450.sh \
+	rhbz563450b.sh \
+	rhbz576879.sh \
+	rhbz578407.sh \
+	rhbz580246.sh \
+	rhbz602997.sh \
+	rhbz690819.sh \
+	rhbz789960.sh \
+	rhbz811649.sh \
+	rhbz895904.sh \
+	rhbz909624.sh \
+	rhbz957772.sh \
+	rhbz975797.sh \
+	test-noexec-stack.pl
+
+localtests_PROGRAMS = \
+	rhbz1055452 \
+	rhbz501893 \
+	rhbz790721 \
+	rhbz914931
+
+# Note that we cannot create a simple 'check:' target since
+# automake will (silently) overrule it, so we do this instead:
+
+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 --upstream-qemu
+
+check-with-upstream-libvirt:
+	$(top_builddir)/run $(top_builddir)/test-harness --upstream-libvirt
+
+check-fast:
+	$(top_builddir)/run $(top_builddir)/test-harness --fast
+
+check-slow:
+	$(top_builddir)/run $(top_builddir)/test-harness --slow
+
+EXTRA_DIST += tests.mk
-- 
2.0.4




More information about the Libguestfs mailing list