Max Moroz | 3a92890 | 2018-05-15 14:39:50 | [diff] [blame] | 1 | # Code Coverage in Chromium |
| 2 | |
Prakhar | e84bb3b | 2021-11-29 03:28:44 | [diff] [blame] | 3 | ### Coverage Dashboard: [link](https://analysis.chromium.org/coverage/p/chromium) |
Yuke Liao | d3b4627 | 2018-03-14 18:25:14 | [diff] [blame] | 4 | |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 5 | Table of contents: |
Max Moroz | 3a92890 | 2018-05-15 14:39:50 | [diff] [blame] | 6 | |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 7 | - [Coverage Infrastructure](#coverage-infra) |
| 8 | * [Coverage Builders](#coverage-builders) |
| 9 | * [Coverage Service](#coverage-service) |
| 10 | * [Coverage Clients](#coverage-clients) |
Roberto Carrillo | bc1560e | 2019-01-30 20:08:58 | [diff] [blame] | 11 | - [Local Coverage Script](#local-coverage-script) |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 12 | * [Step 0 Download Tooling](#step-0-download-tooling) |
| 13 | * [Step 1 Build](#step-1-build) |
| 14 | * [Step 2 Create Raw Profiles](#step-2-create-raw-profiles) |
| 15 | * [Step 3 Create Indexed Profile](#step-3-create-indexed-profile) |
| 16 | * [Step 4 Create Coverage Reports](#step-4-create-coverage-reports) |
Max Moroz | d73e45f | 2018-04-24 18:32:47 | [diff] [blame] | 17 | - [Contacts](#contacts) |
| 18 | - [FAQ](#faq) |
Yuke Liao | d3b4627 | 2018-03-14 18:25:14 | [diff] [blame] | 19 | |
Yuke Liao | d3b4627 | 2018-03-14 18:25:14 | [diff] [blame] | 20 | |
Prakhar | f41864b0 | 2022-07-18 19:03:51 | [diff] [blame] | 21 | This document is divided into two parts. |
| 22 | - The first part introduces the code coverage infrastructure that |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 23 | continuously generates code coverage information for the whole codebase and for |
| 24 | specific CLs in Gerrit. For the latter, refer to |
Roberto Carrillo | 5221fc1 | 2019-01-30 21:34:50 | [diff] [blame] | 25 | [code\_coverage\_in\_gerrit.md](code_coverage_in_gerrit.md). |
Prakhar | f41864b0 | 2022-07-18 19:03:51 | [diff] [blame] | 26 | - The second part talks about how to generate code coverage locally for Clang-compiled languages like C++. Refer to [android code coverage instructions] for instructions for java code. |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 27 | |
| 28 | ## Coverage Infrastructure |
| 29 | |
| 30 | ![coverage infra diagram] |
| 31 | |
| 32 | There are 3 layers in the system: |
| 33 | |
| 34 | ### Coverage Builders |
| 35 | |
| 36 | The first layer is the LUCI builders that |
| 37 | - build instrumented targets, |
| 38 | - run the instrumented tests, |
| 39 | - merge the results into single streams, |
| 40 | - upload data to cloud storage. |
| 41 | |
| 42 | There are two types of builder: |
| 43 | |
| 44 | CI Builder |
| 45 | |
Yuke Liao | 43bbbcd5 | 2019-06-21 19:34:50 | [diff] [blame] | 46 | The code coverage CI Builders periodically build all the test targets and fuzzer |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 47 | targets for a given platform and instrument all available source files. Then |
| 48 | save the coverage data to a dedicated storage bucket. |
| 49 | |
| 50 | CQ Builder |
| 51 | |
| 52 | The code coverage CQ builders instrument only the files changed for a given CL. |
Yuke Liao | 43bbbcd5 | 2019-06-21 19:34:50 | [diff] [blame] | 53 | More information about per-cl coverage info in [this |
Roberto Carrillo | 5221fc1 | 2019-01-30 21:34:50 | [diff] [blame] | 54 | doc](code_coverage_in_gerrit.md). |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 55 | |
| 56 | ### Coverage Service |
| 57 | |
| 58 | The second layer in the system consists of an AppEngine application that |
| 59 | consumes the coverage data from the builders above, structures it and stores it |
| 60 | in cloud datastore. It then serves the information to the clients below. |
| 61 | |
| 62 | ### Coverage Clients |
| 63 | |
| 64 | In the last layer we currently have two clients that consume the service: |
| 65 | |
| 66 | #### Coverage Dashboard |
| 67 | |
| 68 | The [coverage dashboard] front end is hosted in the same application as the |
| 69 | service above. |
| 70 | It shows the full-code coverage reports with links to the builds that generated |
| 71 | them, as well as per-directory and per-component aggregation, and can be drilled |
| 72 | down to the single line of code level of detail. |
| 73 | |
Yuke Liao | 43bbbcd5 | 2019-06-21 19:34:50 | [diff] [blame] | 74 | Refer to the following screenshots: |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 75 | |
| 76 | ##### Directory View |
| 77 | |
Yuke Liao | 43bbbcd5 | 2019-06-21 19:34:50 | [diff] [blame] | 78 | See coverage breakdown by directories (default landing page). |
| 79 | |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 80 | ![coverage dashboard directory view] |
| 81 | |
| 82 | ##### Component View |
| 83 | |
Yuke Liao | 43bbbcd5 | 2019-06-21 19:34:50 | [diff] [blame] | 84 | Use the view dropdown menu to switch between directory and component. |
| 85 | |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 86 | ![coverage dashboard component view] |
| 87 | |
| 88 | ##### Source View |
| 89 | |
Yuke Liao | 43bbbcd5 | 2019-06-21 19:34:50 | [diff] [blame] | 90 | Click on a particular source file in one of the views above to see line-by-line |
| 91 | coverage breakdown, and it's useful to identify: |
| 92 | - Uncovered lines and code blocks that lack test coverage. |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 93 | - Potentially dead code. See [dead code example]. |
Yuke Liao | 43bbbcd5 | 2019-06-21 19:34:50 | [diff] [blame] | 94 | - Hot spots in your code. |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 95 | |
| 96 | ![coverage dashboard file view] |
| 97 | |
Yuke Liao | 43bbbcd5 | 2019-06-21 19:34:50 | [diff] [blame] | 98 | ##### Project View |
| 99 | |
| 100 | Click on "Previous Reports" to check out the coverage history of the project. |
| 101 | |
| 102 | ![coverage dashboard link to previous reports] |
| 103 | |
| 104 | List of historical coverage reports are in reverse chronological order. |
| 105 | |
| 106 | ![coverage dashboard previous reports] |
| 107 | |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 108 | #### Gerrit Coverage View |
| 109 | |
| 110 | The other client supported at the moment is the gerrit plugin for code coverage. |
| 111 | |
| 112 | ![gerrit coverage view] |
| 113 | |
| 114 | See [this doc](code_coverage_in_gerrit.md) for information about the feature |
| 115 | that allows gerrit to display code coverage information generated for a given CL |
| 116 | by CQ bot. Or see this |
Roberto Carrillo | 5221fc1 | 2019-01-30 21:34:50 | [diff] [blame] | 117 | [15-second video tutorial](https://www.youtube.com/watch?v=cxXlYcSgIPE). |
Yuke Liao | d3b4627 | 2018-03-14 18:25:14 | [diff] [blame] | 118 | |
Roberto Carrillo | bc1560e | 2019-01-30 20:08:58 | [diff] [blame] | 119 | ## Local Coverage Script |
Prakhar | f41864b0 | 2022-07-18 19:03:51 | [diff] [blame] | 120 | This [documentation] explains how to use Clang’s source-based coverage |
| 121 | features in general. The [coverage script] automates the process described below and provides a |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 122 | one-stop service to generate code coverage reports locally in just one command. |
Yuke Liao | d3b4627 | 2018-03-14 18:25:14 | [diff] [blame] | 123 | |
Ben Joyce | 8828236 | 2021-01-29 23:53:31 | [diff] [blame] | 124 | This script is currently supported on Android, Linux, Mac, iOS and ChromeOS |
| 125 | platforms. |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 126 | |
| 127 | Here is an example usage: |
| 128 | |
Yuke Liao | d3b4627 | 2018-03-14 18:25:14 | [diff] [blame] | 129 | ``` |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 130 | $ gn gen out/coverage \ |
Bryce Thomas | c9137cf | 2020-03-31 19:47:17 | [diff] [blame] | 131 | --args="use_clang_coverage=true is_component_build=false |
| 132 | dcheck_always_on=true is_debug=false" |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 133 | $ python tools/code_coverage/coverage.py \ |
| 134 | crypto_unittests url_unittests \ |
| 135 | -b out/coverage -o out/report \ |
| 136 | -c 'out/coverage/crypto_unittests' \ |
| 137 | -c 'out/coverage/url_unittests --gtest_filter=URLParser.PathURL' \ |
| 138 | -f url/ -f crypto/ |
| 139 | ``` |
| 140 | The command above builds `crypto_unittests` and `url_unittests` targets and then |
Max Moroz | a5a9527 | 2018-08-31 16:20:55 | [diff] [blame] | 141 | runs them individually with their commands and arguments specified by the `-c` flag. |
Abhishek Arya | af9811f2 | 2018-05-11 22:17:48 | [diff] [blame] | 142 | For `url_unittests`, it only runs the test `URLParser.PathURL`. The coverage report |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 143 | is filtered to include only files and sub-directories under `url/` and `crypto/` |
| 144 | directories. |
| 145 | |
Abhishek Arya | af9811f2 | 2018-05-11 22:17:48 | [diff] [blame] | 146 | Aside from automating the process, this script provides visualization features to |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 147 | view code coverage breakdown by directories and by components, similar to the |
| 148 | views in the [coverage dashboard](#coverage-dashboard) above. |
Abhishek Arya | af9811f2 | 2018-05-11 22:17:48 | [diff] [blame] | 149 | |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 150 | ## Workflow |
| 151 | This section presents the workflow of generating code coverage reports using two |
| 152 | unit test targets in Chromium repo as an example: `crypto_unittests` and |
| 153 | `url_unittests`, and the following diagram shows a step-by-step overview of the |
| 154 | process. |
| 155 | |
| 156 |  |
| 157 | |
| 158 | ### Step 0 Download Tooling |
| 159 | Generating code coverage reports requires llvm-profdata and llvm-cov tools. |
Zequan Wu | 6d00cccd | 2021-03-15 22:40:44 | [diff] [blame] | 160 | You can get them by adding `"checkout_clang_coverage_tools": True,` to |
| 161 | `custom_vars` in the `.gclient` config and run `gclient runhooks`. You can also |
| 162 | download the tools manually ([tools link]) |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 163 | |
| 164 | ### Step 1 Build |
| 165 | In Chromium, to compile code with coverage enabled, one needs to add |
Yuke Liao | 8c0868fe6 | 2019-10-22 21:02:33 | [diff] [blame] | 166 | `use_clang_coverage=true`, `is_component_build=false` and `is_debug=false` GN |
| 167 | flags to the args.gn file in the build output directory. Under the hood, they |
| 168 | ensure `-fprofile-instr-generate` and `-fcoverage-mapping` flags are passed to |
| 169 | the compiler. |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 170 | |
| 171 | ``` |
| 172 | $ gn gen out/coverage \ |
Yuke Liao | 8c0868fe6 | 2019-10-22 21:02:33 | [diff] [blame] | 173 | --args='use_clang_coverage=true is_component_build=false is_debug=false' |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 174 | $ gclient runhooks |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 175 | $ autoninja -C out/coverage crypto_unittests url_unittests |
Yuke Liao | d3b4627 | 2018-03-14 18:25:14 | [diff] [blame] | 176 | ``` |
| 177 | |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 178 | ### Step 2 Create Raw Profiles |
Yuke Liao | bc35726b | 2018-10-31 22:16:21 | [diff] [blame] | 179 | The next step is to run the instrumented binaries. When the program exits, it |
Abhishek Arya | af9811f2 | 2018-05-11 22:17:48 | [diff] [blame] | 180 | writes a raw profile for each process. Because Chromium runs tests in |
| 181 | multiple processes, the number of processes spawned can be as many as a few |
| 182 | hundred, resulting in the generation of a few hundred gigabytes’ raw |
| 183 | profiles. To limit the number of raw profiles, `%Nm` pattern in |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 184 | `LLVM_PROFILE_FILE` environment variable is used to run tests in multi-process |
| 185 | mode, where `N` is the number of raw profiles. With `N = 4`, the total size of |
Ben Joyce | 8828236 | 2021-01-29 23:53:31 | [diff] [blame] | 186 | the raw profiles are limited to a few gigabytes. (If working on Android, the |
| 187 | .profraw files will be located in ./out/coverage/coverage by default.) |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 188 | |
| 189 | ``` |
Ben Joyce | 739fdb20 | 2021-01-13 19:22:22 | [diff] [blame] | 190 | $ export LLVM_PROFILE_FILE="out/report/crypto_unittests.%4m.profraw" |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 191 | $ ./out/coverage/crypto_unittests |
| 192 | $ ls out/report/ |
| 193 | crypto_unittests.3657994905831792357_0.profraw |
| 194 | ... |
| 195 | crypto_unittests.3657994905831792357_3.profraw |
| 196 | ``` |
| 197 | |
| 198 | ### Step 3 Create Indexed Profile |
| 199 | Raw profiles must be indexed before generating code coverage reports, and this |
| 200 | is done using the `merge` command of `llvm-profdata` tool, which merges multiple |
Abhishek Arya | af9811f2 | 2018-05-11 22:17:48 | [diff] [blame] | 201 | raw profiles (.profraw) and indexes them to create a single profile (.profdata). |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 202 | |
| 203 | At this point, all the raw profiles can be thrown away because their information |
Abhishek Arya | af9811f2 | 2018-05-11 22:17:48 | [diff] [blame] | 204 | is already contained in the indexed profile. |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 205 | |
| 206 | ``` |
| 207 | $ llvm-profdata merge -o out/report/coverage.profdata \ |
| 208 | out/report/crypto_unittests.3657994905831792357_0.profraw |
| 209 | ... |
| 210 | out/report/crypto_unittests.3657994905831792357_3.profraw |
| 211 | out/report/url_unittests.714228855822523802_0.profraw |
| 212 | ... |
| 213 | out/report/url_unittests.714228855822523802_3.profraw |
| 214 | $ ls out/report/coverage.profdata |
| 215 | out/report/coverage.profdata |
| 216 | ``` |
| 217 | |
| 218 | ### Step 4 Create Coverage Reports |
| 219 | Finally, `llvm-cov` is used to render code coverage reports. There are different |
Abhishek Arya | af9811f2 | 2018-05-11 22:17:48 | [diff] [blame] | 220 | report generation modes, and all of them require the following as input: |
| 221 | - Indexed profile |
| 222 | - All built target binaries |
Roberto Carrillo | 5221fc1 | 2019-01-30 21:34:50 | [diff] [blame] | 223 | - All exercised source files |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 224 | |
Abhishek Arya | af9811f2 | 2018-05-11 22:17:48 | [diff] [blame] | 225 | For example, the following command can be used to generate per-file line-by-line |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 226 | code coverage report: |
| 227 | |
| 228 | ``` |
| 229 | $ llvm-cov show -output-dir=out/report -format=html \ |
| 230 | -instr-profile=out/report/coverage.profdata \ |
Choongwoo Han | 5675252 | 2021-06-10 17:38:34 | [diff] [blame] | 231 | -compilation-dir=out/coverage \ |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 232 | -object=out/coverage/url_unittests \ |
| 233 | out/coverage/crypto_unittests |
| 234 | ``` |
| 235 | |
Ben Joyce | 8828236 | 2021-01-29 23:53:31 | [diff] [blame] | 236 | If creating a report for Android, the -object arg would be the lib.unstripped |
| 237 | file, ie out/coverage/lib.unstripped/libcrypto_unittests__library.so |
| 238 | |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 239 | For more information on how to use llvm-cov, please refer to the [guide]. |
Yuke Liao | d3b4627 | 2018-03-14 18:25:14 | [diff] [blame] | 240 | |
Max Moroz | d73e45f | 2018-04-24 18:32:47 | [diff] [blame] | 241 | ## Contacts |
| 242 | |
| 243 | ### Reporting problems |
Yuke Liao | d3b4627 | 2018-03-14 18:25:14 | [diff] [blame] | 244 | For any breakage report and feature requests, please [file a bug]. |
| 245 | |
Max Moroz | d73e45f | 2018-04-24 18:32:47 | [diff] [blame] | 246 | ### Mailing list |
Yuke Liao | bc35726b | 2018-10-31 22:16:21 | [diff] [blame] | 247 | For questions and general discussions, please join [code-coverage group]. |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 248 | |
Max Moroz | d73e45f | 2018-04-24 18:32:47 | [diff] [blame] | 249 | ## FAQ |
| 250 | |
| 251 | ### Can I use `is_component_build=true` for code coverage build? |
| 252 | |
| 253 | Yes, code coverage instrumentation works with both component and non-component |
| 254 | builds. Component build is usually faster to compile, but can be up to several |
| 255 | times slower to run with code coverage instrumentation. For more information, |
Max Moroz | c5e364a | 2018-04-25 23:19:49 | [diff] [blame] | 256 | see [crbug.com/831939]. |
| 257 | |
| 258 | ### I am getting some warnings while using the script, is that fine? |
| 259 | |
Abhishek Arya | af9811f2 | 2018-05-11 22:17:48 | [diff] [blame] | 260 | Usually this is not a critical issue, but in general we tend not to have any |
Max Moroz | c5e364a | 2018-04-25 23:19:49 | [diff] [blame] | 261 | warnings. Please check the list of [known issues], and if there is a similar |
| 262 | bug, leave a comment with the command you run, the output you get, and Chromium |
Yuke Liao | 03c64407 | 2019-07-30 18:33:40 | [diff] [blame] | 263 | revision you use. Otherwise, please [file a bug] providing the same information. |
Max Moroz | c5e364a | 2018-04-25 23:19:49 | [diff] [blame] | 264 | |
| 265 | ### How do crashes affect code coverage? |
| 266 | |
Max Moroz | a5a9527 | 2018-08-31 16:20:55 | [diff] [blame] | 267 | If a crash of any type occurs (e.g. Segmentation Fault or ASan error), the |
| 268 | crashing process might not dump coverage information necessary to generate |
Max Moroz | c5e364a | 2018-04-25 23:19:49 | [diff] [blame] | 269 | code coverage report. For single-process applications (e.g. fuzz targets), that |
Max Moroz | a5a9527 | 2018-08-31 16:20:55 | [diff] [blame] | 270 | means no coverage might be reported at all. For multi-process applications, the |
| 271 | report might be incomplete. It is important to fix the crash first. If this is |
Abhishek Arya | af9811f2 | 2018-05-11 22:17:48 | [diff] [blame] | 272 | happening only in the coverage instrumented build, please [file a bug]. |
Max Moroz | d73e45f | 2018-04-24 18:32:47 | [diff] [blame] | 273 | |
Max Moroz | a5a9527 | 2018-08-31 16:20:55 | [diff] [blame] | 274 | ### How do assertions affect code coverage? |
| 275 | |
| 276 | If a crash is caused by CHECK or DCHECK, the coverage dump will still be written |
| 277 | on the disk ([crrev.com/c/1172932]). However, if a crashing process calls the |
| 278 | standard [assert] directly or through a custom wrapper, the dump will not be |
| 279 | written (see [How do crashes affect code coverage?]). |
| 280 | |
Max Moroz | 63cd04d | 2018-05-02 16:40:23 | [diff] [blame] | 281 | ### Is it possible to obtain code coverage from a full Chromium build? |
| 282 | |
| 283 | Yes, with some important caveats. It is possible to build `chrome` target with |
| 284 | code coverage instrumentation enabled. However, there are some inconveniences |
| 285 | involved: |
| 286 | |
Kai Ninomiya | 6f537eb | 2023-01-04 23:43:47 | [diff] [blame] | 287 | * Linking may take a while, especially if you use a non-component build. |
| 288 | * The binary is huge (2-4GB). |
| 289 | * The browser may be noticeably slow and laggy. |
Max Moroz | 63cd04d | 2018-05-02 16:40:23 | [diff] [blame] | 290 | |
| 291 | For more information, please see [crbug.com/834781]. |
| 292 | |
Max Moroz | 3a92890 | 2018-05-15 14:39:50 | [diff] [blame] | 293 | ### Why do we see significantly different coverage reported on different revisions? |
| 294 | |
| 295 | There can be two possible scenarios: |
| 296 | |
| 297 | * It can be a one time flakiness due to a broken build or failing tests. |
| 298 | * It can be caused by extension of the test suite used for generating code |
| 299 | coverage reports. When we add new tests to the suite, the aggregate coverage |
| 300 | reported usually grows after that. |
| 301 | |
| 302 | ### How can I improve [coverage dashboard]? |
| 303 | |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 304 | The code for the service and dashboard currently lives along with findit at |
John Palmer | 046f987 | 2021-05-24 01:24:56 | [diff] [blame] | 305 | [this location](https://chromium.googlesource.com/infra/infra/+/main/appengine/findit/) |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 306 | because of significant shared logic. |
| 307 | |
| 308 | The code used by the bots that generate the coverage data lives (among other |
| 309 | places) in the |
John Palmer | 046f987 | 2021-05-24 01:24:56 | [diff] [blame] | 310 | [code coverage recipe module](https://chromium.googlesource.com/chromium/tools/build/+/main/scripts/slave/recipe_modules/code_coverage/). |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 311 | |
Max Moroz | 3a92890 | 2018-05-15 14:39:50 | [diff] [blame] | 312 | ### Why is coverage for X not reported or unreasonably low, even though there is a test for X? |
| 313 | |
| 314 | There are several reasons why coverage reports can be incomplete or incorrect: |
| 315 | |
| 316 | * A particular test is not used for code coverage report generation. Please |
Roberto Carrillo | 5221fc1 | 2019-01-30 21:34:50 | [diff] [blame] | 317 | [file a bug]. |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 318 | * A test may have a build failure or a runtime crash. Please check the build |
| 319 | for that particular report (rightmost column on the [coverage dashboard]). |
Max Moroz | 3a92890 | 2018-05-15 14:39:50 | [diff] [blame] | 320 | If there is any failure, please upload a CL with the fix. If you can't fix it, |
| 321 | feel free to [file a bug]. |
| 322 | * A particular test may not be available on a particular platform. As of now, |
Yuke Liao | 43bbbcd5 | 2019-06-21 19:34:50 | [diff] [blame] | 323 | only reports generated on Linux and CrOS are available on the |
| 324 | [coverage dashboard]. |
Max Moroz | 3a92890 | 2018-05-15 14:39:50 | [diff] [blame] | 325 | |
Max Moroz | 3a92890 | 2018-05-15 14:39:50 | [diff] [blame] | 326 | ### Is coverage reported for the code executed inside the sandbox? |
| 327 | |
Yuke Liao | 8c0868fe6 | 2019-10-22 21:02:33 | [diff] [blame] | 328 | Yes! |
Max Moroz | 3a92890 | 2018-05-15 14:39:50 | [diff] [blame] | 329 | |
Max Moroz | d73e45f | 2018-04-24 18:32:47 | [diff] [blame] | 330 | |
Max Moroz | a5a9527 | 2018-08-31 16:20:55 | [diff] [blame] | 331 | [assert]: http://man7.org/linux/man-pages/man3/assert.3.html |
Yuke Liao | bc35726b | 2018-10-31 22:16:21 | [diff] [blame] | 332 | [code-coverage group]: https://groups.google.com/a/chromium.org/forum/#!forum/code-coverage |
Max Moroz | 3a92890 | 2018-05-15 14:39:50 | [diff] [blame] | 333 | [code-coverage repository]: https://chrome-internal.googlesource.com/chrome/tools/code-coverage |
Prakhar | 74514ba | 2022-05-19 17:14:04 | [diff] [blame] | 334 | [coverage dashboard]: https://analysis.chromium.org/coverage/p/chromium |
Yuke Liao | 1ffc8cb6 | 2018-04-06 19:09:07 | [diff] [blame] | 335 | [coverage script]: https://cs.chromium.org/chromium/src/tools/code_coverage/coverage.py |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 336 | [coverage infra diagram]: images/code_coverage_infra_diagram.png |
| 337 | [coverage dashboard file view]: images/code_coverage_dashboard_file_view.png |
| 338 | [coverage dashboard component view]: images/code_coverage_dashboard_component_view.png |
| 339 | [coverage dashboard directory view]: images/code_coverage_dashboard_directory_view.png |
Yuke Liao | 43bbbcd5 | 2019-06-21 19:34:50 | [diff] [blame] | 340 | [coverage dashboard link to previous reports]: images/code_coverage_dashboard_link_to_previous_reports.png |
| 341 | [coverage dashboard previous reports]: images/code_coverage_dashboard_previous_reports.png |
Max Moroz | 3a92890 | 2018-05-15 14:39:50 | [diff] [blame] | 342 | [crbug.com/821617]: https://crbug.com/821617 |
Max Moroz | c5e364a | 2018-04-25 23:19:49 | [diff] [blame] | 343 | [crbug.com/831939]: https://crbug.com/831939 |
Max Moroz | 63cd04d | 2018-05-02 16:40:23 | [diff] [blame] | 344 | [crbug.com/834781]: https://crbug.com/834781 |
Max Moroz | a5a9527 | 2018-08-31 16:20:55 | [diff] [blame] | 345 | [crrev.com/c/1172932]: https://crrev.com/c/1172932 |
Max Moroz | 3a92890 | 2018-05-15 14:39:50 | [diff] [blame] | 346 | [clang roll]: https://crbug.com/841908 |
Abhishek Arya | b23b1a7 | 2018-05-17 20:11:09 | [diff] [blame] | 347 | [dead code example]: https://chromium.googlesource.com/chromium/src/+/ac6e09311fcc7e734be2ef21a9ccbbe04c4c4706 |
Max Moroz | c5e364a | 2018-04-25 23:19:49 | [diff] [blame] | 348 | [documentation]: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html |
Yuke Liao | 03c64407 | 2019-07-30 18:33:40 | [diff] [blame] | 349 | [file a bug]: https://bugs.chromium.org/p/chromium/issues/entry?components=Infra%3ETest%3ECodeCoverage |
Yuke Liao | 43bbbcd5 | 2019-06-21 19:34:50 | [diff] [blame] | 350 | [gerrit coverage view]: images/code_coverage_annotations.png |
Max Moroz | c5e364a | 2018-04-25 23:19:49 | [diff] [blame] | 351 | [guide]: http://llvm.org/docs/CommandGuide/llvm-cov.html |
Max Moroz | a5a9527 | 2018-08-31 16:20:55 | [diff] [blame] | 352 | [How do crashes affect code coverage?]: #how-do-crashes-affect-code-coverage |
Yuke Liao | 03c64407 | 2019-07-30 18:33:40 | [diff] [blame] | 353 | [known issues]: https://bugs.chromium.org/p/chromium/issues/list?q=component:Infra%3ETest%3ECodeCoverage |
Roberto Carrillo | 3b56786 | 2019-01-30 19:01:25 | [diff] [blame] | 354 | [tools link]: https://storage.googleapis.com/chromium-browser-clang-staging/ |
Prakhar | f41864b0 | 2022-07-18 19:03:51 | [diff] [blame] | 355 | [android code coverage instructions]: https://chromium.googlesource.com/chromium/src/+/HEAD/build/android/docs/coverage.md |