[Libguestfs] [PATCH nbdkit 13/13] tests: Port some tests to Windows.

Richard W.M. Jones rjones at redhat.com
Thu Aug 20 11:37:46 UTC 2020


The vast majority of tests fail currently because Unix domain sockets
have not been implemented.  There is some hope we could make them
work, see:
https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/
---
 server/Makefile.am             | 10 +++++++-
 tests/Makefile.am              | 47 +++++++++++++++++++++++++++-------
 server/test-public.c           | 11 ++++++++
 common/utils/test-quotes.c     | 14 ++++++++++
 tests/test-ansi-c.sh           |  2 +-
 tests/test-binary.sh           |  3 ++-
 tests/test-cxx.sh              |  3 ++-
 tests/test-flush.sh            |  2 +-
 tests/test-layers.sh           |  2 +-
 tests/test-shutdown.sh         |  2 +-
 tests/test-stdio.sh            |  2 +-
 tests/functions.sh.in          |  4 ++-
 tests/test-exit-with-parent.c  |  5 +++-
 tests/test-layers.c            | 29 ++++++++++++++++++---
 tests/test-socket-activation.c |  9 +++++++
 tests/test-stdio-plugin.c      |  2 ++
 tests/test.c                   | 26 +++++++++++++++++--
 .gitignore                     |  1 +
 18 files changed, 149 insertions(+), 25 deletions(-)

diff --git a/server/Makefile.am b/server/Makefile.am
index 11b3042e..984e8133 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -174,7 +174,15 @@ test_public_CPPFLAGS = \
 	-I$(top_srcdir)/common/replacements \
 	-I$(top_srcdir)/common/utils \
 	$(NULL)
-test_public_CFLAGS = $(WARNINGS_CFLAGS) $(VALGRIND_CFLAGS)
+test_public_CFLAGS = \
+	$(PTHREAD_CFLAGS) \
+	$(WARNINGS_CFLAGS) \
+	$(VALGRIND_CFLAGS) \
+	$(NULL)
+test_public_LDFLAGS = \
+	$(PTHREAD_LIBS)	\
+	$(NULL)
 test_public_LDADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(top_builddir)/common/replacements/libcompat.la \
 	$(NULL)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 516b5a40..bac867e7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -60,14 +60,9 @@ noinst_LTLIBRARIES =
 EXTRA_DIST = README.tests
 EXTRA_PROGRAMS =
 
-# Ensure we're testing the local copy by running everything through
-# the nbdkit helper script in the top build directory.
-#
 # Use the 'direct' backend, and ensure maximum libguestfs debugging.
-#
 # Enable libnbd debugging.
 TESTS_ENVIRONMENT = \
-	PATH=$(abs_top_builddir):$(PATH) \
 	SRCDIR=$(srcdir) \
 	LIBGUESTFS_ATTACH_METHOD=appliance \
 	LIBGUESTFS_DEBUG=1 \
@@ -75,10 +70,30 @@ TESTS_ENVIRONMENT = \
 	LIBNBD_DEBUG=1 \
 	$(NULL)
 
+if !IS_WINDOWS
+# Ensure we're testing the local copy by running everything through
+# the nbdkit helper script in the top build directory.
+TESTS_ENVIRONMENT += PATH=$(abs_top_builddir):$(PATH)
+else
+# Since most tests refer to "nbdkit" but on Windows the wrapper is
+# called "nbdkit.exe", we must make a "wrapper wrapper" called
+# "nbdkit" in some other directory, and the tests/ directory is
+# convenient.  For some reason a symlink doesn't work here.
+noinst_SCRIPTS = nbdkit
+nbdkit: Makefile
+	rm -f $@
+	echo 'exec $(abs_top_builddir)/nbdkit.exe "$$@"' > $@
+	chmod 0555 $@
+CLEANFILES += nbdkit
+TESTS_ENVIRONMENT += PATH=$(abs_builddir):$(PATH)
+endif
+
 # Common disk image shared with several tests.  These are built
 # conditionally, so tests should check the files they need exist and
 # skip if not present.
+if !IS_WINDOWS
 if HAVE_MKE2FS_WITH_D
+
 check_DATA += disk disk.tar
 CLEANFILES += disk disk.tar
 
@@ -119,7 +134,8 @@ disk.tar.xz: disk.tar
 	xz --best --block-size=32768 --keep $<
 endif HAVE_LIBLZMA
 
-endif
+endif HAVE_MKE2FS_WITH_D
+endif !IS_WINDOWS
 
 #----------------------------------------------------------------------
 # Use 'make check' to run the ordinary tests as non-root.  The
