diff options
author | Chase Qi <chase.qi@linaro.org> | 2016-08-05 14:58:27 +0800 |
---|---|---|
committer | Chase Qi <chase.qi@linaro.org> | 2016-08-08 20:59:26 +0800 |
commit | f6eca3dd9986995047f6d5813c3c7d81692df554 (patch) | |
tree | c5ce05ccb4eecf2cc0b43020f3fe7b5676b3d0cb /common/scripts/include/sh-test-lib | |
parent | c2db176f4977a46a8873af8a340a8b9d4228e350 (diff) |
common: add dd write/read speed test
Change-Id: Icffb4b39b26fe12effb2c472273d6952ef5192a9
Signed-off-by: Chase Qi <chase.qi@linaro.org>
Diffstat (limited to 'common/scripts/include/sh-test-lib')
-rwxr-xr-x | common/scripts/include/sh-test-lib | 86 |
1 files changed, 78 insertions, 8 deletions
diff --git a/common/scripts/include/sh-test-lib b/common/scripts/include/sh-test-lib index f57a2ef..5c1e4a1 100755 --- a/common/scripts/include/sh-test-lib +++ b/common/scripts/include/sh-test-lib @@ -19,19 +19,26 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # Author: Ricardo Salveti <rsalveti@linaro.org> -# Maintainer Botao Sun <botao.sun@linaro.org> +# Author: Botao Sun <botao.sun@linaro.org> +# Maintainer: Chase Qi <chase.qi@linaro.org> error_msg() { local msg="$1" - test -z "$msg" && msg="Unknown error" - echo "ERROR: $msg" >&2 + test -z "${msg}" && msg="Unknown error" + echo "ERROR: ${msg}" >&2 exit 1 } warn_msg() { local msg="$1" - test -z "$msg" && msg="Unknown error" - printf "WARNING: %s\n\n" "$msg" >&2 + test -z "${msg}" && msg="Unknown error" + printf "WARNING: %s\n\n" "${msg}" >&2 +} + +info_msg() { + local msg="$1" + test -z "${msg}" && msg="Unknown info" + printf "INFO: %s\n\n" "${msg}" >&1 } check_return_fail() { @@ -45,17 +52,80 @@ check_return_fail() { fail_test() { local reason="$1" - echo "${TEST}: FAIL - ${reason}" + echo "${test}: fail - ${reason}" } pass_test() { - echo "${TEST}: PASS" + echo "${test}: pass" } check_root() { - if [ $(id -ru) -eq 0 ]; then + if [ "$(id -ru)" -eq 0 ]; then return 0 else return 1 fi } + +check_return() { + local exit_code="$?" + 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}" + else + echo "${test} pass" | tee -a "${RESULT_FILE}" + fi +} + +add_metric() { + 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" + + echo "${test} pass ${measurement} ${units}" | tee -a "${RESULT_FILE}" +} + +dist_name() { + if [ -x /usr/bin/lsb_release ]; then + dist="$(lsb_release -si)" + elif [ -f /etc/lsb-release ]; then + . /etc/lsb-release + dist="${DISTRIB_ID}" + elif [ -f /etc/debian_version ]; then + dist="Debian" + elif [ -f /etc/fedora-release ]; then + dist="Fedora" + elif [ -f /etc/centos-release ]; then + dist="CentOS" + else + dist="Unknown" + warn_msg "Unsupported distro: cannot determine distribution name" + fi +} + +install_deps() { + local pkgs="$1" + dist_name + case "${dist}" in + Debian|Ubuntu) + apt-get update + apt-get install -y -q ${pkgs} + ;; + CentOS) + yum -e 0 -y install ${pkgs} + ;; + Fedora) + dnf -e 0 -y install ${pkgs} + ;; + Unknown) + warn_msg "Unsupported distro: package install skipped" + ;; + esac +} |