nbdkit/0002-tests-Test-the-nbdkit-command-line-more-thoroughly.patch
Richard W.M. Jones fe5a3ca24a Backport some upstream patches, fixing a minor bug and adding more tests.
Also:
- Enable the tests since kernel bug is fixed.
2014-02-21 12:50:51 +00:00

494 lines
17 KiB
Diff

From 76d7450b5b5abea8781fbe99c0053bbd9704d247 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sun, 16 Feb 2014 12:10:01 +0000
Subject: [PATCH 2/2] tests: Test the nbdkit command line more thoroughly.
---
tests/Makefile.am | 28 ++++++++++++++--
tests/test-captive.sh | 54 +++++++++++++++++++++++++++++++
tests/test-dump-config.sh | 41 ++++++++++++++++++++++++
tests/test-foreground.sh | 80 ++++++++++++++++++++++++++++++++++++++++++++++
tests/test-help-plugin.sh | 41 ++++++++++++++++++++++++
tests/test-help.sh | 41 ++++++++++++++++++++++++
tests/test-single.sh | 40 +++++++++++++++++++++++
tests/test-start.sh | 81 +++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 403 insertions(+), 3 deletions(-)
create mode 100755 tests/test-captive.sh
create mode 100755 tests/test-dump-config.sh
create mode 100755 tests/test-foreground.sh
create mode 100755 tests/test-help-plugin.sh
create mode 100755 tests/test-help.sh
create mode 100755 tests/test-single.sh
create mode 100755 tests/test-start.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 417cb3d..619bed2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -33,9 +33,31 @@
CLEANFILES = *~
MAINTAINERCLEANFILES =
-EXTRA_DIST = test.pl test.py
+EXTRA_DIST = \
+ test-captive.sh \
+ test-dump-config.sh \
+ test-foreground.sh \
+ test-help.sh \
+ test-help-plugin.sh \
+ test.pl \
+ test.py \
+ test-single.sh \
+ test-start.sh
+
+# Basic server command line and start-up tests.
+
+TESTS = \
+ test-help.sh \
+ test-help-plugin.sh \
+ test-dump-config.sh \
+ test-start.sh \
+ test-foreground.sh \
+ test-single.sh \
+ test-captive.sh
+
+# In-depth tests need libguestfs, since that is a convenient way to
+# drive qemu.
-# Tests need libguestfs, since that is a convenient way to drive qemu.
if HAVE_LIBGUESTFS
# Use the 'direct' backend, and ensure maximum libguestfs debugging is
@@ -52,7 +74,7 @@ libtest_la_CFLAGS = $(WARNINGS_CFLAGS)
# Basic connection test.
check_PROGRAMS = test-connect
-TESTS = test-connect
+TESTS += test-connect
check_DATA =
test_connect_SOURCES = test-connect.c test.h
diff --git a/tests/test-captive.sh b/tests/test-captive.sh
new file mode 100755
index 0000000..5f18b5f
--- /dev/null
+++ b/tests/test-captive.sh
@@ -0,0 +1,54 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2014 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
+set -x
+
+# 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
+
+# Check the output.
+if [ "$(cat captive.out)" != "nbd=nbd:unix:$(pwd)/captive.sock
+port=
+socket=$(pwd)/captive.sock" ]; then
+ echo "$0: unexpected output"
+ cat captive.out
+ exit 1
+fi
+
+rm captive.sock captive.out
diff --git a/tests/test-dump-config.sh b/tests/test-dump-config.sh
new file mode 100755
index 0000000..1ed7fb7
--- /dev/null
+++ b/tests/test-dump-config.sh
@@ -0,0 +1,41 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2014 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 --dump-config)"
+if [[ ! ( "$output" =~ ^libdir= ) ]]; then
+ echo "$0: unexpected output from nbdkit --dump-config"
+ echo "$output"
+ exit 1
+fi
diff --git a/tests/test-foreground.sh b/tests/test-foreground.sh
new file mode 100755
index 0000000..daa733e
--- /dev/null
+++ b/tests/test-foreground.sh
@@ -0,0 +1,80 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2014 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
+set -x
+
+# 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 &
+bg_pid=$!
+
+# We may have to wait a short time for the pid file to appear.
+for i in `seq 1 10`; do
+ if test -f foreground.pid; then
+ break
+ fi
+ sleep 1
+done
+if ! test -f foreground.pid; then
+ echo "$0: PID file was not created"
+ exit 1
+fi
+
+pid="$(cat foreground.pid)"
+
+test "$bg_pid" -eq "$pid"
+
+# Check the socket was created (and is a socket).
+test -S foreground.sock
+
+# Kill the process.
+kill $pid
+
+# Check the process exits (eventually).
+for i in `seq 1 10`; do
+ if ! kill -s 0 $pid; then
+ break;
+ fi
+ sleep 1
+done
+if kill -s 0 $pid; then
+ echo "$0: process did not exit after sending a signal"
+ exit 1
+fi
+
+rm foreground.pid foreground.sock
diff --git a/tests/test-help-plugin.sh b/tests/test-help-plugin.sh
new file mode 100755
index 0000000..dba1028
--- /dev/null
+++ b/tests/test-help-plugin.sh
@@ -0,0 +1,41 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2014 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 ../plugins/file/.libs/nbdkit-file-plugin.so --help)"
+if [[ ! ( "$output" =~ "nbdkit file plugin" ) ]]; then
+ echo "$0: unexpected output from nbdkit file --help"
+ echo "$output"
+ exit 1
+fi
diff --git a/tests/test-help.sh b/tests/test-help.sh
new file mode 100755
index 0000000..299480b
--- /dev/null
+++ b/tests/test-help.sh
@@ -0,0 +1,41 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2014 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 --help)"
+if [[ ! ( "$output" =~ dump-config ) ]]; then
+ echo "$0: unexpected output from nbdkit --help"
+ echo "$output"
+ exit 1
+fi
diff --git a/tests/test-single.sh b/tests/test-single.sh
new file mode 100755
index 0000000..ab0827d
--- /dev/null
+++ b/tests/test-single.sh
@@ -0,0 +1,40 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2014 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
+set -x
+
+# 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
diff --git a/tests/test-start.sh b/tests/test-start.sh
new file mode 100755
index 0000000..7422040
--- /dev/null
+++ b/tests/test-start.sh
@@ -0,0 +1,81 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2014 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
+set -x
+
+# 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
+
+# We may have to wait a short time for the pid file to appear.
+for i in `seq 1 10`; do
+ if test -f start.pid; then
+ break
+ fi
+ sleep 1
+done
+if ! test -f start.pid; then
+ echo "$0: PID file was not created"
+ exit 1
+fi
+
+pid="$(cat start.pid)"
+
+# Check the process exists.
+kill -s 0 $pid
+
+# Check the socket was created (and is a socket).
+test -S start.sock
+
+# Kill the process.
+kill $pid
+
+# Check the process exits (eventually).
+for i in `seq 1 10`; do
+ if ! kill -s 0 $pid; then
+ break;
+ fi
+ sleep 1
+done
+if kill -s 0 $pid; then
+ echo "$0: process did not exit after sending a signal"
+ exit 1
+fi
+
+rm start.pid start.sock
--
1.8.4.2