@@ -190,7 +206,6 @@ TESTS += \
 	test-tls-psk.sh \
 	test-ip.sh \
 	test-vsock.sh \
-	test-socket-activation \
 	test-foreground.sh \
 	test-debug-flags.sh \
 	test-long-name.sh \
@@ -229,16 +244,21 @@ EXTRA_DIST += \
 	test-single-sh.sh \
 	test-single.sh \
 	test-start.sh \
-	test-stdio.sh \
 	test-swap.sh \
 	test-tls-psk.sh \
 	test-tls.sh \
 	test-version-example1.sh \
 	test-version-filter.sh \
 	test-version-plugin.sh \
+	$(NULL)
+if !IS_WINDOWS
+TESTS += \
 	test-vsock.sh \
 	$(NULL)
+endif
 
+if !IS_WINDOWS
+TESTS += test-socket-activation
 check_PROGRAMS += \
 	test-socket-activation \
 	$(NULL)
@@ -249,7 +269,10 @@ test_socket_activation_CPPFLAGS = \
 	-I$(top_srcdir)/common/protocol \
 	$(NULL)
 test_socket_activation_CFLAGS = $(WARNINGS_CFLAGS)
+endif
 
+if !IS_WINDOWS
+TESTS += test-stdio.sh
 # check_LTLIBRARIES won't build a shared library (see automake manual).
 # So we have to do this and add a dependency.
 noinst_LTLIBRARIES += \
@@ -261,7 +284,10 @@ test_stdio_plugin_la_SOURCES = \
 	test-stdio-plugin.c \
 	$(top_srcdir)/include/nbdkit-plugin.h \
 	$(NULL)
-test_stdio_plugin_la_CPPFLAGS = -I$(top_srcdir)/include
+test_stdio_plugin_la_CPPFLAGS = \
+	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/common/replacements \
+	$(NULL)
 test_stdio_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
 # For use of the -rpath option, see:
 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
@@ -269,8 +295,11 @@ test_stdio_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \
 	$(NULL)
 test_stdio_plugin_la_LIBADD = \
+	$(top_builddir)/common/replacements/libcompat.la \
+	$(top_builddir)/common/utils/libutils.la \
 	$(IMPORT_LIBRARY_ON_WINDOWS) \
 	$(NULL)
+endif
 
 # check_LTLIBRARIES won't build a shared library (see automake manual).
 # So we have to do this and add a dependency.
diff --git a/server/test-public.c b/server/test-public.c
index 8ea2ee00..f14e7841 100644
--- a/server/test-public.c
+++ b/server/test-public.c
@@ -41,6 +41,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <pthread.h>
+
 #include "internal.h"
 
 static bool error_flagged;
@@ -53,11 +55,20 @@ nbdkit_error (const char *fs, ...)
   error_flagged = true;
 }
 
+void
+nbdkit_debug (const char *fs, ...)
+{
+}
+
 bool listen_stdin;
 bool configured;
 
 volatile int quit;
+#ifndef WIN32
 int quit_fd = -1;
+#else
+extern HANDLE quit_fd;
+#endif
 
 struct connection *
 threadlocal_get_conn (void)
diff --git a/common/utils/test-quotes.c b/common/utils/test-quotes.c
index dbd17d2e..bb825788 100644
--- a/common/utils/test-quotes.c
+++ b/common/utils/test-quotes.c
@@ -43,6 +43,8 @@
 
 #include "utils.h"
 
+#ifdef HAVE_OPEN_MEMSTREAM
+
 static bool
 test (const char *orig, const char *fnname, void (*fn) (const char *, FILE *),
       const char *exp)
@@ -97,3 +99,15 @@ main (void)
   }
   return fail ? EXIT_FAILURE : EXIT_SUCCESS;
 }
+
+#else /* !OPEN_MEMSTREAM */
+
+int
+main (int argc, char *argv[])
+{
+  fprintf (stderr, "%s: test skipped because no support for open_memstream\n",
+           argv[0]);
+  exit (77);
+}
+
+#endif /* !OPEN_MEMSTREAM */
diff --git a/tests/test-ansi-c.sh b/tests/test-ansi-c.sh
index e04c23f9..bd5e11ff 100755
--- a/tests/test-ansi-c.sh
+++ b/tests/test-ansi-c.sh
@@ -35,4 +35,4 @@ set -e
 
 # We only really care that the plugin compiled, so we don't
 # need to run it properly.
