Compile Python 2 and Python 3 versions of the plugin.

This commit is contained in:
Richard W.M. Jones 2016-10-03 14:27:41 +01:00
parent 8389ff205e
commit 3637d72126
12 changed files with 2187 additions and 8 deletions

View File

@ -0,0 +1,29 @@
From da13491740d2bf3086856aefe70481f9d1ca851e Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 9 Jul 2016 12:22:03 +0100
Subject: [PATCH 01/11] docs: Small clarification to nbdkit-plugin man page.
---
docs/nbdkit-plugin.pod | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/nbdkit-plugin.pod b/docs/nbdkit-plugin.pod
index 4a44285..30e1f86 100644
--- a/docs/nbdkit-plugin.pod
+++ b/docs/nbdkit-plugin.pod
@@ -348,9 +348,9 @@ C<.flush> callback has been defined.
int is_rotational (void *handle);
This is called during the option negotiation phase to find out if the
-backing disk is a rotational medium (like a disk) or not (like an
-SSD). If true, this may cause the client to reorder requests to make
-them more efficient for a slow rotating disk.
+backing disk is a rotational medium (like a traditional hard disk) or
+not (like an SSD). If true, this may cause the client to reorder
+requests to make them more efficient for a slow rotating disk.
If there is an error, C<.is_rotational> should call C<nbdkit_error>
with an error message and return C<-1>.
--
2.7.4

View File

@ -0,0 +1,26 @@
From f90e301de0481fda86d7acf91e21dfbc3a3a4916 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 9 Jul 2016 13:25:14 +0100
Subject: [PATCH 02/11] Mention Ruby in the README.
Fixes commit 242c63f88f619aac33a7d002136d58a2cdf3afe1.
---
README | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README b/README
index 246dda5..4ea812c 100644
--- a/README
+++ b/README
@@ -13,7 +13,7 @@ The key features are:
* Well-documented, simple plugin API with a stable ABI guarantee.
Let's you export "unconventional" block devices easily.
-* You can write plugins in C, Perl, Python or OCaml.
+* You can write plugins in C, Perl, Python, OCaml or Ruby.
For documentation, see the docs/ directory.
--
2.7.4

View File

