All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shivaprasad G Bhat <sbhat@linux.ibm.com>
To: nvdimm@lists.linux.dev, dan.j.williams@intel.com,
	vishal.l.verma@intel.com
Cc: aneesh.kumar@linux.ibm.com, sbhat@linux.ibm.com, vaibhav@linux.ibm.com
Subject: [RFC ndctl PATCH 5/9] test: Assign provider name based on the test family
Date: Mon, 18 Apr 2022 12:10:55 -0500	[thread overview]
Message-ID: <165030184936.3224737.4501499015485134399.stgit@lep8c.aus.stglabs.ibm.com> (raw)
In-Reply-To: <165030175745.3224737.6985015146263991065.stgit@lep8c.aus.stglabs.ibm.com>

The provider name is used by test scripts in a hard-coded fashion
like nfit_test.X today.

With the kernel modules names being different per nvdimm family
and the provider name too would change because of that.

The patch reassigns the correct provider name based on the test family.

The default family and the provider is set to INTEL to keep the
original behaviour intact.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
---
 test.h                        |    6 ++++++
 test/ack-shutdown-count-set.c |   11 +++--------
 test/core.c                   |   23 +++++++++++++++++++----
 test/daxdev-errors.sh         |    2 +-
 test/dsm-fail.c               |   27 ++++++++++++++++++---------
 test/libndctl.c               |    8 ++++----
 test/pmem_namespaces.c        |    4 +++-
 7 files changed, 54 insertions(+), 27 deletions(-)

diff --git a/test.h b/test.h
index cb61e0d9..7c7f620c 100644
--- a/test.h
+++ b/test.h
@@ -6,6 +6,12 @@
 
 struct ndctl_test;
 struct ndctl_ctx;
+
+extern char TEST_PROVIDER0[15];
+extern char TEST_PROVIDER1[15];
+extern int ndctl_test_family;
+void init_env(void);
+
 struct ndctl_test *ndctl_test_new(unsigned int kver, const char *testname);
 int ndctl_test_result(struct ndctl_test *test, int rc);
 int ndctl_test_get_skipped(struct ndctl_test *test);
diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
index 5d38ad9d..d35ee717 100644
--- a/test/ack-shutdown-count-set.c
+++ b/test/ack-shutdown-count-set.c
@@ -56,7 +56,7 @@ static void reset_bus(struct ndctl_bus *bus)
 
 static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 {
-	struct ndctl_bus *bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
+	struct ndctl_bus *bus = ndctl_bus_get_by_provider(ctx, TEST_PROVIDER0);
 	struct ndctl_dimm *dimm;
 	struct ndctl_region *region;
 	struct log_ctx log_ctx;
@@ -117,17 +117,12 @@ static int test_ack_shutdown_count_set(int loglevel, struct ndctl_test *test,
 
 int main(int argc, char *argv[])
 {
-	char *test_env = getenv("NDCTL_TEST_FAMILY");
 	struct ndctl_test *test = ndctl_test_new(0, argv[0]);
 	struct ndctl_ctx *ctx;
 	int rc;
 
-	if (!test) {
-		fprintf(stderr, "failed to initialize test\n");
-		return EXIT_FAILURE;
-	}
-
-	if (test_env && strcmp(test_env, "PAPR") == 0)
+	init_env();
+	if (ndctl_test_family == NVDIMM_FAMILY_PAPR)
 		return ndctl_test_result(test, 77);
 
 	rc = ndctl_new(&ctx);
diff --git a/test/core.c b/test/core.c
index 130e4aed..f5cf6c82 100644
--- a/test/core.c
+++ b/test/core.c
@@ -24,6 +24,21 @@ struct ndctl_test {
 	int skip;
 };
 
+char TEST_PROVIDER0[15] = "nfit_test.0";
+char TEST_PROVIDER1[15] = "nfit_test.1";
+int ndctl_test_family = NVDIMM_FAMILY_INTEL;
+
+void init_env(void)
+{
+	char *test_env = getenv("NDCTL_TEST_FAMILY");
+
+	if (test_env && strcmp(test_env, "PAPR") == 0) {
+		ndctl_test_family = NVDIMM_FAMILY_PAPR;
+		strcpy(TEST_PROVIDER0, "ndtest.0");
+		strcpy(TEST_PROVIDER1, "ndtest.1");
+	}
+}
+
 static unsigned int get_system_kver(void)
 {
 	const char *kver = getenv("KVER");
@@ -177,9 +192,9 @@ void ndctl_test_module_remove(struct kmod_ctx **ctx, struct kmod_module **mod,
 		struct ndctl_region *region;
 
 		if ((strcmp(ndctl_bus_get_provider(bus),
-			   "nfit_test.0") != 0) &&
+			   TEST_PROVIDER0) != 0) &&
 			strcmp(ndctl_bus_get_provider(bus),
-				"nfit_test.1") != 0)
+				TEST_PROVIDER1) != 0)
 			continue;
 
 		ndctl_region_foreach(bus, region)
@@ -360,7 +375,7 @@ retry:
 			struct ndctl_region *region;
 
 			if (strcmp(ndctl_bus_get_provider(bus),
-				   "nfit_test.0") != 0)
+				   TEST_PROVIDER0) != 0)
 				continue;
 			ndctl_region_foreach(bus, region)
 				ndctl_region_disable_invalidate(region);
