From: <svn...@op...> - 2009-04-03 19:38:39
|
Author: bellmich Date: Fri Apr 3 21:38:13 2009 New Revision: 1030 URL: http://libsyncml.opensync.org/changeset/1030 Log: added support for coverage analysis If you want to get the coverage then run cmake and execute coverage.sh. Added: trunk/tests/coverage.sh.cmake (contents, props changed) Modified: trunk/tests/CMakeLists.txt Modified: trunk/tests/CMakeLists.txt ============================================================================== --- trunk/tests/CMakeLists.txt Fri Apr 3 17:12:26 2009 (r1029) +++ trunk/tests/CMakeLists.txt Fri Apr 3 21:38:13 2009 (r1030) @@ -71,3 +71,4 @@ ENDIF( ENABLE_UNIT_TEST ) +CONFIGURE_FILE( "coverage.sh.cmake" "${CMAKE_BINARY_DIR}/coverage.sh") Added: trunk/tests/coverage.sh.cmake ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/tests/coverage.sh.cmake Fri Apr 3 21:38:13 2009 (r1030) @@ -0,0 +1,65 @@ +#!/bin/sh + +echo -n "Checking Code Coverage of unit tests" +DATE=$( date +%Y%m%d%H%M%S ) + +if [ -d .svn ]; then + REV=`LANG=C svn info | grep Revision | cut -c 11-` + echo " for SVN Revision: $REV" + TITLE="libsyncml_SVN"$REV"_"$DATE +else + echo ":" + TITLE="libsyncml_"$DATE +fi +echo $TITLE + +if ! [ -d coverage/html ]; then + mkdir -p coverage/html +fi + +## compile tests +RESULT=`find ${CMAKE_CURRENT_BINARY_DIR} -name "*.o" -print | wc -l` +if [ "$RESULT" == "0" ]; then + make +fi + +## create gcda files +RESULT=`find ${CMAKE_CURRENT_BINARY_DIR} -name "*.gcda" -print | wc -l` +if [ "$RESULT" == "0" ]; then + ctest -R "^error$" +fi + +## analyze statistics +lcov \ + --test-name "$TITLE" \ + --base-directory ${CMAKE_SOURCE_DIR} \ + --directory ${CMAKE_CURRENT_BINARY_DIR} \ + --quiet \ + --capture \ + --output-file coverage/$TITLE.info +genhtml --legend -t "$TITLE" -o coverage/html/$TITLE coverage/$TITLE.info &> /dev/null + +cd coverage/html/ +ln -sf $TITLE LATEST +cd ../../ + +## cleanup gcda files +lcov \ + --test-name "$TITLE" \ + --base-directory ${CMAKE_SOURCE_DIR} \ + --directory ${CMAKE_BINARY_DIR} \ + --quiet \ + --zerocounters \ + --output-file coverage/$TITLE.info + +echo -n "Code Coverage is: " +grep " %</td>" coverage/html/$TITLE/index.html | sed -e "s/^[^>]*>//g" -e "s/<[^>]*>//g" +echo -n "" +echo -e "\nTroubleshooting:\n If the Code Coverage number is quite low (less then 51%):" +echo -e "\t-Did you run any unit tests before $0?" +echo -e "\t-Did you build with enable_profiling=1?" +echo -e "\t-Run ALL available unit tests!" +echo -e "\t-Check if testcases in unit test are disabled!" +echo -e "\t-Fix unit tests and their test cases!" +echo -e "\t-Write new and more test cases!" +exit 0 |