Skip to content

Commit

Permalink
coverage: coverage runs for a single test target. (#3922)
Browse files Browse the repository at this point in the history
Useful when exploring fuzzer code coverage with the checked-in corpus, e.g. #3921.

Signed-off-by: Harvey Tuch <htuch@google.com>
  • Loading branch information
htuch authored Jul 23, 2018
1 parent a5478ee commit 391150a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
8 changes: 8 additions & 0 deletions bazel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ then log back in and it should start working.
The latest coverage report for master is available
[here](https://s3.amazonaws.com/lyft-envoy/coverage/report-master/coverage.html).

It's also possible to specialize the coverage build to a single test target. This is useful
when doing things like exploring the coverage of a fuzzer over its corpus. This can be done with
the `COVERAGE_TARGET` and `VALIDATE_COVERAGE` environment variables, e.g.:

```
COVERAGE_TARGET=//test/common/common:base64_fuzz_test VALIDATE_COVERAGE=false test/run_envoy_bazel_coverage.sh
```

# Cleaning the build and test artifacts

`bazel clean` will nuke all the build/test artifacts from the Bazel cache for
Expand Down
24 changes: 14 additions & 10 deletions test/run_envoy_bazel_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set -e
[[ -z "${BAZEL_COVERAGE}" ]] && BAZEL_COVERAGE=bazel
[[ -z "${GCOVR}" ]] && GCOVR=gcovr
[[ -z "${WORKSPACE}" ]] && WORKSPACE=envoy
[[ -z "${VALIDATE_COVERAGE}" ]] && VALIDATE_COVERAGE=true

# This is the target that will be run to generate coverage data. It can be overriden by consumer
# projects that want to run coverage on a different/combined target.
Expand Down Expand Up @@ -56,7 +57,7 @@ COVERAGE_SUMMARY="${COVERAGE_DIR}/coverage_summary.txt"
pushd "${GCOVR_DIR}"
for f in $(find -L bazel-out/ -name "*.gcno")
do
cp --parents "$f" bazel-out/k8-dbg/bin/test/coverage/coverage_tests.runfiles/"${WORKSPACE}"
cp --parents "$f" bazel-out/k8-dbg/bin/"${COVERAGE_TARGET/:/\/}".runfiles/"${WORKSPACE}"
done
popd

Expand All @@ -76,13 +77,16 @@ rm "${SRCDIR}"/test/coverage/BUILD

[[ -z "${ENVOY_COVERAGE_DIR}" ]] || rsync -av "${COVERAGE_DIR}"/ "${ENVOY_COVERAGE_DIR}"

COVERAGE_VALUE=$(grep -Po 'lines: \K(\d|\.)*' "${COVERAGE_SUMMARY}")
COVERAGE_THRESHOLD=98.0
COVERAGE_FAILED=$(echo "${COVERAGE_VALUE}<${COVERAGE_THRESHOLD}" | bc)
if test ${COVERAGE_FAILED} -eq 1; then
echo Code coverage ${COVERAGE_VALUE} is lower than limit of ${COVERAGE_THRESHOLD}
exit 1
else
echo Code coverage ${COVERAGE_VALUE} is good and higher than limit of ${COVERAGE_THRESHOLD}
if [ "$VALIDATE_COVERAGE" == "true" ]
then
COVERAGE_VALUE=$(grep -Po 'lines: \K(\d|\.)*' "${COVERAGE_SUMMARY}")
COVERAGE_THRESHOLD=98.0
COVERAGE_FAILED=$(echo "${COVERAGE_VALUE}<${COVERAGE_THRESHOLD}" | bc)
if test ${COVERAGE_FAILED} -eq 1; then
echo Code coverage ${COVERAGE_VALUE} is lower than limit of ${COVERAGE_THRESHOLD}
exit 1
else
echo Code coverage ${COVERAGE_VALUE} is good and higher than limit of ${COVERAGE_THRESHOLD}
fi
echo "HTML coverage report is in ${COVERAGE_DIR}/coverage.html"
fi
echo "HTML coverage report is in ${COVERAGE_DIR}/coverage.html"

0 comments on commit 391150a

Please sign in to comment.