@@ -386,7 +401,7 @@ retry:
 		struct ndctl_region *region;
 		struct ndctl_dimm *dimm;
 
-		if (strcmp(ndctl_bus_get_provider(bus), "nfit_test.0") != 0)
+		if (strcmp(ndctl_bus_get_provider(bus), TEST_PROVIDER0) != 0)
 			continue;
 
 		ndctl_region_foreach (bus, region)
diff --git a/test/daxdev-errors.sh b/test/daxdev-errors.sh
index f32f8b80..d80a536c 100755
--- a/test/daxdev-errors.sh
+++ b/test/daxdev-errors.sh
@@ -66,7 +66,7 @@ test -x $TEST_PATH/daxdev-errors
 $TEST_PATH/daxdev-errors $busdev $region
 
 # check badblocks, should be empty
-if read sector len < /sys/bus/platform/devices/nfit_test.0/$busdev/$region/badblocks; then
+if read sector len < /sys/bus/platform/devices/$NFIT_TEST_BUS0/$busdev/$region/badblocks; then
 	echo "badblocks empty, expected"
 fi
 [ -n "$sector" ] && echo "fail: $LINENO" && exit 1
diff --git a/test/dsm-fail.c b/test/dsm-fail.c
index e7a35ca6..382d8da3 100644
--- a/test/dsm-fail.c
+++ b/test/dsm-fail.c
@@ -18,8 +18,6 @@
 #include <ndctl/ndctl.h>
 #include <test.h>
 
