Skip to content

Commit 2dfd5e7

Browse files
committed
some enhancements of the coverage generation script
1 parent c7ae30d commit 2dfd5e7

File tree

1 file changed

+62
-24
lines changed

1 file changed

+62
-24
lines changed

generate_coverage.sh

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
2-
basepath=`pwd`
2+
basepath="`pwd`"
33

44
function print_help {
55
echo "#######################################################################"
@@ -26,35 +26,73 @@ then
2626
exit -1
2727
fi
2828

29-
builddir=${1}
30-
cd ${builddir}
29+
builddir="${basepath}/${1}"
30+
if [[ ! -d "${builddir}" ]]
31+
then
32+
echo "ERROR: Given build directory '${bilddir}' does not exist."
33+
exit -1
34+
fi
35+
cd "${builddir}"
3136

32-
rm -rf ${basepath}/coverage
33-
mkdir -p ${basepath}/coverage
37+
coveragedir="${basepath}/coverage"
38+
rm -rf "${coveragedir}"
39+
mkdir -p "${coveragedir}"
3440

35-
for testdir in `find ${basepath}/${builddir} -type d | grep -o 'tests/.*/.*\dir'`
41+
for testdir in `find ${builddir} -type d | grep -o 'tests/.*/.*\dir'`
3642
do
37-
testname=`expr "$testdir" : '.*\(test_[a-zA-Z\-_]*\)\.dir'`
38-
echo "Gathering Coverage for ${testname}"
39-
cd $testdir
40-
lcov --zerocounters --directory .
41-
cd ${basepath}/${builddir}
42-
ctest -R $testname
43-
cd $testdir
44-
lcov --directory . --capture --output-file ${testname}.info.tmp
45-
lcov --extract ${testname}.info.tmp "*${basepath}/include/**/*" --output-file ${testname}.info
46-
rm ${testname}.info.tmp
47-
cd ${basepath}/${builddir}
48-
if [[ -e all_tests.info ]]
43+
testname=`expr "${testdir}" : '.*\(test_[a-zA-Z\-_]*\)\.dir'`
44+
echo "# ${testname}"
45+
cd "${testdir}"
46+
echo " Deleting old tracing data"
47+
lcov --zerocounters --directory . \
48+
> "${coveragedir}/log_${testname}_zero.log" 2&>1
49+
50+
cd "${builddir}"
51+
echo " Running test and generating tracing data"
52+
ctest -R ${testname} \
53+
> "${coveragedir}/log_${testname}_test.log"
54+
if [[ $? -ne 0 ]]
55+
then
56+
echo "ERROR: test '${testname}' failed."
57+
echo " See '${coveragedir}/log_${testname}_test.log' for details."
58+
cd ${basepath}
59+
exit -1
60+
fi
61+
62+
cd "${testdir}"
63+
echo " Capturing all tracing data"
64+
lcov --directory . --capture --output-file "${testname}.info.tmp" \
65+
> "${coveragedir}/log_${testname}_capture.log"
66+
67+
echo " Extracting interesting tracing data"
68+
lcov --extract "${testname}.info.tmp" "*${basepath}/include/**/*" \
69+
--output-file "${testname}.info" \
70+
> "${coveragedir}/log_${testname}_extract.log"
71+
rm "${testname}.info.tmp"
72+
73+
cd "${builddir}"
74+
echo " Aggegrating coverage data"
75+
if [[ -e "${coveragedir}/all_tests.info" ]]
4976
then
50-
lcov --add-tracefile all_tests.info --add-tracefile ${testdir}/${testname}.info --output-file all_tests.info
77+
lcov --add-tracefile "${coveragedir}/all_tests.info" \
78+
--add-tracefile "${testdir}/${testname}.info" \
79+
--output-file "${coveragedir}/all_tests.info" \
80+
> "${coveragedir}/log_${testname}_aggregate.log"
5181
else
52-
lcov --add-tracefile ${testdir}/${testname}.info --output-file all_tests.info
82+
lcov --add-tracefile "${testdir}/${testname}.info" \
83+
--output-file "${coveragedir}/all_tests.info" \
84+
> "${coveragedir}/log_${testname}_aggregate.log"
5385
fi
5486
done
5587

5688
cd ${basepath}
57-
genhtml --output-directory ./coverage \
58-
--demangle-cpp --num-spaces 2 --sort \
59-
--title "PFASST++ Test Coverage" --prefix ${basepath}/include \
60-
--function-coverage --branch-coverage --legend ${basepath}/${builddir}/all_tests.info
89+
echo "# Generating HTML report"
90+
genhtml --output-directory "${coveragedir}" \
91+
--demangle-cpp --num-spaces 2 --sort \
92+
--title "PFASST++ Test Coverage" --prefix "${basepath}/include" \
93+
--function-coverage --branch-coverage --legend \
94+
"${coveragedir}/all_tests.info" \
95+
> "${coveragedir}/log_generate.log"
96+
97+
echo "# Coverage report can be found in ${coveragedir}/index.html"
98+
echo "# Everything done."

0 commit comments

Comments
 (0)