2009-04-28 08:52:41 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
check_coverage() {
|
|
|
|
|
source_file=$1
|
|
|
|
|
source_dir=$(dirname ${source_file})
|
|
|
|
|
base_file=$(basename ${source_file} .cpp)
|
|
|
|
|
test_program=tests/${base_file}test
|
|
|
|
|
coverage_data=${source_dir}/${base_file}.gcda
|
2009-04-28 11:33:39 +01:00
|
|
|
|
|
|
|
|
if [ ! -f ${test_program}.cpp ]
|
2009-04-29 01:12:53 +01:00
|
|
|
then
|
2009-07-17 09:35:52 +02:00
|
|
|
if [ ${report} -eq 1 -o ${single} -eq 1 ]
|
2009-04-29 01:12:53 +01:00
|
|
|
then
|
2009-11-09 03:10:17 +00:00
|
|
|
if grep -l DOXYGEN_SHOULD_SKIP_THIS ${source_file} > /dev/null
|
|
|
|
|
then
|
|
|
|
|
true
|
|
|
|
|
else
|
|
|
|
|
echo No test for ${source_file}
|
|
|
|
|
fi
|
2009-04-29 01:12:53 +01:00
|
|
|
fi
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ ${report} -eq 1 ]
|
2009-04-28 08:52:41 +01:00
|
|
|
then
|
|
|
|
|
return
|
|
|
|
|
fi
|
2009-04-28 11:33:39 +01:00
|
|
|
|
|
|
|
|
if [ ! -x ${test_program} ]
|
|
|
|
|
then
|
2009-05-06 15:06:53 +01:00
|
|
|
echo Test programs have not been built for ${source_file}
|
2010-03-19 02:38:50 +00:00
|
|
|
return
|
2009-04-28 11:33:39 +01:00
|
|
|
fi
|
2009-04-28 08:52:41 +01:00
|
|
|
|
|
|
|
|
if [ ${source_file} -nt ${test_program} ]
|
|
|
|
|
then
|
2009-05-21 19:11:51 +01:00
|
|
|
echo Test build is out of date for ${source_file}
|
2009-04-28 08:52:41 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2009-04-28 18:54:54 +01:00
|
|
|
if [ -f ${coverage_data} ]
|
|
|
|
|
then
|
|
|
|
|
rm -f ${coverage_data}
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
${test_program} > /dev/null 2>&1
|
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo FAIL
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2009-04-28 08:52:41 +01:00
|
|
|
if [ ! -f ${coverage_data} ]
|
|
|
|
|
then
|
2009-04-28 11:33:39 +01:00
|
|
|
if [ ! -f ${source_dir}/${base_file}.gcno ]
|
|
|
|
|
then
|
2009-07-17 09:35:52 +02:00
|
|
|
if [ ${single} -eq 1 ]
|
|
|
|
|
then
|
|
|
|
|
echo No code to be covered in ${source_file}
|
|
|
|
|
fi
|
2009-04-28 11:33:39 +01:00
|
|
|
return
|
|
|
|
|
fi
|
2009-05-06 17:44:42 +01:00
|
|
|
echo No coverage data ${coverage_data} for ${source_file}
|
2009-04-28 08:52:41 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ ${test_program} -nt ${coverage_data} ]
|
|
|
|
|
then
|
2009-04-28 18:54:54 +01:00
|
|
|
echo Coverage is out of date for ${source_file}
|
2009-04-28 08:52:41 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2012-08-03 12:49:58 +01:00
|
|
|
coverage_digest=$( (cd ${source_dir} && LC_ALL=C gcov ${source_file}) | \
|
2012-08-02 18:30:41 +01:00
|
|
|
grep -A 1 -e "^File '${base_file}.cpp" \
|
2012-08-03 12:49:58 +01:00
|
|
|
-e "^File '${base_file}.h" \
|
2012-08-02 18:30:41 +01:00
|
|
|
-e "^File '${base_file}_impl.h" | \
|
2012-08-03 12:49:58 +01:00
|
|
|
grep -e "^Lines" -e "^File" | \
|
|
|
|
|
sed "s/^File '\([A-Za-z0-9_]\+\.\(h\|cpp\)\)'.*$/${source_dir}\/\1/" |
|
2010-11-19 00:59:10 +00:00
|
|
|
sed "s/^Lines executed:\([0-9]\+\.[0-9]\+\)% of .*$/\1/")
|
2009-04-28 11:33:39 +01:00
|
|
|
|
2012-08-03 12:49:58 +01:00
|
|
|
echo ${coverage_digest}
|
2009-04-28 08:52:41 +01:00
|
|
|
}
|
|
|
|
|
|
2009-04-29 01:12:53 +01:00
|
|
|
usage() {
|
2009-06-24 02:54:39 +01:00
|
|
|
echo "Automate running coverage tools, and generate concise report."
|
|
|
|
|
echo "usage: run_coverage_tests.sh [OPTION]"
|
|
|
|
|
echo " run_coverage_tests.sh [SOURCEFILE]"
|
|
|
|
|
echo "Options:"
|
2009-11-09 03:11:30 +00:00
|
|
|
echo " -r Report source files with no coverage test"
|
2009-06-24 02:54:39 +01:00
|
|
|
echo " -c Re-configure the build to include coverage data"
|
|
|
|
|
echo " -h Display this usage data"
|
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
|
|
To pruduce results run this build requires an in-tree build with gcc
|
|
|
|
|
configured to include coverage data. Use the -c option to run configure
|
|
|
|
|
with the right options, and run "make clean all check" to fully prepare
|
|
|
|
|
the build. Running without arguments shows results for all source files
|
|
|
|
|
in the configured directories.
|
|
|
|
|
|
|
|
|
|
Each file is covered by a test derived from it's name. For example the
|
|
|
|
|
following file:
|
|
|
|
|
|
|
|
|
|
rulesets/Character.cpp
|
|
|
|
|
|
|
|
|
|
should be covered by;
|
|
|
|
|
|
|
|
|
|
tests/Charactertest.cpp
|
|
|
|
|
|
|
|
|
|
To see line by line data, run this script on Character.cpp only:
|
|
|
|
|
|
|
|
|
|
./scripts/run_coverage_tests.sh rulesets/Character.cpp
|
|
|
|
|
|
|
|
|
|
and the line by line report will be in this file:
|
|
|
|
|
|
|
|
|
|
rulesets/Character.cpp.gcov
|
|
|
|
|
EOF
|
2009-04-29 01:12:53 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-28 18:10:09 +00:00
|
|
|
DIRS="physics common modules rulesets server client tools"
|
2009-04-28 08:52:41 +01:00
|
|
|
|
2009-04-29 01:12:53 +01:00
|
|
|
declare -i report=0
|
2009-05-04 20:01:08 +01:00
|
|
|
declare -i configure=0
|
2009-07-17 09:35:52 +02:00
|
|
|
declare -i single=0
|
2009-04-29 01:12:53 +01:00
|
|
|
|
2009-05-04 20:01:08 +01:00
|
|
|
while getopts "hrc" options
|
2009-04-29 01:12:53 +01:00
|
|
|
do
|
|
|
|
|
case $options in
|
|
|
|
|
r ) report=1;;
|
2009-05-04 20:01:08 +01:00
|
|
|
c ) configure=1;;
|
2009-04-29 01:12:53 +01:00
|
|
|
h ) usage
|
|
|
|
|
exit 0;;
|
|
|
|
|
* ) usage
|
|
|
|
|
exit 1;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
2009-05-04 20:01:08 +01:00
|
|
|
if [ ${configure} -eq 1 ]
|
|
|
|
|
then
|
|
|
|
|
CXXFLAGS="-g --coverage" ./configure --prefix=/opt/worldforge --enable-debug=yes --enable-binreloc=no
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2009-04-29 12:31:44 +01:00
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
|
|
|
|
|
if [ -n "$1" ]
|
|
|
|
|
then
|
|
|
|
|
if [ -f "$1" ]
|
|
|
|
|
then
|
2009-07-17 09:35:52 +02:00
|
|
|
single=1
|
2009-04-29 12:31:44 +01:00
|
|
|
check_coverage $1
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2009-04-28 08:52:41 +01:00
|
|
|
for dir in ${DIRS}
|
|
|
|
|
do
|
|
|
|
|
for source_file in ${dir}/*.cpp
|
|
|
|
|
do
|
|
|
|
|
check_coverage ${source_file}
|
|
|
|
|
done
|
|
|
|
|
done
|
2009-04-29 01:12:53 +01:00
|
|
|
|