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 <[email protected]>
Signed-off-by: Vaibhav Jain <[email protected]>
---
 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");



Reply via email to