[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 2/2] nbd: Add testsuite coverage
From: |
Eric Blake |
Subject: |
[PATCH v3 2/2] nbd: Add testsuite coverage |
Date: |
Mon, 2 Mar 2020 12:15:32 -0600 |
* HACKING (Using NBD connections in tests): New section.
(Writing tests that depend on a certain capability): New capability.
* testsuite/Makefile.am (check-DEJAGNU): Expose NBD witnesses.
* configure.ac (AC_CHECK_PROGS): Check for nbdkit.
* testsuite/lib/poke-dg.exp (dg-require): Add 'nbd' capability.
(dg-tmpdir): New command to create safe short temp dir.
(dg-nbd): New command to spawn nbdkit server.
(poke_finish): Clean up nbdkit.
* testsuite/poke.cmd/nbd-1.pk: New test of '.nbd'.
* testsuite/poke.pkl/open-3.pk: New test of open("nbd...").
* testsuite/poke.pkl/ios-nbd-1.pk: New test of nbd I/O.
---
ChangeLog | 15 ++++++++
HACKING | 32 +++++++++++++++--
configure.ac | 5 +--
testsuite/Makefile.am | 1 +
testsuite/lib/poke-dg.exp | 63 ++++++++++++++++++++++++++++++++-
testsuite/poke.cmd/nbd-1.pk | 7 ++++
testsuite/poke.pkl/ios-nbd-1.pk | 9 +++++
testsuite/poke.pkl/open-3.pk | 7 ++++
8 files changed, 133 insertions(+), 6 deletions(-)
create mode 100644 testsuite/poke.cmd/nbd-1.pk
create mode 100644 testsuite/poke.pkl/ios-nbd-1.pk
create mode 100644 testsuite/poke.pkl/open-3.pk
diff --git a/ChangeLog b/ChangeLog
index 9dbbd997..c53faff4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2020-03-02 Eric Blake <address@hidden>
+
+ nbd: Add testsuite coverage
+ * HACKING (Using NBD connections in tests): New section.
+ (Writing tests that depend on a certain capability): New capability.
+ * testsuite/Makefile.am (check-DEJAGNU): Expose NBD witnesses.
+ * configure.ac (AC_CHECK_PROGS): Check for nbdkit.
+ * testsuite/lib/poke-dg.exp (dg-require): Add 'nbd' capability.
+ (dg-tmpdir): New command to create safe short temp dir.
+ (dg-nbd): New command to spawn nbdkit server.
+ (poke_finish): Clean up nbdkit.
+ * testsuite/poke.cmd/nbd-1.pk: New test of '.nbd'.
+ * testsuite/poke.pkl/open-3.pk: New test of open("nbd...").
+ * testsuite/poke.pkl/ios-nbd-1.pk: New test of nbd I/O.
+
2020-03-02 Eric Blake <address@hidden>
Add optional nbd:// io space support
diff --git a/HACKING b/HACKING
index 2a62a8ec..a0500409 100644
--- a/HACKING
+++ b/HACKING
@@ -61,7 +61,8 @@ along with GNU poke. If not, see
<https://www.gnu.org/licenses/>.
5.4 Put each test in its own file
5.5 dg-output may require a newline
5.6 Using data files in tests
- 5.7 Writing tests that depend on a certain capability
+ 5.7 Using NBD connections in tests
+ 5.8 Writing tests that depend on a certain capability
6 Fuzzing poke
6.1 Grammarinator
7 Deciding on What to Work on
@@ -271,8 +272,10 @@ libnbd
~~~~~~
GNU poke optionally uses libnbd to expose an io space for data served
-by an arbitrary NBD (Network Block Device) server. The package names are:
- - On Red Hat distributions: libnbd-devel
+by an arbitrary NBD (Network Block Device) server. Testing this
+further requires nbdkit to quickly provide an arbitrary NBD server.
+The package names are:
+ - On Red Hat distributions: libnbd-devel, nbdkit-basic-plugins
See http://libguestfs.org/libnbd.3.html for more information.
@@ -474,6 +477,27 @@ which is the name of the temporary file to create::
The file created by the last dg-data (be it anonymous or named) is the
current IO space.
+Using NBD connections in tests
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If your test requires an NBD server (only useful when poke is compiled
+with libnbd), the dg-nbd directive is what you need. It has one form::
+
+ /* { dg-nbd { 0x1 0x2 ...} [dg-tmpdir]/sock } */
+
+This utilizes nbdkit to serve an in-memory disk with initial contents
+over a named Unix socket. Note that the data argument is not written
+in Poke, but rather the syntax accepted by nbdkit-data-plugin's data=
+argument. nbdkit then creates a Unix socket server for the data, and
+will be shut down gracefully when the testsuite completes. Use of the
+utility directive [dg-tmpdir] ensures that the socket name will not be
+too long while still respecting $TMPDIR (defaulting to a new
+subdirectory of /tmp), since $objdir may be arbitrarily deep.
+
+To use the server as an IO space, your test will then follow up with::
+
+ /* { dg-command "open (\"nbd+unix:///?socket=[dg-tmpdir]/sock\")" } */
+
Writing tests that depend on a certain capability
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -496,6 +520,8 @@ The supported capabilities are:
libtextstyle
poke is built with libtextstyle support.
+nbd
+ poke is built with NBD io space support, and dg-nbd works.
Fuzzing poke
------------
diff --git a/configure.ac b/configure.ac
index b210805b..38135cf5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,13 +82,14 @@ dnl Jitter
AC_JITTER_SUBPACKAGE([jitter])
-dnl libnbd for nbd:// io spaces (optional)
+dnl libnbd for nbd:// io spaces (optional). Testing it also requires nbdkit
PKG_CHECK_MODULES([LIBNBD], [libnbd], [
AC_SUBST([LIBNBD_CFLAGS])
AC_SUBST([LIBNBD_LIBS])
AC_DEFINE([HAVE_LIBNBD], [1], [libnbd found at compile time])
libnbd_enabled=yes
-], [libnbd_enabled=no])
+ AC_CHECK_PROGS([NBDKIT], [nbdkit], [no])
+], [libnbd_enabled=no NBDKIT=no])
AM_CONDITIONAL([NBD], [test "x$libnbd_enabled" = "xyes"])
dnl Used in Makefile.am. See the note there.
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 7508c776..2e191938 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -26,6 +26,7 @@ check-DEJAGNU: site.exp
if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
CC_FOR_TARGET="$(CC_FOR_TARGET)" CFLAGS_FOR_TARGET="$(CFLAGS)" \
HAVE_LIBTEXTSTYLE="$(HAVE_LIBTEXTSTYLE)" \
+ NBDKIT="$(NBDKIT)" \
POKESTYLESDIR="$(top_srcdir)/etc" \
POKEPICKLESDIR="$(top_srcdir)/pickles" \
POKEDATADIR="$(top_srcdir)/src" \
diff --git a/testsuite/lib/poke-dg.exp b/testsuite/lib/poke-dg.exp
index 28a49281..0478c10c 100644
--- a/testsuite/lib/poke-dg.exp
+++ b/testsuite/lib/poke-dg.exp
@@ -25,6 +25,7 @@ load_lib dg.exp
set poke_commands {}
set poke_data_files {}
+set poke_nbd_pids {}
# Append the specified command to `poke_commands'. The commands added
# this way will be executed in order by the poke invocation.
@@ -62,6 +63,11 @@ proc dg-require { args } {
# Mark the test as unsupported
set do-what [list [lindex do-what 0] N P]
}
+ if {[lindex $args 1] == "nbd" \
+ && $::env(NBDKIT) == "no"} {
+ # Mark the test as unsupported
+ set do-what [list [lindex do-what 0] N P]
+ }
}
# Create a temporary data file containing the data specified as an
@@ -119,6 +125,56 @@ proc dg-data { args } {
}
}
+# Return the name of a temporary directory honoring $TMPDIR. The
+# directory and all content therein will be cleaned up at the end of
+# the testsuite.
+#
+# dg-tmpdir
+
+proc dg-tmpdir { args } {
+ global poke_data_files
+
+ set tmpdir /tmp
+ catch {set tmpdir $::env(TMPDIR)}
+ set subdir [file join $tmpdir poketest.[pid]]
+
+ if {! [file exists $subdir]} {
+ file mkdir $subdir
+ lappend poke_data_files $subdir
+ }
+ return $subdir
+}
+
+# Create a temporary NBD server with the given initial contents over
+# the given Unix socket (dg-tmpdir is useful for creating a
+# reasonable-length socket name). The server will be cleaned up at
+# the end of the testsuite.
+#
+# The data argument is passed to nbdkit's data plugin (which parses
+# slightly differently than the Poke language).
+#
+# The test can then use open ("nbd+unix:///?socket=[dg-tmpdir]/sock"),
+# if nbd support was compiled in (the test is automatically skipped
+# otherwise).
+#
+# dg-nbd data socketname
+
+proc dg-nbd { args } {
+ global poke_commands
+ global poke_nbd_pids
+
+ if { [llength $args] != 3 } {
+ error "[lindex $args 0]: invalid arguments"
+ }
+ dg-require nbd
+
+ set data [lindex $args 1]
+ set sock [lindex $args 2]
+
+ set fh [open |[list nbdkit -f -U $sock data data=$data]]
+ lappend poke_nbd_pids [pid $fh]
+}
+
# We set LC_ALL and LANG to C so that we get the same error messages
# as expected.
setenv LC_ALL C
@@ -133,7 +189,7 @@ proc poke-dg-test { prog do_what extra_tool_flags } {
set VALGRIND ""
# Uncomment the following couple of lines to run the testsuite with
- # valgring.
+ # valgrind.
# set VALGRIND "valgrind --quiet
--suppressions=${srcdir}/../etc/boehm-gc.suppressions \
# --tool=memcheck --gen-suppressions=all"
@@ -174,6 +230,11 @@ proc poke-dg-test { prog do_what extra_tool_flags } {
# This function is invoked by dg-finish.
proc poke_finish {} {
global poke_data_files
+ global poke_nbd_pids
+
+ foreach p $poke_nbd_pids {
+ exec kill $p
+ }
foreach f $poke_data_files {
file delete -force $f
diff --git a/testsuite/poke.cmd/nbd-1.pk b/testsuite/poke.cmd/nbd-1.pk
new file mode 100644
index 00000000..0d158cb6
--- /dev/null
+++ b/testsuite/poke.cmd/nbd-1.pk
@@ -0,0 +1,7 @@
+/* { dg-do run } */
+/* { dg-nbd {0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80} [dg-tmpdir]/nbd-1 } */
+
+/* { dg-command ".nbd nbd+unix:///?socket=[dg-tmpdir]/nbd-1" } */
+/* { dg-command {.set obase 16} } */
+/* { dg-command { byte[8] @ 0#B } } */
+/* { dg-output {[0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80]} } */
diff --git a/testsuite/poke.pkl/ios-nbd-1.pk b/testsuite/poke.pkl/ios-nbd-1.pk
new file mode 100644
index 00000000..4c49a771
--- /dev/null
+++ b/testsuite/poke.pkl/ios-nbd-1.pk
@@ -0,0 +1,9 @@
+/* { dg-do run } */
+/* { dg-nbd {0 0 0 0x10} [dg-tmpdir]/ios-nbd-1 } */
+
+/* { dg-command { .set obase 10 } } */
+/* { dg-command "defvar foo = open
(\"nbd+unix:///?socket=[dg-tmpdir]/ios-nbd-1\")" } */
+/* { dg-command { byte @ 2#B = 66 } } */
+/* { dg-command { int32 @ 0#B } } */
+/* { dg-output "16912" } */
+/* { dg-command { close (foo) } } */
diff --git a/testsuite/poke.pkl/open-3.pk b/testsuite/poke.pkl/open-3.pk
new file mode 100644
index 00000000..d647bbda
--- /dev/null
+++ b/testsuite/poke.pkl/open-3.pk
@@ -0,0 +1,7 @@
+/* { dg-do run } */
+/* { dg-nbd {0x10} [dg-tmpdir]/open-3 } */
+
+/* { dg-command { .set obase 10 } } */
+/* { dg-command "defvar foo = open
(\"nbd+unix:///?socket=[dg-tmpdir]/open-3\")" } */
+/* { dg-command { get_ios == foo } } */
+/* { dg-output "1" } */
--
2.25.1