Add a new unit test to test all the features of the inject-error
command.
Cc: Dan Williams <[email protected]>
Signed-off-by: Vishal Verma <[email protected]>
---
test/Makefile.am | 3 +-
test/inject-error.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 91 insertions(+), 1 deletion(-)
create mode 100755 test/inject-error.sh
diff --git a/test/Makefile.am b/test/Makefile.am
index ac3547e..8cec451 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -13,7 +13,8 @@ TESTS =\
multi-dax.sh \
btt-check.sh \
label-compat.sh \
- blk-exhaust.sh
+ blk-exhaust.sh \
+ inject-error.sh
check_PROGRAMS =\
libndctl \
diff --git a/test/inject-error.sh b/test/inject-error.sh
new file mode 100755
index 0000000..a8348df
--- /dev/null
+++ b/test/inject-error.sh
@@ -0,0 +1,89 @@
+#!/bin/bash -Ex
+
+# Copyright(c) 2015-2017 Intel Corporation. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+[ -f "../ndctl/ndctl" ] && [ -x "../ndctl/ndctl" ] && ndctl="../ndctl/ndctl"
+[ -f "./ndctl/ndctl" ] && [ -x "./ndctl/ndctl" ] && ndctl="./ndctl/ndctl"
+[ -z "$ndctl" ] && echo "Couldn't find an ndctl binary" && exit 1
+bus="nfit_test.0"
+json2var="s/[{}\",]//g; s/:/=/g"
+dev=""
+mode=""
+size=""
+sector_size=""
+blockdev=""
+bs=4096
+rc=77
+
+trap 'err $LINENO' ERR
+
+# sample json:
+# {
+# "dev":"namespace5.0",
+# "mode":"sector",
+# "size":32440320,
+# "uuid":"51805176-e124-4635-ae17-0e6a4a16671a",
+# "sector_size":4096,
+# "blockdev":"pmem5s"
+# }
+
+# $1: Line number
+# $2: exit code
+err()
+{
+ [ -n "$2" ] && rc="$2"
+ echo "test/btt-check: failed at line $1"
+ exit "$rc"
+}
+
+check_min_kver()
+{
+ local ver="$1"
+ : "${KVER:=$(uname -r)}"
+
+ [ -n "$ver" ] || return 1
+ [[ "$ver" == "$(echo -e "$ver\n$KVER" | sort -V | head -1)" ]]
+}
+
+check_min_kver "4.15" || { echo "kernel $KVER may not support error
injection"; exit $rc; }
+
+create()
+{
+ json=$($ndctl create-namespace -b "$bus" -t pmem -m sector)
+ eval "$(echo "$json" | sed -e "$json2var")"
+ [ -n "$dev" ] || err "$LINENO" 2
+ [ "$mode" = "sector" ] || err "$LINENO" 2
+ [ -n "$size" ] || err "$LINENO" 2
+ [ -n "$sector_size" ] || err "$LINENO" 2
+ [ -n "$blockdev" ] || err "$LINENO" 2
+ [ $size -gt 0 ] || err "$LINENO" 2
+}
+
+reset()
+{
+ $ndctl disable-region -b "$bus" all
+ $ndctl zero-labels -b "$bus" all
+ $ndctl enable-region -b "$bus" all
+}
+
+do_tests()
+{
+ # TODO
+ return
+}
+
+modprobe nfit_test
+rc=1
+create && reset
+do_tests
+reset
+exit 0
--
2.9.5
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm