opencv_run_all_tests_unix.sh.in 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/bin/bash
  2. # Usage info
  3. usage()
  4. {
  5. cat << EOF
  6. usage: $0 [options]
  7. This script runs the OpenCV tests on linux device.
  8. OPTIONS:
  9. -h Show this message
  10. -c Color output
  11. EOF
  12. }
  13. # Parse options
  14. COLOR_OUTPUT=0
  15. while getopts “hc” OPTION
  16. do
  17. case $OPTION in
  18. h)
  19. usage
  20. exit 0
  21. ;;
  22. c)
  23. COLOR_OUTPUT=1
  24. ;;
  25. ?)
  26. usage
  27. exit 1
  28. ;;
  29. esac
  30. done
  31. # Text style
  32. if [ $COLOR_OUTPUT -eq 1 ]; then
  33. TEXT_RED="$(tput setaf 1)"
  34. TEXT_GREEN="$(tput setaf 2)"
  35. TEXT_CYAN="$(tput setaf 6)"
  36. TEXT_RESET="$(tput sgr0)"
  37. else
  38. TEXT_RED=""
  39. TEXT_GREEN=""
  40. TEXT_CYAN=""
  41. TEXT_RESET=""
  42. fi
  43. # Test binaries and data paths
  44. OPENCV_TEST_PATH=@CMAKE_INSTALL_PREFIX@/@OPENCV_TEST_INSTALL_PATH@
  45. OPENCV_PYTHON_TESTS=@OPENCV_PYTHON_TESTS_LIST@
  46. export OPENCV_TEST_DATA_PATH=@CMAKE_INSTALL_PREFIX@/share/OpenCV/testdata
  47. CUR_DIR=`pwd`
  48. if [ -d "$CUR_DIR" -a -w "$CUR_DIR" ]; then
  49. echo "${TEXT_CYAN}CUR_DIR : $CUR_DIR${TEXT_RESET}"
  50. else
  51. echo "${TEXT_RED}Error: Do not have permissions to write to $CUR_DIR${TEXT_RESET}"
  52. echo "${TEXT_RED}Please run the script from directory with write access${TEXT_RESET}"
  53. exit 1
  54. fi
  55. # Run tests
  56. SUMMARY_STATUS=0
  57. FAILED_TESTS=""
  58. PASSED_TESTS=""
  59. for t in "$OPENCV_TEST_PATH/"opencv_test_* "$OPENCV_TEST_PATH/"opencv_perf_*;
  60. do
  61. test_name=`basename "$t"`
  62. cmd="$t --perf_min_samples=1 --perf_force_samples=1 --gtest_output=xml:$test_name.xml"
  63. seg_reg="s/^/${TEXT_CYAN}[$test_name]${TEXT_RESET} /" # append test name
  64. if [ $COLOR_OUTPUT -eq 1 ]; then
  65. seg_reg="${seg_reg};s/\[==========\]/${TEXT_GREEN}&${TEXT_RESET}/g" # green for [==========]
  66. seg_reg="${seg_reg};s/\[----------\]/${TEXT_GREEN}&${TEXT_RESET}/g" # green for [----------]
  67. seg_reg="${seg_reg};s/\[ RUN \]/${TEXT_GREEN}&${TEXT_RESET}/g" # green for [ RUN ]
  68. seg_reg="${seg_reg};s/\[ OK \]/${TEXT_GREEN}&${TEXT_RESET}/g" # green for [ OK ]
  69. seg_reg="${seg_reg};s/\[ FAILED \]/${TEXT_RED}&${TEXT_RESET}/g" # red for [ FAILED ]
  70. seg_reg="${seg_reg};s/\[ PASSED \]/${TEXT_GREEN}&${TEXT_RESET}/g" # green for [ PASSED ]
  71. fi
  72. echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} RUN : $cmd"
  73. eval "$cmd" | tee "$test_name.log" | sed -r "$seg_reg"
  74. ret=${PIPESTATUS[0]}
  75. echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} RETURN_CODE : $ret"
  76. if [ $ret -ne 0 ]; then
  77. echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} ${TEXT_RED}FAILED${TEXT_RESET}"
  78. SUMMARY_STATUS=1
  79. FAILED_TESTS="$FAILED_TESTS $test_name"
  80. else
  81. echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} ${TEXT_GREEN}OK${TEXT_RESET}"
  82. PASSED_TESTS="$PASSED_TESTS $test_name"
  83. fi
  84. echo ""
  85. done
  86. for t in $OPENCV_PYTHON_TESTS;
  87. do
  88. test_name=`basename "$t"`
  89. cmd="py.test --junitxml $test_name.xml \"$OPENCV_TEST_PATH\"/$t"
  90. seg_reg="s/^/${TEXT_CYAN}[$test_name]${TEXT_RESET} /" # append test name
  91. echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} RUN : $cmd"
  92. eval "$cmd" | tee "$test_name.log" | sed -r "$seg_reg"
  93. ret=${PIPESTATUS[0]}
  94. echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} RETURN_CODE : $ret"
  95. if [ $ret -ne 0 ]; then
  96. echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} ${TEXT_RED}FAILED${TEXT_RESET}"
  97. SUMMARY_STATUS=1
  98. FAILED_TESTS="$FAILED_TESTS $test_name"
  99. else
  100. echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} ${TEXT_GREEN}OK${TEXT_RESET}"
  101. PASSED_TESTS="$PASSED_TESTS $test_name"
  102. fi
  103. echo ""
  104. done
  105. # Remove temporary test files
  106. rm -f /tmp/__opencv_temp.*
  107. # Report final status
  108. echo "${TEXT_CYAN}===============================================================${TEXT_RESET}"
  109. echo "${TEXT_CYAN}PASSED TESTS : $PASSED_TESTS${TEXT_RESET}"
  110. echo "${TEXT_CYAN}FAILED TESTS : $FAILED_TESTS${TEXT_RESET}"
  111. if [ $SUMMARY_STATUS -eq 0 ]; then
  112. echo "${TEXT_GREEN}STATUS : OK${TEXT_RESET}"
  113. echo "${TEXT_GREEN}STATUS : All OpenCV tests finished successfully${TEXT_RESET}"
  114. else
  115. echo "${TEXT_RED}STATUS : FAIL${TEXT_RESET}"
  116. echo "${TEXT_RED}STATUS : OpenCV tests finished with status $SUMMARY_STATUS${TEXT_RESET}"
  117. fi
  118. exit $SUMMARY_STATUS