1#!/bin/sh
2
3known_tests=(
4  nfc_test_utils
5)
6
7known_remote_tests=(
8)
9
10
11usage() {
12  binary="$(basename "$0")"
13  echo "Usage: ${binary} --help"
14  echo "       ${binary} [-i <iterations>] [-s <specific device>] [--all] [<test name>[.<filter>] ...] [--<arg> ...]"
15  echo
16  echo "Unknown long arguments are passed to the test."
17  echo
18  echo "Known test names:"
19
20  for name in "${known_tests[@]}"
21  do
22    echo "    ${name}"
23  done
24
25  echo
26  echo "Known tests that need a remote device:"
27  for name in "${known_remote_tests[@]}"
28  do
29    echo "    ${name}"
30  done
31}
32
33iterations=1
34device=
35tests=()
36test_args=()
37while [ $# -gt 0 ]
38do
39  case "$1" in
40    -h|--help)
41      usage
42      exit 0
43      ;;
44    -i)
45      shift
46      if [ $# -eq 0 ]; then
47        echo "error: number of iterations expected" 1>&2
48        usage
49        exit 2
50      fi
51      iterations=$(( $1 ))
52      shift
53      ;;
54    -s)
55      shift
56      if [ $# -eq 0 ]; then
57        echo "error: no device specified" 1>&2
58        usage
59        exit 2
60      fi
61      device="$1"
62      shift
63      ;;
64    --all)
65      tests+=( "${known_tests[@]}" )
66      shift
67      ;;
68    --*)
69      test_args+=( "$1" )
70      shift
71      ;;
72    *)
73      tests+=( "$1" )
74      shift
75      ;;
76  esac
77done
78
79if [ "${#tests[@]}" -eq 0 ]; then
80  tests+=( "${known_tests[@]}" )
81fi
82
83adb=( "adb" )
84if [ -n "${device}" ]; then
85  adb+=( "-s" "${device}" )
86fi
87
88failed_tests=()
89for spec in "${tests[@]}"
90do
91  name="${spec%%.*}"
92  binary="/data/nativetest/${name}/${name}"
93
94  push_command=( "${adb[@]}" push {"${ANDROID_PRODUCT_OUT}",}"${binary}" )
95  test_command=( "${adb[@]}" shell "${binary}" )
96  if [ "${name}" != "${spec}" ]; then
97    filter="${spec#*.}"
98    test_command+=( "--gtest_filter=${filter}" )
99  fi
100  test_command+=( "${test_args[@]}" )
101
102  echo "--- ${name} ---"
103  echo "pushing..."
104  "${push_command[@]}"
105  echo "running..."
106  failed_count=0
107  for i in $(seq 1 ${iterations})
108  do
109    "${test_command[@]}" || failed_count=$(( $failed_count + 1 ))
110  done
111
112  if [ $failed_count != 0 ]; then
113    failed_tests+=( "${name} ${failed_count}/${iterations}" )
114  fi
115done
116
117if [ "${#failed_tests[@]}" -ne 0 ]; then
118  for failed_test in "${failed_tests[@]}"
119  do
120    echo "!!! FAILED TEST: ${failed_test} !!!"
121  done
122  exit 1
123fi
124
125exit 0
126