diff mbox

[1/2] test: add some helper function for test script

Message ID 20180611164531.8242-2-msys.mizuma@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Masayoshi Mizuma June 11, 2018, 4:45 p.m. UTC
From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>

Some test scripts have same function. So, this patch introduces
the functions to 'test/common' new file.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
---
 test/common | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 test/common
diff mbox

Patch

diff --git a/test/common b/test/common
new file mode 100644
index 0000000..7e64eec
--- /dev/null
+++ b/test/common
@@ -0,0 +1,57 @@ 
+
+# Global variables
+
+# ndctl
+#
+if [ -f "../ndctl/ndctl" ] && [ -x "../ndctl/ndctl" ]; then
+	export ndctl=../ndctl/ndctl
+elif [ -f "./ndctl/ndctl" ] && [ -x "./ndctl/ndctl" ]; then
+	export ndctl=./ndctl/ndctl
+else
+	echo "Couldn't find an ndctl binary"
+	exit 1
+fi
+
+# Functions
+
+# err
+# $1: line number which error detected
+# $2: cleanup function (optional)
+#
+err()
+{
+	echo test/$(basename $0): failed at line $1
+	[ -n "$2" ] && "$2"
+	exit $rc
+}
+
+# check_min_kver
+# $1: Supported kernel version. format: X.Y
+#
+check_min_kver()
+{
+	local ver="$1"
+	: "${KVER:=$(uname -r)}"
+
+	[ -n "$ver" ] || return 1
+	[[ "$ver" == "$(echo -e "$ver\n$KVER" | sort -V | head -1)" ]]
+}
+
+# do_skip
+# $1: Skip message
+#
+do_skip()
+{
+	echo kernel $(uname -r): $1
+	exit 77
+}
+
+# check_prereq
+# $1: command to check
+#
+check_prereq()
+{
+	if ! command -v "$1" >/dev/null; then
+		do_skip "missing $1, skipping..."
+	fi
+}