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