run_unit_tests.sh 2.2 KB

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