diff options
author | Ulf Adams <ulfjack@google.com> | 2018-04-26 00:39:43 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-04-26 00:41:39 -0700 |
commit | 1441a3a387b5576da232cb038c91bde2e01cd9ff (patch) | |
tree | 07b85c2d97f5c52f2c0f425a08103f0eca9ed90c /tools/test | |
parent | b425ec5df5c2dfb22dca517183338dc2687371ed (diff) |
Prototype support for llvm coverage
https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
Closes #5036.
Usage with statically linked tests (works with clang 3.9 or later):
BAZEL_USE_LLVM_NATIVE_COVERAGE=1 GCOV=llvm-profdata-3.9 CC=clang-3.9 /tmp/bazel coverage --instrumentation_filter=src/main/cpp --dynamic_mode=off src/test/cpp:option_processor_test
(LLVM_COV_CMD="llvm-cov-3.9 show -format=html -output-dir=$(pwd)/report/ -instr-profile bazel-out/k8-fastbuild/testlogs/src/test/cpp/option_processor_test/coverage.dat bazel-out/k8-fastbuild/bin/src/test/cpp/option_processor_test" && cd bazel-os-bazel && $LLVM_COV_CMD)
Usage with dynamically linked tests (requires clang 4.0 or later):
BAZEL_USE_LLVM_NATIVE_COVERAGE=1 GCOV=llvm-profdata-4.0 CC=clang-4.0 bazel coverage --instrumentation_filter=src/main/cpp src/test/cpp:option_processor_test
(LLVM_COV_CMD="llvm-cov-4.0 show -format=html -output-dir=$(pwd)/report/ -instr-profile bazel-out/k8-fastbuild/testlogs/src/test/cpp/option_processor_test/coverage.dat bazel-out/k8-fastbuild/bin/src/test/cpp/option_processor_test $(cat bazel-out/k8-fastbuild/bin/src/test/cpp/option_processor_test.runfiles_manifest | cut -d' ' -f 2 | egrep "\.so$" | xargs -n 1 -I xxx echo -n "-object xxx ")" && cd bazel-os-bazel && $LLVM_COV_CMD)
PiperOrigin-RevId: 194357292
Diffstat (limited to 'tools/test')
-rwxr-xr-x | tools/test/collect_coverage.sh | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tools/test/collect_coverage.sh b/tools/test/collect_coverage.sh index b9579cac99..143696a912 100755 --- a/tools/test/collect_coverage.sh +++ b/tools/test/collect_coverage.sh @@ -88,6 +88,7 @@ fi if [[ "$COVERAGE_LEGACY_MODE" ]]; then export GCOV_PREFIX_STRIP=3 export GCOV_PREFIX="${COVERAGE_DIR}" + export LLVM_PROFILE_FILE="${COVERAGE_DIR}/%h-%p-%m.profraw" fi cd "$TEST_SRCDIR/$TEST_WORKSPACE" @@ -107,11 +108,17 @@ fi cd $ROOT -# If LCOV_MERGER is not set, use the legacy, awful, C++-only method to convert -# coverage files. -# NB: This is here just so that we don't regress. Do not add support for new -# coverage features here. Implement it instead properly in LcovMerger. -if [[ "$COVERAGE_LEGACY_MODE" ]]; then +USES_LLVM_COV= +if stat --printf='' "${COVERAGE_DIR}"/*.profraw 2>/dev/null; then + USES_LLVM_COV=1 +fi + +if [[ "$USES_LLVM_COV" ]]; then + "${COVERAGE_GCOV_PATH}" merge -output "${COVERAGE_OUTPUT_FILE}" "${COVERAGE_DIR}"/*.profraw + exit $TEST_STATUS + +# If LCOV_MERGER is not set, use the legacy C++-only method to convert coverage files. +elif [[ "$COVERAGE_LEGACY_MODE" ]]; then cat "${COVERAGE_MANIFEST}" | grep ".gcno$" | while read path; do mkdir -p "${COVERAGE_DIR}/$(dirname ${path})" cp "${ROOT}/${path}" "${COVERAGE_DIR}/${path}" |