Merge pull request #3674 from jet47:colorize-run-test-script-2.4

This commit is contained in:
Vadim Pisarevsky 2015-02-05 07:35:01 +00:00
commit 98f9a013d1

View File

@ -1,36 +1,99 @@
#!/bin/sh
# Text style
TEXT_RED="$(tput setaf 1)"
TEXT_GREEN="$(tput setaf 2)"
TEXT_CYAN="$(tput setaf 6)"
TEXT_RESET="$(tput sgr0)"
# Test binaries and data paths
OPENCV_TEST_PATH=@CMAKE_INSTALL_PREFIX@/@OPENCV_TEST_INSTALL_PATH@
OPENCV_PYTHON_TESTS=@OPENCV_PYTHON_TESTS_LIST@
export OPENCV_TEST_DATA_PATH=@CMAKE_INSTALL_PREFIX@/share/OpenCV/testdata
# Run tests
SUMMARY_STATUS=0
FAILED_TESTS=""
PASSED_TESTS=""
for t in "$OPENCV_TEST_PATH/"opencv_test_* "$OPENCV_TEST_PATH/"opencv_perf_*;
do
report="`basename "$t"`-`date --rfc-3339=date`.xml"
"$t" --perf_min_samples=1 --perf_force_samples=1 --gtest_output=xml:"$report"
TEST_STATUS=$?
if [ $TEST_STATUS -ne 0 ]; then
SUMMARY_STATUS=$TEST_STATUS
fi
test_name=`basename "$t"`
report="$test_name-`date --rfc-3339=date`.xml"
cmd="$t --perf_min_samples=1 --perf_force_samples=1 --gtest_output=xml:\"$report\""
seg_reg="s/^/${TEXT_CYAN}[$test_name]${TEXT_RESET} /" # append test name
seg_reg="${seg_reg};s/\[==========\]/${TEXT_GREEN}&${TEXT_RESET}/g" # green for [==========]
seg_reg="${seg_reg};s/\[----------\]/${TEXT_GREEN}&${TEXT_RESET}/g" # green for [----------]
seg_reg="${seg_reg};s/\[ RUN \]/${TEXT_GREEN}&${TEXT_RESET}/g" # green for [ RUN ]
seg_reg="${seg_reg};s/\[ OK \]/${TEXT_GREEN}&${TEXT_RESET}/g" # green for [ OK ]
seg_reg="${seg_reg};s/\[ FAILED \]/${TEXT_RED}&${TEXT_RESET}/g" # red for [ FAILED ]
seg_reg="${seg_reg};s/\[ PASSED \]/${TEXT_GREEN}&${TEXT_RESET}/g" # green for [ PASSED ]
echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} RUN : $cmd"
eval "$cmd" | sed -r "$seg_reg"
ret=${PIPESTATUS[0]}
echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} RETURN_CODE : $ret"
if [ $ret -ne 0 ]; then
echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} ${TEXT_RED}FAILED${TEXT_RESET}"
SUMMARY_STATUS=1
FAILED_TESTS="$FAILED_TESTS $test_name"
else
echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} ${TEXT_GREEN}OK${TEXT_RESET}"
PASSED_TESTS="$PASSED_TESTS $test_name"
fi
echo ""
done
for t in $OPENCV_PYTHON_TESTS;
do
report="`basename "$t"`-`date --rfc-3339=date`.xml"
py.test --junitxml $report "$OPENCV_TEST_PATH"/$t
TEST_STATUS=$?
if [ $TEST_STATUS -ne 0 ]; then
SUMMARY_STATUS=$TEST_STATUS
fi
test_name=`basename "$t"`
report="$test_name-`date --rfc-3339=date`.xml"
cmd="py.test --junitxml $report \"$OPENCV_TEST_PATH\"/$t"
seg_reg="s/^/${TEXT_CYAN}[$test_name]${TEXT_RESET} /" # append test name
echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} RUN : $cmd"
eval "$cmd" | sed -r "$seg_reg"
ret=${PIPESTATUS[0]}
echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} RETURN_CODE : $ret"
if [ $ret -ne 0 ]; then
echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} ${TEXT_RED}FAILED${TEXT_RESET}"
SUMMARY_STATUS=1
FAILED_TESTS="$FAILED_TESTS $test_name"
else
echo "${TEXT_CYAN}[$test_name]${TEXT_RESET} ${TEXT_GREEN}OK${TEXT_RESET}"
PASSED_TESTS="$PASSED_TESTS $test_name"
fi
echo ""
done
# Remove temporary test files
rm -f /tmp/__opencv_temp.*
# Report final status
echo "${TEXT_CYAN}===============================================================${TEXT_RESET}"
echo "${TEXT_CYAN}PASSED TESTS : $PASSED_TESTS${TEXT_RESET}"
echo "${TEXT_CYAN}FAILED TESTS : $FAILED_TESTS${TEXT_RESET}"
if [ $SUMMARY_STATUS -eq 0 ]; then
echo "All OpenCV tests finished successfully"
echo "${TEXT_GREEN}STATUS : OK${TEXT_RESET}"
echo "${TEXT_GREEN}STATUS : All OpenCV tests finished successfully${TEXT_RESET}"
else
echo "OpenCV tests finished with status $SUMMARY_STATUS"
echo "${TEXT_RED}STATUS : FAIL${TEXT_RESET}"
echo "${TEXT_RED}STATUS : OpenCV tests finished with status $SUMMARY_STATUS${TEXT_RESET}"
fi
return $SUMMARY_STATUS
exit $SUMMARY_STATUS