Blame SOURCES/0019-test-Don-t-skip-tests-if-nfit-modules-are-missing.patch

26ccd9
From 1649ad9c3e2c6e9c47870c8d3b54f10b24177bc7 Mon Sep 17 00:00:00 2001
26ccd9
From: Santosh Sivaraj <santosh@fossix.org>
26ccd9
Date: Thu, 13 May 2021 11:42:16 +0530
26ccd9
Subject: [PATCH 019/217] test: Don't skip tests if nfit modules are missing
26ccd9
26ccd9
For NFIT to be available ACPI is a must, so don't fail when nfit modules
26ccd9
are missing on a platform that doesn't support ACPI.
26ccd9
26ccd9
Link: https://lore.kernel.org/r/20210513061218.760322-2-santosh@fossix.org
26ccd9
Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
26ccd9
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
---
26ccd9
 test.h                        |  2 +-
26ccd9
 test/ack-shutdown-count-set.c |  2 +-
26ccd9
 test/blk_namespaces.c         |  2 +-
26ccd9
 test/core.c                   | 28 ++++++++++++++++++++++++++--
26ccd9
 test/dpa-alloc.c              |  2 +-
26ccd9
 test/dsm-fail.c               |  2 +-
26ccd9
 test/libndctl.c               |  2 +-
26ccd9
 test/multi-pmem.c             |  2 +-
26ccd9
 test/parent-uuid.c            |  2 +-
26ccd9
 test/pmem_namespaces.c        |  2 +-
26ccd9
 10 files changed, 35 insertions(+), 11 deletions(-)
26ccd9
26ccd9
diff --git a/test.h b/test.h
26ccd9
index cba8d41..7de13fe 100644
26ccd9
--- a/test.h
26ccd9
+++ b/test.h
26ccd9
@@ -20,7 +20,7 @@ void builtin_xaction_namespace_reset(void);
26ccd9
 
26ccd9
 struct kmod_ctx;
26ccd9
 struct kmod_module;
26ccd9
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
26ccd9
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
26ccd9
 		struct ndctl_ctx *nd_ctx, int log_level,
26ccd9
 		struct ndctl_test *test);
26ccd9
 
