From 3d1bc8474e38b17ae4ee1660c2a2fc0edf023961 Mon Sep 17 00:00:00 2001 From: Chase Qi Date: Fri, 26 Aug 2016 14:47:16 +0800 Subject: v2: linux: add dd write/read speed test - Added Linux dd write/read speed test - Optimized sh-test-lib Change-Id: I3bccfda212535e9a36b8e231b69c0dd2367a88f6 Signed-off-by: Chase Qi --- automated/lib/sh-test-lib | 51 +++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'automated/lib/sh-test-lib') diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib index 15ef4e0..fca1153 100755 --- a/automated/lib/sh-test-lib +++ b/automated/lib/sh-test-lib @@ -5,55 +5,47 @@ export LANG error_msg() { local msg="$1" - test -z "${msg}" && msg="Unknown error" + [ -z "${msg}" ] && msg="Unknown error" printf "ERROR: %s\n" "${msg}" >&2 exit 1 } warn_msg() { local msg="$1" - test -z "${msg}" && msg="Unknown error" + [ -z "${msg}" ] && msg="Unknown error" printf "WARNING: %s\n" "${msg}" >&2 } info_msg() { local msg="$1" - test -z "${msg}" && msg="Unknown info" + [ -z "${msg}" ] && msg="Unknown info" printf "INFO: %s\n" "${msg}" >&1 } -check_return_fail() { - if [ $? -ne 0 ]; then - fail_test "$1" +check_root() { + if [ "$(id -ru)" -eq 0 ]; then return 0 else return 1 fi } -fail_test() { - local reason="$1" - echo "${test}: fail - ${reason}" -} - -pass_test() { - echo "${test}: pass" -} +exit_on_fail() { + local exit_code="$?" + [ "$#" -ne 1 ] && error_msg "Usage: exit_on_fail test" + local test="$1" -check_root() { - if [ "$(id -ru)" -eq 0 ]; then - return 0 - else - return 1 + if [ "${exit_code}" -ne 0 ]; then + echo "${test} fail" | tee -a "${RESULT_FILE}" + exit 1 fi } check_return() { local exit_code="$?" + [ "$#" -ne 1 ] && error_msg "Usage: check_return test" local test="$1" - test -z "${test}" && warn_msg "Test name is empty" - if [ "${exit_code}" -ne 0 ]; then echo "${test} fail" | tee -a "${RESULT_FILE}" return "${exit_code}" @@ -64,15 +56,16 @@ check_return() { } add_metric() { + if [ "$#" -ne 4 ]; then + warn_msg "The number of parameters less then 4" + error_msg "Usage: add_metric test result measurement units" + fi local test="$1" - local measurement="$2" - local units="$3" - - test -z "${test}" && warn_msg "Test name is empty" - test -z "${measurement}" && warn_msg "Test measurement is empty" - test -z "${units}" && warn_msg "Test units is empty" + local result="$2" + local measurement="$3" + local units="$4" - echo "${test} pass ${measurement} ${units}" | tee -a "${RESULT_FILE}" + echo "${test} ${result} ${measurement} ${units}" | tee -a "${RESULT_FILE}" } dist_name() { @@ -95,6 +88,8 @@ dist_name() { install_deps() { local pkgs="$1" + [ -z "${pkgs}" ] && error_msg "Usage: install_deps pkgs" + # skip_install parmater is optional. local skip_install="$2" if [ "${skip_install}" = "True" ] || [ "${skip_install}" = "true" ]; then -- cgit v1.2.3