Skip to content

Commit

Permalink
Enable C++ branch coverage when using gcov 8 or later.
Browse files Browse the repository at this point in the history
Branch coverage was disabled due to a gcov bug, but this was fixed for
GCC 8: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84879.

It doesn't make sense to disable all C++ branch coverage for
everyone because of a bug in an old GCC version.

RELNOTES: Enable C++ branch coverage if gcov version is 8 or newer.
  • Loading branch information
c-mita committed Jul 11, 2023
1 parent 3f7965f commit a2c261f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tools/test/collect_cc_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ function gcov_coverage() {
mkdir -p "${COVERAGE_DIR}/$(dirname ${gcno_path})"
cp "$ROOT/${gcno_path}" "${COVERAGE_DIR}/${gcno_path}"
fi

# Extract gcov's version: the output of `gcov --version` contains the
# version as a set of major-minor-patch numbers, of which we extract
# the major version.
# gcov --version outputs a line like:
# gcov (Debian 7.3.0-5) 7.3.0
# llvm-cov gcov --version outputs a line like:
# LLVM version 9.0.1
gcov_major_version=$("${GCOV}" --version | sed -n -E -e 's/^.*\s([0-9]+)\.[0-9]+\.[0-9]+\s?.*$/\1/p')

# Invoke gcov to generate a code coverage report with the flags:
# -i Output gcov file in an intermediate text format.
# The output is a single .gcov file per .gcda file.
Expand All @@ -148,7 +158,15 @@ function gcov_coverage() {
# Don't generate branch coverage (-b) because of a gcov issue that
# segfaults when both -i and -b are used (see
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84879).
"${GCOV}" -i $COVERAGE_GCOV_OPTIONS -o "$(dirname ${gcda})" "${gcda}"

# Don't generate branch coverage (-b) when using gcov 7 or earlier
# because of a gcov issue that segfaults when both -i and -b are used
# (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84879).
if [[ $gcov_major_version -le 7 ]]; then
"${GCOV}" -i $COVERAGE_GCOV_OPTIONS -o "$(dirname ${gcda})" "${gcda}"
else
"${GCOV}" -i -b $COVERAGE_GCOV_OPTIONS -o "$(dirname ${gcda})" "${gcda}"
fi

# Check the type of output: gcov 9 or later outputs compressed JSON
# files, but earlier versions of gcov, and all versions of llvm-cov,
Expand Down

0 comments on commit a2c261f

Please sign in to comment.