diff options
author | Chase Qi <chase.qi@linaro.org> | 2016-11-18 15:44:26 +0800 |
---|---|---|
committer | Milosz Wasilewski <milosz.wasilewski@linaro.org> | 2016-11-18 11:42:30 +0000 |
commit | 57cd01011c15d2cc062e7ce5ef79aca90a9b049b (patch) | |
tree | 7a6de3f774ec9c4b3606765abdad47b4cf79eab4 | |
parent | feb3a24015949861e3c8cb75a0a70787760e0739 (diff) |
automated: Linux dd: improvements and bug fixes
* enable sh argument '-e'
* stop using partition and filesystem type variables in test case ID
* use convert_to_mb for result calculation which support floating point
* cope with shellcheck
Change-Id: I8f87c296280299d103eeb6f686b3fd8fecd62eb6
Signed-off-by: Chase Qi <chase.qi@linaro.org>
-rwxr-xr-x | automated/linux/dd-wr-speed/dd-wr-speed.sh | 61 |
1 files changed, 22 insertions, 39 deletions
diff --git a/automated/linux/dd-wr-speed/dd-wr-speed.sh b/automated/linux/dd-wr-speed/dd-wr-speed.sh index 6ba6723..d3e4946 100755 --- a/automated/linux/dd-wr-speed/dd-wr-speed.sh +++ b/automated/linux/dd-wr-speed/dd-wr-speed.sh @@ -1,10 +1,11 @@ -#!/bin/sh +#!/bin/sh -e +# shellcheck disable=SC1091 . ../../lib/sh-test-lib OUTPUT="$(pwd)/output" RESULT_FILE="${OUTPUT}/result.txt" +export RESULT_FILE ITERATION="5" -UNITS="MB/s" usage() { echo "Usage: $0 [-p <partition>] [-t <type>] [-i <iteration>] [-s <true>]" 1>&2 @@ -36,7 +37,8 @@ prepare_partition() { | awk -F '"' '{print $2}') # If PARTITION specified, its FS_TYPE needs to be specified explicitly. - [ -z "${FS_TYPE}" ] && error_msg "Please specify ${FS_TYPE} explicitly" + [ -z "${FS_TYPE}" ] && \ + error_msg "Please specify ${PARTITION} filesystem with -t" # Try to format the partition if it is unformatted or not the same as # the filesystem type specified with parameter '-t'. @@ -50,12 +52,7 @@ prepare_partition() { else echo "y" | mkfs -t "${FS_TYPE}" "${PARTITION}" fi - - if [ $? -ne 0 ]; then - error_msg "unable to format ${PARTITION}" - else - info_msg "${PARTITION} formatted to ${FS_TYPE}" - fi + info_msg "${PARTITION} formatted to ${FS_TYPE}" fi fi @@ -64,11 +61,7 @@ prepare_partition() { if [ -z "${mount_point}" ]; then mount_point="/mnt" mount "${PARTITION}" "${mount_point}" - if [ $? -ne 0 ]; then - error_msg "Unable to mount ${PARTITION}" - else - info_msg "${PARTITION} mounted to ${mount_point}" - fi + info_msg "${PARTITION} mounted to ${mount_point}" fi cd "${mount_point}" fi @@ -101,41 +94,28 @@ dd_read() { } parse_output() { - local test="$1" - local test_case_id="${test}" - if ! [ -f "${OUTPUT}/${test}-output.txt" ]; then - warn_msg "output file is missing" + test_case_id="$1" + if ! [ -f "${OUTPUT}/${test_case_id}-output.txt" ]; then + warn_msg "${test_case_id} output file is missing" return 1 fi - # Fixup test-case-id with filesystem type and partion name. - [ -n "${FS_TYPE}" ] && test_case_id="${FS_TYPE}-${test_case_id}" - if [ -n "${PARTITION}" ]; then - partition_no="$(echo "${PARTITION}" |awk -F '/' '{print $NF}')" - test_case_id="${partition_no}-${test_case_id}" - fi - itr=1 - while read line; do + while read -r line; do if echo "${line}" | egrep -q "(M|G)B/s"; then measurement="$(echo "${line}" | awk '{print $(NF-1)}')" - units="$(echo "${line}" | awk '{print $NF}')" - - if [ "${units}" = "GB/s" ]; then - measurement=$(( measurement * 1024 )) - elif [ "${units}" = "KB/s" ]; then - measurement=$(( measurement / 1024 )) - fi + units="$(echo "${line}" | awk '{print substr($NF,1,2)}')" + result=$(convert_to_mb "${measurement}" "${units}") - add_metric "${test_case_id}-itr${itr}" "pass" "${measurement}" "${UNITS}" + add_metric "${test_case_id}-itr${itr}" "pass" "${result}" "MB/s" itr=$(( itr + 1 )) fi - done < "${OUTPUT}/${test}-output.txt" + done < "${OUTPUT}/${test_case_id}-output.txt" # For mutiple times dd test, calculate the mean, min and max values. # Save them to result.txt. if [ "${ITERATION}" -gt 1 ]; then - eval "$(grep "${test}" "${OUTPUT}"/result.txt \ + eval "$(grep "${test_case_id}" "${OUTPUT}"/result.txt \ | awk '{ if(min=="") {min=max=$3}; if($3>max) {max=$3}; @@ -146,9 +126,12 @@ parse_output() { print "mean="total/count, "min="min, "max="max; }')" - add_metric "${test_case_id}-mean" "pass" "${mean}" "${UNITS}" - add_metric "${test_case_id}-min" "pass" "${min}" "${UNITS}" - add_metric "${test_case_id}-max" "pass" "${max}" "${UNITS}" + # shellcheck disable=SC2154 + add_metric "${test_case_id}-mean" "pass" "${mean}" "MB/s" + # shellcheck disable=SC2154 + add_metric "${test_case_id}-min" "pass" "${min}" "MB/s" + # shellcheck disable=SC2154 + add_metric "${test_case_id}-max" "pass" "${max}" "MB/s" fi } |