Code coverage can be checked using Clang's source-based coverage tools. You
must use the GN argument use_clang_coverage=true. It is recommended to do
this in a separate output directory since the added instrumentation will affect
performance and generate profile data every time a binary is run. You can read
more about Clang coverage in the
Clang documentation.
When you upload a change to Gerrit and run CQ tryjobs:
- The
linux_x64trybot instruments the files modified by your CL and runsopenscreen_unittestsande2e_tests. - In the Gerrit review UI, line coverage changes are highlighted directly in the diff viewer.
- On the LUCI build page for
try/linux_x64, click thehtml reportlink (under thecalculate code coveragestep or in the build overview) to open an interactive HTML report showing coverage for files touched by the CL.
When changes land on main:
- The
ci/linux_x64postsubmit builder instruments all source files in the repository and runsopenscreen_unittestsande2e_tests. - On the LUCI build page for
ci/linux_x64, anhtml reportlink is provided under thecalculate code coveragestep. - The full repository coverage HTML report can be viewed directly in your
browser at:
https://storage.cloud.google.com/code-coverage-data/postsubmit/chromium.googlesource.com/openscreen/<commit_hash>/ci/linux_x64/<build_id>/html_report/index.html
To measure and inspect full repository coverage entirely on your local workstation:
-
Configure and build with coverage enabled:
gn gen out/coverage --args="use_clang_coverage=true is_debug=false" ninja -C out/coverage openscreen_unittests -
Run tests with
LLVM_PROFILE_FILEset to produce raw profile data:LLVM_PROFILE_FILE="default.profraw" out/coverage/openscreen_unittests -
Merge the raw profile data into an indexed
.profdatafile:third_party/llvm-build/Release+Asserts/bin/llvm-profdata merge \ -sparse default.profraw -o coverage.profdata -
Generate the HTML report:
third_party/llvm-build/Release+Asserts/bin/llvm-cov show \ out/coverage/openscreen_unittests \ -instr-profile=coverage.profdata \ -format=html \ -output-dir=out/coverage_html \ [filter paths]Note:
[filter paths]is an optional list of subdirectories or source files (e.g.,cast/orcast/streaming/) to restrict the report scope. If omitted, all repository sources are included. -
View the report: Open
out/coverage_html/index.htmlin your browser.
If you want to view or query coverage for a specific landed commit without
running all unit tests locally, you can download the merged .profdata
produced by the CI builder:
-
Build the binary locally at the target commit:
gn gen out/coverage --args="use_clang_coverage=true is_debug=false" ninja -C out/coverage openscreen_unittests -
Locate the build details on the LUCI
ci/linux_x64console to get the<commit_hash>and<build_id>.
-
Download the merged profile data:
gsutil cp \ gs://code-coverage-data/postsubmit/chromium.googlesource.com/openscreen/<commit_hash>/ci/linux_x64/<build_id>/merged.profdata \ . -
Generate the HTML report using your local binary and the downloaded profile data:
third_party/llvm-build/Release+Asserts/bin/llvm-cov show \ out/coverage/openscreen_unittests \ -instr-profile=merged.profdata \ -format=html \ -output-dir=out/coverage_html \ [filter paths] -
View the report: Open
out/coverage_html/index.htmlin your browser.
The same process can be used to check the coverage of a fuzzer's corpus. Just
add -runs=0 to the fuzzer arguments to ensure it only runs the existing corpus
and exits:
LLVM_PROFILE_FILE="fuzzer.profraw" out/coverage/<fuzzer_name> -runs=0