blob: b09487592e313d0ed55d64b9d87f1d9f27b2ec49 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#!/bin/sh -ex
HOST_OUTPUT="$(pwd)/output"
LOCAL_DEVICE_OUTPUT="${HOST_OUTPUT}/device-output"
DEVICE_OUTPUT="/data/local/tmp/dd-wr-speed"
SN=""
BOOT_TIMEOUT="300"
ITERATION="5"
PARTITION=""
RESULT_FILE="${HOST_OUTPUT}/result.txt"
export RESULT_FILE
usage() {
echo "Usage: $0 [-p <partition>] [-i <iteration>] [-s <sn>] [-t <timeout>]" 1>&2
exit 1
}
while getopts ":p:i:s:t:" 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}" ;;
t) BOOT_TIMEOUT="${OPTARG}" ;;
*) usage ;;
esac
done
# shellcheck disable=SC1091
. ../../lib/sh-test-lib
# shellcheck disable=SC1091
. ../../lib/android-test-lib
parse_output() {
test_case_id="$1"
if ! [ -f "${LOCAL_DEVICE_OUTPUT}/${test_case_id}-output.txt" ]; then
warn_msg "${test_case_id} result file missing"
return 1
fi
# Parse raw output and add results to ${RESULT_FILE}.
itr=1
info_msg "Parsing ${test_case_id} output..."
while read -r line; do
if echo "${line}" | grep -E "(M|G)B/s"; then
# busybox dd print test result in the format "39.8MB/s".
units=$(echo "${line}" | awk '{print substr($NF,(length($NF)-3),2)}')
measurement=$(echo "${line}" | awk '{print substr($NF,1,(length($NF)-4))}')
measurement=$(convert_to_mb "${measurement}" "${units}")
add_metric "${test_case_id}-itr${itr}" "pass" "${measurement}" "MB/s"
itr=$(( itr + 1 ))
fi
done < "${LOCAL_DEVICE_OUTPUT}/${test_case_id}"-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_case_id}" "${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;
}')"
# 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
}
# Test run.
create_out_dir "${HOST_OUTPUT}"
mkdir -p "${LOCAL_DEVICE_OUTPUT}"
initialize_adb
wait_boot_completed "${BOOT_TIMEOUT}"
detect_abi
# shellcheck disable=SC2154
adb_push "../../bin/${abi}/busybox" "/data/local/tmp/bin/"
adb_push "./device-script.sh" "/data/local/tmp/bin"
info_msg "About to run dd speed test on device ${SN}"
adb -s "${SN}" shell "echo /data/local/tmp/bin/device-script.sh ${ITERATION} ${DEVICE_OUTPUT} ${PARTITION} | su" 2>&1 | tee "${HOST_OUTPUT}/device-stdout.log"
adb_pull "${DEVICE_OUTPUT}" "${LOCAL_DEVICE_OUTPUT}"
parse_output "dd-write"
parse_output "dd-read"
|