anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

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

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