-nbdkit .libs/test-ansi-c-plugin.so --version
+nbdkit .libs/test-ansi-c-plugin.$SOEXT --version
diff --git a/tests/test-binary.sh b/tests/test-binary.sh
index b3c54d8a..fa82bd57 100755
--- a/tests/test-binary.sh
+++ b/tests/test-binary.sh
@@ -42,7 +42,8 @@ set -e
 requires cut --version
 
 binary1="$( nbdkit --dump-config           | grep ^binary= | cut -d= -f2 )"
-binary2="$( ../server/nbdkit --dump-config | grep ^binary= | cut -d= -f2 )"
+binary2="$( ../server/nbdkit$EXEEXT --dump-config |
+                                             grep ^binary= | cut -d= -f2 )"
 
 echo binary1=$binary1
 echo binary2=$binary2
diff --git a/tests/test-cxx.sh b/tests/test-cxx.sh
index 45a06567..81b5477d 100755
--- a/tests/test-cxx.sh
+++ b/tests/test-cxx.sh
@@ -36,4 +36,5 @@ set -e
 # We only really care that the plugin compiled, so we don't
 # need to run it properly.
 libs=./.libs
-nbdkit --filter=$libs/test-cxx-filter.so $libs/test-cxx-plugin.so --version
+nbdkit --filter=$libs/test-cxx-filter.$SOEXT \
+       $libs/test-cxx-plugin.$SOEXT --version
diff --git a/tests/test-flush.sh b/tests/test-flush.sh
index 9b353dff..67e54570 100755
--- a/tests/test-flush.sh
+++ b/tests/test-flush.sh
@@ -35,7 +35,7 @@ set -x
 
 requires nbdsh --version
 
-plugin=.libs/test-flush-plugin.so
+plugin=.libs/test-flush-plugin.$SOEXT
 requires test -f $plugin
 
 files="test-flush.err"
diff --git a/tests/test-layers.sh b/tests/test-layers.sh
index 83d1a9e9..0e3f010a 100755
--- a/tests/test-layers.sh
+++ b/tests/test-layers.sh
@@ -38,7 +38,7 @@ files="test-layers.out"
 rm -f $files
 cleanup_fn rm -f $files
 
-cmd="nbdkit --filter=.libs/test-layers-filter3.so --filter=.libs/test-layers-filter2.so --filter=.libs/test-layers-filter1.so .libs/test-layers-plugin.so"
+cmd="nbdkit --filter=.libs/test-layers-filter3.$SOEXT --filter=.libs/test-layers-filter2.$SOEXT --filter=.libs/test-layers-filter1.$SOEXT .libs/test-layers-plugin.$SOEXT"
 
 $cmd --help > test-layers.out
 cat test-layers.out ||:
diff --git a/tests/test-shutdown.sh b/tests/test-shutdown.sh
index 651fe3c5..231a3876 100755
--- a/tests/test-shutdown.sh
+++ b/tests/test-shutdown.sh
@@ -36,7 +36,7 @@ set -x
 requires qemu-img --version
 requires qemu-io --version
 
-plugin=.libs/test-shutdown-plugin.so
+plugin=.libs/test-shutdown-plugin.$SOEXT
 requires test -f $plugin
 
 sock=`mktemp -u`
diff --git a/tests/test-stdio.sh b/tests/test-stdio.sh
index b8d31367..2cafb6c5 100755
--- a/tests/test-stdio.sh
+++ b/tests/test-stdio.sh
@@ -35,7 +35,7 @@ set -xe
 
 requires nbdsh -c 'exit (not h.supports_uri ())'
 
-plugin=.libs/test-stdio-plugin.so
+plugin=.libs/test-stdio-plugin.$SOEXT
 requires test -f $plugin
 
 sock1=`mktemp -u`
diff --git a/tests/functions.sh.in b/tests/functions.sh.in
index 6dc9b6eb..035bcddd 100644
--- a/tests/functions.sh.in
+++ b/tests/functions.sh.in
@@ -36,6 +36,8 @@
 CXX="@CXX@"
 OCAMLOPT="@OCAMLOPT@"
 PYTHON="@PYTHON@"
+SOEXT="@SOEXT@"
+EXEEXT="@EXEEXT@"
 
 # cleanup_fn f [args]
 #
@@ -188,7 +190,7 @@ foreach_plugin ()
     for p in @plugins@; do
         # Was the plugin built?
         d="@top_builddir@/plugins/$p"
-        if [ -f "$d/.libs/nbdkit-$p-plugin.so" ] ||
+        if [ -f "$d/.libs/nbdkit-$p-plugin.$SOEXT" ] ||
            [ -f "$d/nbdkit-$p-plugin" ]; then
             # Yes so run the test.
             "$f" "$p" "$@"
