[Pdbg] [PATCH v2 2/5] tests: Update driver to pass test_wrapper argument

Amitay Isaacs amitay at ozlabs.org
Wed Nov 14 16:14:08 AEDT 2018


Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 tests/driver.sh      | 15 +++++++++++----
 tests/test_driver.sh | 10 ++++++++--
 tests/test_hw_bmc.sh |  6 ++++--
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/tests/driver.sh b/tests/driver.sh
index 6df34b3..9e92135 100644
--- a/tests/driver.sh
+++ b/tests/driver.sh
@@ -44,8 +44,9 @@
 #
 # test_wrapper
 #
-#    To execute commands in a special context, test_wrapper function can be
-#    defined.  This function will be passed all the arguments to test_run
+#    Register a test wrapper function.  If test_wrapper is called without
+#    an argument, then the test wrapper function is set to default.
+#    The test wrapper function will be passed all the arguments to test_run
 #    command.
 #
 #
@@ -222,9 +223,15 @@ test_wrapper_default ()
 	"$@"
 }
 
+test_wrapper_func=test_wrapper_default
+
 test_wrapper ()
 {
-	test_wrapper_default "$@"
+	if [ $# -eq 0 ] ; then
+		test_wrapper_func=test_wrapper_default
+	else
+		test_wrapper_func="$1"
+	fi
 }
 
 result_filter_default ()
@@ -337,7 +344,7 @@ test_run ()
 
 	stderr_file=$(mktemp)
 
-	output_raw=$(test_wrapper "$@" 2>"$stderr_file")
+	output_raw=$($test_wrapper_func "$@" 2>"$stderr_file")
 	rc=$?
 
 	if [ $rc -ne $required_rc ] ; then
diff --git a/tests/test_driver.sh b/tests/test_driver.sh
index 6e8343a..803f69f 100755
--- a/tests/test_driver.sh
+++ b/tests/test_driver.sh
@@ -52,10 +52,14 @@ echo_stderr ()
 	echo "$*" >&2
 }
 
+test_wrapper echo_stderr
+
 echo "match stderr"
 test_result 0 --
 test_result_stderr foo
-test_run echo_stderr foo
+test_run foo
+
+test_wrapper
 
 echo
 
@@ -73,11 +77,13 @@ test_run echo 666
 
 echo
 
-test_wrapper ()
+prefix_output ()
 {
 	echo "output: $*"
 }
 
+test_wrapper prefix_output
+
 test_result 0 "output: foobar"
 test_run foobar
 
diff --git a/tests/test_hw_bmc.sh b/tests/test_hw_bmc.sh
index c65a630..c35597b 100755
--- a/tests/test_hw_bmc.sh
+++ b/tests/test_hw_bmc.sh
@@ -40,7 +40,7 @@ copy_pdbg ()
 			${BMC_USER}@${BMC_HOST}:${PDBG_PATH}
 }
 
-test_wrapper ()
+run_over_ssh ()
 {
 	sshpass -p "$BMC_PASS" \
 		ssh ${BMC_USER}@${BMC_HOST} \
@@ -64,7 +64,7 @@ do_skip ()
 
 
 echo -n "Checking if the host is up... "
-output=$(test_wrapper /usr/sbin/obmcutil state | grep CurrentHostState)
+output=$(run_over_ssh /usr/sbin/obmcutil state | grep CurrentHostState)
 rc=$?
 if [ $rc -ne 0 ] || \
     [ "$output" = "CurrentHostState    : xyz.openbmc_project.State.Host.HostState.Running" ] ; then
@@ -75,6 +75,8 @@ else
 	echo "$output"
 fi
 
+test_wrapper run_over_ssh
+
 result_filter ()
 {
 	sed -E -e 's#0x[[:xdigit:]]{16}#HEX16#' \
-- 
2.19.1



More information about the Pdbg mailing list