forked from envoyproxy/nighthawk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_nighthawk_bazel_coverage.sh
executable file
·61 lines (49 loc) · 2.25 KB
/
run_nighthawk_bazel_coverage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# derived from test/run_envoy_bazel_coverage.sh over the Envoy repo.
set -eo pipefail
set +x
set -u
SRCDIR="${SRCDIR:=${PWD}}"
ENVOY_COVERAGE_DIR="${ENVOY_COVERAGE_DIR:=}"
COVERAGE_THRESHOLD=${COVERAGE_THRESHOLD:=0}
echo "Starting run_nighthawk_bazel_coverage.sh..."
echo " PWD=$(pwd)"
echo " SRCDIR=${SRCDIR}"
echo " COVERAGE_THRESHOLD=${COVERAGE_THRESHOLD}"
COVERAGE_DIR="${SRCDIR}"/generated/coverage
rm -rf "${COVERAGE_DIR}"
mkdir -p "${COVERAGE_DIR}"
# This is the target that will be run to generate coverage data. It can be overridden by consumer
# projects that want to run coverage on a different/combined target.
# Command-line arguments take precedence over ${COVERAGE_TARGET}.
if [[ $# -gt 0 ]]; then
COVERAGE_TARGETS=$*
elif [[ -n "${COVERAGE_TARGET}" ]]; then
COVERAGE_TARGETS=${COVERAGE_TARGET}
else
COVERAGE_TARGETS=//test/...
fi
# The environment variable CI is used to determine if some expensive tests that
# cannot run locally should be executed.
# E.g. test_http_h1_mini_stress_test_open_loop.
BAZEL_BUILD_OPTIONS+=" --test_timeout=900 --config=test-coverage --test_tag_filters=-nocoverage --test_env=ENVOY_IP_TEST_VERSIONS=v4only --action_env=CI"
bazel coverage ${BAZEL_BUILD_OPTIONS} --cache_test_results=no --test_output=all -- ${COVERAGE_TARGETS}
COVERAGE_DATA="${COVERAGE_DIR}/coverage.dat"
cp bazel-out/_coverage/_coverage_report.dat "${COVERAGE_DATA}"
COVERAGE_VALUE=$(genhtml --prefix ${PWD} --output "${COVERAGE_DIR}" "${COVERAGE_DATA}" | grep lines... | cut -d ' ' -f 4)
COVERAGE_VALUE=${COVERAGE_VALUE%?}
echo "Zipping coverage report to ${SRCDIR}/coverage_html.zip".
zip -r "${SRCDIR}/coverage_html.zip" "${COVERAGE_DIR}"
[[ -z "${ENVOY_COVERAGE_DIR}" ]] || rsync -av "${COVERAGE_DIR}"/ "${ENVOY_COVERAGE_DIR}"
if [ "$COVERAGE_THRESHOLD" != "0" ]
then
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
fi
echo "HTML coverage report is in ${COVERAGE_DIR}/index.html"
echo "If running in Azure Pipelines, the coverage report is published as a pipeline artifact."