aboutsummaryrefslogtreecommitdiff
path: root/utils/utils_test.sh
diff options
context:
space:
mode:
authorJulien Duraj <julien.duraj@linaro.org>2017-03-02 19:28:33 +0100
committerJulien Duraj <julien.duraj@linaro.org>2017-03-14 16:21:43 +0000
commit91ba67e5fb9699ce082f3791e3c5f9d10eacc440 (patch)
tree1d62a4f887ec137a3122a78a9bd8ba1eeac2a9e0 /utils/utils_test.sh
parent16968043b3479343fb0079370edf39bf1fa17157 (diff)
Refactor end of scripts main function
Since we always do the same thing at the end of a test script, i.e. Stop the timer, print the status, exit with a suitable exit code, refactor this into the utils section. Also, move non android specific {start,end} functions from utils_android to utils Change-Id: Ie489dd5ad4e6559132170addd4c85f54d397945b
Diffstat (limited to 'utils/utils_test.sh')
-rw-r--r--utils/utils_test.sh61
1 files changed, 61 insertions, 0 deletions
diff --git a/utils/utils_test.sh b/utils/utils_test.sh
new file mode 100644
index 0000000..003cbb4
--- /dev/null
+++ b/utils/utils_test.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+# Common test functions
+
+# Global cumulative test summary and return code.
+TESTS_SUMMARY=
+# shellcheck disable=SC2034
+TESTS_RETURN_CODE=0
+
+start_test() {
+ start_timer "$@"
+}
+
+end_test() {
+ stop_timer "$1"
+
+ log I "$0 Finished!"
+ dump_timer "$1" "$(get_workspace)/time_test.txt"
+
+ local log_level
+ case ${TESTS_RETURN_CODE} in
+ 0) log_level="S" ;;
+ *) log_level="E" ;;
+ esac
+
+ log "${log_level}" "Test Summary:\n${TESTS_SUMMARY}"
+
+ exit "${TESTS_RETURN_CODE}"
+}
+
+start_section() {
+ log I "Starting section: $1"
+ TESTS_SUMMARY+=$(printf "%-25s" "$1")
+ start_timer "$1"
+ start_logging "$(get_workspace)/log_build_$1.txt"
+}
+
+end_section() {
+ stop_logging "$(get_workspace)/log_build_$1.txt"
+ stop_timer "$1"
+ local test_time=$(print_timer "$1")
+ TESTS_SUMMARY+=$(printf "TOOK: %-10s" "${test_time}")
+
+ if [[ $2 -ne 0 ]]; then
+ log E "Section: $1 FAILED"
+ TESTS_SUMMARY+="FAILED\n"
+ # shellcheck disable=SC2034
+ TESTS_RETURN_CODE=$2
+ else
+ log S "Section $1 PASSED"
+ TESTS_SUMMARY+="PASSED\n"
+ fi
+}
+
+skip_section() {
+ log I "Skipping section $1"
+ stop_logging "$(get_workspace)/log_build_$1.txt"
+ stop_timer "$1"
+ TESTS_SUMMARY+=$(printf "TOOK: %-10s" "0s")
+ TESTS_SUMMARY+="SKIPPED\n"
+}