From 80b83f39a8b365455880d8dabbcb86249c1ecd6b Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 25 Jul 2018 14:09:58 +0100
Subject: [PATCH] vddk: Add a very simple test.
We cannot do anything like a real test without the proprietary
library. However by making a dummy library which contains some stub
functions we can test --dump-plugin output.
(cherry picked from commit 70f7227ecc9b7c8d628987cb12ca7541bf485d66)
---
tests/Makefile.am | 21 ++++++++++++++++++
tests/dummy-vddk.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/test-vddk.sh | 45 +++++++++++++++++++++++++++++++++++++++
3 files changed, 128 insertions(+)
create mode 100644 tests/dummy-vddk.c
create mode 100755 tests/test-vddk.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c0c2155..2973268 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -75,6 +75,7 @@ EXTRA_DIST = \
test-random-sock.sh \
test-tls.sh \
test-tls-psk.sh \
+ test-vddk.sh \
test-version.sh \
test-version-filter.sh \
test-version-plugin.sh \
@@ -365,6 +366,26 @@ test_streaming_SOURCES = test-streaming.c test.h
test_streaming_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
test_streaming_LDADD = libtest.la $(LIBGUESTFS_LIBS)
+# VDDK plugin test.
+# This only tests that the plugin can be loaded against a
+# dummy VDDK library, it is not a detailed test.
+
+# check_LTLIBRARIES won't build a shared library (see automake manual).
+# So we have to do this and add a dependency.
+noinst_LTLIBRARIES += libvixDiskLib.la
+TESTS += test-vddk.sh
+
+libvixDiskLib_la_SOURCES = \
+ dummy-vddk.c
+libvixDiskLib_la_CPPFLAGS = \
+ -I$(top_srcdir)/plugins/vddk
+libvixDiskLib_la_CXXFLAGS = \
+ $(WARNINGS_CFLAGS)
+# For use of the -rpath option, see:
+# https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
+libvixDiskLib_la_LDFLAGS = \
+ -shared -version-number 6:0:0 -rpath /nowhere
+
# xz plugin test.
if HAVE_LIBLZMA
if HAVE_GUESTFISH
diff --git a/tests/dummy-vddk.c b/tests/dummy-vddk.c
new file mode 100644
index 0000000..e9069c9
--- /dev/null
+++ b/tests/dummy-vddk.c
@@ -0,0 +1,62 @@
+/* nbdkit
+ * Copyright (C) 2018 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.
+ */
+
+/* This file pretends to be libvixDiskLib.so.6.
+ *
+ * In fact because we don't check the result from dlsym and because we
+ * only call a few APIs in the --dump-plugin path there are only a few
+ * stub functions needed.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "vddk-structs.h"
+
+VixError
+VixDiskLib_InitEx (uint32_t major, uint32_t minor,
+ VixDiskLibGenericLogFunc *log_function,
+ VixDiskLibGenericLogFunc *warn_function,
+ VixDiskLibGenericLogFunc *panic_function,
+ const char *lib_dir, const char *config_file)
+{
+ /* Do nothing, only exit with no error. */
+ return VIX_OK;
+}
+
+void
+VixDiskLib_Exit (void)
+{
+ /* Do nothing. */
+}
diff --git a/tests/test-vddk.sh b/tests/test-vddk.sh
new file mode 100755
index 0000000..5ccfff1
--- /dev/null
+++ b/tests/test-vddk.sh
@@ -0,0 +1,45 @@
+#!/bin/bash -
+# nbdkit
+# Copyright (C) 2018 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 -x
+set -e
+
+rm -f test-vddk.out
+
+LD_LIBRARY_PATH=.libs:$LD_LIBRARY_PATH \
+nbdkit vddk --dump-plugin > test-vddk.out
+cat test-vddk.out
+
+grep ^vddk_default_libdir= test-vddk.out
+
+rm test-vddk.out
--
1.8.3.1