diff options
author | Naresh Kamboju <naresh.kamboju@linaro.org> | 2016-09-02 08:04:42 +0000 |
---|---|---|
committer | Linaro Code Review <review@review.linaro.org> | 2016-09-02 08:04:42 +0000 |
commit | d805476cd80076ab2da02962b1f964748efd27bd (patch) | |
tree | 03f2671ed813e670719a59f60b6fdcc2c25c702d | |
parent | 44023f46ae4b1a3579b480ed858abf1c6a9e100e (diff) | |
parent | d469bcef58196c215a2c806014ab8c053d229f21 (diff) |
Merge "v2: android: add dd write/read speed test"
-rwxr-xr-x | automated/android/dd-wr-speed/dd-wr-speed.sh | 108 | ||||
-rw-r--r-- | automated/android/dd-wr-speed/dd-wr-speed.yaml | 32 | ||||
-rwxr-xr-x | automated/android/dd-wr-speed/device-script.sh | 62 |
3 files changed, 202 insertions, 0 deletions
diff --git a/automated/android/dd-wr-speed/dd-wr-speed.sh b/automated/android/dd-wr-speed/dd-wr-speed.sh new file mode 100755 index 0000000..bd38473 --- /dev/null +++ b/automated/android/dd-wr-speed/dd-wr-speed.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +HOST_OUTPUT="$(pwd)/output" +DEVICE_OUTPUT="/sdcard/tests/dd-wr-speed" +RESULT_FILE="${HOST_OUTPUT}/result.txt" +ITERATION="5" +PARTITION="" + +usage() { + echo "Usage: $0 [-p <partition>] [-i <iteration>] [-s <sn>]" 1>&2 + exit 1 +} + +while getopts "p:i:s:" o; do + case "$o" in + # "/data" partition will be used by default. Use '-p' to specify an + # external partition as needed, the partition will be formatted to vfat, + # and all data will be lost. + p) PARTITION="${OPTARG}" ;; + # You may need to run dd test 4-5 times for an accurate evaluation. + i) ITERATION="${OPTARG}" ;; + # Specify device serial number when more than one device connected. + s) SN="${OPTARG}" ;; + *) usage ;; + esac +done + +. ../../lib/sh-test-lib +. ../../lib/android-test-lib + +parse_output() { + local test="$1" + local test_case_id="${test}" + local UNITS="MB/s" + + if ! [ -f "${HOST_OUTPUT}/${test}-output.txt" ]; then + warn_msg "${test} result file missing" + return + fi + + # Fixup test case id with partition and filesystem. + if [ -n "${PARTITION}" ]; then + partition_name="$(basename "${PARTITION}")" + test_case_id="${partition_name}-vfat-${test_case_id}" + else + filesystem="$(adb -s "${SN}" shell mount \ + | grep "/data" | awk '{print $3}')" + test_case_id="emmc-${filesystem}-${test_case_id}" + fi + + # Parse raw output and add results to ${RESULT_FILE}. + itr=1 + info_msg "Parsing ${test} output..." + while read line; do + if echo "${line}" | egrep -q "(M|G)B/s"; then + # busybox dd print test result in the format "39.8MB/s". + result="$(echo "${line}" | awk '{print $NF}')" + units="$(printf "%s" "${result}" | tail -c 4)" + measurement="$(printf "%s" "${result}" | tr -d "${units}")" + + if [ "${units}" = "GB/s" ]; then + measurement=$(( measurement * 1024 )) + elif [ "${units}" = "KB/s" ]; then + measurement=$(( measurement / 1024 )) + fi + + add_metric "${test_case_id}-itr${itr}" "pass" "${measurement}" "${UNITS}" + itr=$(( itr + 1 )) + fi + done < "${HOST_OUTPUT}/${test}"-output.txt + + # For multiple times dd test, calculate the mean, min and max values. + # Save them to ${RESULT_FILE}. + if [ "${ITERATION}" -gt 1 ]; then + eval "$(grep "${test}" "${HOST_OUTPUT}"/result.txt \ + | awk '{ + if(min=="") {min=max=$3}; + if($3>max) {max=$3}; + if($3< min) {min=$3}; + total+=$3; count+=1; + } + END { + 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}" + fi +} + +# Test run. +[ -d "${HOST_OUTPUT}" ] && mv "${HOST_OUTPUT}" "${HOST_OUTPUT}-$(date +%Y%m%d%H%M%S)" +mkdir -p "${HOST_OUTPUT}" + +initialize_adb +detect_abi +install "../../bin/${abi}/busybox" +install "./device-script.sh" + +info_msg "About to run dd speed test on device ${SN}" +adb -s "${SN}" shell device-script.sh "${ITERATION}" "${PARTITION}" "${DEVICE_OUTPUT}" 2>&1 \ + | tee "${HOST_OUTPUT}"/device-run.log + +pull_output "${DEVICE_OUTPUT}" "${HOST_OUTPUT}" + +parse_output "dd-write" +parse_output "dd-read" diff --git a/automated/android/dd-wr-speed/dd-wr-speed.yaml b/automated/android/dd-wr-speed/dd-wr-speed.yaml new file mode 100644 index 0000000..f7b59f1 --- /dev/null +++ b/automated/android/dd-wr-speed/dd-wr-speed.yaml @@ -0,0 +1,32 @@ +metadata: + name: dd-speed-test + format: "Lava-Test-Shell Test Definition 1.0" + description: "dd write/read speed test." + maintainer: + - chase.qi@linaro.org + os: + - android + devices: + - hi6220-hikey + - apq8016-sbc + scope: + - performance + environment: + - lava-test-shell + - local-test-runner + +params: + # /data partition will be tested by default. + # Use '-p' specify partition. Example "/dev/block/mmcblk1p1" + PARTITION: "" + # You may need to run dd test 4-5 times for an accurate evaluation. + ITERATION: "5" + # Specify device serial number for adb connection if more than one device + # connected. + SN: "" + +run: + steps: + - cd ./automated/android/dd-wr-speed + - ./dd-wr-speed.sh -p "${PARTITION}" -i "${ITERATION}" -s "${SN}" + - ../../utils/send-to-lava.sh ./output/result.txt diff --git a/automated/android/dd-wr-speed/device-script.sh b/automated/android/dd-wr-speed/device-script.sh new file mode 100755 index 0000000..66ce843 --- /dev/null +++ b/automated/android/dd-wr-speed/device-script.sh @@ -0,0 +1,62 @@ +#!/system/bin/sh + +ITERATION="$1" +PARTITION="$2" +OUTPUT="$3" + +if [ "$#" -ne 3 ]; then + echo "ERROR: Usage: $0 ITERATION PARTITION OUTPUT" + exit 1 +fi + +[ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}-$(date +%Y%m%d%H%M%S)" +mkdir -p "${OUTPUT}" && cd "${OUTPUT}" + +# If partition specified, format it to vfat, and mount it to /mnt/dd_test. +# Then enter the mount point to do dd test. +if [ -n "${PARTITION}" ]; then + partition_name="$(basename "${PARTITION}")" + partition_numbers="$(grep "${partition_name}" /proc/partitions \ + | awk '{print $1","$2}')" + + if [ -z "${partition_numbers}" ]; then + echo "ERROR: ${PARTITION} NOT found" && exit 1 + else + # Attemp to umount it in case it is mounted by Android vold. + umount "/dev/block/vold/public:${partition_numbers}" > /dev/null 2>&1 + umount "${PARTITION}" > /dev/null 2>&1 + + echo "INFO: formatting ${PARTITION} to vfat..." + busybox mkfs.vfat "${PARTITION}" + sync && sleep 10 + + mkdir -p /mnt/dd_test + mount -t vfat "/dev/block/vold/public:${partition_numbers}" \ + /mnt/dd_test/ + if [ $? -eq 0 ]; then + echo "INFO: Mounted ${PARTITION} to /mnt/dd_test" + else + echo "ERROR: failed to mount ${PARTITION}" && exit 1 + fi + + cd /mnt/dd_test + echo "INFO: dd test directory: $(pwd)" + fi +fi + +# Run dd write/read test. +for i in $(seq "${ITERATION}"); do + echo + echo "INFO: Running dd write test [$i/${ITERATION}]" + echo 3 > /proc/sys/vm/drop_caches + busybox dd if=/dev/zero of=dd.img bs=1048576 count=1024 conv=fsync 2>&1 \ + | tee -a "${OUTPUT}"/dd-write-output.txt + + echo + echo "INFO: Running dd read test [$i/${ITERATION}]" + echo 3 > /proc/sys/vm/drop_caches + busybox dd if=dd.img of=/dev/null bs=1048576 count=1024 2>&1 \ + | tee -a "${OUTPUT}"/dd-read-output.txt + + rm dd.img +done |