Skip to content

Commit

Permalink
Collect and maintain branch coverage (#1575)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vihangm authored Jun 26, 2023
1 parent 524af8b commit 1eaeee2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ coverage --instrument_test_targets
coverage --define PL_COVERAGE=true
coverage --copt -DPL_COVERAGE
coverage --test_tag_filters=-requires_root,-requires_bpf,-no_coverage,-disabled,-no_gcc
coverage --action_env=COVERAGE_GCOV_OPTIONS=-b


try-import %workspace%/bes.bazelrc
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ user.bazelrc
# A cache directory to be use by Bazel.
.bazel-cache

# Coverage output file
coverage.info

# Arc liberate cache
.phutil_module_cache

Expand Down
22 changes: 12 additions & 10 deletions ci/collect_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ check_config
# Print config parameters.
print_config

lcov_opts=(--rc lcov_branch_coverage=1)

cd $(bazel info workspace)

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

# Print out the summary.
lcov --summary ${COVERAGE_FILE}
lcov "${lcov_opts[@]}" --summary ${COVERAGE_FILE}

# Remove test files from the coverage files.
lcov -r ${COVERAGE_FILE} '**/*_test.cc' -o ${COVERAGE_FILE}
lcov -r ${COVERAGE_FILE} '**/*_mock.cc' -o ${COVERAGE_FILE}
lcov -r ${COVERAGE_FILE} '**/*_mock.h' -o ${COVERAGE_FILE}
lcov -r ${COVERAGE_FILE} '**/*_test.go' -o ${COVERAGE_FILE}
lcov -r ${COVERAGE_FILE} '**/*.gen.go' -o ${COVERAGE_FILE}
lcov -r ${COVERAGE_FILE} '**/*-mock.tsx' -o ${COVERAGE_FILE}
lcov -r ${COVERAGE_FILE} '**/*-mock.ts' -o ${COVERAGE_FILE}
lcov -r ${COVERAGE_FILE} 'src/ui/src/types/generated/**' -o ${COVERAGE_FILE}
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*_test.cc' -o ${COVERAGE_FILE}
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*_mock.cc' -o ${COVERAGE_FILE}
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*_mock.h' -o ${COVERAGE_FILE}
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*_test.go' -o ${COVERAGE_FILE}
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*.gen.go' -o ${COVERAGE_FILE}
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*-mock.tsx' -o ${COVERAGE_FILE}
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} '**/*-mock.ts' -o ${COVERAGE_FILE}
lcov "${lcov_opts[@]}" -r ${COVERAGE_FILE} 'src/ui/src/types/generated/**' -o ${COVERAGE_FILE}

# Print out the final summary.
lcov --summary ${COVERAGE_FILE}
lcov "${lcov_opts[@]}" --summary ${COVERAGE_FILE}

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

0 comments on commit 1eaeee2

Please sign in to comment.