Jack He | c27d257 | 2018-07-25 12:02:22 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # A utility script that runs benchmark on Android device |
| 3 | # |
| 4 | # Note: Only one Android device can be connected when running this script |
| 5 | # |
| 6 | # Example usage: |
| 7 | # $ cd system/bt |
| 8 | # $ ./test/run_benchmarks.sh bluetooth_benchmark_example |
| 9 | |
| 10 | known_benchmarks=( |
| 11 | bluetooth_benchmark_thread_performance |
Hansong Zhang | 438b08c | 2018-08-14 14:29:23 -0700 | [diff] [blame] | 12 | bluetooth_benchmark_timer_performance |
Jack He | c27d257 | 2018-07-25 12:02:22 -0700 | [diff] [blame] | 13 | ) |
| 14 | |
| 15 | usage() { |
| 16 | binary="$(basename "$0")" |
| 17 | echo "Usage: ${binary} --help" |
| 18 | echo " ${binary} [-i <iterations>] [-s <specific device>] [--all] [<benchmark name>[.<filter>] ...] [--<arg> ...]" |
| 19 | echo |
| 20 | echo "Unknown long arguments are passed to the benchmark." |
| 21 | echo |
| 22 | echo "Known benchmark names:" |
| 23 | |
| 24 | for name in "${known_benchmarks[@]}" |
| 25 | do |
| 26 | echo " ${name}" |
| 27 | done |
| 28 | } |
| 29 | |
| 30 | iterations=1 |
| 31 | device= |
| 32 | benchmarks=() |
| 33 | benchmark_args=() |
| 34 | while [ $# -gt 0 ] |
| 35 | do |
| 36 | case "$1" in |
| 37 | -h|--help) |
| 38 | usage |
| 39 | exit 0 |
| 40 | ;; |
| 41 | -i) |
| 42 | shift |
| 43 | if [ $# -eq 0 ]; then |
| 44 | echo "error: number of iterations expected" 1>&2 |
| 45 | usage |
| 46 | exit 2 |
| 47 | fi |
| 48 | iterations=$(( $1 )) |
| 49 | shift |
| 50 | ;; |
| 51 | -s) |
| 52 | shift |
| 53 | if [ $# -eq 0 ]; then |
| 54 | echo "error: no device specified" 1>&2 |
| 55 | usage |
| 56 | exit 2 |
| 57 | fi |
| 58 | device="$1" |
| 59 | shift |
| 60 | ;; |
| 61 | --all) |
| 62 | benchmarks+=( "${known_benchmarks[@]}" ) |
| 63 | shift |
| 64 | ;; |
| 65 | --*) |
| 66 | benchmark_args+=( "$1" ) |
| 67 | shift |
| 68 | ;; |
| 69 | *) |
| 70 | benchmarks+=( "$1" ) |
| 71 | shift |
| 72 | ;; |
| 73 | esac |
| 74 | done |
| 75 | |
| 76 | if [ "${#benchmarks[@]}" -eq 0 ]; then |
| 77 | benchmarks+=( "${known_benchmarks[@]}" ) |
| 78 | fi |
| 79 | |
| 80 | adb=( "adb" ) |
| 81 | if [ -n "${device}" ]; then |
| 82 | adb+=( "-s" "${device}" ) |
| 83 | fi |
| 84 | |
| 85 | source ${ANDROID_BUILD_TOP}/build/envsetup.sh |
| 86 | target_arch=$(gettargetarch) |
| 87 | |
| 88 | failed_benchmarks=() |
| 89 | for spec in "${benchmarks[@]}" |
| 90 | do |
| 91 | name="${spec%%.*}" |
| 92 | if [[ $target_arch == *"64"* ]]; then |
| 93 | binary="/data/benchmarktest64/${name}/${name}" |
| 94 | else |
| 95 | binary="/data/benchmarktest/${name}/${name}" |
| 96 | fi |
| 97 | |
| 98 | push_command=( "${adb[@]}" push {"${ANDROID_PRODUCT_OUT}",}"${binary}" ) |
| 99 | benchmark_command=( "${adb[@]}" shell "${binary}" ) |
| 100 | if [ "${name}" != "${spec}" ]; then |
| 101 | filter="${spec#*.}" |
| 102 | benchmark_command+=( "--benchmark_filter=${filter}" ) |
| 103 | fi |
| 104 | benchmark_command+=( "${benchmark_args[@]}" ) |
| 105 | |
| 106 | echo "--- ${name} ---" |
| 107 | echo "pushing..." |
| 108 | "${push_command[@]}" |
| 109 | echo "running..." |
| 110 | failed_count=0 |
| 111 | for i in $(seq 1 ${iterations}) |
| 112 | do |
| 113 | "${benchmark_command[@]}" || failed_count=$(( $failed_count + 1 )) |
| 114 | done |
| 115 | |
| 116 | if [ $failed_count != 0 ]; then |
| 117 | failed_benchmarks+=( "${name} ${failed_count}/${iterations}" ) |
| 118 | fi |
| 119 | done |
| 120 | |
| 121 | if [ "${#failed_benchmarks[@]}" -ne 0 ]; then |
| 122 | for failed_benchmark in "${failed_benchmarks[@]}" |
| 123 | do |
| 124 | echo "!!! FAILED TEST: ${failed_benchmark} !!!" |
| 125 | done |
| 126 | exit 1 |
| 127 | fi |
| 128 | |
| 129 | exit 0 |