Blame SOURCES/0008-vddk-Add-a-very-simple-test.patch

b61625
From 80b83f39a8b365455880d8dabbcb86249c1ecd6b Mon Sep 17 00:00:00 2001
b61625
From: "Richard W.M. Jones" <rjones@redhat.com>
b61625
Date: Wed, 25 Jul 2018 14:09:58 +0100
b61625
Subject: [PATCH] vddk: Add a very simple test.
b61625
b61625
We cannot do anything like a real test without the proprietary
b61625
library.  However by making a dummy library which contains some stub
b61625
functions we can test --dump-plugin output.
b61625
b61625
(cherry picked from commit 70f7227ecc9b7c8d628987cb12ca7541bf485d66)
b61625
---
b61625
 tests/Makefile.am  | 21 ++++++++++++++++++
b61625
 tests/dummy-vddk.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
b61625
 tests/test-vddk.sh | 45 +++++++++++++++++++++++++++++++++++++++
b61625
 3 files changed, 128 insertions(+)
b61625
 create mode 100644 tests/dummy-vddk.c
b61625
 create mode 100755 tests/test-vddk.sh
b61625
b61625
diff --git a/tests/Makefile.am b/tests/Makefile.am
b61625
index c0c2155..2973268 100644
b61625
--- a/tests/Makefile.am
b61625
+++ b/tests/Makefile.am
b61625
@@ -75,6 +75,7 @@ EXTRA_DIST = \
b61625
 	test-random-sock.sh \
b61625
 	test-tls.sh \
b61625
 	test-tls-psk.sh \
b61625
+	test-vddk.sh \
b61625
 	test-version.sh \
b61625
 	test-version-filter.sh \
b61625
 	test-version-plugin.sh \
b61625
@@ -365,6 +366,26 @@ test_streaming_SOURCES = test-streaming.c test.h
b61625
 test_streaming_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
b61625
 test_streaming_LDADD = libtest.la $(LIBGUESTFS_LIBS)
b61625
 
b61625
+# VDDK plugin test.
b61625
+# This only tests that the plugin can be loaded against a
b61625
+# dummy VDDK library, it is not a detailed test.
b61625
+
b61625
+# check_LTLIBRARIES won't build a shared library (see automake manual).
b61625
+# So we have to do this and add a dependency.
b61625
+noinst_LTLIBRARIES += libvixDiskLib.la
b61625
+TESTS += test-vddk.sh
b61625
+
b61625
+libvixDiskLib_la_SOURCES = \
b61625
+	dummy-vddk.c
b61625
+libvixDiskLib_la_CPPFLAGS = \
b61625
+	-I$(top_srcdir)/plugins/vddk
b61625
+libvixDiskLib_la_CXXFLAGS = \
b61625
+        $(WARNINGS_CFLAGS)
b61625
+# For use of the -rpath option, see:
b61625
+# https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
b61625
+libvixDiskLib_la_LDFLAGS = \
b61625
+	-shared -version-number 6:0:0 -rpath /nowhere
b61625
+
b61625
 # xz plugin test.
b61625
 if HAVE_LIBLZMA
b61625
 if HAVE_GUESTFISH
b61625
diff --git a/tests/dummy-vddk.c b/tests/dummy-vddk.c
b61625
new file mode 100644
b61625
index 0000000..e9069c9
b61625
--- /dev/null
b61625
+++ b/tests/dummy-vddk.c
b61625
@@ -0,0 +1,62 @@
b61625
+/* nbdkit
b61625
+ * Copyright (C) 2018 Red Hat Inc.
b61625
+ * All rights reserved.
b61625
+ *
b61625
+ * Redistribution and use in source and binary forms, with or without
b61625
+ * modification, are permitted provided that the following conditions are
b61625
+ * met:
b61625
+ *
b61625
+ * * Redistributions of source code must retain the above copyright
b61625
+ * notice, this list of conditions and the following disclaimer.
b61625
+ *
b61625
+ * * Redistributions in binary form must reproduce the above copyright
b61625
+ * notice, this list of conditions and the following disclaimer in the
b61625
+ * documentation and/or other materials provided with the distribution.
b61625
+ *
b61625
+ * * Neither the name of Red Hat nor the names of its contributors may be
b61625
+ * used to endorse or promote products derived from this software without
b61625
+ * specific prior written permission.
b61625
+ *
b61625
+ * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
b61625
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
b61625
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
b61625
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
b61625
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b61625
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b61625
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b61625
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b61625
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b61625
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b61625
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b61625
+ * SUCH DAMAGE.
b61625
+ */
b61625
+
b61625
+/* This file pretends to be libvixDiskLib.so.6.
b61625
+ *
b61625
+ * In fact because we don't check the result from dlsym and because we
b61625
+ * only call a few APIs in the --dump-plugin path there are only a few
b61625
+ * stub functions needed.
b61625
+ */
b61625
+
b61625
+#include <stdio.h>
b61625
+#include <stdlib.h>
b61625
+#include <stdint.h>
b61625
+
b61625
+#include "vddk-structs.h"
b61625
+
b61625
+VixError
b61625
+VixDiskLib_InitEx (uint32_t major, uint32_t minor,
b61625
+                   VixDiskLibGenericLogFunc *log_function,
b61625
+                   VixDiskLibGenericLogFunc *warn_function,
b61625
+                   VixDiskLibGenericLogFunc *panic_function,
b61625
+                   const char *lib_dir, const char *config_file)
b61625
+{
b61625
+  /* Do nothing, only exit with no error. */
b61625
+  return VIX_OK;
b61625
+}
b61625
+
b61625
+void
b61625
+VixDiskLib_Exit (void)
b61625
+{
b61625
+  /* Do nothing. */
b61625
+}
b61625
diff --git a/tests/test-vddk.sh b/tests/test-vddk.sh
b61625
new file mode 100755
b61625
index 0000000..5ccfff1
b61625
--- /dev/null
b61625
+++ b/tests/test-vddk.sh
b61625
@@ -0,0 +1,45 @@
b61625
+#!/bin/bash -
b61625
+# nbdkit
b61625
+# Copyright (C) 2018 Red Hat Inc.
b61625
+# All rights reserved.
b61625
+#
b61625
+# Redistribution and use in source and binary forms, with or without
b61625
+# modification, are permitted provided that the following conditions are
b61625
+# met:
b61625
+#
b61625
+# * Redistributions of source code must retain the above copyright
b61625
+# notice, this list of conditions and the following disclaimer.
b61625
+#
b61625
+# * Redistributions in binary form must reproduce the above copyright
b61625
+# notice, this list of conditions and the following disclaimer in the
b61625
+# documentation and/or other materials provided with the distribution.
b61625
+#
b61625
+# * Neither the name of Red Hat nor the names of its contributors may be
b61625
+# used to endorse or promote products derived from this software without
b61625
+# specific prior written permission.
b61625
+#
b61625
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
b61625
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
b61625
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
b61625
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
b61625
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b61625
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b61625
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b61625
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b61625
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b61625
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b61625
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b61625
+# SUCH DAMAGE.
b61625
+
b61625
+set -x
b61625
+set -e
b61625
+
b61625
+rm -f test-vddk.out
b61625
+
b61625
+LD_LIBRARY_PATH=.libs:$LD_LIBRARY_PATH \
b61625
+nbdkit vddk --dump-plugin > test-vddk.out
b61625
+cat test-vddk.out
b61625
+
b61625
+grep ^vddk_default_libdir= test-vddk.out
b61625
+
b61625
+rm test-vddk.out
b61625
-- 
b61625
1.8.3.1
b61625