1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#!/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 ${CMAKE_BINARY_DIR}/coverage/html ]; then
mkdir -p ${CMAKE_BINARY_DIR}/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 .
fi
## analyze statistics
lcov \
--test-name "$TITLE" \
--base-directory ${CMAKE_SOURCE_DIR} \
--directory ${CMAKE_BINARY_DIR} \
--quiet \
--capture \
--output-file ${CMAKE_BINARY_DIR}/coverage/$TITLE.info
genhtml --legend -t "$TITLE" -o ${CMAKE_BINARY_DIR}/coverage/html/$TITLE ${CMAKE_BINARY_DIR}/coverage/$TITLE.info &> /dev/null
cd ${CMAKE_BINARY_DIR}/coverage/html/
if [ -e LATEST ]; then rm -f LATEST; fi
ln -s $TITLE LATEST
cd ${CMAKE_BINARY_DIR}
## 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
|