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.
  • Loading branch information
c-mita committed Jul 10, 2023
1 parent 70e31da commit 08a11ad
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tools/test/collect_cc_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ 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_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 @@ -145,15 +151,14 @@ function gcov_coverage() {
# they correspond to. One .gcov file is produced for each source
# (or header) file containing code which was compiled to produce the
# .gcda files.
# 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}"

# 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_major_version=$("${GCOV}" --version | sed -n -E -e 's/^.*\s([0-9]+)\.[0-9]+\.[0-9]+\s?.*$/\1/p')
# 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 gcov version so we can process the data correctly
if [[ $gcov_major_version -ge 9 ]]; then
Expand Down

0 comments on commit 08a11ad

Please sign in to comment.