Restore branch coverage for tests on Linux

This commit is contained in:
Thomas Jensen 2023-12-02 14:36:19 +01:00
parent 1cbd1f933c
commit 15c72d4d99
No known key found for this signature in database
GPG Key ID: A4ACEE270D0FB7DB
2 changed files with 14 additions and 3 deletions

View File

@ -152,19 +152,20 @@ function measure_coverage()
mkdir -p "${testResultsDir}"
cp ${OUT_DIR}/*.gc* "${testResultsDir}"
lcov --capture --directory "${testResultsDir}" --base-directory ${SRC_DIR} --test-name "${tcBaseName}" --quiet \
--exclude '*/lex.yy.c' --exclude '*/parser.c' --rc branch_coverage=1 \
--exclude '*/lex.yy.c' --exclude '*/parser.c' --rc "${branchCoverage}=1" \
--output-file "${testResultsDir}/coverage.info"
echo -n " Coverage: "
lcov --summary "${testResultsDir}/coverage.info" 2>&1 | grep 'lines...' | grep -oP '\d+\.\d*%'
fi
}
function consolidate_coverage()
{
echo -e "\nConsolidating test coverage ..."
pushd ${OUT_DIR}/test-results || exit 1
find . -name "*.info" | xargs printf -- '--add-tracefile %s\n' | xargs --exit \
lcov --rc branch_coverage=1 --exclude '*/lex.yy.c' --exclude '*/parser.c' \
lcov --rc "${branchCoverage}=1" --exclude '*/lex.yy.c' --exclude '*/parser.c' \
--output-file ../${COVERAGE_FILE} --add-tracefile ../${BASELINE_FILE}
popd || exit 1
echo ""
@ -265,6 +266,11 @@ parse_arguments "$@"
check_prereqs
cov_baseline
declare branchCoverage=lcov_branch_coverage
if [[ $(uname) == "Darwin" ]]; then
branchCoverage=branch_coverage
fi
# Execute the entire test suite
if [ ${opt_suite} == true ]; then
declare -i overallResult=0

View File

@ -21,6 +21,11 @@ declare -r tcBaseName=unittest
declare -r testResultsDir=${OUT_DIR}/test-results/${tcBaseName}
declare -r testReportDir=${OUT_DIR}/report-utest
declare branchCoverage=lcov_branch_coverage
if [[ $(uname) == "Darwin" ]]; then
branchCoverage=branch_coverage
fi
if test -n "$(find ${OUT_DIR} -maxdepth 1 -name '*.gcda' -print -quit)" \
&& test -n "$(find ${OUT_DIR} -maxdepth 1 -name '*.gcno' -print -quit)" \
&& test -n "$(lcov --version)"
@ -29,7 +34,7 @@ then
mkdir -p ${testReportDir}
cp ${OUT_DIR}/*.gc* ${testResultsDir}
lcov --capture --directory ${testResultsDir} --base-directory ${SRC_DIR} --test-name ${tcBaseName} --quiet \
--exclude '*/lex.yy.c' --exclude '*/parser.c' --rc branch_coverage=1 \
--exclude '*/lex.yy.c' --exclude '*/parser.c' --rc "${branchCoverage}=1" \
--output-file ${testResultsDir}/coverage.info
echo -n "[ Coverage ] "
genhtml --title "Boxes / Unit Tests" --branch-coverage --legend --output-directory ${testReportDir} \