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