@ -0,0 +1,324 @@
From 04ea431bd119dedd4f9ba063049b1f30102ac8a3 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 9 Jul 2016 15:18:06 +0100
Subject: [PATCH 03/11] Implement --dump-plugin option.
For example:
$ nbdkit example1 --dump-plugin
path=/usr/lib64/nbdkit/plugins/nbdkit-example1-plugin.so
name=example1
version=1.1.12
api_version=1
struct_size=176
thread_model=serialize_all_requests
has_load=1
has_open=1
has_get_size=1
has_pread=1
---
docs/nbdkit.pod | 7 +++++-
src/internal.h | 3 ++-
src/main.c | 53 ++++++++++++++++++++++++++++------------
src/plugins.c | 61 ++++++++++++++++++++++++++++++++++++++++++++---
tests/Makefile.am | 2 ++
tests/test-dump-plugin.sh | 44 ++++++++++++++++++++++++++++++++++
6 files changed, 150 insertions(+), 20 deletions(-)
create mode 100755 tests/test-dump-plugin.sh
diff --git a/docs/nbdkit.pod b/docs/nbdkit.pod
index 728aad3..12575fa 100644
--- a/docs/nbdkit.pod
+++ b/docs/nbdkit.pod
@@ -6,7 +6,8 @@ nbdkit - A toolkit for creating NBD servers
=head1 SYNOPSIS
- nbdkit [--dump-config] [-e EXPORTNAME] [-f] [-g GROUP] [-i IPADDR]
+ nbdkit [--dump-config] [--dump-plugin]
+ [-e EXPORTNAME] [-f] [-g GROUP] [-i IPADDR]
[--newstyle] [--oldstyle] [-P PIDFILE] [-p PORT] [-r]
[--run CMD] [-s] [-U SOCKET] [-u USER] [-v] [-V]
PLUGIN [key=value [key=value [...]]]
@@ -74,6 +75,10 @@ Display brief command line usage information and exit.
Dump out the compile-time configuration values and exit.
+=item B<--dump-plugin>
+
+Dump out information about the plugin and exit.
+
=item B<-e> EXPORTNAME
=item B<--export> EXPORTNAME
diff --git a/src/internal.h b/src/internal.h
index f58086a..bc4fa12 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -88,7 +88,8 @@ extern void plugin_register (const char *_filename, void *_dl, struct nbdkit_plu
extern void plugin_cleanup (void);
extern const char *plugin_name (void);
extern void plugin_usage (void);
-extern void plugin_version (void);
+extern const char *plugin_version (void);
+extern void plugin_dump_fields (void);
extern void plugin_config (const char *key, const char *value);
extern void plugin_config_complete (void);
extern void plugin_lock_connection (void);
diff --git a/src/main.c b/src/main.c
index 9529f19..9453cce 100644
--- a/src/main.c
+++ b/src/main.c
@@ -89,6 +89,7 @@ static const char *short_options = "e:fg:i:nop:P:rsu:U:vV";
static const struct option long_options[] = {
{ "help", 0, NULL, HELP_OPTION },
{ "dump-config",0, NULL, 0 },
+ { "dump-plugin",0, NULL, 0 },
{ "export", 1, NULL, 'e' },
{ "export-name",1, NULL, 'e' },
{ "exportname", 1, NULL, 'e' },
@@ -119,7 +120,8 @@ static const struct option long_options[] = {
static void
usage (void)
{
- printf ("nbdkit [--dump-config] [-e EXPORTNAME] [-f] [-g GROUP] [-i IPADDR]\n"
+ printf ("nbdkit [--dump-config] [--dump-plugin]\n"
+ " [-e EXPORTNAME] [-f] [-g GROUP] [-i IPADDR]\n"
" [--newstyle] [--oldstyle] [-P PIDFILE] [-p PORT] [-r]\n"
" [--run CMD] [-s] [-U SOCKET] [-u USER] [-v] [-V]\n"
" PLUGIN [key=value [key=value [...]]]\n"
@@ -151,7 +153,7 @@ main (int argc, char *argv[])
{
int c;
int option_index;
- int help = 0, version = 0;
+ int help = 0, version = 0, dump_plugin = 0;
tls_init ();
@@ -166,6 +168,9 @@ main (int argc, char *argv[])
dump_config ();
exit (EXIT_SUCCESS);
}
+ else if (strcmp (long_options[option_index].name, "dump-plugin") == 0) {
+ dump_plugin = 1;
+ }
else if (strcmp (long_options[option_index].name, "run") == 0) {
run = optarg;
foreground = 1;
@@ -261,6 +266,14 @@ main (int argc, char *argv[])
display_version ();
exit (EXIT_SUCCESS);
}
+ if (dump_plugin) {
+ /* Incorrect use of --dump-plugin. */
+ fprintf (stderr,
+ "%s: use 'nbdkit plugin --dump-plugin' or\n"
+ "'nbdkit /path/to/plugin.so --dump-plugin'\n",
+ program_name);
+ exit (EXIT_FAILURE);
+ }
/* Otherwise this is an error. */
fprintf (stderr,
@@ -292,6 +305,29 @@ main (int argc, char *argv[])
open_plugin_so (filename);
+ if (help) {
+ usage ();
+ printf ("\n%s:\n\n", filename);
+ plugin_usage ();
+ exit (EXIT_SUCCESS);
+ }
+
+ if (version) {
+ const char *v;
+
+ display_version ();
+ printf ("%s", plugin_name ());
+ if ((v = plugin_version ()) != NULL)
+ printf (" %s", v);
+ printf ("\n");
+ exit (EXIT_SUCCESS);
+ }
+
+ if (dump_plugin) {
+ plugin_dump_fields ();
+ exit (EXIT_SUCCESS);
+ }
+
/* Find key=value configuration parameters for this plugin. */
++optind;
while (optind < argc && (p = strchr (argv[optind], '=')) != NULL) {
@@ -304,19 +340,6 @@ main (int argc, char *argv[])
++optind;
}
- if (help) {
- usage ();
- printf ("\n%s:\n\n", filename);
- plugin_usage ();
- exit (EXIT_SUCCESS);
- }
-
- if (version) {
- display_version ();
- plugin_version ();
- exit (EXIT_SUCCESS);
- }
-
plugin_config_complete ();
/* If we supported export names, then we'd continue in the loop
diff --git a/src/plugins.c b/src/plugins.c
index 0834874..8f38761 100644
--- a/src/plugins.c
+++ b/src/plugins.c
@@ -189,15 +189,70 @@ plugin_usage (void)
}
}
-void
+const char *
plugin_version (void)
{
assert (dl);
- printf ("%s", plugin.name);
+ return plugin.version;
+}
+
+/* This implements the --dump-plugin option. */
+void
+plugin_dump_fields (void)
+{
+ char *path;
+
+ path = nbdkit_absolute_path (filename);
+ printf ("path=%s\n", path);
+ free (path);
+
+ printf ("name=%s\n", plugin.name);
if (plugin.version)
- printf (" %s", plugin.version);
+ printf ("version=%s\n", plugin.version);
+
+ printf ("api_version=%d\n", plugin._api_version);
+ printf ("struct_size=%" PRIu64 "\n", plugin._struct_size);
+ printf ("thread_model=");
+ switch (plugin._thread_model) {
+ case NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS:
+ printf ("serialize_connections");
+ break;
+ case NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS:
+ printf ("serialize_all_requests");
+ break;
+ case NBDKIT_THREAD_MODEL_SERIALIZE_REQUESTS:
+ printf ("serialize_requests");
+ break;
+ case NBDKIT_THREAD_MODEL_PARALLEL:
+ printf ("parallel");
+ break;
+ default:
+ printf ("%d # unknown thread model!", plugin._thread_model);
+ break;
+ }
printf ("\n");
+
+#define HAS(field) if (plugin.field) printf ("has_%s=1\n", #field)
+ HAS (longname);
+ HAS (description);
+ HAS (load);
+ HAS (unload);
+ HAS (config);
+ HAS (config_complete);
+ HAS (config_help);
+ HAS (open);
+ HAS (close);
+ HAS (get_size);
+ HAS (can_write);
+ HAS (can_flush);
+ HAS (is_rotational);
+ HAS (can_trim);
+ HAS (pread);
+ HAS (pwrite);
+ HAS (flush);
+ HAS (trim);
+#undef HAS
}
void
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 04bc0bc..2c936bf 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -37,6 +37,7 @@ EXTRA_DIST = \
README.tests \
test-captive.sh \
test-dump-config.sh \
+ test-dump-plugin.sh \
test-foreground.sh \
test-help.sh \
test-help-plugin.sh \
@@ -55,6 +56,7 @@ TESTS = \
test-help.sh \
test-help-plugin.sh \
test-dump-config.sh \
+ test-dump-plugin.sh \
test-start.sh \
test-foreground.sh \
test-single.sh \
diff --git a/tests/test-dump-plugin.sh b/tests/test-dump-plugin.sh
new file mode 100755
index 0000000..5cde25b
--- /dev/null
+++ b/tests/test-dump-plugin.sh
@@ -0,0 +1,44 @@
+#!/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/example1/.libs/nbdkit-example1-plugin.so --dump-plugin
+ )"
+if [[ ! ( "$output" =~ ^path= ) ]]; then
+ echo "$0: unexpected output from nbdkit --dump-plugin"
+ echo "$output"
+ exit 1
+fi
--
2.7.4

View File

@ -0,0 +1,73 @@
From c149420eac39b8f3bf7d870d1f030c68870f7c51 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 9 Jul 2016 20:06:57 +0100
Subject: [PATCH 04/11] Update copyright date on a few files.
---
LICENSE | 2 +-
Makefile.am | 2 +-
docs/nbdkit.pod | 2 +-
include/nbdkit-plugin.h | 2 +-
tests/Makefile.am | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/LICENSE b/LICENSE
index 5e5cc77..5b4109f 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,5 +1,5 @@
nbdkit
-Copyright (C) 2013 Red Hat Inc.
+Copyright (C) 2013-2016 Red Hat Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
diff --git a/Makefile.am b/Makefile.am
index 6b48dff..aade60d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
# nbdkit
-# Copyright (C) 2013 Red Hat Inc.
+# Copyright (C) 2013-2016 Red Hat Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
diff --git a/docs/nbdkit.pod b/docs/nbdkit.pod
index 12575fa..2b11eed 100644
--- a/docs/nbdkit.pod
+++ b/docs/nbdkit.pod
@@ -404,7 +404,7 @@ Richard W.M. Jones
=head1 COPYRIGHT
-Copyright (C) 2013 Red Hat Inc.
+Copyright (C) 2013-2016 Red Hat Inc.
=head1 LICENSE
diff --git a/include/nbdkit-plugin.h b/include/nbdkit-plugin.h
index 8352675..bc9794e 100644
--- a/include/nbdkit-plugin.h
+++ b/include/nbdkit-plugin.h
@@ -1,5 +1,5 @@
/* nbdkit
- * Copyright (C) 2013 Red Hat Inc.
+ * Copyright (C) 2013-2016 Red Hat Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2c936bf..08fd02a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,5 @@
# nbdkit
-# Copyright (C) 2013-2014 Red Hat Inc.
+# Copyright (C) 2013-2016 Red Hat Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
--
2.7.4

View File

@ -0,0 +1,441 @@
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

View File

@ -0,0 +1,896 @@
From 271150d19fb222949763a5d562a4139c82f322b8 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 9 Jul 2016 21:15:46 +0100
Subject: [PATCH 06/11] Add support for testing under valgrind.
Use 'make check-valgrind' to run all the tests under valgrind.
---
Makefile.am | 3 +++
README | 11 ++++++++++
configure.ac | 12 +++++++++++
tests/Makefile.am | 50 ++++++++++++++++++++++++++++++--------------
tests/test-captive.sh | 2 +-
tests/test-connect.sh | 34 ++++++++++++++++++++++++++++++
tests/test-dump-config.sh | 2 +-
tests/test-dump-plugin.sh | 2 +-
tests/test-file.sh | 34 ++++++++++++++++++++++++++++++
tests/test-foreground.sh | 2 +-
tests/test-gzip.sh | 34 ++++++++++++++++++++++++++++++
tests/test-help-plugin.sh | 2 +-
tests/test-help.sh | 2 +-
tests/test-ipv4.sh | 2 +-
tests/test-newstyle.sh | 34 ++++++++++++++++++++++++++++++
tests/test-ocaml.sh | 34 ++++++++++++++++++++++++++++++
tests/test-oldstyle.sh | 34 ++++++++++++++++++++++++++++++
tests/test-perl.sh | 34 ++++++++++++++++++++++++++++++
tests/test-python.sh | 34 ++++++++++++++++++++++++++++++
tests/test-random-sock.sh | 2 +-
tests/test-ruby.sh | 34 ++++++++++++++++++++++++++++++
tests/test-single.sh | 2 +-
tests/test-start.sh | 2 +-
tests/test-streaming.sh | 34 ++++++++++++++++++++++++++++++
tests/test-version-plugin.sh | 2 +-
tests/test-version.sh | 2 +-
tests/test-xz.sh | 34 ++++++++++++++++++++++++++++++
valgrind-suppressions | 32 ++++++++++++++++++++++++++++
28 files changed, 478 insertions(+), 28 deletions(-)
create mode 100755 tests/test-connect.sh
create mode 100755 tests/test-file.sh
create mode 100755 tests/test-gzip.sh
create mode 100755 tests/test-newstyle.sh
create mode 100755 tests/test-ocaml.sh
create mode 100755 tests/test-oldstyle.sh
create mode 100755 tests/test-perl.sh
create mode 100755 tests/test-python.sh
create mode 100755 tests/test-ruby.sh
create mode 100755 tests/test-streaming.sh
create mode 100755 tests/test-xz.sh
create mode 100644 valgrind-suppressions
diff --git a/Makefile.am b/Makefile.am
index aade60d..3c5c650 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -40,3 +40,6 @@ EXTRA_DIST = \
SUBDIRS = docs plugins include src tests
CLEANFILES = *~
+
+check-valgrind:
+ $(MAKE) -C tests check-valgrind
diff --git a/README b/README
index 4ea812c..135c8d5 100644
--- a/README
+++ b/README
@@ -78,6 +78,16 @@ For the OCaml plugin:
- OCaml >= 4.02.2 which has support for shared libraries, see:
http://caml.inria.fr/mantis/view.php?id=6693
+To test for memory leaks ('make check-valgrind'):
+
+ - valgrind
+
+For non-essential enhancements to the test suite:
+
+ - socat
+
+ - ss (from iproute package)
+
After installing any dependencies:
To build from tarball: To build from git:
@@ -86,6 +96,7 @@ After installing any dependencies:
./configure ./configure
make make
make check make check
+ make check-valgrind make check-valgrind
Optionally run this as root to install everything:
diff --git a/configure.ac b/configure.ac
index 3c75397..c064420 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,6 +109,18 @@ or the configure test may be wrong.
The code will still compile, but is likely to leak memory and other
resources when it runs.])])
+dnl Check for valgrind.
+AC_CHECK_PROG([VALGRIND],[valgrind],[valgrind],[no])
+AS_IF([test "x$VALGRIND" != "xno"],[
+ # Substitute the whole valgrind command.
+ VG='$(VALGRIND) --vgdb=no --leak-check=full --error-exitcode=119 --suppressions=$(abs_top_srcdir)/valgrind-suppressions --trace-children=no --child-silent-after-fork=yes --run-libc-freeres=no'
+],[
+ # Valgrind is not installed, substitute something which will break.
+ VG=VALGRIND_IS_NOT_INSTALLED
+])
+AC_SUBST([VG])
+AM_SUBST_NOTMAKE([VG])
+
dnl Check for Perl POD.
AC_CHECK_PROG([POD2MAN], [pod2man], [pod2man], [no])
AM_CONDITIONAL([HAVE_POD2MAN], [test "x$POD2MAN" != "xno"])
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6f6cfa2..afb9975 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -36,22 +36,38 @@ MAINTAINERCLEANFILES =
EXTRA_DIST = \
README.tests \
test-captive.sh \
+ test-connect.sh \
test-dump-config.sh \
test-dump-plugin.sh \
+ test-file.sh \
test-foreground.sh \
+ test-gzip.sh \
test-help.sh \
test-help-plugin.sh \
test-ipv4.sh \
- test.pl \
- test.py \
+ test-newstyle.sh \
test_ocaml_plugin.ml \
test-ocaml.c \
+ test-ocaml.sh \
+ test-oldstyle.sh \
+ test.pl \
+ test-perl.sh \
+ test.py \
+ test-python.sh \
test.rb \
test-single.sh \
test-start.sh \
test-random-sock.sh \
+ test-ruby.sh \
+ test-streaming.sh \
test-version.sh \
- test-version-plugin.sh
+ test-version-plugin.sh \
+ test-xz.sh
+
+# Use 'make check' to run the ordinary tests. To run all the tests
+# under valgrind, use the following rule:
+check-valgrind:
+ $(MAKE) VG="@VG@" check
# Basic server command line and start-up tests.
@@ -87,19 +103,21 @@ check_LTLIBRARIES = libtest.la
libtest_la_SOURCES = test.c test.h
libtest_la_CFLAGS = $(WARNINGS_CFLAGS)
-# Basic connection test.
-check_PROGRAMS = test-connect
-TESTS += test-connect
+check_PROGRAMS =
check_DATA =
check_SCRIPTS =
+# Basic connection test.
+check_PROGRAMS += test-connect
+TESTS += test-connect.sh
+
test_connect_SOURCES = test-connect.c test.h
test_connect_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
test_connect_LDADD = libtest.la $(LIBGUESTFS_LIBS)
# file plugin test.
check_PROGRAMS += test-file
-TESTS += test-file
+TESTS += test-file.sh
check_DATA += file-data
MAINTAINERCLEANFILES += file-data
@@ -114,7 +132,7 @@ file-data:
# newstyle protocol test.
check_PROGRAMS += test-newstyle
-TESTS += test-newstyle
+TESTS += test-newstyle.sh
test_newstyle_SOURCES = test-newstyle.c test.h
test_newstyle_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
@@ -122,7 +140,7 @@ test_newstyle_LDADD = libtest.la $(LIBGUESTFS_LIBS)
# oldstyle protocol test.
check_PROGRAMS += test-oldstyle
-TESTS += test-oldstyle
+TESTS += test-oldstyle.sh
test_oldstyle_SOURCES = test-oldstyle.c test.h
test_oldstyle_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
@@ -133,7 +151,7 @@ if HAVE_ZLIB
if HAVE_GUESTFISH
check_PROGRAMS += test-gzip
-TESTS += test-gzip
+TESTS += test-gzip.sh
check_DATA += disk disk.gz
MAINTAINERCLEANFILES += disk disk.gz
@@ -158,7 +176,7 @@ if HAVE_LIBLZMA
if HAVE_GUESTFISH
check_PROGRAMS += test-xz
-TESTS += test-xz
+TESTS += test-xz.sh
check_DATA += disk.xz
MAINTAINERCLEANFILES += disk.xz
@@ -177,7 +195,7 @@ endif
if HAVE_PERL
check_PROGRAMS += test-perl
-TESTS += test-perl
+TESTS += test-perl.sh
test_perl_SOURCES = test-lang-plugins.c test.h
test_perl_CFLAGS = \
@@ -191,7 +209,7 @@ endif
if HAVE_PYTHON
check_PROGRAMS += test-python
-TESTS += test-python
+TESTS += test-python.sh
test_python_SOURCES = test-lang-plugins.c test.h
test_python_CFLAGS = \
@@ -205,7 +223,7 @@ endif
if HAVE_OCAML
check_PROGRAMS += test-ocaml
-TESTS += test-ocaml
+TESTS += test-ocaml.sh
# This is somewhat different from the other tests because we have
# to build an actual plugin here.
@@ -227,7 +245,7 @@ endif
if HAVE_RUBY
check_PROGRAMS += test-ruby
-TESTS += test-ruby
+TESTS += test-ruby.sh
test_ruby_SOURCES = test-lang-plugins.c test.h
test_ruby_CFLAGS = \
@@ -240,7 +258,7 @@ endif
# streaming plugin test.
check_PROGRAMS += test-streaming
# Doesn't work:
-#TESTS += test-streaming
+#TESTS += test-streaming.sh
test_streaming_SOURCES = test-streaming.c test.h
test_streaming_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
diff --git a/tests/test-captive.sh b/tests/test-captive.sh
index 098024b..1ac0844 100755
--- a/tests/test-captive.sh
+++ b/tests/test-captive.sh
@@ -39,7 +39,7 @@ source ./functions.sh
rm -f captive.sock captive.out
-../src/nbdkit -U captive.sock `nbdkit_plugin example1` --run '
+$VG ../src/nbdkit -U captive.sock `nbdkit_plugin example1` --run '
sleep 5; echo nbd=$nbd; echo port=$port; echo socket=$unixsocket
' > captive.out
diff --git a/tests/test-connect.sh b/tests/test-connect.sh
new file mode 100755
index 0000000..37b1e32
--- /dev/null
+++ b/tests/test-connect.sh
@@ -0,0 +1,34 @@
+#!/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.
+
+exec $VG ./test-connect
diff --git a/tests/test-dump-config.sh b/tests/test-dump-config.sh
index 6c01adb..7910e11 100755
--- a/tests/test-dump-config.sh
+++ b/tests/test-dump-config.sh
@@ -33,7 +33,7 @@
set -e
-output="$(../src/nbdkit --dump-config)"
+output="$($VG ../src/nbdkit --dump-config)"
if [[ ! ( "$output" =~ ^bindir= ) ]]; then
echo "$0: unexpected output from nbdkit --dump-config"
echo "$output"
diff --git a/tests/test-dump-plugin.sh b/tests/test-dump-plugin.sh
index 2517689..8d9b8fd 100755
--- a/tests/test-dump-plugin.sh
+++ b/tests/test-dump-plugin.sh
@@ -34,7 +34,7 @@
set -e
source ./functions.sh
-output="$(../src/nbdkit `nbdkit_plugin example1` --dump-plugin)"
+output="$($VG ../src/nbdkit `nbdkit_plugin example1` --dump-plugin)"
if [[ ! ( "$output" =~ name\=example1 ) ]]; then
echo "$0: unexpected output from nbdkit --dump-plugin"
echo "$output"
diff --git a/tests/test-file.sh b/tests/test-file.sh
new file mode 100755
index 0000000..f5012a8
--- /dev/null
+++ b/tests/test-file.sh
@@ -0,0 +1,34 @@
+#!/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.
+
+exec $VG ./test-file
diff --git a/tests/test-foreground.sh b/tests/test-foreground.sh
index 6d23bf4..e76b52d 100755
--- a/tests/test-foreground.sh
+++ b/tests/test-foreground.sh
@@ -39,7 +39,7 @@ source ./functions.sh
rm -f foreground.pid foreground.sock
-../src/nbdkit \
+$VG ../src/nbdkit \
-f -P foreground.pid -U foreground.sock `nbdkit_plugin example1` &
bg_pid=$!
diff --git a/tests/test-gzip.sh b/tests/test-gzip.sh
new file mode 100755
index 0000000..085798e
--- /dev/null
+++ b/tests/test-gzip.sh
@@ -0,0 +1,34 @@
+#!/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.
+
+exec $VG ./test-gzip
diff --git a/tests/test-help-plugin.sh b/tests/test-help-plugin.sh
index 92bb277..94359c2 100755
--- a/tests/test-help-plugin.sh
+++ b/tests/test-help-plugin.sh
@@ -34,7 +34,7 @@
set -e
source ./functions.sh
-output="$(../src/nbdkit `nbdkit_plugin file` --help)"
+output="$($VG ../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-help.sh b/tests/test-help.sh
index 299480b..c98e7d7 100755
--- a/tests/test-help.sh
+++ b/tests/test-help.sh
@@ -33,7 +33,7 @@
set -e
-output="$(../src/nbdkit --help)"
+output="$($VG ../src/nbdkit --help)"
if [[ ! ( "$output" =~ dump-config ) ]]; then
echo "$0: unexpected output from nbdkit --help"
echo "$output"
diff --git a/tests/test-ipv4.sh b/tests/test-ipv4.sh
index 8eda61c..024d2ee 100755
--- a/tests/test-ipv4.sh
+++ b/tests/test-ipv4.sh
@@ -56,7 +56,7 @@ for port in `seq 49152 65535`; do
done
echo picked unused port $port
-../src/nbdkit -P ipv4.pid -p $port `nbdkit_plugin example1`
+$VG ../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
diff --git a/tests/test-newstyle.sh b/tests/test-newstyle.sh
new file mode 100755
index 0000000..62176aa
--- /dev/null
+++ b/tests/test-newstyle.sh
@@ -0,0 +1,34 @@
+#!/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.
+
+exec $VG ./test-newstyle
diff --git a/tests/test-ocaml.sh b/tests/test-ocaml.sh
new file mode 100755
index 0000000..e90c9c5
--- /dev/null
+++ b/tests/test-ocaml.sh
@@ -0,0 +1,34 @@
+#!/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.
+
+exec $VG ./test-ocaml
diff --git a/tests/test-oldstyle.sh b/tests/test-oldstyle.sh
new file mode 100755
index 0000000..db2705a
--- /dev/null
+++ b/tests/test-oldstyle.sh
@@ -0,0 +1,34 @@
+#!/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.
+
+exec $VG ./test-oldstyle
diff --git a/tests/test-perl.sh b/tests/test-perl.sh
new file mode 100755
index 0000000..44af3ee
--- /dev/null
+++ b/tests/test-perl.sh
@@ -0,0 +1,34 @@
+#!/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.
+
+exec $VG ./test-perl
diff --git a/tests/test-python.sh b/tests/test-python.sh
new file mode 100755
index 0000000..4738cc1
--- /dev/null
+++ b/tests/test-python.sh
@@ -0,0 +1,34 @@
+#!/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.
+
+exec $VG ./test-python
diff --git a/tests/test-random-sock.sh b/tests/test-random-sock.sh
index a4c58d3..7b0293b 100755
--- a/tests/test-random-sock.sh
+++ b/tests/test-random-sock.sh
@@ -37,4 +37,4 @@ source ./functions.sh
# Test nbdkit -U - + captive nbdkit.
-../src/nbdkit -U - `nbdkit_plugin example1` --run 'sleep 5'
+$VG ../src/nbdkit -U - `nbdkit_plugin example1` --run 'sleep 5'
diff --git a/tests/test-ruby.sh b/tests/test-ruby.sh
new file mode 100755
index 0000000..50a6e7c
--- /dev/null
+++ b/tests/test-ruby.sh
@@ -0,0 +1,34 @@
+#!/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.
+
+exec $VG ./test-ruby
diff --git a/tests/test-single.sh b/tests/test-single.sh
index a06ea5d..ec83e2f 100755
--- a/tests/test-single.sh
+++ b/tests/test-single.sh
@@ -38,4 +38,4 @@ source ./functions.sh
# Test nbdkit -s option.
# XXX Not sure what is a really good test of this.
-../src/nbdkit -s `nbdkit_plugin example1` </dev/null
+$VG ../src/nbdkit -s `nbdkit_plugin example1` </dev/null
diff --git a/tests/test-start.sh b/tests/test-start.sh
index 6041cd4..8df7ab4 100755
--- a/tests/test-start.sh
+++ b/tests/test-start.sh
@@ -40,7 +40,7 @@ source ./functions.sh
rm -f start.pid start.sock
-../src/nbdkit -P start.pid -U start.sock `nbdkit_plugin example1`
+$VG ../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-streaming.sh b/tests/test-streaming.sh
new file mode 100755
index 0000000..1ed0d9d
--- /dev/null
+++ b/tests/test-streaming.sh
@@ -0,0 +1,34 @@
+#!/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.
+
+exec $VG ./test-streaming
diff --git a/tests/test-version-plugin.sh b/tests/test-version-plugin.sh
index da99dbf..6d058a3 100755
--- a/tests/test-version-plugin.sh
+++ b/tests/test-version-plugin.sh
@@ -34,7 +34,7 @@
set -e
source ./functions.sh
-output="$(../src/nbdkit `nbdkit_plugin file` --version)"
+output="$($VG ../src/nbdkit `nbdkit_plugin file` --version)"
if [[ ! ( "$output" =~ file\ ) ]]; then
echo "$0: unexpected output from nbdkit file --version"
echo "$output"
diff --git a/tests/test-version.sh b/tests/test-version.sh
index 9a2e356..ebd4242 100755
--- a/tests/test-version.sh
+++ b/tests/test-version.sh
@@ -33,7 +33,7 @@
set -e
-output="$(../src/nbdkit --version)"
+output="$($VG ../src/nbdkit --version)"
if [[ ! ( "$output" =~ ^nbdkit\ 1\. ) ]]; then
echo "$0: unexpected output from nbdkit --version"
echo "$output"
diff --git a/tests/test-xz.sh b/tests/test-xz.sh
new file mode 100755
index 0000000..a8cbcfd
--- /dev/null
+++ b/tests/test-xz.sh
@@ -0,0 +1,34 @@
+#!/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.
+
+exec $VG ./test-xz
diff --git a/valgrind-suppressions b/valgrind-suppressions
new file mode 100644
index 0000000..068465f
--- /dev/null
+++ b/valgrind-suppressions
@@ -0,0 +1,32 @@
+# nbdkit valgrind suppressions
+# 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.
+
--
2.7.4

View File

@ -0,0 +1,26 @@
From 51551cfb115b2b7183d21fc0825f312434162323 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sun, 10 Jul 2016 17:10:30 +0100
Subject: [PATCH 07/11] tests: Fix memory leak in OCaml test harness (found by
valgrind).
---
tests/test-ocaml.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/test-ocaml.c b/tests/test-ocaml.c
index 08b2e98..e77ff00 100644
--- a/tests/test-ocaml.c
+++ b/tests/test-ocaml.c
@@ -106,6 +106,8 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
+ free (data);
+
data = guestfs_pread_device (g, "/dev/sda", 8 * 512, 0, &size);
if (!data)
exit (EXIT_FAILURE);
--
2.7.4

View File

@ -0,0 +1,58 @@
From 558dc7d84b46a1924e06808caa8b113238961fd3 Mon Sep 17 00:00:00 2001
From: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Date: Mon, 26 Sep 2016 17:07:41 +0200
Subject: [PATCH 08/11] Improve memory management of nbdkit python plugin
example
Hi,
the nbdkit python plugin example has suboptimal memory management:
- it creates the disk image as a string on init
- it casts the string to bytearray on every read
- it copies the string before and the string after the written region,
then reassembles those pieces together with the written region to a new
disk image string
This is not a problem as long as the image is small, but in my tests
with a 5 GB sized image nbdkit already used 15 GB RAM directly after
startup, and even more (20-25 GB) on the first write.
This changes the code to use bytearray everywhere and use the proper
methods to change bytearray objects directly. With the patch applied,
nbdkit with a 5 GB image will still only use 5 GB RAM even during heavy
read/write activity.
Regards,
Carl-Daniel
---
plugins/python/example.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/plugins/python/example.py b/plugins/python/example.py
index aa099eb..184896e 100644
--- a/plugins/python/example.py
+++ b/plugins/python/example.py
@@ -29,7 +29,7 @@
# reconnect to the same server you should see the same disk. You
# could also put this into the handle, so there would be a fresh disk
# per handle.
-disk = "\0" * (1024*1024);
+disk = bytearray(1024 * 1024)
# This just prints the extra command line parameters, but real plugins
# should parse them and reject any unknown parameters.
@@ -50,9 +50,9 @@ def get_size(h):
def pread(h, count, offset):
global disk
- return bytearray (disk[offset:offset+count])
+ return disk[offset:offset+count]
def pwrite(h, buf, offset):
global disk
end = offset + len (buf)
- disk = disk[:offset] + buf + disk[end:]
+ disk[offset:end] = buf
--
2.7.4

View File

@ -0,0 +1,43 @@
From 90e5af07e54ce77f8b9d7b20af52306ea2b12c6e Mon Sep 17 00:00:00 2001
From: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Date: Mon, 26 Sep 2016 17:14:37 +0200
Subject: [PATCH 09/11] nbdkit: Talk about Python in the Python plugin
---
plugins/python/python.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/plugins/python/python.c b/plugins/python/python.c
index a59d11e..fcbb9f2 100644
--- a/plugins/python/python.c
+++ b/plugins/python/python.c
@@ -437,7 +437,7 @@ py_can_write (void *handle)
Py_DECREF (r);
return ret;
}
- /* No Perl can_write callback, but there's a Perl pwrite callback
+ /* No Python can_write callback, but there's a Python pwrite callback
* defined, so return 1. (In C modules, nbdkit would do this).
*/
else if (callback_defined ("pwrite", NULL))
@@ -470,7 +470,7 @@ py_can_flush (void *handle)
Py_DECREF (r);
return ret;
}
- /* No Perl can_flush callback, but there's a Perl flush callback
+ /* No Python can_flush callback, but there's a Python flush callback
* defined, so return 1. (In C modules, nbdkit would do this).
*/
else if (callback_defined ("flush", NULL))
@@ -531,7 +531,7 @@ py_can_trim (void *handle)
Py_DECREF (r);
return ret;
}
- /* No Perl can_trim callback, but there's a Perl trim callback
+ /* No Python can_trim callback, but there's a Python trim callback
* defined, so return 1. (In C modules, nbdkit would do this).
*/
else if (callback_defined ("trim", NULL))
--
2.7.4

View File

@ -0,0 +1,117 @@
From fe8e47a7295900951e4510bdf582dc6b836efad5 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 3 Oct 2016 13:55:26 +0100
Subject: [PATCH 10/11] Fix build for Python 3.
Python 3 does not have PyString_FromString. Use a near-equivalent
instead.
To build for Python 3 you must point the PYTHON environment variable
to the Python 3 interpreter when configuring. For example:
PYTHON=/usr/bin/python3 ./configure
---
README | 10 ++++++++++
configure.ac | 13 ++++++++++++-
plugins/python/nbdkit-python-plugin.pod | 9 +++++++++
plugins/python/python.c | 9 +++++++++
4 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/README b/README
index 135c8d5..2723d5e 100644
--- a/README
+++ b/README
@@ -102,6 +102,16 @@ Optionally run this as root to install everything:
make install
+Python
+------
+
+By default nbdkit uses the Python version of the Python interpreter
+called "python" on the current $PATH. To use another version of
+Python you may need to set the PYTHON environment variable when
+configuring. For example:
+
+ PYTHON=/usr/bin/python3 ./configure
+
Tests
-----
diff --git a/configure.ac b/configure.ac
index c064420..a475e8e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -201,7 +201,18 @@ AS_IF([test "x$PYTHON" != "xno" && test "x$enable_python" != "xno"],[
])
])
- dnl XXX Could check these actually work.
+ dnl Check for various functions needed by the bindings.
+ old_LIBS="$LIBS"
+
+ PYTHON_BLDLIBRARY=`$PYTHON -c "import distutils.sysconfig; \
+ print (distutils.sysconfig.get_config_var('BLDLIBRARY'))"`
+ AC_CHECK_LIB([c],[PyString_FromString],
+ [AC_DEFINE([HAVE_PYSTRING_FROMSTRING],1,
+ [Found PyString_FromString in libpython.])],
+ [],[$PYTHON_BLDLIBRARY])
+
+ LIBS="$old_LIBS"
+
])
AM_CONDITIONAL([HAVE_PYTHON],[test "x$enable_python" != "xno" && test "x$PYTHON" != "xno"])
AC_SUBST([PYTHON_CFLAGS])
diff --git a/plugins/python/nbdkit-python-plugin.pod b/plugins/python/nbdkit-python-plugin.pod
index 70d3e17..9b0f0ef 100644
--- a/plugins/python/nbdkit-python-plugin.pod
+++ b/plugins/python/nbdkit-python-plugin.pod
@@ -16,6 +16,15 @@ L<nbdkit(1)>, allowing you to write nbdkit plugins in Python.
Broadly speaking, Python nbdkit plugins work like C ones, so you should
read L<nbdkit-plugin(3)> first.
+=head2 PYTHON 2 AND PYTHON 3
+
+The Python plugin has to be compiled for either Python 2 or Python 3
+when building nbdkit. You can set the C<PYTHON> environment variable
+to the desired interpreter, otherwise nbdkit will use the interpreter
+called C<python> on the current C<$PATH>. For example:
+
+ PYTHON=/usr/bin/python3 ./configure
+
=head2 USING A PYTHON NBDKIT PLUGIN
Assuming you have a Python script which is an nbdkit plugin, you run it
diff --git a/plugins/python/python.c b/plugins/python/python.c
index fcbb9f2..0504715 100644
--- a/plugins/python/python.c
+++ b/plugins/python/python.c
@@ -133,7 +133,11 @@ py_config (const char *key, const char *value)
/* Note that because closeit flag == 1, fp is now closed. */
/* The script should define a module called __main__. */
+#ifdef HAVE_PYSTRING_FROMSTRING
modname = PyString_FromString ("__main__");
+#else
+ modname = PyUnicode_FromString ("__main__");
+#endif
module = PyImport_Import (modname);
Py_DECREF (modname);
if (!module) {
@@ -154,8 +158,13 @@ py_config (const char *key, const char *value)
PyErr_Clear ();
args = PyTuple_New (2);
+#ifdef HAVE_PYSTRING_FROMSTRING
PyTuple_SetItem (args, 0, PyString_FromString (key));
PyTuple_SetItem (args, 1, PyString_FromString (value));
+#else
+ PyTuple_SetItem (args, 0, PyUnicode_FromString (key));
+ PyTuple_SetItem (args, 1, PyUnicode_FromString (value));
+#endif
r = PyObject_CallObject (fn, args);
Py_DECREF (fn);
Py_DECREF (args);
--
2.7.4

View File

@ -0,0 +1,42 @@
From 8b7a591c981df7db19334481cb43f95e9f5c420d Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 3 Oct 2016 14:14:25 +0100
Subject: [PATCH 11/11] tests: python: Use bytearray in the test.
Fixes the test on Python 3. Improves efficiency and memory usage of
the test on Python 2.
This makes the equivalent change to
commit 558dc7d84b46a1924e06808caa8b113238961fd3.
---
tests/test.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/test.py b/tests/test.py
index ffe0872..5d68b32 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -1,4 +1,4 @@
-disk = "\0" * (1024*1024);
+disk = bytearray (1024*1024);
def config_complete():
pass
@@ -24,12 +24,12 @@ def can_trim(h):
def pread(h, count, offset):
global disk
- return bytearray (disk[offset:offset+count])
+ return disk[offset:offset+count]
def pwrite(h, buf, offset):
global disk
end = offset + len (buf)
- disk = disk[:offset] + buf + disk[end:]
+ disk[offset:end] = buf
def flush(h):
pass
--
2.7.4

View File

@ -6,7 +6,7 @@
Name: nbdkit Name: nbdkit
Version: 1.1.12 Version: 1.1.12
Release: 1%{?dist} Release: 2%{?dist}
Summary: NBD server Summary: NBD server
License: BSD License: BSD
@ -14,6 +14,23 @@ URL: https://github.com/libguestfs/nbdkit
Source0: http://libguestfs.org/download/nbdkit/%{name}-%{version}.tar.gz Source0: http://libguestfs.org/download/nbdkit/%{name}-%{version}.tar.gz
# All upstream patches since 1.1.12, up to the point that
# Python 3 support was added.
Patch1: 0001-docs-Small-clarification-to-nbdkit-plugin-man-page.patch
Patch2: 0002-Mention-Ruby-in-the-README.patch
Patch3: 0003-Implement-dump-plugin-option.patch
Patch4: 0004-Update-copyright-date-on-a-few-files.patch
Patch5: 0005-tests-Multiple-small-additions-and-cleanups-to-the-t.patch
Patch6: 0006-Add-support-for-testing-under-valgrind.patch
Patch7: 0007-tests-Fix-memory-leak-in-OCaml-test-harness-found-by.patch
Patch8: 0008-Improve-memory-management-of-nbdkit-python-plugin-ex.patch
Patch9: 0009-nbdkit-Talk-about-Python-in-the-Python-plugin.patch
Patch10: 0010-Fix-build-for-Python-3.patch
Patch11: 0011-tests-python-Use-bytearray-in-the-test.patch
# Because the patches touch Makefile.am etc.
BuildRequires: autoconf, automake, libtool
BuildRequires: /usr/bin/pod2man BuildRequires: /usr/bin/pod2man
%if 0%{?have_libguestfs} %if 0%{?have_libguestfs}
BuildRequires: libguestfs-devel BuildRequires: libguestfs-devel
@ -24,7 +41,8 @@ BuildRequires: zlib-devel
BuildRequires: libcurl-devel BuildRequires: libcurl-devel
BuildRequires: perl-devel BuildRequires: perl-devel
BuildRequires: perl(ExtUtils::Embed) BuildRequires: perl(ExtUtils::Embed)
BuildRequires: python-devel BuildRequires: python2-devel
BuildRequires: python3-devel
%ifarch %{ocaml_native_compiler} %ifarch %{ocaml_native_compiler}
# Requires OCaml 4.02.2 which contains fix for # Requires OCaml 4.02.2 which contains fix for
# http://caml.inria.fr/mantis/view.php?id=6693 # http://caml.inria.fr/mantis/view.php?id=6693
@ -170,15 +188,46 @@ Requires: %{name}%{?_isa} = %{version}-%{release}
This package lets you write Perl plugins for %{name}. This package lets you write Perl plugins for %{name}.
%package plugin-python %package plugin-python-common
Summary: Python plugin for %{name} Summary: Python 2 and 3 plugin common files for %{name}
License: BSD License: BSD
Requires: %{name}%{?_isa} = %{version}-%{release} Requires: %{name}%{?_isa} = %{version}-%{release}
%description plugin-python %description plugin-python-common
This package lets you write Python plugins for %{name}. This package contains common files shared between Python 2
and Python 3 %{name} plugins.
You should not install this package directly. Instead install
either %{name}-plugin-python2 or %{name}-plugin-python3.
%package plugin-python2
Summary: Python 2 plugin for %{name}
License: BSD
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: %{name}-plugin-python-common = %{version}-%{release}
Provides: %{name}-plugin-python = %{version}-%{release}
Obsoletes: %{name}-plugin-python <= %{version}-%{release}
%description plugin-python2
This package lets you write Python 2 plugins for %{name}.
%package plugin-python3
Summary: Python 3 plugin for %{name}
License: BSD
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: %{name}-plugin-python-common = %{version}-%{release}
%description plugin-python3
This package lets you write Python 3 plugins for %{name}.
%package plugin-ruby %package plugin-ruby
@ -231,17 +280,52 @@ plugins for %{name}.
%setup -q %setup -q
%autopatch -p1 %autopatch -p1
# Because the patches touch Makefile.am etc.
autoreconf -i
%build %build
# Force immediate binding for hardened build for plugins. # Force immediate binding for hardened build for plugins.
# https://bugzilla.redhat.com/show_bug.cgi?id=977446#c13 # https://bugzilla.redhat.com/show_bug.cgi?id=977446#c13
export LDFLAGS="$LDFLAGS -Wl,-z,now" export LDFLAGS="$LDFLAGS -Wl,-z,now"
# Build for Python 3 in a separate subdirectory. Upstream does not
# support srcdir!=builddir so copy the whole source.
copy="$(mktemp -d)"
cp -a . "$copy"
mv "$copy" python3
%configure --disable-static %configure --disable-static
make %{?_smp_mflags} make %{?_smp_mflags}
pushd python3
PYTHON=/usr/bin/python3 \
%configure --disable-static --disable-perl --disable-ocaml --disable-ruby
make %{?_smp_mflags}
popd
%install %install
# Install for Python 2 and Python 3 separately.
# We do the Python 3 install first since that build is
# incomplete.
pushd python3
%make_install %make_install
popd
pushd $RPM_BUILD_ROOT%{_libdir}/nbdkit/plugins/
mv nbdkit-python-plugin.so nbdkit-python3-plugin.so
popd
%make_install
pushd $RPM_BUILD_ROOT%{_libdir}/nbdkit/plugins/
mv nbdkit-python-plugin.so nbdkit-python2-plugin.so
# For backwards compatibility, "the" python plugin is Python 2.
# Probably we will change this in future if Fedora switches
# exclusively to Python 3.
ln -s nbdkit-python2-plugin.so nbdkit-python-plugin.so
popd
# Delete libtool crap. # Delete libtool crap.
find $RPM_BUILD_ROOT -name '*.la' -delete find $RPM_BUILD_ROOT -name '*.la' -delete
@ -261,10 +345,19 @@ export LIBGUESTFS_TRACE=1
%ifnarch %{arm} %{ix86} ppc %{power64} %ifnarch %{arm} %{ix86} ppc %{power64}
# Broken on F25 because of https://bugzilla.redhat.com/show_bug.cgi?id=1344016 # Broken on F25 because of https://bugzilla.redhat.com/show_bug.cgi?id=1344016
%if 0%{?fedora} < 25 %if 0%{?fedora} < 25
make check || { make check || {
cat tests/test-suite.log cat tests/test-suite.log
exit 1 exit 1
} }
pushd python3
make check || {
cat tests/test-suite.log
exit 1
}
popd
%endif %endif
%endif %endif
@ -339,12 +432,20 @@ make check || {
%{_mandir}/man3/nbdkit-perl-plugin.3* %{_mandir}/man3/nbdkit-perl-plugin.3*
%files plugin-python %files plugin-python-common
%doc LICENSE README %doc LICENSE README
%{_libdir}/%{name}/plugins/nbdkit-python-plugin.so
%{_mandir}/man3/nbdkit-python-plugin.3* %{_mandir}/man3/nbdkit-python-plugin.3*
%files plugin-python2
%{_libdir}/%{name}/plugins/nbdkit-python-plugin.so
%{_libdir}/%{name}/plugins/nbdkit-python2-plugin.so
%files plugin-python3
%{_libdir}/%{name}/plugins/nbdkit-python3-plugin.so
%files plugin-ruby %files plugin-ruby
%doc LICENSE README %doc LICENSE README
%{_libdir}/%{name}/plugins/nbdkit-ruby-plugin.so %{_libdir}/%{name}/plugins/nbdkit-ruby-plugin.so
@ -375,6 +476,9 @@ make check || {
%changelog %changelog
* Mon Oct 03 2016 Richard W.M. Jones <rjones@redhat.com> - 1.1.12-2
- Compile Python 2 and Python 3 versions of the plugin.
* Wed Jun 08 2016 Richard W.M. Jones <rjones@redhat.com> - 1.1.12-1 * Wed Jun 08 2016 Richard W.M. Jones <rjones@redhat.com> - 1.1.12-1
- New upstream version 1.1.12 - New upstream version 1.1.12
- Enable Ruby plugin. - Enable Ruby plugin.