[Libguestfs] [PATCH nbdkit 3/4] tests: Move common code for testing every plugin to tests/functions.sh.

Richard W.M. Jones rjones at redhat.com
Tue Sep 11 18:47:32 UTC 2018


This resurrects the unused tests/functions.sh file (although now we
need to generate it from tests/functions.sh.in).  Put the common code
for running a test against every plugin here.

Because of the previous commits we can now use the plugins list
directly from configure.ac instead of needing to use weird shell
script, although we still need to preserve the test that the plugin
was built so that the tests continue to work if a plugin is disabled
or not built through missing dependencies.
---
 .gitignore                              |  1 +
 configure.ac                            |  1 +
 tests/Makefile.am                       |  1 -
 tests/{functions.sh => functions.sh.in} | 23 +++++++++++++++++++----
 tests/test-dump-plugin.sh               | 19 ++++++++-----------
 tests/test-help.sh                      | 18 ++++++++----------
 tests/test-version.sh                   | 18 ++++++++----------
 7 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/.gitignore b/.gitignore
index a21484e..b8396f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,6 +55,7 @@ Makefile.in
 /tests/disk.xz
 /tests/ext2.img
 /tests/file-data
+/tests/functions.sh
 /tests/keys.psk
 /tests/offset-data
 /tests/partition-disk
diff --git a/configure.ac b/configure.ac
index 3a02c66..518b2bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -651,6 +651,7 @@ AC_CONFIG_FILES([Makefile
                  filters/truncate/Makefile
                  src/Makefile
                  src/nbdkit.pc
+                 tests/functions.sh
                  tests/Makefile])
 
 AC_OUTPUT
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a7d0c2d..23316ea 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -35,7 +35,6 @@ include $(top_srcdir)/common-rules.mk
 MAINTAINERCLEANFILES =
 
 EXTRA_DIST = \
-	functions.sh \
 	make-pki.sh \
 	make-psk.sh \
 	python-exception.py \
diff --git a/tests/functions.sh b/tests/functions.sh.in
similarity index 74%
rename from tests/functions.sh
rename to tests/functions.sh.in
index e54bb9d..4071384 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh.in
@@ -1,5 +1,7 @@
 # nbdkit
-# Copyright (C) 2017 Red Hat Inc.
+# Common functions used by the tests.
+# @configure_input@
+# Copyright (C) 2017-2018 Red Hat Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -30,6 +32,19 @@
 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 
-# Some functions used by the tests.
-
-# (Currently empty)
+# foreach_plugin f
+#
+# For each plugin that was built, call test function f with the plugin
+# name as argument.
+foreach_plugin ()
+{
+    for p in @plugins@; do
+        # Was the plugin built?
+        d=@top_builddir@/plugins/$p
+        if [ -f $d/.libs/nbdkit-$p-plugin.so ] ||
+           [ -f $d/nbdkit-$p-plugin ]; then
+            # Yes so run the test.
+            "$1" "$p"
+        fi
+    done
+}
diff --git a/tests/test-dump-plugin.sh b/tests/test-dump-plugin.sh
index e08db84..77bd995 100755
--- a/tests/test-dump-plugin.sh
+++ b/tests/test-dump-plugin.sh
@@ -31,9 +31,9 @@
 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 
+source functions.sh
 set -e
 set -x
-source ./functions.sh
 
 # Basic check that the name field is present.
 output="$(nbdkit example1 --dump-plugin)"
@@ -51,15 +51,11 @@ if [[ ! ( "$output" =~ example2_extra\=hello ) ]]; then
     exit 1
 fi
 
-# Get a list of all plugins and run --dump-plugin on all of them.
+# Run nbdkit plugin --dump-plugin for each plugin.
 # However some of these tests are expected to fail.
-plugins="$(
-    cd ..;
-    ls -1 plugins/*/.libs/nbdkit-*-plugin.so plugins/*/nbdkit-*-plugin |
-        sed 's,^plugins/\([^/]*\)/.*,\1,'
-)"
-for p in $plugins; do
-    case "$p${NBDKIT_VALGRIND:+-valgrind}" in
+test ()
+{
+    case "$1${NBDKIT_VALGRIND:+-valgrind}" in
         vddk | vddk-valgrind)
             # VDDK won't run without special environment variables
             # being set, so ignore it.
@@ -70,7 +66,8 @@ for p in $plugins; do
             # Plugins written in scripting languages can't run under valgrind.
             ;;
         *)
-            nbdkit $p --dump-plugin
+            nbdkit $1 --dump-plugin
             ;;
     esac
-done
+}
+foreach_plugin test
diff --git a/tests/test-help.sh b/tests/test-help.sh
index f1a988c..9bda3c2 100755
--- a/tests/test-help.sh
+++ b/tests/test-help.sh
@@ -31,6 +31,7 @@
 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 
+source functions.sh
 set -e
 
 output="$(nbdkit --help)"
@@ -40,15 +41,11 @@ if [[ ! ( "$output" =~ dump-config ) ]]; then
     exit 1
 fi
 
-# Get a list of all plugins and run --help on all of them.
+# Run nbdkit plugin --help for each plugin.
 # However some of these tests are expected to fail.
-plugins="$(
-    cd ..;
-    ls -1 plugins/*/.libs/nbdkit-*-plugin.so plugins/*/nbdkit-*-plugin |
-        sed 's,^plugins/\([^/]*\)/.*,\1,'
-)"
-for p in $plugins; do
-    case "$p${NBDKIT_VALGRIND:+-valgrind}" in
+test ()
+{
+    case "$1${NBDKIT_VALGRIND:+-valgrind}" in
         vddk | vddk-valgrind)
             # VDDK won't run without special environment variables
             # being set, so ignore it.
@@ -59,7 +56,8 @@ for p in $plugins; do
             # Plugins written in scripting languages can't run under valgrind.
             ;;
         *)
-            nbdkit $p --help
+            nbdkit $1 --help
             ;;
     esac
-done
+}
+foreach_plugin test
diff --git a/tests/test-version.sh b/tests/test-version.sh
index 39fe74a..262e1a2 100755
--- a/tests/test-version.sh
+++ b/tests/test-version.sh
@@ -31,6 +31,7 @@
 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 
+source functions.sh
 set -e
 
 output="$(nbdkit --version)"
@@ -40,15 +41,11 @@ if [[ ! ( "$output" =~ ^nbdkit\ 1\. ) ]]; then
     exit 1
 fi
 
-# Get a list of all plugins and run --version on all of them.
+# Run nbdkit plugin --version for each plugin.
 # However some of these tests are expected to fail.
-plugins="$(
-    cd ..;
-    ls -1 plugins/*/.libs/nbdkit-*-plugin.so plugins/*/nbdkit-*-plugin |
-        sed 's,^plugins/\([^/]*\)/.*,\1,'
-)"
-for p in $plugins; do
-    case "$p${NBDKIT_VALGRIND:+-valgrind}" in
+test ()
+{
+    case "$1${NBDKIT_VALGRIND:+-valgrind}" in
         vddk | vddk-valgrind)
             # VDDK won't run without special environment variables
             # being set, so ignore it.
@@ -59,7 +56,8 @@ for p in $plugins; do
             # Plugins written in scripting languages can't run under valgrind.
             ;;
         *)
-            nbdkit $p --version
+            nbdkit $1 --version
             ;;
     esac
-done
+}
+foreach_plugin test
-- 
2.19.0.rc0




More information about the Libguestfs mailing list