The ndtest driver does not have the payloads defined for various
smart fields like the media|ctrl temperature, threshold parameters
for the current PAPR PDSM.

So, the patch makes the below changes to have a valid inject-smart
test run on the ndtest driver.
test/inject-smart.sh - Test only the shutdown_state and dimm_health
as only those are supported on ndtest. Skip rest of the tests. Reorder
the code for cleanliness
list-list-smart-dimms.c - Separate out filter_dimm implementation for
papr family with the relevant check.

Signed-off-by: Shivaprasad G Bhat <[email protected]>
Signed-off-by: Vaibhav Jain <[email protected]>

---

Depends on the kernel patch -
https://patchwork.kernel.org/project/linux-nvdimm/patch/165027233876.3035289.4353747702027907365.st...@lep8c.aus.stglabs.ibm.com/

Changelog:

Since v2:
Link: 
https://patchwork.kernel.org/project/linux-nvdimm/patch/163102901146.260256.6712219128280188987.stgit@99912bbcb4c7/
* Addedd the init_env() call and use the bus name post environment
  initialization.
* Split the patch to have the libndctl test specific fixes separately
* Updating the skip file to not skip the test, as it works now with this
  patch

Since v1:
Link: 
https://patchwork.kernel.org/project/linux-nvdimm/patch/162737350565.3944327.6662473656483436466.st...@lep8c.aus.stglabs.ibm.com/
* Updated the commit message description

 test/inject-smart.sh   |   14 +++++++++-----
 test/list-smart-dimm.c |   33 ++++++++++++++++++++++++++++++++-
 test/meson.build       |    2 +-
 test/skip_PAPR.js      |    3 +--
 4 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/test/inject-smart.sh b/test/inject-smart.sh
index 80af058a..07d04fb6 100755
--- a/test/inject-smart.sh
+++ b/test/inject-smart.sh
@@ -4,7 +4,6 @@
 
 rc=77
 . $(dirname $0)/common
-bus="$NFIT_TEST_BUS0"
 inj_val="42"
 
 trap 'err $LINENO' ERR
@@ -152,14 +151,18 @@ do_tests()
        $NDCTL inject-smart -b $bus --uninject-all $dimm
 
        # start tests
-       for field in "${fields_val[@]}"; do
-               test_field $field $inj_val
-       done
-
        for field in "${fields_bool[@]}"; do
                test_field $field
        done
 
+       if [ $NDCTL_TEST_FAMILY == "PAPR" ]; then
+               return
+       fi
+
+       for field in "${fields_val[@]}"; do
+               test_field $field $inj_val
+       done
+
        for field in "${fields_thresh[@]}"; do
                test_field $field $inj_val "thresh"
        done
@@ -168,6 +171,7 @@ do_tests()
 check_min_kver "4.19" || do_skip "kernel $KVER may not support smart 
(un)injection"
 check_prereq "jq"
 _init
+bus="$NFIT_TEST_BUS0"
 rc=1
 
 jlist=$($TEST_PATH/list-smart-dimm -b $bus)
diff --git a/test/list-smart-dimm.c b/test/list-smart-dimm.c
index f94277e8..7ad6c751 100644
--- a/test/list-smart-dimm.c
+++ b/test/list-smart-dimm.c
@@ -7,6 +7,7 @@
 #include <ndctl/libndctl.h>
 #include <util/parse-options.h>
 
+#include <test.h>
 #include <ndctl/filter.h>
 #include <ndctl/ndctl.h>
 #include <ndctl/json.h>
@@ -28,6 +29,32 @@ static bool filter_region(struct ndctl_region *region,
        return true;
 }
 
+static void filter_ndtest_dimm(struct ndctl_dimm *dimm,
+                              struct ndctl_filter_ctx *ctx)
+{
+       struct list_filter_arg *lfa = ctx->list;
+       struct json_object *jdimm;
+
+       if (!ndctl_dimm_is_cmd_supported(dimm, ND_CMD_SMART))
+               return;
+
+       if (!lfa->jdimms) {
+               lfa->jdimms = json_object_new_array();
+               if (!lfa->jdimms) {
+                       fail("\n");
+                       return;
+               }
+       }
+
+       jdimm = util_dimm_to_json(dimm, lfa->flags);
+       if (!jdimm) {
+               fail("\n");
+               return;
+       }
+
+       json_object_array_add(lfa->jdimms, jdimm);
+}
+
 static void filter_dimm(struct ndctl_dimm *dimm, struct ndctl_filter_ctx *ctx)
 {
        struct list_filter_arg *lfa = ctx->list;
@@ -92,6 +119,7 @@ int main(int argc, const char *argv[])
        struct ndctl_filter_ctx fctx = { 0 };
        struct list_filter_arg lfa = { 0 };
 
+       init_env();
        rc = ndctl_new(&ctx);
        if (rc < 0)
                return EXIT_FAILURE;
@@ -102,7 +130,10 @@ int main(int argc, const char *argv[])
                usage_with_options(u, options);
 
        fctx.filter_bus = filter_bus;
-       fctx.filter_dimm = filter_dimm;
+       if (ndctl_test_family == NVDIMM_FAMILY_PAPR)
+               fctx.filter_dimm = filter_ndtest_dimm;
+       else
+               fctx.filter_dimm = filter_dimm;
        fctx.filter_region = filter_region;
        fctx.filter_namespace = NULL;
        fctx.list = &lfa;
diff --git a/test/meson.build b/test/meson.build
index b33fe3b9..1f804afd 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -76,7 +76,7 @@ daxdev_errors = executable('daxdev-errors', [
   include_directories : root_inc,
 )
 
-list_smart_dimm = executable('list-smart-dimm', [
+list_smart_dimm = executable('list-smart-dimm', testcore + [
     'list-smart-dimm.c',
     '../ndctl/filter.c',
     '../util/json.c',
diff --git a/test/skip_PAPR.js b/test/skip_PAPR.js
index ec967c98..97ceda82 100644
--- a/test/skip_PAPR.js
+++ b/test/skip_PAPR.js
@@ -25,8 +25,7 @@
  "align.sh",           //              ""
  "dm.sh",              //              ""
  "mmap.sh",            //              ""
- "monitor.sh",         // To be fixed
- "inject-smart.sh"     //    ""
+ "monitor.sh"          // To be fixed
 ]
 
 // NOTE: The libjson-c doesn't like comments in json files, so keep the file



Reply via email to