[ndctl] Enable ndctl tests for emulated pmem devices
diff mbox series

Message ID 20190607052558.15037-1-santosh@fossix.org
State New
Headers show
Series
  • [ndctl] Enable ndctl tests for emulated pmem devices
Related show

Commit Message

Santosh Sivaraj June 7, 2019, 5:25 a.m. UTC
For QEMU emulated devices, nfit drivers need not be loaded, also the
nfit_test, libnvdimm_test modules are not required. This patch adds a
configure option to enable testing on qemu without nfit dependencies.

Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
---
 configure.ac         | 30 ++++++++++++++++++++++++++++++
 test/common          | 14 +++++++++++---
 test/core.c          |  7 ++++++-
 test/create.sh       |  6 +++++-
 test/daxdev-errors.c |  1 -
 test/dpa-alloc.c     |  2 --
 test/libndctl.c      |  2 --
 7 files changed, 52 insertions(+), 10 deletions(-)

Comments

Dan Williams June 21, 2019, 12:59 a.m. UTC | #1
On Thu, Jun 6, 2019 at 10:26 PM Santosh Sivaraj <santosh@fossix.org> wrote:
>
> For QEMU emulated devices, nfit drivers need not be loaded, also the
> nfit_test, libnvdimm_test modules are not required. This patch adds a
> configure option to enable testing on qemu without nfit dependencies.

This looks useful, I only quibble with it being a compile time option.
I'd prefer an environment variable to allow this to be overridden at
test run time, perhaps "WITH_NFIT". You can have a compile time option
to set the WITH_NFIT default, but otherwise it would be useful to be
able to disable NFIT requiring tests even on x86.

Patch
diff mbox series

diff --git a/configure.ac b/configure.ac
index 6dca96e..115f59e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -148,6 +148,36 @@  fi
 AC_SUBST([BASH_COMPLETION_DIR])
 AM_CONDITIONAL([ENABLE_BASH_COMPLETION], [test "x$with_bash" = "xyes"])
 
+AC_CANONICAL_HOST
+AS_CASE([$host_cpu],
+  [x86_64|arm*],
+  [
+	AC_DEFINE([ACPI], [1], ["Build for ACPI NFIT"])
+  ]
+)
+
+# Build on a qemu
+AC_ARG_ENABLE(qemu-test,
+  [ --enable-qemu-test   Enable compilation for testing on qemu],
+  [case "${enableval}" in
+     yes | no ) QEMU_PMEM_TEST="${enableval}" ;;
+     *) AC_MSG_ERROR(bad value ${enableval} for --enable-qemu-test) ;;
+   esac],
+  [QEMU_PMEM_TEST="yes"]
+)
+
+AM_CONDITIONAL([QEMU_PMEM_TEST], [test "x$QEMU_PMEM_TEST" = "xyes"])
+
+if test "x$QEMU_PMEM_TEST" = "xyes"; then
+    AC_DEFINE([QEMU_PMEM_TEST], [1], ["build for qemu pmem testing"])
+    AC_DEFINE_UNQUOTED([NFIT_PROVIDER0], [["$BUS_PROVIDER0"]], ["pmem device"])
+    AC_DEFINE_UNQUOTED([NFIT_PROVIDER1], [["$BUS_PROVIDER1"]], ["pmem device"])
+    AC_MSG_NOTICE([building for pmem testing on qemu])
+else
+    AC_DEFINE_UNQUOTED([NFIT_PROVIDER0], [["nfit_test.0"]], ["nfit device"])
+    AC_DEFINE_UNQUOTED([NFIT_PROVIDER1], [["nfit_test.1"]], ["nfit device"])
+fi
+
 AC_ARG_ENABLE([local],
         AS_HELP_STRING([--disable-local], [build against kernel ndctl.h @<:@default=system@:>@]),
         [], [enable_local=yes])
diff --git a/test/common b/test/common
index 1b9d3da..5a75e22 100644
--- a/test/common
+++ b/test/common
@@ -17,8 +17,14 @@  fi
 
 # NFIT_TEST_BUS[01]
 #
