#!/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 if [ ! -f ${test_program}.cpp ] then if [ ${report} -eq 1 -o ${single} -eq 1 ] then if grep -l DOXYGEN_SHOULD_SKIP_THIS ${source_file} > /dev/null then true else echo No test for ${source_file} fi fi return fi if [ ${report} -eq 1 ] then return fi if [ ! -x ${test_program} ] then echo Test programs have not been built for ${source_file} return fi if [ ${source_file} -nt ${test_program} ] then echo Test build is out of date for ${source_file} exit 1 fi 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 if [ ! -f ${coverage_data} ] then if [ ! -f ${source_dir}/${base_file}.gcno ] then if [ ${single} -eq 1 ] then echo No code to be covered in ${source_file} fi return fi echo No coverage data ${coverage_data} for ${source_file} exit 1 fi if [ ${test_program} -nt ${coverage_data} ] then echo Coverage is out of date for ${source_file} exit 1 fi coverage_digest=$( (cd ${source_dir} && LC_ALL=C gcov ${source_file}) | \ grep -A 1 -e "^File '${base_file}.cpp" \ -e "^File '${base_file}.h" \ -e "^File '${base_file}_impl.h" | \ grep -e "^Lines" -e "^File" | \ sed "s/^File '\([A-Za-z0-9_]\+\.\(h\|cpp\)\)'.*$/${source_dir}\/\1/" | sed "s/^Lines executed:\([0-9]\+\.[0-9]\+\)% of .*$/\1/") echo ${coverage_digest} } usage() { echo "Automate running coverage tools, and generate concise report." echo "usage: run_coverage_tests.sh [OPTION]" echo " run_coverage_tests.sh [SOURCEFILE]" echo "Options:" echo " -r Report source files with no coverage test" echo " -c Re-configure the build to include coverage data" echo " -h Display this usage data" cat <