Yuke Liao | 8bc0085 | 2019-01-29 19:22:39 | [diff] [blame] | 1 | # Code Coverage in Gerrit |
| 2 | |
Yuke Liao | 0e5a20e | 2019-06-17 19:52:57 | [diff] [blame] | 3 | Tests are critical because they find bugs and regressions, enforce better |
| 4 | designs and make code easier to maintain. **Code coverage helps you ensure your |
| 5 | tests are thorough**. |
Yuke Liao | 8bc0085 | 2019-01-29 19:22:39 | [diff] [blame] | 6 | |
Yuke Liao | 0e5a20e | 2019-06-17 19:52:57 | [diff] [blame] | 7 | Chromium CLs can show a line-by-line breakdown of test coverage. **You can use |
Yuke Liao | 78aa43b | 2019-08-29 16:58:17 | [diff] [blame] | 8 | it to ensure you only submit well-tested code**. |
Yuke Liao | 0e5a20e | 2019-06-17 19:52:57 | [diff] [blame] | 9 | |
Yuke Liao | 78aa43b | 2019-08-29 16:58:17 | [diff] [blame] | 10 | To see code coverage for a Chromium CL, **trigger a CQ dry run**, and once the |
Yuke Liao | a085b98 | 2019-10-24 21:37:11 | [diff] [blame] | 11 | builds finish and code coverage data is processed successfully, **look at the |
| 12 | change view to see absolute and incremental code coverage percentages**: |
| 13 | |
| 14 | ![code_coverage_percentages] |
| 15 | |
| 16 | Absolute coverage percentage is the percentage of lines covered by tests |
| 17 | out of **all the lines** in the file, while incremental coverage percentage only |
| 18 | accounts for **newly added or modified lines**. |
| 19 | |
| 20 | To further dig into specific lines that are not covered by tests, **look at the |
| 21 | right column of the side by side diff view**: |
Yuke Liao | 8bc0085 | 2019-01-29 19:22:39 | [diff] [blame] | 22 | |
Yuke Liao | 0e5a20e | 2019-06-17 19:52:57 | [diff] [blame] | 23 | ![code_coverage_annotations] |
| 24 | |
Yuke Liao | 78aa43b | 2019-08-29 16:58:17 | [diff] [blame] | 25 | **Code coverage data is shared between patchsets that are commit-message-edit or |
| 26 | trivial-rebase away**, however, if a newly uploaded patchset has |
| 27 | non-trivial code change, a new CQ dry run must be triggered before coverage data |
| 28 | shows up again. |
| 29 | |
Yuke Liao | 6e57a8a | 2019-11-12 22:23:49 | [diff] [blame] | 30 | The code coverage tool currently supports: |
| 31 | * C/C++ code for [Chromium on Linux]. |
| 32 | * C/C++ code for [Chromium on Chromium OS]. |
| 33 | |
Yuke Liao | 0e5a20e | 2019-06-17 19:52:57 | [diff] [blame] | 34 | support for more platforms and more languages is in progress. |
| 35 | |
Yuke Liao | 8bc0085 | 2019-01-29 19:22:39 | [diff] [blame] | 36 | ## Contacts |
| 37 | |
| 38 | ### Reporting problems |
| 39 | For any breakage report and feature requests, please [file a bug]. |
| 40 | |
| 41 | ### Mailing list |
| 42 | For questions and general discussions, please join [code-coverage group]. |
| 43 | |
| 44 | ## FAQ |
Yuke Liao | 8bc0085 | 2019-01-29 19:22:39 | [diff] [blame] | 45 | ### Why is coverage not shown even though the try job finished successfully? |
| 46 | |
| 47 | There are several possible reasons: |
Yuke Liao | 8bc0085 | 2019-01-29 19:22:39 | [diff] [blame] | 48 | * A particular source file/test may not be available on a particular project or |
| 49 | platform. As of now, only `chromium/src` project and `Linux` platform is |
| 50 | supported. |
| 51 | * There is a bug in the pipeline. Please [file a bug] to report the breakage. |
| 52 | |
| 53 | ### How does it work? |
| 54 | |
| 55 | Please refer to [code_coverage.md] for how code coverage works in Chromium in |
| 56 | general, and specifically, for per-CL coverage in Gerrit, the |
| 57 | [clang_code_coverage_wrapper] is used to compile and instrument ONLY the source |
Yuke Liao | 0e5a20e | 2019-06-17 19:52:57 | [diff] [blame] | 58 | files 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 |
| 60 | in Gerrit. |
Yuke Liao | 8bc0085 | 2019-01-29 19:22:39 | [diff] [blame] | 61 | |
| 62 | |
| 63 | [choose_tryjobs]: images/code_coverage_choose_tryjobs.png |
| 64 | [linux_coverage_rel]: images/code_coverage_linux_coverage_rel.png |
Yuke Liao | 0e5a20e | 2019-06-17 19:52:57 | [diff] [blame] | 65 | [code_coverage_annotations]: images/code_coverage_annotations.png |
Yuke Liao | a085b98 | 2019-10-24 21:37:11 | [diff] [blame] | 66 | [code_coverage_percentages]: images/code_coverage_percentages.png |
Yuke Liao | 03c64407 | 2019-07-30 18:33:40 | [diff] [blame] | 67 | [file a bug]: https://bugs.chromium.org/p/chromium/issues/entry?components=Infra%3ETest%3ECodeCoverage |
Yuke Liao | 8bc0085 | 2019-01-29 19:22:39 | [diff] [blame] | 68 | [code-coverage group]: https://groups.google.com/a/chromium.org/forum/#!forum/code-coverage |
| 69 | [code_coverage.md]: code_coverage.md |
John Palmer | 046f987 | 2021-05-24 01:24:56 | [diff] [blame] | 70 | [clang_code_coverage_wrapper]: https://chromium.googlesource.com/chromium/src/+/main/docs/clang_code_coverage_wrapper.md |
Yuke Liao | 8bc0085 | 2019-01-29 19:22:39 | [diff] [blame] | 71 | [chromium-coverage Gerrit plugin]: https://chromium.googlesource.com/infra/gerrit-plugins/code-coverage/ |
John Palmer | 046f987 | 2021-05-24 01:24:56 | [diff] [blame] | 72 | [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 |