blob: 1dbd8a68a68e8c016115431c5f7b3fe9f5bc262a [file] [log] [blame] [view]
Yuke Liao8bc00852019-01-29 19:22:391# Code Coverage in Gerrit
2
Yuke Liao0e5a20e2019-06-17 19:52:573Tests are critical because they find bugs and regressions, enforce better
4designs and make code easier to maintain. **Code coverage helps you ensure your
5tests are thorough**.
Yuke Liao8bc00852019-01-29 19:22:396
Yuke Liao0e5a20e2019-06-17 19:52:577Chromium CLs can show a line-by-line breakdown of test coverage. **You can use
Yuke Liao78aa43b2019-08-29 16:58:178it to ensure you only submit well-tested code**.
Yuke Liao0e5a20e2019-06-17 19:52:579
Yuke Liao78aa43b2019-08-29 16:58:1710To see code coverage for a Chromium CL, **trigger a CQ dry run**, and once the
Yuke Liaoa085b982019-10-24 21:37:1111builds finish and code coverage data is processed successfully, **look at the
12change view to see absolute and incremental code coverage percentages**:
13
14![code_coverage_percentages]
15
16Absolute coverage percentage is the percentage of lines covered by tests
17out of **all the lines** in the file, while incremental coverage percentage only
18accounts for **newly added or modified lines**.
19
20To further dig into specific lines that are not covered by tests, **look at the
21right column of the side by side diff view**:
Yuke Liao8bc00852019-01-29 19:22:3922
Yuke Liao0e5a20e2019-06-17 19:52:5723![code_coverage_annotations]
24
Yuke Liao78aa43b2019-08-29 16:58:1725**Code coverage data is shared between patchsets that are commit-message-edit or
26trivial-rebase away**, however, if a newly uploaded patchset has
27non-trivial code change, a new CQ dry run must be triggered before coverage data
28shows up again.
29
Yuke Liao6e57a8a2019-11-12 22:23:4930The code coverage tool currently supports:
31* C/C++ code for [Chromium on Linux].
32* C/C++ code for [Chromium on Chromium OS].
33
Yuke Liao0e5a20e2019-06-17 19:52:5734support for more platforms and more languages is in progress.
35
Yuke Liao8bc00852019-01-29 19:22:3936## Contacts
37
38### Reporting problems
39For any breakage report and feature requests, please [file a bug].
40
41### Mailing list
42For questions and general discussions, please join [code-coverage group].
43
44## FAQ
Yuke Liao8bc00852019-01-29 19:22:3945### Why is coverage not shown even though the try job finished successfully?
46
47There are several possible reasons:
Yuke Liao8bc00852019-01-29 19:22:3948* A particular source file/test may not be available on a particular project or
49platform. As of now, only `chromium/src` project and `Linux` platform is
50supported.
51* There is a bug in the pipeline. Please [file a bug] to report the breakage.
52
53### How does it work?
54
55Please refer to [code_coverage.md] for how code coverage works in Chromium in
56general, and specifically, for per-CL coverage in Gerrit, the
57[clang_code_coverage_wrapper] is used to compile and instrument ONLY the source
Yuke Liao0e5a20e2019-06-17 19:52:5758files that are affected by the CL for the sake of performance and a
59[chromium-coverage Gerrit plugin] is used to display code coverage information
60in Gerrit.
Yuke Liao8bc00852019-01-29 19:22:3961
62
63[choose_tryjobs]: images/code_coverage_choose_tryjobs.png
64[linux_coverage_rel]: images/code_coverage_linux_coverage_rel.png
Yuke Liao0e5a20e2019-06-17 19:52:5765[code_coverage_annotations]: images/code_coverage_annotations.png
Yuke Liaoa085b982019-10-24 21:37:1166[code_coverage_percentages]: images/code_coverage_percentages.png
Yuke Liao03c644072019-07-30 18:33:4067[file a bug]: https://bugs.chromium.org/p/chromium/issues/entry?components=Infra%3ETest%3ECodeCoverage
Yuke Liao8bc00852019-01-29 19:22:3968[code-coverage group]: https://groups.google.com/a/chromium.org/forum/#!forum/code-coverage
69[code_coverage.md]: code_coverage.md
John Palmer046f9872021-05-24 01:24:5670[clang_code_coverage_wrapper]: https://chromium.googlesource.com/chromium/src/+/main/docs/clang_code_coverage_wrapper.md
Yuke Liao8bc00852019-01-29 19:22:3971[chromium-coverage Gerrit plugin]: https://chromium.googlesource.com/infra/gerrit-plugins/code-coverage/
John Palmer046f9872021-05-24 01:24:5672[Chromium on Chromium OS]: https://chromium.googlesource.com/chromium/src/+/main/docs/chromeos_build_instructions.md
73[Chromium on Linux]: https://chromium.googlesource.com/chromium/src/+/main/docs/linux/build_instructions.md