diff --git a/tools/test/collect_cc_coverage.sh b/tools/test/collect_cc_coverage.sh index 20253ac0ee487a..4635372f037fc2 100755 --- a/tools/test/collect_cc_coverage.sh +++ b/tools/test/collect_cc_coverage.sh @@ -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. @@ -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,