diff --git a/tests/test-exit-with-parent.c b/tests/test-exit-with-parent.c
index 27fe4028..e7e8254d 100644
--- a/tests/test-exit-with-parent.c
+++ b/tests/test-exit-with-parent.c
@@ -38,9 +38,12 @@
 #include <inttypes.h>
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>
 #include <sys/types.h>
+
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
-#include <errno.h>
+#endif
 
 #include "exit-with-parent.h"
 #include "test.h"
diff --git a/tests/test-layers.c b/tests/test-layers.c
index dd826f36..459d05ec 100644
--- a/tests/test-layers.c
+++ b/tests/test-layers.c
@@ -53,8 +53,14 @@
 #include <unistd.h>
 #include <errno.h>
 #include <sys/types.h>
+
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 
 #include <pthread.h>
 
@@ -71,6 +77,8 @@
 #define program_name "nbdkit"
 #endif
 
+#ifndef WIN32
+
 static void *start_log_capture (void *);
 static void log_verify_seen (const char *msg);
 static void log_verify_seen_in_order (const char *msg, ...)
@@ -135,10 +143,10 @@ main (int argc, char *argv[])
              * isn't reliably called unless we disable parallel.
              */
             "-t", "1",
-            "--filter", ".libs/test-layers-filter3.so",
-            "--filter", ".libs/test-layers-filter2.so",
-            "--filter", ".libs/test-layers-filter1.so",
-            ".libs/test-layers-plugin.so",
+            "--filter", ".libs/test-layers-filter3." SOEXT,
+            "--filter", ".libs/test-layers-filter2." SOEXT,
+            "--filter", ".libs/test-layers-filter1." SOEXT,
+            ".libs/test-layers-plugin." SOEXT,
             "foo=bar",
             NULL);
     perror ("exec: nbdkit");
@@ -787,3 +795,16 @@ log_free (void)
   log_buf = NULL;
   log_len = 0;
 }
+
+#else /* WIN32 */
+
+/* A lot of porting work required for Windows.  For now, skip the test. */
+int
+main (int argc, char *argv[])
+{
+  fprintf (stderr, "%s: test skipped because not ported to Windows.\n",
+           argv[0]);
+  exit (77);
+}
+
+#endif /* WIN32 */
diff --git a/tests/test-socket-activation.c b/tests/test-socket-activation.c
index d2db8e3e..9f847039 100644
--- a/tests/test-socket-activation.c
+++ b/tests/test-socket-activation.c
@@ -54,9 +54,18 @@
 #include <signal.h>
 #include <errno.h>
 #include <sys/types.h>
+
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#endif
+
+#ifdef HAVE_SYS_UN_H
 #include <sys/un.h>
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 
 #include "byte-swapping.h"
 #include "nbd-protocol.h"
diff --git a/tests/test-stdio-plugin.c b/tests/test-stdio-plugin.c
index 0a071e17..09382a09 100644
--- a/tests/test-stdio-plugin.c
+++ b/tests/test-stdio-plugin.c
@@ -46,6 +46,8 @@
 #define NBDKIT_API_VERSION 2
 #include <nbdkit-plugin.h>
 
+#include "getline.h"
+
 static const char *msg = "input";
 
 /* Check whether stdin/out match /dev/null */
diff --git a/tests/test.c b/tests/test.c
index 8eb1a525..3a48daa7 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -37,15 +37,22 @@
 #include <stdarg.h>
 #include <string.h>
 #include <unistd.h>
-#include <sys/types.h>
-#include <sys/wait.h>
 #include <signal.h>
 #include <errno.h>
+
 #undef NDEBUG /* Keep test strong even for nbdkit built without assertions */
 #include <assert.h>
 
+#include <sys/types.h>
+
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
+
 #include "test.h"
 
+#ifndef WIN32
+
 /* 'test_start_nbdkit' below makes assumptions about the format of
  * these strings.
  */
@@ -218,3 +225,18 @@ test_start_nbdkit (const char *arg, ...)
 
   return 0;
 }
+
+#else /* WIN32 */
+
+/* All of the above code will require a lot of porting work for
+ * Windows.  At the moment the test gets skipped.
+ */
+int
+test_start_nbdkit (const char *arg, ...)
+{
+  fprintf (stderr, "%s: test skipped because not ported to Windows.\n",
+           program_name);
+  exit (77);
+}
+
+#endif
diff --git a/.gitignore b/.gitignore
index 6919a4d7..3cab4ff3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -106,6 +106,7 @@ plugins/*/*.3
 /tests/file-data
 /tests/functions.sh
 /tests/keys.psk
+/tests/nbdkit
 /tests/partition-disk
 /tests/pki
 /tests/split1
-- 
2.27.0




More information about the Libguestfs mailing list