summaryrefslogtreecommitdiff
path: root/automated/lib
diff options
context:
space:
mode:
authorChase Qi <chase.qi@linaro.org>2016-10-27 10:27:43 +0800
committerMilosz Wasilewski <milosz.wasilewski@linaro.org>2016-10-27 10:56:57 +0000
commitc2e2f698aa666e3ead64aecfa4d12d965798a6f3 (patch)
tree1bf0960a93d4b768014710bc303455c6b733fbd5 /automated/lib
parent38ea4d3f88337fe36d83e8b61d7496eedcba7d25 (diff)
downloadtest-definitions-pipe-c2e2f698aa666e3ead64aecfa4d12d965798a6f3.tar.gz
v2: sh-test-lib: add run_test_case function
When shell argument "-e" set and "$?" is non-zero, test script will exit immediately. check_return and exit_on_fail would not work. run_test_case should be used instead. run_test_case runs test command within if block and able to give pass/fail respectively. "skip_list" is supported as an optional parameter. It skip the following tests and exit when skip_list isn't empty. Change-Id: I0f4040f37b6d9daa0558bac0d6bf87ba1c3bd904 Signed-off-by: Chase Qi <chase.qi@linaro.org>
Diffstat (limited to 'automated/lib')
-rwxr-xr-xautomated/lib/sh-test-lib24
1 files changed, 24 insertions, 0 deletions
diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib
index 11873cd..4894875 100755
--- a/automated/lib/sh-test-lib
+++ b/automated/lib/sh-test-lib
@@ -70,6 +70,30 @@ check_return() {
fi
}
+# When shell argument "-e" set in test script, check_return and exit_on_fail
+# would NOT work. run_test_case should be used instead.
+run_test_case() {
+ [ "$#" -lt 2 ] && error_msg "Usage: run_test_case <test_command> <test_case_id> [skip_list]"
+ local test_command="$1"
+ local test_case_id="$2"
+ local skip_list="$3"
+
+ if eval "${test_command}"; then
+ echo "${test_case_id} pass" | tee -a "${RESULT_FILE}"
+ else
+ echo "${test_case_id} fail" | tee -a "${RESULT_FILE}"
+ # When skip_list isn't empty, skip the tests and exit.
+ if [ -n "${skip_list}" ]; then
+ for i in ${skip_list}; do
+ echo "$i skip" | tee -a "${RESULT_FILE}"
+ done
+ exit 0
+ fi
+ fi
+
+ return 0
+}
+
report_pass() {
[ "$#" -ne 1 ] && error_msg "Usage: report_pass test"
local test="$1"