26ccd9
diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
26ccd9
index fb1d82b..c561ff3 100644
26ccd9
--- a/test/ack-shutdown-count-set.c
26ccd9
+++ b/test/ack-shutdown-count-set.c
26ccd9
@@ -99,7 +99,7 @@ static int test_ack_shutdown_count_set(int loglevel, struct ndctl_test *test,
26ccd9
 	int result = EXIT_FAILURE, err;
26ccd9
 
26ccd9
 	ndctl_set_log_priority(ctx, loglevel);
26ccd9
-	err = nfit_test_init(&kmod_ctx, &mod, NULL, loglevel, test);
26ccd9
+	err = ndctl_test_init(&kmod_ctx, &mod, NULL, loglevel, test);
26ccd9
 	if (err < 0) {
26ccd9
 		result = 77;
26ccd9
 		ndctl_test_skip(test);
26ccd9
diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
26ccd9
index d7f00cb..f076e85 100644
26ccd9
--- a/test/blk_namespaces.c
26ccd9
+++ b/test/blk_namespaces.c
26ccd9
@@ -228,7 +228,7 @@ int test_blk_namespaces(int log_level, struct ndctl_test *test,
26ccd9
 
26ccd9
 	if (!bus) {
26ccd9
 		fprintf(stderr, "ACPI.NFIT unavailable falling back to nfit_test\n");
26ccd9
-		rc = nfit_test_init(&kmod_ctx, &mod, NULL, log_level, test);
26ccd9
+		rc = ndctl_test_init(&kmod_ctx, &mod, NULL, log_level, test);
26ccd9
 		ndctl_invalidate(ctx);
26ccd9
 		bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
26ccd9
 		if (rc < 0 || !bus) {
26ccd9
diff --git a/test/core.c b/test/core.c
26ccd9
index cc7d8d9..2b03aa9 100644
26ccd9
--- a/test/core.c
26ccd9
+++ b/test/core.c
26ccd9
@@ -11,6 +11,7 @@
26ccd9
 #include <util/log.h>
26ccd9
 #include <util/sysfs.h>
26ccd9
 #include <ndctl/libndctl.h>
26ccd9
+#include <ndctl/ndctl.h>
26ccd9
 #include <ccan/array_size/array_size.h>
26ccd9
 
26ccd9
 #define KVER_STRLEN 20
26ccd9
@@ -106,11 +107,11 @@ int ndctl_test_get_skipped(struct ndctl_test *test)
26ccd9
 	return test->skip;
26ccd9
 }
26ccd9
 
26ccd9
-int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
26ccd9
+int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
26ccd9
 		struct ndctl_ctx *nd_ctx, int log_level,
26ccd9
 		struct ndctl_test *test)
26ccd9
 {
26ccd9
-	int rc;
26ccd9
+	int rc, family = -1;
26ccd9
 	unsigned int i;
26ccd9
 	const char *name;
26ccd9
 	struct ndctl_bus *bus;
26ccd9
@@ -127,10 +128,28 @@ int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
26ccd9
 		"nd_e820",
26ccd9
 		"nd_pmem",
26ccd9
 	};
26ccd9
+	char *test_env;
26ccd9
 
26ccd9
 	log_init(&log_ctx, "test/init", "NDCTL_TEST");
26ccd9
 	log_ctx.log_priority = log_level;
26ccd9
 
26ccd9
+	/*
26ccd9
+	 * The following two checks determine the platform family. For
26ccd9
+	 * Intel/platforms which support ACPI, check sysfs; for other platforms
26ccd9
+	 * determine from the environment variable NVDIMM_TEST_FAMILY
26ccd9
+	 */
26ccd9
+	if (access("/sys/bus/acpi", F_OK) == 0)
26ccd9
+		family = NVDIMM_FAMILY_INTEL;
26ccd9
+
26ccd9
+	test_env = getenv("NDCTL_TEST_FAMILY");
26ccd9
+	if (test_env && strcmp(test_env, "PAPR") == 0)
26ccd9
+		family = NVDIMM_FAMILY_PAPR;
26ccd9
+
26ccd9
+	if (family == -1) {
26ccd9
+		log_err(&log_ctx, "Cannot determine NVDIMM family\n");
26ccd9
+		return -ENOTSUP;
26ccd9
+	}
26ccd9
+
26ccd9
 	*ctx = kmod_new(NULL, NULL);
26ccd9
 	if (!*ctx)
26ccd9
 		return -ENXIO;
26ccd9
@@ -185,6 +204,11 @@ retry:
26ccd9
 
26ccd9
 		path = kmod_module_get_path(*mod);
26ccd9
 		if (!path) {
26ccd9
+			if (family != NVDIMM_FAMILY_INTEL &&
26ccd9
+			    (strcmp(name, "nfit") == 0 ||
26ccd9
+			     strcmp(name, "nd_e820") == 0))
26ccd9
+				continue;
26ccd9
+
26ccd9
 			log_err(&log_ctx, "%s.ko: failed to get path\n", name);
26ccd9
 			break;
26ccd9
 		}
26ccd9
diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
26ccd9
index e922009..0b3bb7a 100644
26ccd9
--- a/test/dpa-alloc.c
26ccd9
+++ b/test/dpa-alloc.c
26ccd9
@@ -289,7 +289,7 @@ int test_dpa_alloc(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx)
26ccd9
 		return 77;
26ccd9
 
26ccd9
 	ndctl_set_log_priority(ctx, loglevel);
26ccd9
-	err = nfit_test_init(&kmod_ctx, &mod, NULL, loglevel, test);
26ccd9
+	err = ndctl_test_init(&kmod_ctx, &mod, NULL, loglevel, test);
26ccd9
 	if (err < 0) {
26ccd9
 		ndctl_test_skip(test);
26ccd9
 		fprintf(stderr, "nfit_test unavailable skipping tests\n");
26ccd9
diff --git a/test/dsm-fail.c b/test/dsm-fail.c
26ccd9
index 9dfd8b0..0a6383d 100644
26ccd9
--- a/test/dsm-fail.c
26ccd9
+++ b/test/dsm-fail.c
26ccd9
@@ -346,7 +346,7 @@ int test_dsm_fail(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx)
26ccd9
 	int result = EXIT_FAILURE, err;
26ccd9
 
26ccd9
 	ndctl_set_log_priority(ctx, loglevel);
26ccd9
-	err = nfit_test_init(&kmod_ctx, &mod, NULL, loglevel, test);
26ccd9
+	err = ndctl_test_init(&kmod_ctx, &mod, NULL, loglevel, test);
26ccd9
 	if (err < 0) {
26ccd9
 		result = 77;
26ccd9
 		ndctl_test_skip(test);
26ccd9
diff --git a/test/libndctl.c b/test/libndctl.c
26ccd9
index c42f785..d9b50f4 100644
26ccd9
--- a/test/libndctl.c
26ccd9
+++ b/test/libndctl.c
26ccd9
@@ -2708,7 +2708,7 @@ int test_libndctl(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx)
26ccd9
 	daxctl_set_log_priority(daxctl_ctx, loglevel);
26ccd9
 	ndctl_set_private_data(ctx, test);
26ccd9
 
26ccd9
-	err = nfit_test_init(&kmod_ctx, &mod, ctx, loglevel, test);
26ccd9
+	err = ndctl_test_init(&kmod_ctx, &mod, ctx, loglevel, test);
26ccd9
 	if (err < 0) {
26ccd9
 		ndctl_test_skip(test);
26ccd9
 		fprintf(stderr, "nfit_test unavailable skipping tests\n");
26ccd9
diff --git a/test/multi-pmem.c b/test/multi-pmem.c
26ccd9
index 3d10952..3ea08cc 100644
26ccd9
--- a/test/multi-pmem.c
26ccd9
+++ b/test/multi-pmem.c
26ccd9
@@ -249,7 +249,7 @@ int test_multi_pmem(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx
26ccd9
 
26ccd9
 	ndctl_set_log_priority(ctx, loglevel);
26ccd9
 
26ccd9
-	err = nfit_test_init(&kmod_ctx, &mod, NULL, loglevel, test);
26ccd9
+	err = ndctl_test_init(&kmod_ctx, &mod, NULL, loglevel, test);
26ccd9
 	if (err < 0) {
26ccd9
 		result = 77;
26ccd9
 		ndctl_test_skip(test);
26ccd9
diff --git a/test/parent-uuid.c b/test/parent-uuid.c
26ccd9
index 6424e9f..bded33a 100644
26ccd9
--- a/test/parent-uuid.c
26ccd9
+++ b/test/parent-uuid.c
26ccd9
@@ -218,7 +218,7 @@ int test_parent_uuid(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ct
26ccd9
 		return 77;
26ccd9
 
26ccd9
 	ndctl_set_log_priority(ctx, loglevel);
26ccd9
-	err = nfit_test_init(&kmod_ctx, &mod, NULL, loglevel, test);
26ccd9
+	err = ndctl_test_init(&kmod_ctx, &mod, NULL, loglevel, test);
26ccd9
 	if (err < 0) {
26ccd9
 		ndctl_test_skip(test);
26ccd9
 		fprintf(stderr, "nfit_test unavailable skipping tests\n");
26ccd9
diff --git a/test/pmem_namespaces.c b/test/pmem_namespaces.c
26ccd9
index f0f2edd..a4db1ae 100644
26ccd9
--- a/test/pmem_namespaces.c
26ccd9
+++ b/test/pmem_namespaces.c
26ccd9
@@ -191,7 +191,7 @@ int test_pmem_namespaces(int log_level, struct ndctl_test *test,
26ccd9
 
26ccd9
 	if (!bus) {
26ccd9
 		fprintf(stderr, "ACPI.NFIT unavailable falling back to nfit_test\n");
26ccd9
-		rc = nfit_test_init(&kmod_ctx, &mod, NULL, log_level, test);
26ccd9
+		rc = ndctl_test_init(&kmod_ctx, &mod, NULL, log_level, test);
26ccd9
 		ndctl_invalidate(ctx);
26ccd9
 		bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
26ccd9
 		if (rc < 0 || !bus) {
26ccd9
-- 
26ccd9
2.27.0
26ccd9