-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- open source CoverageCommand.java - add a collect-coverage.sh script - update test-setup.sh to be compatible with the coverage collector - update StandaloneTestStrategy to provide the necessary env variables - update StandaloneTestStrategy to set the right command line for coverage - add support for C++ coverage An HTML report can then be generated with genhtml like this: genhtml -o report/ -p "$(readlink -f bazel-<project>)" path/to/coverage.dat Progress on #1118. -- MOS_MIGRATED_REVID=140125715
- Loading branch information
Showing
9 changed files
with
451 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
327 changes: 327 additions & 0 deletions
327
src/main/java/com/google/devtools/build/lib/runtime/commands/CoverageCommand.java
Large diffs are not rendered by default.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
src/main/java/com/google/devtools/build/lib/runtime/commands/coverage.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
Usage: blaze %{command} <options> <test-targets> | ||
|
||
Builds and runs the specified test targets using the specified options while | ||
collecting code coverage statistics. Optionally, it also generates combined | ||
HTML report containing coverage results for all executed tests. | ||
|
||
This command accepts all valid options to 'test' and 'build', and inherits | ||
defaults for 'test' (and 'build') from your .blazerc. If you don't use | ||
.blazerc, don't forget to pass all your 'build' options to '%{command}' too. | ||
|
||
See 'blaze help target-syntax' for details and examples on how to | ||
specify targets. | ||
|
||
%{options} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
filegroup( | ||
name = "coverage_support", | ||
srcs = ["collect-coverage.sh"], | ||
) | ||
|
||
filegroup( | ||
name = "coverage_report_generator", | ||
srcs = ["dummy_coverage_report_generator"], | ||
) | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob(["*"]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2016 The Bazel Authors. All rights reserved. | ||
# | ||
# 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. | ||
|
||
ROOT="$PWD" | ||
if [[ $COVERAGE_OUTPUT_FILE != /* ]]; then | ||
COVERAGE_OUTPUT_FILE="${ROOT}/${COVERAGE_OUTPUT_FILE}" | ||
fi | ||
if [[ "$COVERAGE_MANIFEST" != /* ]]; then | ||
export COVERAGE_MANIFEST="${ROOT}/${COVERAGE_MANIFEST}" | ||
fi | ||
|
||
export COVERAGE_DIR="$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX)" | ||
trap "{ rm -rf ${COVERAGE_DIR} }" EXIT | ||
|
||
# C++ env variables | ||
export GCOV_PREFIX_STRIP=3 | ||
export GCOV_PREFIX="${COVERAGE_DIR}" | ||
|
||
touch "${COVERAGE_OUTPUT_FILE}" | ||
|
||
DIR="$TEST_SRCDIR" | ||
if [ ! -z "$TEST_WORKSPACE" ]; then | ||
DIR="$DIR"/"$TEST_WORKSPACE" | ||
fi | ||
cd "$DIR" || { echo "Could not chdir $DIR"; exit 1; } | ||
"$@" | ||
TEST_STATUS=$? | ||
|
||
if [[ ${TEST_STATUS} -ne 0 ]]; then | ||
echo "--" | ||
echo "Coverage runner: Not collecting coverage for failed test." | ||
echo "The following commands failed with status ${TEST_STATUS}:" | ||
echo "$@" | ||
exit ${TEST_STATUS} | ||
fi | ||
|
||
echo "--" | ||
echo "Post-processing coverage results:" | ||
|
||
cat "${COVERAGE_MANIFEST}" | grep ".gcno$" | while read path; do | ||
mkdir -p "${COVERAGE_DIR}/$(dirname ${path})" | ||
cp "${ROOT}/${path}" "${COVERAGE_DIR}/${path}" | ||
done | ||
|
||
# Unfortunately, lcov messes up the source file names if it can't find the files | ||
# at their relative paths. Workaround by creating empty source files according | ||
# to the manifest (i.e., only for files that are supposed to be instrumented). | ||
cat "${COVERAGE_MANIFEST}" | egrep ".(cc|h)$" | while read path; do | ||
mkdir -p "${COVERAGE_DIR}/$(dirname ${path})" | ||
touch "${COVERAGE_DIR}/${path}" | ||
done | ||
|
||
# Run lcov over the .gcno and .gcda files to generate the lcov tracefile. | ||
/usr/bin/lcov -c --no-external -d "${COVERAGE_DIR}" -o "${COVERAGE_OUTPUT_FILE}" | ||
|
||
# The paths are all wrong, because they point to /tmp. Fix up the paths to | ||
# point to the exec root instead (${ROOT}). | ||
sed -i -e "s*${COVERAGE_DIR}*${ROOT}*g" "${COVERAGE_OUTPUT_FILE}" | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters