nbdkit/0005-tests-Multiple-small-additions-and-cleanups-to-the-t.patch
2016-10-03 14:42:55 +01:00

442 lines
14 KiB
Diff

From 8477cf49de988a15b3fc58d91c54efef295543fd Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 9 Jul 2016 20:14:58 +0100
Subject: [PATCH 05/11] tests: Multiple small additions and cleanups to the
test scripts.
Use a common 'functions.sh' file for test functions.
---
TODO | 2 ++
tests/Makefile.am | 10 ++++--
tests/functions.sh | 39 +++++++++++++++++++++
tests/test-captive.sh | 7 ++--
tests/test-dump-plugin.sh | 8 ++---
tests/test-foreground.sh | 4 +--
tests/test-help-plugin.sh | 3 +-
tests/test-ipv4.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++
tests/test-random-sock.sh | 5 ++-
tests/test-single.sh | 3 +-
tests/test-start.sh | 5 ++-
tests/test-version-plugin.sh | 42 ++++++++++++++++++++++
tests/test-version.sh | 41 ++++++++++++++++++++++
13 files changed, 232 insertions(+), 20 deletions(-)
create mode 100644 tests/functions.sh
create mode 100755 tests/test-ipv4.sh
create mode 100755 tests/test-version-plugin.sh
create mode 100755 tests/test-version.sh
diff --git a/TODO b/TODO
index 30bf72e..6c5bb5b 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,5 @@
+* Listen on specific interfaces or protocols (eg. only IPv6).
+
* Can we do language bindings using #!'s?
You would enter:
nbdkit foo [args]
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 08fd02a..6f6cfa2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -41,6 +41,7 @@ EXTRA_DIST = \
test-foreground.sh \
test-help.sh \
test-help-plugin.sh \
+ test-ipv4.sh \
test.pl \
test.py \
test_ocaml_plugin.ml \
@@ -48,20 +49,25 @@ EXTRA_DIST = \
test.rb \
test-single.sh \
test-start.sh \
- test-random-sock.sh
+ test-random-sock.sh \
+ test-version.sh \
+ test-version-plugin.sh
# Basic server command line and start-up tests.
TESTS = \
test-help.sh \
test-help-plugin.sh \
+ test-version.sh \
+ test-version-plugin.sh \
test-dump-config.sh \
test-dump-plugin.sh \
test-start.sh \
test-foreground.sh \
test-single.sh \
test-captive.sh \
- test-random-sock.sh
+ test-random-sock.sh \
+ test-ipv4.sh
# In-depth tests need libguestfs, since that is a convenient way to
# drive qemu.
diff --git a/tests/functions.sh b/tests/functions.sh
new file mode 100644
index 0000000..4ebddbb
--- /dev/null
+++ b/tests/functions.sh
@@ -0,0 +1,39 @@
+# nbdkit
+# Copyright (C) 2016 Red Hat Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the name of Red Hat nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+# Some functions used by the tests.
+
+# Return the path to a named nbdkit plugin.
+nbdkit_plugin ()
+{
+ echo "../plugins/$1/.libs/nbdkit-$1-plugin.so"
+}
diff --git a/tests/test-captive.sh b/tests/test-captive.sh
index 5f18b5f..098024b 100755
--- a/tests/test-captive.sh
+++ b/tests/test-captive.sh
@@ -33,14 +33,15 @@
set -e
set -x
+source ./functions.sh
# Test nbdkit --run (captive nbdkit) option.
rm -f captive.sock captive.out
-../src/nbdkit -U captive.sock \
- ../plugins/example1/.libs/nbdkit-example1-plugin.so \
- --run 'sleep 5; echo nbd=$nbd; echo port=$port; echo socket=$unixsocket' > captive.out
+../src/nbdkit -U captive.sock `nbdkit_plugin example1` --run '
+ sleep 5; echo nbd=$nbd; echo port=$port; echo socket=$unixsocket
+ ' > captive.out
# Check the output.
if [ "$(cat captive.out)" != "nbd=nbd:unix:$(pwd)/captive.sock
diff --git a/tests/test-dump-plugin.sh b/tests/test-dump-plugin.sh
index 5cde25b..2517689 100755
--- a/tests/test-dump-plugin.sh
+++ b/tests/test-dump-plugin.sh
@@ -32,12 +32,10 @@
# SUCH DAMAGE.
set -e
+source ./functions.sh
-output="$(
- ../src/nbdkit \
- ../plugins/example1/.libs/nbdkit-example1-plugin.so --dump-plugin
- )"
-if [[ ! ( "$output" =~ ^path= ) ]]; then
+output="$(../src/nbdkit `nbdkit_plugin example1` --dump-plugin)"
+if [[ ! ( "$output" =~ name\=example1 ) ]]; then
echo "$0: unexpected output from nbdkit --dump-plugin"
echo "$output"
exit 1
diff --git a/tests/test-foreground.sh b/tests/test-foreground.sh
index daa733e..6d23bf4 100755
--- a/tests/test-foreground.sh
+++ b/tests/test-foreground.sh
@@ -33,14 +33,14 @@
set -e
set -x
+source ./functions.sh
# Test nbdkit -f option.
rm -f foreground.pid foreground.sock
../src/nbdkit \
- -f -P foreground.pid -U foreground.sock \
- ../plugins/example1/.libs/nbdkit-example1-plugin.so &
+ -f -P foreground.pid -U foreground.sock `nbdkit_plugin example1` &
bg_pid=$!
# We may have to wait a short time for the pid file to appear.
diff --git a/tests/test-help-plugin.sh b/tests/test-help-plugin.sh
index dba1028..92bb277 100755
--- a/tests/test-help-plugin.sh
+++ b/tests/test-help-plugin.sh
@@ -32,8 +32,9 @@
# SUCH DAMAGE.
set -e
+source ./functions.sh
-output="$(../src/nbdkit ../plugins/file/.libs/nbdkit-file-plugin.so --help)"
+output="$(../src/nbdkit `nbdkit_plugin file` --help)"
if [[ ! ( "$output" =~ "nbdkit file plugin" ) ]]; then
echo "$0: unexpected output from nbdkit file --help"
echo "$output"
diff --git a/tests/test-ipv4.sh b/tests/test-ipv4.sh
new file mode 100755
index 0000000..8eda61c
--- /dev/null
+++ b/tests/test-ipv4.sh
@@ -0,0 +1,83 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2016 Red Hat Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the name of Red Hat nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+# Every other test uses a Unix domain socket. This tests nbdkit over
+# IPv4 localhost connections.
+#
+# XXX We should be able to test "just IPv6". However there is
+# currently no option to listen only on particular interfaces.
+
+set -e
+source ./functions.sh
+
+# Don't fail if certain commands aren't available.
+if ! ss --version; then
+ echo "$0: 'ss' command not available"
+ exit 77
+fi
+if ! socat -h; then
+ echo "$0: 'socat' command not available"
+ exit 77
+fi
+
+# Find an unused port to listen on.
+for port in `seq 49152 65535`; do
+ if ! ss -ltn | grep -sqE ":$port\b"; then break; fi
+done
+echo picked unused port $port
+
+../src/nbdkit -P ipv4.pid -p $port `nbdkit_plugin example1`
+
+# We may have to wait a short time for the pid file to appear.
+for i in `seq 1 10`; do
+ if test -f ipv4.pid; then
+ break
+ fi
+ sleep 1
+done
+if ! test -f ipv4.pid; then
+ echo "$0: PID file was not created"
+ exit 1
+fi
+
+pid="$(cat ipv4.pid)"
+
+# Check the process exists.
+kill -s 0 $pid
+
+# Check we can connect to the socket.
+socat TCP:localhost:$port STDIO </dev/null
+
+# Kill the process.
+kill $pid
+rm ipv4.pid
diff --git a/tests/test-random-sock.sh b/tests/test-random-sock.sh
index 0a3a13e..a4c58d3 100755
--- a/tests/test-random-sock.sh
+++ b/tests/test-random-sock.sh
@@ -33,9 +33,8 @@
set -e
set -x
+source ./functions.sh
# Test nbdkit -U - + captive nbdkit.
-../src/nbdkit -U - \
- ../plugins/example1/.libs/nbdkit-example1-plugin.so \
- --run 'sleep 5'
+../src/nbdkit -U - `nbdkit_plugin example1` --run 'sleep 5'
diff --git a/tests/test-single.sh b/tests/test-single.sh
index ab0827d..a06ea5d 100755
--- a/tests/test-single.sh
+++ b/tests/test-single.sh
@@ -33,8 +33,9 @@
set -e
set -x
+source ./functions.sh
# Test nbdkit -s option.
# XXX Not sure what is a really good test of this.
-../src/nbdkit -s ../plugins/example1/.libs/nbdkit-example1-plugin.so </dev/null
+../src/nbdkit -s `nbdkit_plugin example1` </dev/null
diff --git a/tests/test-start.sh b/tests/test-start.sh
index 7422040..6041cd4 100755
--- a/tests/test-start.sh
+++ b/tests/test-start.sh
@@ -33,15 +33,14 @@
set -e
set -x
+source ./functions.sh
# Test nbdkit starts up, forks in the background, writes a PID file,
# and can be killed.
rm -f start.pid start.sock
-../src/nbdkit \
- -P start.pid -U start.sock \
- ../plugins/example1/.libs/nbdkit-example1-plugin.so
+../src/nbdkit -P start.pid -U start.sock `nbdkit_plugin example1`
# We may have to wait a short time for the pid file to appear.
for i in `seq 1 10`; do
diff --git a/tests/test-version-plugin.sh b/tests/test-version-plugin.sh
new file mode 100755
index 0000000..da99dbf
--- /dev/null
+++ b/tests/test-version-plugin.sh
@@ -0,0 +1,42 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2016 Red Hat Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the name of Red Hat nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+set -e
+source ./functions.sh
+
+output="$(../src/nbdkit `nbdkit_plugin file` --version)"
+if [[ ! ( "$output" =~ file\ ) ]]; then
+ echo "$0: unexpected output from nbdkit file --version"
+ echo "$output"
+ exit 1
+fi
diff --git a/tests/test-version.sh b/tests/test-version.sh
new file mode 100755
index 0000000..9a2e356
--- /dev/null
+++ b/tests/test-version.sh
@@ -0,0 +1,41 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2016 Red Hat Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the name of Red Hat nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+set -e
+
+output="$(../src/nbdkit --version)"
+if [[ ! ( "$output" =~ ^nbdkit\ 1\. ) ]]; then
+ echo "$0: unexpected output from nbdkit --version"
+ echo "$output"
+ exit 1
+fi
--
2.7.4