summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChase Qi <chase.qi@linaro.org>2016-10-25 11:39:59 +0800
committerChase Qi <chase.qi@linaro.org>2016-10-25 17:59:45 +0800
commite4cf6d458e06580dbb37066781ca0ecf48b150ac (patch)
treed868c44a559683a0d95378cd785543ecf9d09a95
parentae7807fbdc457301892b2d4734c7f7f5dbba94e0 (diff)
v2: sh-test-lib: add convert_to_mb function
Change-Id: I91764f7abc7ca2fb1995d9fb110c32d3b5f8c2f5 Signed-off-by: Chase Qi <chase.qi@linaro.org>
-rwxr-xr-xautomated/lib/sh-test-lib19
1 files changed, 19 insertions, 0 deletions
diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib
index e4f4b8a..b0fa164 100755
--- a/automated/lib/sh-test-lib
+++ b/automated/lib/sh-test-lib
@@ -178,3 +178,22 @@ validate_check_sum() {
return 1
fi
}
+
+convert_to_mb() {
+ [ "$#" -ne 2 ] && error_msg "Usage: convert_to_mb value units"
+ if ! echo "$1" | egrep -q "^[0-9.]+$"; then
+ error_msg "The first argument isn't a number"
+ fi
+ local value="$1"
+ local units="$2"
+
+ case "${units}" in
+ KB|kb) value=$(echo "${value}" | awk '{print $1/1024}') ;;
+ MB|mb) ;;
+ GB|gb) value=$(echo "${value}" | awk '{print $1*1024}') ;;
+ TB|tb) value=$(echo "${value}" | awk '{print $1*1024*1024}') ;;
+ *) error_msg "Unsupported units" ;;
+ esac
+
+ echo "${value}"
+}