Skip to content

Commit 1eaeee2

Browse files
authoredJun 26, 2023
Collect and maintain branch coverage (pixie-io#1575)
Summary: gcov doesn't collect branch coverage by default and lcov drops branch coverage from the files if it exists. This change ensures that we maintain and track branch coverage. Type of change: /kind cleanup Test Plan: Ran the coverage build and then the coverage cleanup script. Ensured that it now maintains branch coverage. --------- Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>
1 parent 524af8b commit 1eaeee2

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed
 

‎.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ coverage --instrument_test_targets
226226
coverage --define PL_COVERAGE=true
227227
coverage --copt -DPL_COVERAGE
228228
coverage --test_tag_filters=-requires_root,-requires_bpf,-no_coverage,-disabled,-no_gcc
229+
coverage --action_env=COVERAGE_GCOV_OPTIONS=-b
229230

230231

231232
try-import %workspace%/bes.bazelrc

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ user.bazelrc
5757
# A cache directory to be use by Bazel.
5858
.bazel-cache
5959

60+
# Coverage output file
61+
coverage.info
62+
6063
# Arc liberate cache
6164
.phutil_module_cache
6265

‎ci/collect_coverage.sh

+12-10
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ check_config
138138
# Print config parameters.
139139
print_config
140140

141+
lcov_opts=(--rc lcov_branch_coverage=1)
142+
141143
cd $(bazel info workspace)
142144

143145
# Get coverage from bazel targets.
@@ -147,20 +149,20 @@ bazel coverage --remote_download_outputs=all --combined_report=lcov //src/...
147149
cp --no-preserve=mode "$(bazel info output_path)/_coverage/_coverage_report.dat" ${COVERAGE_FILE}
148150

149151
# Print out the summary.
150-
lcov --summary ${COVERAGE_FILE}
152+
lcov "${lcov_opts[@]}" --summary ${COVERAGE_FILE}
151153

152154
# Remove test files from the coverage files.
153-
lcov -r ${COVERAGE_FILE} '**/*_test.cc' -o ${COVERAGE_FILE}
154-
lcov -r ${COVERAGE_FILE} '**/*_mock.cc' -o ${COVERAGE_FILE}
155-
lcov -r ${COVERAGE_FILE} '**/*_mock.h' -o ${COVERAGE_FILE}
156-
lcov -r ${COVERAGE_FILE} '**/*_test.go' -o ${COVERAGE_FILE}
157-
lcov -r ${COVERAGE_FILE} '**/*.gen.go' -o ${COVERAGE_FILE}
158-
lcov -r ${COVERAGE_FILE} '**/*-mock.tsx' -o ${COVERAGE_FILE}
159-
lcov -r ${COVERAGE_FILE} '**/*-mock.ts' -o ${COVERAGE_FILE}
160-
lcov -r ${COVERAGE_FILE} 'src/ui/src/types/generated/**' -o ${COVERAGE_FILE}
155+
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*_test.cc' -o ${COVERAGE_FILE}
156+
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*_mock.cc' -o ${COVERAGE_FILE}
157+
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*_mock.h' -o ${COVERAGE_FILE}
158+
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*_test.go' -o ${COVERAGE_FILE}
159+
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*.gen.go' -o ${COVERAGE_FILE}
160+
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*-mock.tsx' -o ${COVERAGE_FILE}
161+
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*-mock.ts' -o ${COVERAGE_FILE}
162+
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} 'src/ui/src/types/generated/**' -o ${COVERAGE_FILE}
161163

162164
# Print out the final summary.
163-
lcov --summary ${COVERAGE_FILE}
165+
lcov "${lcov_opts[@]}" --summary ${COVERAGE_FILE}
164166

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

0 commit comments

Comments
 (0)
Please sign in to comment.