From 08a11ad7683d522be4d517d6575758a96c7a703b Mon Sep 17 00:00:00 2001 From: Charles Mita Date: Mon, 10 Jul 2023 15:12:51 +0200 Subject: [PATCH] Enable C++ branch coverage when using gcov 8 or later. 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. --- tools/test/collect_cc_coverage.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tools/test/collect_cc_coverage.sh b/tools/test/collect_cc_coverage.sh index d043562680cddd..8f0cb1b9f3b236 100755 --- a/tools/test/collect_cc_coverage.sh +++ b/tools/test/collect_cc_coverage.sh @@ -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. @@ -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