The patch here attempts to run tests per-family loading their respective kernel test modules based on the environment variable set by the meson scripts. The skip_PAPR.js file is added to ensure there are no false negatives from PAPR family.
The behaviour can be overridden by configure option -Dtest-families=INTEL Or PAPR to run the tests for the specific family. When not running the "meson test" but running tests individually the patch takes precaution to set the default settings to INTEL to keep the current behaviour unaffected on individual tests. Signed-off-by: Shivaprasad G Bhat <[email protected]> Signed-off-by: Vaibhav Jain <[email protected]> --- meson.build | 10 +++++++++ meson_options.txt | 2 ++ test/common | 42 ++++++++++++++++++++++++++++++++-------- test/core.c | 17 +++++++++++++++- test/libndctl.c | 2 +- test/meson.build | 56 ++++++++++++++++++++++++++++++----------------------- 6 files changed, 95 insertions(+), 34 deletions(-) diff --git a/meson.build b/meson.build index 42e11aa2..bf44ba4f 100644 --- a/meson.build +++ b/meson.build @@ -14,6 +14,16 @@ project('ndctl', 'c', ], ) +families = [ 'INTEL', 'PAPR' ] +if get_option('test-families') != '' + families_str=get_option('test-families').split(',') + foreach f : families_str + if not families.contains(f.to_upper().strip()) + error('Invalid test_family "@0@" specified.'.format(f)) + endif + endforeach +endif + # rootprefixdir and rootlibdir setup copied from systemd: rootprefixdir = get_option('rootprefix') rootprefix_default = '/usr' diff --git a/meson_options.txt b/meson_options.txt index aa4a6dc8..95dfb395 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -7,6 +7,8 @@ option('keyutils', type : 'feature', value : 'enabled', description : 'enable nvdimm device passphrase management') option('test', type : 'feature', value : 'disabled', description : 'enable shipping tests in ndctl') +option('test-families', type : 'string', value : 'INTEL,PAPR', + description : 'specify command separated test families in ndctl. Default is INTEL,PAPR') option('destructive', type : 'feature', value : 'disabled', description : 'enable tests that may clobber live system resources') option('poison', type : 'feature', value : 'enabled', diff --git a/test/common b/test/common index 31395ece..743f63bf 100644 --- a/test/common +++ b/test/common @@ -124,7 +124,7 @@ _cleanup() { $NDCTL disable-region -b $NFIT_TEST_BUS0 all $NDCTL disable-region -b $NFIT_TEST_BUS1 all - modprobe -r nfit_test + modprobe -r $TEST_MODULE if [ $NDCTL_TEST_FAMILY == "INTEL" ]; then modprobe -r nfit fi @@ -132,14 +132,40 @@ _cleanup() _init() { - set +e - modprobe nfit_test - if [ $? -ne 0 ]; then - echo "Could not load the nfit_test module." - exit 77 + modules=$(awk -F" " 'BEGIN {ORS=" "} {print $1}' /proc/modules) + if [ "$NDCTL_TEST_FAMILY" == "PAPR" ]; then + TEST_MODULE="ndtest" + if [[ " ${modules[*]} " =~ " nfit " ]] || + [[ " ${modules[*]} " =~ " nfit_test " ]]; then + echo "The test module ${TEST_MODULE}.ko conflicts " + echo "with nfit and nfit_test. Unload them and retry.." + exit 77 + fi + NFIT_TEST_BUS0=ndtest.0 + NFIT_TEST_BUS1=ndtest.1 + else + TEST_MODULE="nfit_test" + if [[ " ${modules[*]} " =~ "ndtest" ]]; then + echo "The test module ${TEST_MODULE}.ko conflicts " + echo "with ndtest. Unload it and retry.." + exit 77 + fi + fi + if [ -d "/lib/modules/`uname -r`/extra/test" ]; then + if [ -f "/lib/modules/`uname -r`/extra/test/${TEST_MODULE}.ko" ]; then + set +e + modprobe ${TEST_MODULE} + if [ $? -ne 0 ]; then + echo "Could not load the ${TEST_MODULE} module." + exit 77 + fi + set -e + trap _cleanup EXIT INT TERM HUP PIPE + else + echo "The test module ${TEST_MODULE}.ko not found. Skipping.." + exit 77 + fi fi - set -e - trap _cleanup EXIT INT TERM HUP PIPE } # json2var diff --git a/test/core.c b/test/core.c index f5cf6c82..ee7f5182 100644 --- a/test/core.c +++ b/test/core.c @@ -260,6 +260,18 @@ int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod, if (test_env && strcmp(test_env, "PAPR") == 0) family = NVDIMM_FAMILY_PAPR; + if ((family == NVDIMM_FAMILY_INTEL) && + (access("/sys/module/ndtest/initstate", F_OK) == 0)) { + fprintf(stderr, + "PAPR specific ndtest module loaded while attempting to test nfit_test\n"); + return -ENOTSUP; + } else if ((family == NVDIMM_FAMILY_PAPR) && + ((access("/sys/module/nfit_test/initstate", F_OK) == 0) || + (access("/sys/module/nfit/initstate", F_OK) == 0))) { + fprintf(stderr, "nfit/nfit_test module loaded while attempting to test ndtest\n"); + return -ENOTSUP; + } + if (family == -1) { log_err(&log_ctx, "Cannot determine NVDIMM family\n"); return -ENOTSUP; @@ -363,7 +375,10 @@ retry: return -ENXIO; } - rc = kmod_module_new_from_name(*ctx, "nfit_test", mod); + if (family == NVDIMM_FAMILY_INTEL) + rc = kmod_module_new_from_name(*ctx, "nfit_test", mod); + else + rc = kmod_module_new_from_name(*ctx, "ndtest", mod); if (rc < 0) { kmod_unref(*ctx); return rc; diff --git a/test/libndctl.c b/test/libndctl.c index ab9f73c9..a70c1ed7 100644 --- a/test/libndctl.c +++ b/test/libndctl.c @@ -2596,7 +2596,7 @@ int test_libndctl(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx) err = ndctl_test_init(&kmod_ctx, &mod, ctx, loglevel, test); if (err < 0) { ndctl_test_skip(test); - fprintf(stderr, "nfit_test unavailable skipping tests\n"); + fprintf(stderr, "test module couldnt not be loaded, skipping tests\n"); return 77; } diff --git a/test/meson.build b/test/meson.build index 395b5333..b33fe3b9 100644 --- a/test/meson.build +++ b/test/meson.build @@ -177,6 +177,11 @@ tests = [ [ 'track-uuid.sh', track_uuid, 'ndctl' ], ] +families_string = get_option('test-families') +if families_string != '' + families=families_string.split(',') +endif + if get_option('destructive').enabled() sub_section = find_program('sub-section.sh') dax_ext4 = find_program('dax-ext4.sh') @@ -212,28 +217,31 @@ if get_option('keyutils').enabled() ] endif -foreach t : tests - test(t[0], t[1], - is_parallel : false, - depends : [ - ndctl_tool, - daxctl_tool, - cxl_tool, - smart_notify, - list_smart_dimm, - dax_pmd, - dax_errors, - daxdev_errors, - dax_dev, - mmap, - ], - suite: t[2], - timeout : 0, - env : [ - 'NDCTL=@0@'.format(ndctl_tool.full_path()), - 'DAXCTL=@0@'.format(daxctl_tool.full_path()), - 'TEST_PATH=@0@'.format(meson.current_build_dir()), - 'DATA_PATH=@0@'.format(meson.current_source_dir()), - ], - ) +foreach f : families + foreach t : tests + test(t[0], t[1], + is_parallel : false, + depends : [ + ndctl_tool, + daxctl_tool, + cxl_tool, + smart_notify, + list_smart_dimm, + dax_pmd, + dax_errors, + daxdev_errors, + dax_dev, + mmap, + ], + suite: [ t[2], f ], + timeout : 0, + env : [ + 'NDCTL=@0@'.format(ndctl_tool.full_path()), + 'DAXCTL=@0@'.format(daxctl_tool.full_path()), + 'TEST_PATH=@0@'.format(meson.current_build_dir()), + 'DATA_PATH=@0@'.format(meson.current_source_dir()), + 'NDCTL_TEST_FAMILY=@0@'.format(f.to_upper().strip()), + ], + ) + endforeach endforeach
