diff mbox

[v2,1/2] nfit, test: Add NFIT_TEST_BUS[01] variable and some helper funtions to common

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

Commit Message

Masayoshi Mizuma June 19, 2018, 7:30 p.m. UTC
From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>

Add following global variable and functions to test/common file.

 - NFIT_TEST_BUS[01] (global variable)
   Buses are created when nfit_test module is loaded.

 - NDCTL (global variable)
   ndctl command path (renamed).

 - _cleanup
   Helper function cleans up nfit_test module.

 - json2var
   Helper function (filter) converts json to var.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
---
 test/common | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/test/common b/test/common
index 8fafa91..fb4e18e 100644
--- a/test/common
+++ b/test/common
@@ -4,17 +4,23 @@ 
 
 # Global variables
 
-# ndctl
+# NDCTL
 #
 if [ -f "../ndctl/ndctl" ] && [ -x "../ndctl/ndctl" ]; then
-	export ndctl=../ndctl/ndctl
+	export NDCTL=../ndctl/ndctl
 elif [ -f "./ndctl/ndctl" ] && [ -x "./ndctl/ndctl" ]; then
-	export ndctl=./ndctl/ndctl
+	export NDCTL=./ndctl/ndctl
 else
 	echo "Couldn't find an ndctl binary"
 	exit 1
 fi
 
+# NFIT_TEST_BUS[01]
+#
+NFIT_TEST_BUS0=nfit_test.0
+NFIT_TEST_BUS1=nfit_test.1
+
+
 # Functions
 
 # err
@@ -58,3 +64,20 @@  check_prereq()
 		do_skip "missing $1, skipping..."
 	fi
 }
+
+# _cleanup
+#
+_cleanup()
+{
+	$NDCTL disable-region -b $NFIT_TEST_BUS0 all
+	$NDCTL disable-region -b $NFIT_TEST_BUS1 all
+	modprobe -r nfit_test
+}
+
+# json2var
+# stdin: json
+#
+json2var()
+{
+	sed -e "s/[{}\",]//g; s/:/=/g"
+}