@@ -150,10 +150,9 @@ do_tests()
}
# setup (reset nfit_test dimms, create the BTT namespace)
-modprobe nfit_test
+_init
rc=1
reset && create
do_tests
reset
-_cleanup
exit 0
@@ -42,7 +42,7 @@ mkdir -p $MNT
trap 'err $LINENO cleanup' ERR
# setup (reset nfit_test dimms)
-modprobe nfit_test
+_init
resetV
rc=1
@@ -144,5 +144,4 @@ dd if=/dev/$blockdev of=/dev/null iflag=direct bs=4096 count=1 && err $LINENO ||
# done, exit
reset
cleanup
-_cleanup
exit 0
@@ -172,11 +172,10 @@ do_tests()
ns_info_wipe
}
-modprobe nfit_test
+_init
check_prereq xxd
rc=1
reset
do_tests
reset
-_cleanup
exit 0
@@ -13,7 +13,7 @@ check_min_kver "4.6" || do_skip "lacks clear poison support"
trap 'err $LINENO' ERR
# setup (reset nfit_test dimms)
-modprobe nfit_test
+_init
reset
rc=1
@@ -72,6 +72,4 @@ if check_min_kver "4.9"; then
fi
fi
-_cleanup
-
exit 0
@@ -113,6 +113,18 @@ _cleanup()
modprobe -r nfit_test
}
+_init()
+{
+ set +e
+ modprobe nfit_test
+ if [ $? -ne 0 ]; then
+ echo "Could not load the nfit_test module."
+ exit 77
+ fi
+ set -e
+ trap _cleanup EXIT INT TERM HUP PIPE
+}
+
# json2var
# stdin: json
#
@@ -14,7 +14,7 @@ check_min_kver "4.5" || do_skip "may lack namespace mode attribute"
trap 'err $LINENO' ERR
# setup (reset nfit_test dimms)
-modprobe nfit_test
+_init
reset
rc=1
@@ -40,6 +40,4 @@ eval $(echo $json | json2var)
# free capacity for blk creation
$NDCTL destroy-namespace -f $dev
-_cleanup
-
exit 0
@@ -14,7 +14,7 @@ check_prereq "jq"
trap 'err $LINENO' ERR
# setup (reset nfit_test dimms)
-modprobe nfit_test
+_init
reset
rc=1
@@ -71,6 +71,4 @@ if read sector len < /sys/bus/platform/devices/nfit_test.0/$busdev/$region/badbl
fi
[ -n "$sector" ] && echo "fail: $LINENO" && exit 1
-_cleanup
-
exit 0
@@ -70,11 +70,10 @@ do_tests()
check_min_kver "4.16" || do_skip "may lack firmware update test handling"
-modprobe nfit_test
+_init
fwupd_reset
detect
rc=1
do_tests
rm -f $image
-_cleanup
exit 0
@@ -79,10 +79,9 @@ do_tests()
check_status
}
-modprobe nfit_test
+_init
rc=1
reset && create
do_tests
reset
-_cleanup
exit 0
@@ -167,7 +167,7 @@ do_tests()
check_min_kver "4.19" || do_skip "kernel $KVER may not support smart (un)injection"
check_prereq "jq"
-modprobe nfit_test
+_init
rc=1
jlist=$($TEST_PATH/list-smart-dimm -b $bus)
@@ -175,5 +175,4 @@ dimm="$(jq '.[]."dev"?, ."dev"?' <<< $jlist | sort | head -1 | xargs)"
test -n "$dimm"
do_tests
-_cleanup
exit 0
@@ -15,7 +15,7 @@ check_prereq "jq"
trap 'err $LINENO' ERR
# setup (reset nfit_test dimms)
-modprobe nfit_test
+_init
$NDCTL disable-region -b $NFIT_TEST_BUS0 all
$NDCTL init-labels -f -b $NFIT_TEST_BUS0 all
@@ -43,6 +43,4 @@ if [ -z $len ]; then
exit 1
fi
-_cleanup
-
exit 0
@@ -31,9 +31,8 @@ do_test()
$NDCTL create-namespace -r $region -t pmem
}
-modprobe nfit_test
+_init
rc=1
reset
do_test
-_cleanup
exit 0
@@ -161,10 +161,9 @@ do_tests()
test_filter_dimmevent
}
-modprobe nfit_test
+_init
rc=1
reset
set_smart_supported_bus
do_tests
-_cleanup
exit 0
@@ -16,7 +16,7 @@ trap 'err $LINENO' ERR
ALIGN_SIZE=`getconf PAGESIZE`
# setup (reset nfit_test dimms)
-modprobe nfit_test
+_init
reset
rc=1
@@ -28,6 +28,4 @@ chardev1=$(echo $json | jq ". | select(.mode == \"devdax\") | .daxregion.devices
json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a $ALIGN_SIZE -s 16M)
chardev2=$(echo $json | jq ". | select(.mode == \"devdax\") | .daxregion.devices[0].chardev")
-_cleanup
-
exit 0
@@ -28,7 +28,7 @@ set -e
trap 'err $LINENO' ERR
# setup (reset nfit_test dimms)
-modprobe nfit_test
+_init
reset
rc=1
@@ -67,5 +67,4 @@ if read -r sector len < "/sys/block/$raw_bdev/badblocks"; then
false
fi
-_cleanup
exit 0
@@ -25,7 +25,7 @@ mkdir -p $MNT
trap 'err $LINENO cleanup' ERR
# setup (reset nfit_test dimms)
-modprobe nfit_test
+_init
reset
rc=1
@@ -110,6 +110,5 @@ echo $((start_sect + 1)) 1 > /sys/block/$blockdev/badblocks
dd if=$MNT/$FILE of=/dev/null iflag=direct bs=4096 count=1 && err $LINENO || true
cleanup
-_cleanup
exit 0
@@ -65,11 +65,10 @@ test_mode()
$NDCTL destroy-namespace $dev
}
-modprobe nfit_test
+_init
rc=1
reset
test_mode "raw"
test_mode "fsdax"
test_mode "sector"
-_cleanup
exit 0
@@ -14,7 +14,7 @@ trap 'err $LINENO' ERR
ALIGN_SIZE=`getconf PAGESIZE`
# setup (reset nfit_test dimms)
-modprobe nfit_test
+_init
reset
reset1
@@ -27,6 +27,4 @@ NAMESPACE=$($NDCTL create-namespace --no-autolabel -r $REGION -m sector -f -l 4K
$NDCTL create-namespace --no-autolabel -e $NAMESPACE -m dax -f -a $ALIGN_SIZE
$NDCTL create-namespace --no-autolabel -e $NAMESPACE -m sector -f -l 4K
-_cleanup
-
exit 0
@@ -246,7 +246,7 @@ if [ "$uid" -ne 0 ]; then
do_skip "run as root or with a sudo login shell for test to work"
fi
-modprobe nfit_test
+_init
setup
check_prereq "keyctl"
rc=1
@@ -275,5 +275,4 @@ test_6_load_keys
test_cleanup
post_cleanup
-_cleanup
exit 0
@@ -11,7 +11,7 @@ set -e
trap 'err $LINENO' ERR
# setup (reset nfit_test dimms)
-modprobe nfit_test
+_init
reset
rc=1
@@ -34,5 +34,4 @@ $NDCTL disable-namespace $dev
uuidgen > /sys/bus/nd/devices/$dev/uuid
$NDCTL enable-namespace $dev
-_cleanup
exit 0
The _cleanup is easily missed to be called at places where trap ERR is set, ex security.sh. The patch moves all the modprobes into the _init in test/common and sets the trap on exit for "any" of the reasons to invoke _cleanup. The patch also gracefully skips the test if the module load fails instead of continuing, which otherwise makes the tests fail erroneously in random places during the tests. Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com> --- test/btt-check.sh | 3 +-- test/btt-errors.sh | 3 +-- test/btt-pad-compat.sh | 3 +-- test/clear.sh | 4 +--- test/common | 12 ++++++++++++ test/create.sh | 4 +--- test/daxdev-errors.sh | 4 +--- test/firmware-update.sh | 3 +-- test/inject-error.sh | 3 +-- test/inject-smart.sh | 3 +-- test/label-compat.sh | 4 +--- test/max_available_extent_ns.sh | 3 +-- test/monitor.sh | 3 +-- test/multi-dax.sh | 4 +--- test/pfn-meta-errors.sh | 3 +-- test/pmem-errors.sh | 3 +-- test/rescan-partitions.sh | 3 +-- test/sector-mode.sh | 4 +--- test/security.sh | 3 +-- test/track-uuid.sh | 3 +-- 20 files changed, 31 insertions(+), 44 deletions(-)