poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/2] nbd: Add testsuite coverage


From: Eric Blake
Subject: [PATCH v2 2/2] nbd: Add testsuite coverage
Date: Thu, 27 Feb 2020 17:02:09 -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 witness.
* configure.ac (AC_CHECK_PROGS): Check for nbdkit.
* testsuite/lib/poke-dg.exp (dg-require): Add 'nbd' capability.
(dg-nbd): New command to spawn nbdkit server.
(poke_finish): Clean up nbdkit.
* testsuite/poke.cmd/nbd.pk: New test of '.nbd'.
* testsuite/poke.pkl/open-3.pk: New test of open("nbd...").
---
 ChangeLog                    | 13 +++++++++
 HACKING                      | 29 +++++++++++++++++---
 configure.ac                 |  5 ++--
 testsuite/Makefile.am        |  1 +
 testsuite/lib/poke-dg.exp    | 53 +++++++++++++++++++++++++++++++++++-
 testsuite/poke.cmd/nbd.pk    |  8 ++++++
 testsuite/poke.pkl/open-3.pk |  8 ++++++
 7 files changed, 110 insertions(+), 7 deletions(-)
 create mode 100644 testsuite/poke.cmd/nbd.pk
 create mode 100644 testsuite/poke.pkl/open-3.pk

diff --git a/ChangeLog b/ChangeLog
index 5caff08e..d4ce216f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2020-02-27  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-nbd): New command to spawn nbdkit server.
+       (poke_finish): Clean up nbdkit.
+       * testsuite/poke.cmd/nbd.pk: New test of '.nbd'.
+       * testsuite/poke.pkl/open-3.pk: New test of open("nbd...").
+
 2020-02-27  Eric Blake  <address@hidden>

        Add optional nbd:// io space support
diff --git a/HACKING b/HACKING
index 2a62a8ec..3d1e2bc0 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,7 +271,9 @@ 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 +476,23 @@ 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 foo.data /tmp/pokenbd.[pid]/sock } */
+
+This serves a previously-created temporary file (use dg-data with the
+named file form) over the named Unix socket.  The server at this
+socket is provided by nbdkit, and will be shut down gracefully when
+the testsuite completes.
+
+To use the server as an IO space, your test will then follow up with::
+
+  /* { dg-command "open (\"nbd+unix:///?socket=/tmp/pokenbd.[pid]/sock\")" } */
+
 Writing tests that depend on a certain capability
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@@ -496,6 +515,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 9e296b49..d79273b2 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..19523d34 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,46 @@ proc dg-data { args } {
     }
 }

+# Create a temporary NBD server for a file previously create with the
+# named form of dg-data, over the given Unix socket.  The server will
+# be cleaned up at the end of the testsuite.
+#
+# It is suggested that socketname be located in a temporary directory
+# created in $TMPDIR, to avoid name length problems.
+#
+# The test can then use open ("nbd+unix:///?socket=socketname"), if
+# nbd support was compiled in.
+#
+# dg-nbd filename socketname
+
+proc dg-nbd { args } {
+    global poke_commands
+    global poke_data_files
+    global poke_nbd_pids
+    global objdir
+
+    if { [llength $args] != 3 } {
+        error "[lindex $args 0]: invalid arguments"
+    }
+    dg-require nbd
+
+    set data [lindex $args 1]
+    set sock [lindex $args 2]
+    set sockdir "[file dirname $sock]"
+
+    if {! [file exists $data]} {
+        error "[lindex $args 0]: file $data not found"
+    }
+
+    file mkdir $sockdir
+    if { [lsearch -exact $poke_data_files $sockdir] == -1} {
+        lappend poke_data_files $sockdir
+    }
+
+    set fh [open "|nbdkit -f -U $sock file $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 +179,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 +220,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.pk b/testsuite/poke.cmd/nbd.pk
new file mode 100644
index 00000000..f7296da9
--- /dev/null
+++ b/testsuite/poke.cmd/nbd.pk
@@ -0,0 +1,8 @@
+/* { dg-do run } */
+/* { dg-data {c*} {0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80} nbddata } */
+/* { dg-nbd nbddata /tmp/pokenbd.[pid]/sock } */
+
+/* { dg-command ".nbd nbd+unix:///?socket=/tmp/pokenbd.[pid]/sock" } */
+/* { 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/open-3.pk b/testsuite/poke.pkl/open-3.pk
new file mode 100644
index 00000000..57b45f2e
--- /dev/null
+++ b/testsuite/poke.pkl/open-3.pk
@@ -0,0 +1,8 @@
+/* { dg-do run } */
+/* { dg-data {c*} {0x10} nbddata } */
+/* { dg-nbd nbddata /tmp/pokenbd.[pid]/open-3 } */
+
+/* { dg-command { .set obase 10 } } */
+/* { dg-command "defvar foo = open 
(\"nbd+unix:///?socket=/tmp/pokenbd.[pid]/open-3\")" } */
+/* { dg-command { get_ios == foo } } */
+/* { dg-output "1" } */
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]