Skip to content

Commit

Permalink
Use LLVM_COV and LLVM_PROFDATA variables over COVERAGE_GCOV_PATH
Browse files Browse the repository at this point in the history
They are provided by the C++ rules and make it clearer what tool is
what. Also changes the C++ LLVM coverage test to specify GCOV as
llvm-cov, since that is the analogous tool and better represents how a
LLVM based tool chain might be configured.
  • Loading branch information
c-mita committed Jul 11, 2023
1 parent fc95f68 commit c898e1d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/test/shell/bazel/bazel_coverage_cc_test_llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function setup_llvm_coverage_tools_for_lcov() {
add_to_bazelrc "common --repo_env=BAZEL_LLVM_PROFDATA=${llvm_profdata}"
add_to_bazelrc "common --repo_env=BAZEL_USE_LLVM_NATIVE_COVERAGE=1"
add_to_bazelrc "common --repo_env=CC=${clang}"
add_to_bazelrc "common --repo_env=GCOV=${llvm_profdata}"
add_to_bazelrc "common --repo_env=GCOV=${llvm_cov}"
add_to_bazelrc "common --experimental_generate_llvm_lcov"
}

Expand Down
8 changes: 3 additions & 5 deletions src/test/shell/bazel/coverage_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ function get_gcov_version() {
# gcov (Debian 7.3.0-5) 7.3.0
# llvm-cov gcov --version outputs a line like:
# LLVM version 9.0.1
local version=$("${gcov_location}" --version | sed -n -E -e 's/^.*\s([0-9]+)\.[0-9]+\.[0-9]+\s?.*$/\1/p')
# gcov (actually llvm-cov) on OS X outputs:
# Apple LLVM version 12.0.5
local version=$("${gcov_location}" --version | sed -n -E -e 's/^.* ([0-9]+)\.[0-9]+\.[0-9]+ ?.*$/\1/p')
if [ "$version" -lt 7 ]; then
echo "gcov versions before 7.0 is not supported."
return 1
fi

# Disable llvm-cov for now - coverage tests on OSX don't work
# TODO(cmita): Fix and enable.
"$gcov_location" -version | grep "LLVM" && \
echo "gcov LLVM version not supported." && return 1
echo "$version"
}

Expand Down
10 changes: 7 additions & 3 deletions tools/test/collect_cc_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
# - ROOT Location from where the code coverage collection
# was invoked.
# - VERBOSE_COVERAGE Print debug info from the coverage scripts
# - LLVM_COV Location of llvm-cov
# - LLVM_PROFDATA Location of llvm-profdata
#
# The script looks in $COVERAGE_DIR for the C++ metadata coverage files (either
# gcda or profraw) and uses either lcov or gcov to get the coverage data.
Expand Down Expand Up @@ -78,7 +80,7 @@ function init_gcov() {
function llvm_coverage_lcov() {
local output_file="${1}"; shift
export LLVM_PROFILE_FILE="${COVERAGE_DIR}/%h-%p-%m.profraw"
"${COVERAGE_GCOV_PATH}" merge -output "${output_file}.data" \
"${LLVM_PROFDATA}" merge -output "${output_file}.data" \
"${COVERAGE_DIR}"/*.profraw

local object_param=""
Expand All @@ -98,7 +100,7 @@ function llvm_coverage_lcov() {
function llvm_coverage_profdata() {
local output_file="${1}"; shift
export LLVM_PROFILE_FILE="${COVERAGE_DIR}/%h-%p-%m.profraw"
"${COVERAGE_GCOV_PATH}" merge -output "${output_file}" \
"${LLVM_PROFDATA}" merge -output "${output_file}" \
"${COVERAGE_DIR}"/*.profraw
}

Expand Down Expand Up @@ -140,7 +142,9 @@ function gcov_coverage() {
# 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')
# gcov (actually llvm-cov) on OS X outputs:
# Apple LLVM version 12.0.5
gcov_major_version=$("${GCOV}" --version | sed -n -E -e 's/^.* ([0-9]+)\.[0-9]+\.[0-9]+ ?.*$/\1/p')

# Invoke gcov to generate a code coverage report with the flags:
# -i Output gcov file in an intermediate text format.
Expand Down

0 comments on commit c898e1d

Please sign in to comment.