OSDN Git Service

[automerger skipped] Send a response to an smp security request depending on the...
[android-x86/system-bt.git] / test / run_unit_tests.sh
1 #!/bin/sh
2
3 known_tests=(
4   audio_bluetooth_hw_test
5   bluetooth-test-audio-hal-interface
6   bluetooth_test_common
7   bluetoothtbd_test
8   net_test_audio_a2dp_hw
9   net_test_avrcp
10   net_test_bluetooth
11   net_test_btcore
12   net_test_bta
13   net_test_btif
14   net_test_btif_profile_queue
15   net_test_btif_config_cache
16   net_test_device
17   net_test_hci
18   net_test_stack
19   net_test_stack_multi_adv
20   net_test_stack_ad_parser
21   net_test_stack_smp
22   net_test_types
23   net_test_btu_message_loop
24   net_test_osi
25   net_test_performance
26   net_test_stack_rfcomm
27   net_test_gatt_conn_multiplexing
28 )
29
30 known_remote_tests=(
31   net_test_rfcomm_suite
32 )
33
34
35 usage() {
36   binary="$(basename "$0")"
37   echo "Usage: ${binary} --help"
38   echo "       ${binary} [-i <iterations>] [-s <specific device>] [--all] [<test name>[.<filter>] ...] [--<arg> ...]"
39   echo
40   echo "Unknown long arguments are passed to the test."
41   echo
42   echo "Known test names:"
43
44   for name in "${known_tests[@]}"
45   do
46     echo "    ${name}"
47   done
48
49   echo
50   echo "Known tests that need a remote device:"
51   for name in "${known_remote_tests[@]}"
52   do
53     echo "    ${name}"
54   done
55 }
56
57 iterations=1
58 device=
59 tests=()
60 test_args=()
61 while [ $# -gt 0 ]
62 do
63   case "$1" in
64     -h|--help)
65       usage
66       exit 0
67       ;;
68     -i)
69       shift
70       if [ $# -eq 0 ]; then
71         echo "error: number of iterations expected" 1>&2
72         usage
73         exit 2
74       fi
75       iterations=$(( $1 ))
76       shift
77       ;;
78     -s)
79       shift
80       if [ $# -eq 0 ]; then
81         echo "error: no device specified" 1>&2
82         usage
83         exit 2
84       fi
85       device="$1"
86       shift
87       ;;
88     --all)
89       tests+=( "${known_tests[@]}" )
90       shift
91       ;;
92     --*)
93       test_args+=( "$1" )
94       shift
95       ;;
96     *)
97       tests+=( "$1" )
98       shift
99       ;;
100   esac
101 done
102
103 if [ "${#tests[@]}" -eq 0 ]; then
104   tests+=( "${known_tests[@]}" )
105 fi
106
107 adb=( "adb" )
108 if [ -n "${device}" ]; then
109   adb+=( "-s" "${device}" )
110 fi
111
112 source ${ANDROID_BUILD_TOP}/build/envsetup.sh
113 target_arch=$(gettargetarch)
114
115 failed_tests=()
116 for spec in "${tests[@]}"
117 do
118   name="${spec%%.*}"
119   if [[ $target_arch == *"64"* ]]; then
120     binary="/data/nativetest64/${name}/${name}"
121   else
122     binary="/data/nativetest/${name}/${name}"
123   fi
124
125   push_command=( "${adb[@]}" push {"${ANDROID_PRODUCT_OUT}",}"${binary}" )
126   test_command=( "${adb[@]}" shell "${binary}" )
127   if [ "${name}" != "${spec}" ]; then
128     filter="${spec#*.}"
129     test_command+=( "--gtest_filter=${filter}" )
130   fi
131   test_command+=( "${test_args[@]}" )
132
133   echo "--- ${name} ---"
134   echo "pushing..."
135   "${push_command[@]}"
136   echo "running..."
137   failed_count=0
138   for i in $(seq 1 ${iterations})
139   do
140     "${test_command[@]}" || failed_count=$(( $failed_count + 1 ))
141   done
142
143   if [ $failed_count != 0 ]; then
144     failed_tests+=( "${name} ${failed_count}/${iterations}" )
145   fi
146 done
147
148 if [ "${#failed_tests[@]}" -ne 0 ]; then
149   for failed_test in "${failed_tests[@]}"
150   do
151     echo "!!! FAILED TEST: ${failed_test} !!!"
152   done
153   exit 1
154 fi
155
156 exit 0