mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-08 13:14:56 +00:00
Add option and target for generating code cov info
The new `tint-generate-coverage` CMake target can be used with the clang toolchain to generate a `lcov.info` file at the root of the project, along with a `coverage.summary` human readable plain text file. The `lcov.info` file can then be used by various tools to display code coverage information in your IDE / code editor. Useful for ensuring decent test coverage. Change-Id: I3d846f6da3af25d3d600d8e028f27b89e35b545f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31121 Commit-Queue: Ben Clayton <bclayton@google.com> Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
bfd81096a5
commit
adb10d60de
65
tools/tint-generate-coverage
Executable file
65
tools/tint-generate-coverage
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2020 The Tint Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# See https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
|
||||
|
||||
set -e # Fail on any error.
|
||||
|
||||
if [ ! -x "$(which llvm-profdata)" ] ; then
|
||||
echo "error: llvm-profdata needs to be on \$PATH to use $0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -x "$(which llvm-cov)" ] ; then
|
||||
echo "error: llvm-cov needs to be on \$PATH to use $0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARGET_EXE=$1
|
||||
|
||||
if [ ! -x "$TARGET_EXE" ] ; then
|
||||
echo "Usage: $0 <executable-path> [optional-args]"
|
||||
echo ""
|
||||
echo "Generates a lcov.info file at the project root, which can be used by"
|
||||
echo "tools such as VSCode's Coverage Gutters extension to visualize code"
|
||||
echo "coverage in the editor".
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
|
||||
ROOT_DIR="$( cd "${SCRIPT_DIR}/.." >/dev/null 2>&1 && pwd )"
|
||||
|
||||
PROFRAW_FILE="${ROOT_DIR}/tint.profraw"
|
||||
PROFDATA_FILE="${ROOT_DIR}/tint.profdata"
|
||||
LCOV_FILE="${ROOT_DIR}/lcov.info"
|
||||
SUMMARY_FILE="${ROOT_DIR}/coverage.summary"
|
||||
|
||||
# Run the executable to generate the raw coverage data
|
||||
# https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#running-the-instrumented-program
|
||||
LLVM_PROFILE_FILE="${PROFRAW_FILE}" $@
|
||||
|
||||
# Index the coverage data
|
||||
# https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#creating-coverage-reports
|
||||
llvm-profdata merge -sparse "${PROFRAW_FILE}" -o "${PROFDATA_FILE}"
|
||||
|
||||
# Export as lcov
|
||||
# https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#exporting-coverage-data
|
||||
llvm-cov export --instr-profile="${PROFDATA_FILE}" --format=lcov --object=${TARGET_EXE} > "${LCOV_FILE}"
|
||||
|
||||
# Generate summary report
|
||||
llvm-cov report --ignore-filename-regex="(.*_test\.cc|third_party/.*)" --instr-profile="${PROFDATA_FILE}" --object=${TARGET_EXE} > "${SUMMARY_FILE}"
|
||||
|
||||
# Clean up
|
||||
rm ${PROFRAW_FILE} ${PROFDATA_FILE}
|
||||
Reference in New Issue
Block a user