-#define DIMM_PATH "/sys/devices/platform/nfit_test.0/nfit_test_dimm/test_dimm0"
-
 static int reset_bus(struct ndctl_bus *bus)
 {
 	struct ndctl_region *region;
@@ -176,10 +174,11 @@ static int test_regions_enable(struct ndctl_bus *bus,
 
 static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 {
-	struct ndctl_bus *bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
+	struct ndctl_bus *bus = ndctl_bus_get_by_provider(ctx, TEST_PROVIDER0);
 	struct ndctl_region *region, *victim_region = NULL;
 	struct ndctl_dimm *dimm, *victim = NULL;
 	char path[1024], buf[SYSFS_ATTR_SIZE];
+	char *dimm_path;
 	struct log_ctx log_ctx;
 	unsigned int handle;
 	int rc, err = 0;
@@ -197,7 +196,14 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 		return -ENXIO;
 	}
 
-	sprintf(path, "%s/handle", DIMM_PATH);
+	if (asprintf(&dimm_path,
+			"/sys/devices/platform/%s/nfit_test_dimm/test_dimm0",
+			TEST_PROVIDER0) < 0) {
+		fprintf(stderr, "Path allocation failed\n");
+		return -ENOMEM;
+	}
+
+	sprintf(path, "%s/handle", dimm_path);
 	rc = __sysfs_read_attr(&log_ctx, path, buf);
 	if (rc) {
 		fprintf(stderr, "failed to retrieve test dimm handle\n");
@@ -280,7 +286,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 		goto out;
 
 
-	rc = set_dimm_response(DIMM_PATH, ND_CMD_GET_CONFIG_SIZE, -EACCES,
+	rc = set_dimm_response(dimm_path, ND_CMD_GET_CONFIG_SIZE, -EACCES,
 			&log_ctx);
 	if (rc)
 		goto out;
@@ -290,7 +296,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 	rc = test_regions_enable(bus, victim, victim_region, true, 2);
 	if (rc)
 		goto out;
-	rc = set_dimm_response(DIMM_PATH, ND_CMD_GET_CONFIG_SIZE, 0, &log_ctx);
+	rc = set_dimm_response(dimm_path, ND_CMD_GET_CONFIG_SIZE, 0, &log_ctx);
 	if (rc)
 		goto out;
 
@@ -300,7 +306,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 	if (rc)
 		goto out;
 
-	rc = set_dimm_response(DIMM_PATH, ND_CMD_GET_CONFIG_DATA, -EACCES,
+	rc = set_dimm_response(dimm_path, ND_CMD_GET_CONFIG_DATA, -EACCES,
 			&log_ctx);
 	if (rc)
 		goto out;
@@ -311,7 +317,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 	rc = test_regions_enable(bus, victim, victim_region, false, 0);
 	if (rc)
 		goto out;
-	rc = set_dimm_response(DIMM_PATH, ND_CMD_GET_CONFIG_DATA, 0, &log_ctx);
+	rc = set_dimm_response(dimm_path, ND_CMD_GET_CONFIG_DATA, 0, &log_ctx);
 	if (rc)
 		goto out;
 	rc = dimms_disable(bus);
@@ -320,7 +326,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 
  out:
 	err = rc;
-	sprintf(path, "%s/fail_cmd", DIMM_PATH);
+	sprintf(path, "%s/fail_cmd", dimm_path);
 	sprintf(buf, "0\n");
 	rc = __sysfs_write_attr(&log_ctx, path, buf);
 	if (rc)
@@ -333,6 +339,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
 		rc = -ENXIO;
 	}
 	reset_bus(bus);
+	free(dimm_path);
 
 	if (rc)
 		err = rc;
@@ -368,6 +375,8 @@ int __attribute__((weak)) main(int argc, char *argv[])
 	struct ndctl_ctx *ctx;
 	int rc;
 
+	init_env();
+
 	if (!test) {
 		fprintf(stderr, "failed to initialize test\n");
 		return EXIT_FAILURE;
diff --git a/test/libndctl.c b/test/libndctl.c
index de95c83e..ab9f73c9 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -73,8 +73,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
@@ -2496,7 +2494,7 @@ static void reset_bus(struct ndctl_bus *bus, enum dimm_reset reset)
 
 static int do_test0(struct ndctl_ctx *ctx, struct ndctl_test *test)
 {
-	struct ndctl_bus *bus = ndctl_bus_get_by_provider(ctx, NFIT_PROVIDER0);
+	struct ndctl_bus *bus = ndctl_bus_get_by_provider(ctx, TEST_PROVIDER0);
 	struct ndctl_region *region;
 	int rc;
 
@@ -2550,7 +2548,7 @@ static int do_test0(struct ndctl_ctx *ctx, struct ndctl_test *test)
 
 static int do_test1(struct ndctl_ctx *ctx, struct ndctl_test *test)
 {
-	struct ndctl_bus *bus = ndctl_bus_get_by_provider(ctx, NFIT_PROVIDER1);
+	struct ndctl_bus *bus = ndctl_bus_get_by_provider(ctx, TEST_PROVIDER1);
 	int rc;
 
 	if (!bus)
@@ -2622,6 +2620,8 @@ int __attribute__((weak)) main(int argc, char *argv[])
 	struct ndctl_ctx *ctx;
 	int rc;
 
+	init_env();
+
 	if (!test) {
 		fprintf(stderr, "failed to initialize test\n");
 		return EXIT_FAILURE;
diff --git a/test/pmem_namespaces.c b/test/pmem_namespaces.c
index f3a00c79..973c9ce3 100644
--- a/test/pmem_namespaces.c
+++ b/test/pmem_namespaces.c
@@ -193,7 +193,7 @@ int test_pmem_namespaces(int log_level, struct ndctl_test *test,
 		fprintf(stderr, "ACPI.NFIT unavailable falling back to nfit_test\n");
 		rc = ndctl_test_init(&kmod_ctx, &mod, NULL, log_level, test);
 		ndctl_invalidate(ctx);
-		bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
+		bus = ndctl_bus_get_by_provider(ctx, TEST_PROVIDER0);
 		if (rc < 0 || !bus) {
 			rc = 77;
 			ndctl_test_skip(test);
@@ -255,6 +255,8 @@ int __attribute__((weak)) main(int argc, char *argv[])
 	struct ndctl_ctx *ctx;
 	int rc;
 
+	init_env();
+
 	comm = argv[0];
 	if (!test) {
 		fprintf(stderr, "failed to initialize test\n");



  parent reply	other threads:[~2022-04-18 17:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-18 17:09 [RFC ndctl PATCH 0/9] test: Enable PAPR test family by default Shivaprasad G Bhat
2022-04-18 17:10 ` [RFC ndctl PATCH 1/9] test/common: Ensure to unload test modules Shivaprasad G Bhat
2022-04-18 17:10 ` [RFC ndctl PATCH 2/9] test: core: Fix module unload failures Shivaprasad G Bhat
2022-04-18 17:10 ` [RFC ndctl PATCH 3/9] test: Unload the nfit module during cleanup Shivaprasad G Bhat
2022-04-18 17:10 ` [RFC ndctl PATCH 4/9] test: Introduce skip file to skip irrelevant tests Shivaprasad G Bhat
2022-04-18 17:10 ` Shivaprasad G Bhat [this message]
2022-04-18 17:11 ` [RFC ndctl PATCH 6/9] test: Enable PAPR test family tests after INTEL family tests Shivaprasad G Bhat
2022-04-18 17:15 ` [ndctl v3 PATCH 7/9] test/libndctl: Enable libndctl tests on ndtest Shivaprasad G Bhat
2022-04-18 17:17 ` [ndctl v3 PATCH 8/9] test/inject-smart: Enable inject-smart " Shivaprasad G Bhat
2022-04-18 17:19 ` [ndctl v3 PATCH 9/9] test/monitor.sh: Partially skip monitor test " Shivaprasad G Bhat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=165030184936.3224737.4501499015485134399.stgit@lep8c.aus.stglabs.ibm.com \
    --to=sbhat@linux.ibm.com \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=dan.j.williams@intel.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=vaibhav@linux.ibm.com \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.