diff mbox

[ndctl,v2,5/6] ndctl/test: update existing unit tests to use inject-error

Message ID 20171013001004.14963-6-vishal.l.verma@intel.com (mailing list archive)
State Accepted
Commit efb1992d1ffc
Headers show

Commit Message

Vishal Verma Oct. 13, 2017, 12:10 a.m. UTC
Until now, various unit tests related to error handling used to expect
'canned' errors to be present in the middle of every nfit_test
namespace. With the ACPI error injection patches for nfit_test, this is
no longer the case. Update the existing unit tests it inject any errors
they need for testing themselves using inject-error, rather than
expecting canned errors.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 test/clear.sh         |  5 ++++-
 test/dax-errors.sh    |  5 ++++-
 test/daxdev-errors.sh | 17 ++++++++++++++---
 3 files changed, 22 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/test/clear.sh b/test/clear.sh
index a60c3d9..c22ff3b 100755
--- a/test/clear.sh
+++ b/test/clear.sh
@@ -54,7 +54,10 @@  eval $(echo $json | sed -e "$json2var")
 [ $dev = "x" ] && echo "fail: $LINENO" && exit 1
 [ $mode != "raw" ] && echo "fail: $LINENO" && exit 1
 
-# check for expected errors in the middle of the namespace
+# inject errors in the middle of the namespace, verify that reading fails
+err_sector="$(((size/512) / 2))"
+err_count=8
+$NDCTL inject-error --block="$err_sector" --count=$err_count $dev
 read sector len < /sys/block/$blockdev/badblocks
 [ $((sector * 2)) -ne $((size /512)) ] && echo "fail: $LINENO" && exit 1
 if dd if=/dev/$blockdev of=/dev/null iflag=direct bs=512 skip=$sector count=$len; then
diff --git a/test/dax-errors.sh b/test/dax-errors.sh
index 5af3859..02bbca8 100755
--- a/test/dax-errors.sh
+++ b/test/dax-errors.sh
@@ -64,7 +64,10 @@  eval $(echo $json | sed -e "$json2var")
 [ $dev = "x" ] && echo "fail: $LINENO" && exit 1
 [ $mode != "raw" ] && echo "fail: $LINENO" && exit 1
 
-# check for expected errors in the middle of the namespace
+# inject errors in the middle of the namespace, verify that reading fails
+err_sector="$(((size/512) / 2))"
+err_count=8
+$NDCTL inject-error --block="$err_sector" --count=$err_count $dev
 read sector len < /sys/block/$blockdev/badblocks
 [ $((sector * 2)) -ne $((size /512)) ] && echo "fail: $LINENO" && exit 1
 if dd if=/dev/$blockdev of=/dev/null iflag=direct bs=512 skip=$sector count=$len; then
diff --git a/test/daxdev-errors.sh b/test/daxdev-errors.sh
index 8115087..e9d9d57 100755
--- a/test/daxdev-errors.sh
+++ b/test/daxdev-errors.sh
@@ -37,6 +37,7 @@  check_min_kver "4.12" || { echo "kernel $KVER lacks dax dev error handling"; exi
 
 set -e
 trap 'err $LINENO' ERR
+rc=1
 
 # setup (reset nfit_test dimms)
 modprobe nfit_test
@@ -68,18 +69,28 @@  chardev=$(echo $json | jq ". | select(.mode == \"dax\") | .daxregion.devices[0].
 #  }
 #}
 
+json1=$($NDCTL list $BUS --mode=dax --namespaces)
+eval $(echo $json1 | sed -e "$json2var")
+nsdev=$dev
+
 json1=$($NDCTL list $BUS)
 eval $(echo $json1 | sed -e "$json2var")
+busdev=$dev
+
+# inject errors in the middle of the namespace
+err_sector="$(((size/512) / 2))"
+err_count=8
+$NDCTL inject-error --block="$err_sector" --count=$err_count $nsdev
 
-read sector len < /sys/bus/platform/devices/nfit_test.0/$dev/$region/badblocks
+read sector len < /sys/bus/nd/devices/$region/badblocks
 echo "sector: $sector len: $len"
 
 # run the daxdev-errors test
 test -x ./daxdev-errors
-./daxdev-errors $dev $region
+./daxdev-errors $busdev $region
 
 # check badblocks, should be empty
-if read sector len < /sys/bus/platform/devices/nfit_test.0/$dev/$region/badblocks; then
+if read sector len < /sys/bus/platform/devices/nfit_test.0/$busdev/$region/badblocks; then
 	echo "badblocks empty, expected"
 fi
 [ -n "$sector" ] && echo "fail: $LINENO" && exit 1