Skip to content

Commit 294f001

Browse files
vihangmcopybaranaut
authored andcommitted
Fixup coverage script
Summary: rules_go reports coverage in LCOV format by default as of version 0.32.0 See bazel-contrib/rules_go#3146 and bazel-contrib/rules_go#3117 So the coverage script was no longer doing the correct thing. This fixes the script. Test Plan: Ran the coverage script locally, generated an HTML report. Ensured that we see cpp, go and js coverage. Reviewers: zasgar, michelle Reviewed By: zasgar Signed-off-by: Vihang Mehta <vihang@pixielabs.ai> Differential Revision: https://phab.corp.pixielabs.ai/D12345 GitOrigin-RevId: 6f4ff98f66fedd68e44f04954688c3efa95616b4
1 parent 3b58f99 commit 294f001

1 file changed

Lines changed: 20 additions & 35 deletions

File tree

ci/collect_coverage.sh

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ GENERATE_HTML=false
2828
UPLOAD_TO_CODECOV=false
2929
HTML_OUTPUT_DIR=""
3030

31-
CC_COVERAGE_FILE="cc_coverage.info"
32-
GO_COVERAGE_FILE="coverage.txt"
33-
UI_OUTPUT=bazel-testlogs/src/ui/ui-tests/coverage.dat
31+
COVERAGE_FILE="coverage.info"
3432

3533
# Print out the usage information and exit.
3634
usage() {
@@ -121,16 +119,11 @@ parse_args() {
121119
}
122120

123121
generate_html() {
124-
genhtml -o ${HTML_OUTPUT_DIR} -s ${CC_COVERAGE_FILE}
125-
126-
echo "****************************************************"
127-
echo "* For Go HTML do the following: "
128-
echo "* go tool cover -html=${GO_COVERAGE_FILE} "
129-
echo "****************************************************"
122+
genhtml -o "${HTML_OUTPUT_DIR}" -s ${COVERAGE_FILE}
130123
}
131124

132125
upload_to_codecov() {
133-
codecov -t "${CODECOV_TOKEN}" -B "${GIT_BRANCH}" -C "${GIT_COMMIT}" -r "${GIT_REPO}" -f "${CC_COVERAGE_FILE}" -f "${GO_COVERAGE_FILE}" -f "${UI_OUTPUT}"
126+
codecov -t "${CODECOV_TOKEN}" -B "${GIT_BRANCH}" -C "${GIT_COMMIT}" -r "${GIT_REPO}" -f "${COVERAGE_FILE}"
134127
}
135128

136129
# We use globs, make sure they are supported.
@@ -151,43 +144,35 @@ cd $(bazel info workspace)
151144
bazel coverage --remote_download_outputs=all //src/...
152145

153146
# Fixup paths for the UI coverage output
154-
sed -i "s|SF:src|SF:src/ui/src|g" ${UI_OUTPUT}
147+
sed -i "s|SF:src|SF:src/ui/src|g" bazel-testlogs/src/ui/ui-tests/coverage.dat
155148

156149
# This finds all the valid coverage files and then creates a list of them
157150
# prefixed by -a, which allows up to add them to the lcov output.
158-
# This part only works for C++ coverage.
159-
file_merge_args=""
160-
for file in bazel-out/**/coverage.dat
161-
do
162-
# Only consider valid files. Some files only contain Go coverage and that
163-
# does not work with LCOV.
164-
lcov --summary "${file}" >/dev/null 2>&1 && file_merge_args+=" -a ${file}"
151+
file_merge_args=()
152+
for file in bazel-out/**/coverage.dat; do
153+
# Only consider valid files.
154+
if [ -s "${file}" ]; then
155+
file_merge_args+=("-a" "${file}")
156+
fi
165157
done
166158

167159
# Merge all the files.
168-
lcov $file_merge_args -o cc_coverage.info
160+
lcov "${file_merge_args[@]}" -o ${COVERAGE_FILE}
169161

170162
# Print out the summary.
171-
lcov --summary ${CC_COVERAGE_FILE}
163+
lcov --summary ${COVERAGE_FILE}
172164

173165
# Remove test files from the coverage files.
174-
lcov -r ${CC_COVERAGE_FILE} '**/*_test.cc' -o ${CC_COVERAGE_FILE}
175-
lcov -r ${CC_COVERAGE_FILE} '**/*_mock.cc' -o ${CC_COVERAGE_FILE}
176-
lcov -r ${CC_COVERAGE_FILE} '**/*_mock.h' -o ${CC_COVERAGE_FILE}
166+
lcov -r ${COVERAGE_FILE} '**/*_test.cc' -o ${COVERAGE_FILE}
167+
lcov -r ${COVERAGE_FILE} '**/*_mock.cc' -o ${COVERAGE_FILE}
168+
lcov -r ${COVERAGE_FILE} '**/*_mock.h' -o ${COVERAGE_FILE}
169+
lcov -r ${COVERAGE_FILE} '**/*_test.go' -o ${COVERAGE_FILE}
170+
lcov -r ${COVERAGE_FILE} '**/*.gen.go' -o ${COVERAGE_FILE}
171+
lcov -r ${COVERAGE_FILE} '**/*-mock.tsx' -o ${COVERAGE_FILE}
172+
lcov -r ${COVERAGE_FILE} '**/*-mock.ts' -o ${COVERAGE_FILE}
177173

178174
# Print out the final summary.
179-
lcov --summary ${CC_COVERAGE_FILE}
180-
181-
# Create go coverage file, by grabbing all the .go entries.
182-
echo "mode: set" > coverage.tmp
183-
for file in bazel-out/**/coverage.dat
184-
do
185-
grep ".go" ${file} >> coverage.tmp || true
186-
done
187-
188-
# Remove test files from the go coverage.
189-
grep -v "_test.go" coverage.tmp > ${GO_COVERAGE_FILE}
190-
rm -f coverage.tmp
175+
lcov --summary ${COVERAGE_FILE}
191176

192177
# Upload to codecov.io.
193178
if [ "${UPLOAD_TO_CODECOV}" = true ]; then

0 commit comments

Comments
 (0)