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