Jonathan Lee | 9925965 | 2022-09-27 23:40:01 | [diff] [blame] | 1 | # Using wptrunner in Chromium (experimental) |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 2 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 3 | [`wptrunner`](https://github.com/web-platform-tests/wpt/tree/master/tools/wptrunner) |
| 4 | is the harness shipped with the WPT project for running the test suite. This |
| 5 | user guide documents *experimental* support in Chromium for `wptrunner`, which |
| 6 | will replace [`run_web_tests.py`](web_platform_tests.md#Running-tests) for |
| 7 | running WPTs in CQ/CI. |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 8 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 9 | For general information on web platform tests, see |
| 10 | [web-platform-tests.org](https://web-platform-tests.org/test-suite-design.html). |
| 11 | |
| 12 | For technical details on the migration to `wptrunner` in Chromium, see the |
| 13 | [project plan](https://docs.google.com/document/d/1VMt0CB8LO_oXHh7OIKsG-61j4nusxPnTuw1v6JqsixY/edit?usp=sharing&resourcekey=0-XbRB7-vjKAg5-s2hWhOPkA). |
| 14 | |
| 15 | *** note |
| 16 | **Warning**: The project is under active development, so expect some rough |
| 17 | edges. This document may be stale. |
| 18 | *** |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 19 | |
| 20 | [TOC] |
| 21 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 22 | ## Differences from `run_web_tests.py` |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 23 | |
| 24 | The main differences between `run_web_tests.py` and `wptrunner` are that: |
| 25 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 26 | 1. `wptrunner` can run both the full `chrome` binary and the stripped-down |
| 27 | `content_shell`. `run_web_tests.py` can only run `content_shell`. |
| 28 | 1. `wptrunner` can communicate with the binary via WebDriver (`chromedriver`), |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 29 | instead of talking directly to the browser binary. |
| 30 | |
| 31 | These differences mean that any feature that works on upstream WPT today (e.g. |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 32 | print-reftests) should work in `wptrunner`, but conversely, features available to |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 33 | `run_web_tests.py` (e.g. the `internals` API) are not yet available to |
| 34 | `wptrunner`. |
| 35 | |
| 36 | ## Running tests locally |
| 37 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 38 | The `wptrunner` wrapper script is |
| 39 | [`//third_party/blink/tools/run_wpt_tests.py`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/tools/run_wpt_tests.py). |
| 40 | First, build the necessary ninja target: |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 41 | |
Jonathan Lee | 9925965 | 2022-09-27 23:40:01 | [diff] [blame] | 42 | ``` sh |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 43 | autoninja -C out/Release wpt_tests_isolate_content_shell |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 44 | ``` |
| 45 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 46 | To run the script, run the command below from `//third_party/blink/tools`: |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 47 | |
Jonathan Lee | 9925965 | 2022-09-27 23:40:01 | [diff] [blame] | 48 | ``` sh |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 49 | ./run_wpt_tests.py [test list] |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 50 | ``` |
| 51 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 52 | Test paths should be given relative to `blink/web_tests/` (*e.g.*, |
| 53 | [`wpt_internal/badging/badge-success.https.html`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/wpt_internal/badging/badge-success.https.html)). |
| 54 | For convenience, the `external/wpt/` prefix can be omitted for the [external test |
| 55 | suite](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/) |
| 56 | (*e.g.*, |
| 57 | [`webauthn/createcredential-timeout.https.html`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webauthn/createcredential-excludecredentials.https.html)). |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 58 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 59 | `run_wpt_tests.py` also accepts directories, which will run all tests under |
| 60 | those directories. |
| 61 | Omitting the test list will run all WPT tests (both internal and external). |
| 62 | Results from the run are placed under `//out/<target>/layout-test-results/`. |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 63 | |
| 64 | Useful flags: |
| 65 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 66 | * `-t/--target`: Select which `//out/` subdirectory to use, e.g. `-t Debug`. |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 67 | Defaults to `Release`. |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 68 | * `-p/--product`: Select which browser (or browser component) to test. Defaults |
| 69 | to `content_shell`, but choices also include [`chrome`, `chrome_android`, and |
| 70 | `android_webview`](https://source.chromium.org/search?q=run_wpt_tests.py%20lang:gn). |
| 71 | * `-v`: Increase verbosity (may provide multiple times). |
| 72 | * `--help`: Show the help text. |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 73 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 74 | ## Experimental Builders |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 75 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 76 | As of Q3 2022, `wptrunner` runs on a handful of experimental FYI CI builders |
| 77 | (mostly Linux): |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 78 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 79 | * [`linux-wpt-content-shell-fyi-rel`](https://ci.chromium.org/p/chromium/builders/ci/linux-wpt-content-shell-fyi-rel), |
| 80 | which runs content shell against `external/wpt/` and `wpt_internal/` |
| 81 | * [`linux-wpt-fyi-rel`](https://ci.chromium.org/p/chromium/builders/ci/linux-wpt-fyi-rel), |
| 82 | which runs Chrome against `external/wpt/` |
| 83 | * [`linux-wpt-identity-fyi-rel`](https://ci.chromium.org/p/chromium/builders/ci/linux-wpt-identity-fyi-rel), |
| 84 | which runs tests under `external/wpt/webauthn/` |
| 85 | * [`linux-wpt-input-fyi-rel`](https://ci.chromium.org/p/chromium/builders/ci/linux-wpt-input-fyi-rel), |
| 86 | which runs tests under `external/wpt/{input-events,pointerevents,uievents}/`, |
Luke Zielinski | 5ce5d37 | 2020-12-01 19:19:47 | [diff] [blame] | 87 | as well as `external/wpt/infrastructure/testdriver/actions/` |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 88 | * Various |
| 89 | [Android](https://ci.chromium.org/p/chromium/g/chromium.android.fyi/console) |
| 90 | builders |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 91 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 92 | Each of these builders has an opt-in trybot mirror with the same name. |
| 93 | To run one of these builders against a CL, click "Choose Tryjobs" in Gerrit, |
| 94 | then search for the builder name. |
Lei Zhang | 5157b57c | 2022-10-07 20:54:53 | [diff] [blame] | 95 | A [`Cq-Include-Trybots:`](https://chromium.googlesource.com/chromium/src/+/main/docs/contributing.md#cl-footer-reference) |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 96 | footer in the CL description can add a `wptrunner` builder to the default CQ |
| 97 | builder set. |
| 98 | Results for the bots use the existing layout test |
| 99 | [results viewer](https://test-results.appspot.com/data/layout_results/linux-wpt-identity-fyi-rel/201/wpt_tests_suite/layout-test-results/results.html). |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 100 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 101 | ## Expectations |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 102 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 103 | [Similar to `run_web_tests.py`](web_test_expectations.md), `wptrunner` allows |
| 104 | engineers to specify what results to expect and which tests to skip. |
| 105 | This information is stored in [WPT metadata |
| 106 | files](https://web-platform-tests.org/tools/wptrunner/docs/expectation.html). |
| 107 | Each metadata file is checked in with an `.ini` suffix appended to its |
| 108 | corresponding test file's path: |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 109 | |
| 110 | ``` |
| 111 | external/wpt/folder/my-test.html |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 112 | external/wpt/folder/my-test-expected.txt <-- run_web_tests.py baseline |
| 113 | external/wpt/folder/my-test.html.ini <-- wptrunner metadata |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 114 | ``` |
| 115 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 116 | A metadata file is roughly equivalent to a `run_web_tests.py` baseline and the |
| 117 | test's corresponding lines in [web test expectation |
| 118 | files](web_test_expectations.md#Kinds-of-expectations-files). |
| 119 | Metadata files record test and subtest expectations in a structured INI-like |
| 120 | text format: |
| 121 | |
Jonathan Lee | 9925965 | 2022-09-27 23:40:01 | [diff] [blame] | 122 | ``` |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 123 | [my-test.html] |
| 124 | expected: OK |
| 125 | bug: crbug.com/123 # Comments start with '#' |
| 126 | |
| 127 | [First subtest name (flaky)] |
| 128 | expected: [PASS, FAIL] # Expect either a pass or a failure |
| 129 | |
| 130 | [Second subtest name: [\]] # The backslash escapes a literal ']' in the subtest name |
| 131 | expected: FAIL |
| 132 | ``` |
| 133 | |
| 134 | The brackets `[...]` denote the start of a (sub)test section, which can be |
| 135 | hierarchically nested with significant indentation. |
| 136 | Each section can contain `<key>: <value>` pairs. |
| 137 | Important keys that `wptrunner` understands: |
| 138 | |
| 139 | * `expected`: The |
| 140 | [statuses](https://firefox-source-docs.mozilla.org/mozbase/mozlog.html#data-format) |
| 141 | to expect. |
| 142 | * Tests commonly have these harness statuses: `OK`, `ERROR`, `TIMEOUT`, or |
| 143 | `CRASH` (for tests without subtests, like reftests, `PASS` replaces `OK` |
| 144 | and `FAIL` replaces `ERROR`) |
| 145 | * Subtests commonly have: `PASS`, `FAIL`, or `TIMEOUT` |
| 146 | * For convenience, `wptrunner` expects `OK` or `PASS` when `expected` is |
| 147 | omitted. |
| 148 | Deleting the entire metadata file implies an all-`PASS` test. |
| 149 | * `disabled`: Any nonempty value will disable the test or ignore the subtest |
| 150 | result. |
| 151 | |
| 152 | *** note |
| 153 | **Note**: As shown in the example above, a `testharness.js` test may have a |
| 154 | test-level status of `OK`, even if some subtests `FAIL`. This is a common |
| 155 | point of confusion: `OK` only means that the test ran to completion and did not |
| 156 | `CRASH` or `TIMEOUT`. `OK` does not imply that every subtest `PASS`ed. |
| 157 | *** |
| 158 | |
| 159 | *** note |
| 160 | **Note**: Currently, `wptrunner` can inherit expectations from |
| 161 | `TestExpectations` files through a [translation |
| 162 | step](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/tools/blinkpy/w3c/wpt_metadata_builder.py). |
| 163 | Due to lost subtest coverage, we are actively working to deprecate this and use |
| 164 | checked-in metadata natively in Chromium. |
| 165 | *** |
| 166 | |
| 167 | ### Conditional Values |
| 168 | |
| 169 | `run_web_tests.py` encodes platform- or flag-specific results using [platform |
| 170 | tags](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/tools/blinkpy/web_tests/port/base.py;l=140-164;drc=023529555939e01068874ddff3a2ea8455125efb;bpv=0;bpt=0) |
| 171 | in test expectations, separate [`FlagExpectations/*` |
| 172 | files](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/FlagExpectations/), |
| 173 | and [baseline fallback](web_test_baseline_fallback.md). |
| 174 | WPT metadata uses a Python-like [conditional |
| 175 | syntax](https://web-platform-tests.org/tools/wptrunner/docs/expectation.html#conditional-values) |
| 176 | instead to store all expectations in one file: |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 177 | |
| 178 | ``` |
| 179 | [my-test.html] |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 180 | expected: |
| 181 | if not debug: FAIL |
| 182 | if os == "mac" or (os == "linux" and version != "trusty"): [FAIL, PASS] |
| 183 | TIMEOUT # If no branch matches, use this default value. |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 184 | ``` |
| 185 | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 186 | To evaluate a conditional value, `wptrunner` takes the right-hand side of the |
| 187 | first branch where the condition evaluates to a truthy value. |
| 188 | Conditions can contain arbitrary Python-like boolean expressions that will be |
| 189 | evaluated against **properties** (*i.e.*, variables) pulled from the [test |
| 190 | environment](https://firefox-source-docs.mozilla.org/build/buildsystem/mozinfo.html). |
| 191 | Properties available in Chromium are shown below: |
| 192 | |
Jonathan Lee | 9925965 | 2022-09-27 23:40:01 | [diff] [blame] | 193 | | Property | Type | Description | Choices | |
| 194 | | - | - | - | - | |
| 195 | | `os` | `str` | OS family | `linux`, `android` | |
| 196 | | `version` | `str` | OS version | Depends on `os` | |
| 197 | | `product` | `str` | Browser or browser component | `chrome`, `content_shell`, `chrome_android`, `android_webview` | |
| 198 | | `processor` | `str` | CPU specifier | `arm`, `x86`, `x86_64` | |
| 199 | | `flag_specific` | `str` | Flag-specific suite name | See [`FlagSpecificConfig`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/FlagSpecificConfig) (will be falsy for the generic suite) | |
| 200 | | `debug` | `bool` | `is_debug` build? | N/A | |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 201 | |
| 202 | ### Test Parameterization |
| 203 | |
| 204 | The WPT suite supports forms of test parameterization where a test file on disk |
| 205 | may map to more than one test ID: [multiglobal `.any.js` |
| 206 | tests](https://web-platform-tests.org/writing-tests/testharness.html#tests-for-other-or-multiple-globals-any-js) |
| 207 | and [test |
| 208 | variants](https://web-platform-tests.org/writing-tests/testharness.html#variants). |
| 209 | The metadata for these parameterizations live in the same file (test file path |
| 210 | with the `.ini` suffix), but under different top-level sections. |
| 211 | For example, suppose a test `external/wpt/a.any.js` generates test IDs |
| 212 | `a.any.html?b`, `a.any.html?c`, `a.any.worker.html?b`, and |
| 213 | `a.any.worker.html?c`. |
| 214 | Then, a file named `external/wpt/a.any.js.ini` stores expectations for all |
| 215 | parameterizations: |
| 216 | |
Jonathan Lee | 9925965 | 2022-09-27 23:40:01 | [diff] [blame] | 217 | ``` |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 218 | [a.any.html?b] |
| 219 | expected: OK |
| 220 | |
| 221 | [a.any.html?c] |
| 222 | expected: CRASH |
| 223 | |
| 224 | [a.any.worker.html?b] |
| 225 | expected: TIMEOUT |
| 226 | |
| 227 | [a.any.worker.html?c] |
| 228 | expected: TIMEOUT |
| 229 | ``` |
| 230 | |
| 231 | ### Directory-Wide Expectations |
| 232 | |
| 233 | To set expectations or disable tests under a directory without editing an `.ini` |
| 234 | file for every test, place a file named `__dir__.ini` under the desired |
| 235 | directory with contents like: |
| 236 | |
Jonathan Lee | 9925965 | 2022-09-27 23:40:01 | [diff] [blame] | 237 | ``` |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 238 | expected: |
| 239 | if os == "linux": CRASH |
| 240 | disabled: |
| 241 | if flag_specific == "highdpi": skip highdpi for these non-rendering tests |
| 242 | ``` |
| 243 | |
| 244 | Note that there is no section heading `[my-test.html]`, but the keys work |
| 245 | exactly the same as for per-test metadata. |
| 246 | |
| 247 | Metadata closer to affected test files take higher precedence. |
| 248 | For example, expectations set by `a/b/test.html.ini` override those of |
| 249 | `a/b/__dir__.ini`, which overrides `a/__dir__.ini`. |
| 250 | |
| 251 | The special value `disabled: @False` can selectively reenable child tests or |
| 252 | directories that would have been disabled by a parent `__dir__.ini`. |
| 253 | |
| 254 | ### Tooling |
| 255 | |
| 256 | To help update expectations in bulk, |
| 257 | [`blink_tool.py`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/tools/blinkpy/tool/blink_tool.py) |
| 258 | has an |
| 259 | [`update-metadata`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/tools/blinkpy/tool/commands/update_metadata.py) |
| 260 | subcommand that can automatically update expectations from try job results |
| 261 | (similar to |
| 262 | [`rebaseline-cl`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/tools/blinkpy/tool/commands/rebaseline_cl.py)). |
| 263 | Example invocation: |
| 264 | |
Jonathan Lee | 9925965 | 2022-09-27 23:40:01 | [diff] [blame] | 265 | ``` sh |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 266 | ./blink_tool.py update-metadata --verbose --bug=123 \ |
| 267 | --build=linux-wpt-content-shell-fyi-rel:30 css/ |
| 268 | ``` |
| 269 | |
| 270 | This will update the `expected` statuses for `external/wpt/css/` (sub)tests that |
| 271 | ran unexpectedly on [build 30 of |
| 272 | `linux-wpt-content-shell-fyi-rel`](https://ci.chromium.org/ui/p/chromium/builders/try/linux-wpt-content-shell-fyi-rel/30/overview). |
| 273 | Any updated test section will be annotated with `bug: crbug.com/123`. |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 274 | |
| 275 | ## Known issues |
| 276 | |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 277 | * There is no debugging support in `run_wpt_tests.py` today. In the future, we |
| 278 | intend to allow pausing the browser after each test, and (long-term) intend to |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 279 | support hooking up `gdb` to test runs. |
Stephen McGruer | 16f7943 | 2020-10-07 13:11:05 | [diff] [blame] | 280 | * There is not yet support for non-Linux platforms. We would love for you to try |
| 281 | it on other operating systems and file bugs against us if it doesn't work! |
| 282 | |
| 283 | Please [file bugs and feature requests](https://crbug.com/new) against |
Jonathan Lee | df7b2af5 | 2022-09-27 18:38:38 | [diff] [blame] | 284 | `Blink>Infra`, tagging the title with `[wptrunner]`. |