run_unit_tests.sh revision a05d9361b618b051170505b0fab5874264178215
1#!/usr/bin/env bash
2
3CR=$'\n'
4
5known_tests=(
6  net_test_btcore
7  net_test_device
8  net_test_hci
9  net_test_osi
10)
11
12usage() {
13  echo "Usage: $0 --help"
14  echo "       $0 [-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
26iterations=1
27device=
28tests=()
29test_args=()
30while [ $# -gt 0 ]; do
31  case "$1" in
32    -h|--help)
33      usage
34      exit 0
35      ;;
36    -i)
37      shift
38      if [ $# -eq 0 ]; then
39        echo "error: number of iterations expected" 1>&2
40        usage
41        exit 1
42      fi
43      iterations=$(( $1 ))
44      shift
45      ;;
46    -s)
47      shift
48      if [ $# -eq 0 ]; then
49        echo "error: no device specified" 1>&2
50        usage
51        exit 1
52      fi
53      device="$1"
54      shift
55      ;;
56    --all)
57      tests+=( ${known_tests[*]} )
58      shift
59      ;;
60    --*)
61      test_args+=( "$1" )
62      shift
63      ;;
64    *)
65      tests+=( $1 )
66      shift
67      ;;
68  esac
69done
70
71if [ ${#tests[*]} -eq 0 ]; then
72  tests+=( ${known_tests[*]} )
73fi
74
75adb="adb${device:+ -s $device}"
76
77failed_tests=''
78for spec in ${tests[*]}
79do
80  name="${spec%%.*}"
81  if [ "${name}" != "${spec}" ]; then
82    filter="${spec#*.}"
83  fi
84  echo "--- $name ---"
85  echo "pushing..."
86  $adb push {$ANDROID_PRODUCT_OUT,}/data/nativetest/$name/$name
87  echo "running..."
88  failed_count=0
89  for i in $(seq 1 ${iterations})
90  do
91    $adb shell data/nativetest/$name/$name${filter:+ "--gtest_filter=${filter}"} ${test_args[*]} || failed_count=$(( $failed_count + 1 ))
92  done
93
94  if [ $failed_count != 0 ]; then
95    failed_tests="$failed_tests$CR!!! FAILED TEST: $name ${failed_count}/${iterations} !!!";
96  fi
97done
98
99if [ "$failed_tests" != "" ]; then
100  echo "$failed_tests";
101  exit 1
102fi
103
104exit 0
105