-NFIT_TEST_BUS0=nfit_test.0
-NFIT_TEST_BUS1=nfit_test.1
+if [ -z $BUS_PROVIDER0]; then
+    NFIT_TEST_BUS0=nfit_test.0
+    NFIT_TEST_BUS1=nfit_test.1
+else
+    NFIT_TEST_BUS0=$BUS_PROVIDER0
+    NFIT_TEST_BUS1=$BUS_PROVIDER1
+    QEMU_PMEM_TEST=yes
+fi
 
 
 # Functions
@@ -71,7 +77,9 @@  _cleanup()
 {
 	$NDCTL disable-region -b $NFIT_TEST_BUS0 all
 	$NDCTL disable-region -b $NFIT_TEST_BUS1 all
-	modprobe -r nfit_test
+	if [ "x$QEMU_PMEM_TEST" = "x" ]; then
+		modprobe -r nfit_test
+	fi
 }
 
 # json2var
diff --git a/test/core.c b/test/core.c
index b9e3bbf..4f5123f 100644
--- a/test/core.c
+++ b/test/core.c
@@ -126,7 +126,9 @@  int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
 	struct ndctl_bus *bus;
 	struct log_ctx log_ctx;
 	const char *list[] = {
+#ifdef ACPI
 		"nfit",
+#endif
 		"device_dax",
 		"dax_pmem",
 		"dax_pmem_core",
@@ -134,7 +136,9 @@  int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
 		"libnvdimm",
 		"nd_blk",
 		"nd_btt",
+#ifdef ACPI
 		"nd_e820",
+#endif
 		"nd_pmem",
 	};
 
@@ -228,10 +232,11 @@  retry:
 		/* caller wants a full nfit_test reset */
 		ndctl_bus_foreach(nd_ctx, bus) {
 			struct ndctl_region *region;
-
+#ifdef ACPI
 			if (strncmp(ndctl_bus_get_provider(bus),
 						"nfit_test", 9) != 0)
 				continue;
+#endif
 			ndctl_region_foreach(bus, region)
 				ndctl_region_disable_invalidate(region);
 		}
diff --git a/test/create.sh b/test/create.sh
index 8d78797..7fdf696 100755
--- a/test/create.sh
+++ b/test/create.sh
@@ -23,7 +23,11 @@  check_min_kver "4.5" || do_skip "may lack namespace mode attribute"
 trap 'err $LINENO' ERR
 
 # setup (reset nfit_test dimms)
-modprobe nfit_test
+if [ -z $QEMU_PMEM_TEST ]; then
+    # setup (reset nfit_test dimms)
+    modprobe nfit_test
+fi
+
 $NDCTL disable-region -b $NFIT_TEST_BUS0 all
 $NDCTL zero-labels -b $NFIT_TEST_BUS0 all
 $NDCTL enable-region -b $NFIT_TEST_BUS0 all
diff --git a/test/daxdev-errors.c b/test/daxdev-errors.c
index 29de16b..c17e42a 100644
--- a/test/daxdev-errors.c
+++ b/test/daxdev-errors.c
@@ -45,7 +45,6 @@  struct check_cmd {
 static sigjmp_buf sj_env;
 static int sig_count;
 
-static const char *NFIT_PROVIDER0 = "nfit_test.0";
 static struct check_cmd *check_cmds;
 
 static void sigbus_hdl(int sig, siginfo_t *siginfo, void *ptr)
diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
index 9a9c6b6..2f100b1 100644
--- a/test/dpa-alloc.c
+++ b/test/dpa-alloc.c
@@ -30,8 +30,6 @@ 
 #include <ndctl/libndctl.h>
 #include <ccan/array_size/array_size.h>
 
-static const char *NFIT_PROVIDER0 = "nfit_test.0";
-static const char *NFIT_PROVIDER1 = "nfit_test.1";
 #define NUM_NAMESPACES 4
 
 struct test_dpa_namespace {
diff --git a/test/libndctl.c b/test/libndctl.c
index 02bb9cc..6c123f8 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -94,8 +94,6 @@ 
  *    dimm.
  */
 
-static const char *NFIT_PROVIDER0 = "nfit_test.0";
-static const char *NFIT_PROVIDER1 = "nfit_test.1";
 #define SZ_4K   0x00001000
 #define SZ_128K 0x00020000
 #define SZ_7M   0x00700000