blob: 57517c162e70a797690fa437cfe587ba6ba4b293 [file] [log] [blame] [view]
Jonathan Lee99259652022-09-27 23:40:011# Using wptrunner in Chromium (experimental)
Stephen McGruer16f79432020-10-07 13:11:052
Jonathan Leedf7b2af52022-09-27 18:38:383[`wptrunner`](https://github.com/web-platform-tests/wpt/tree/master/tools/wptrunner)
4is the harness shipped with the WPT project for running the test suite. This
5user guide documents *experimental* support in Chromium for `wptrunner`, which
6will replace [`run_web_tests.py`](web_platform_tests.md#Running-tests) for
7running WPTs in CQ/CI.
Stephen McGruer16f79432020-10-07 13:11:058
Jonathan Leedf7b2af52022-09-27 18:38:389For general information on web platform tests, see
10[web-platform-tests.org](https://web-platform-tests.org/test-suite-design.html).
11
12For 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
17edges. This document may be stale.
18***
Stephen McGruer16f79432020-10-07 13:11:0519
20[TOC]
21
Jonathan Leedf7b2af52022-09-27 18:38:3822## Differences from `run_web_tests.py`
Stephen McGruer16f79432020-10-07 13:11:0523
24The main differences between `run_web_tests.py` and `wptrunner` are that:
25
Jonathan Leedf7b2af52022-09-27 18:38:38261. `wptrunner` can run both the full `chrome` binary and the stripped-down
27 `content_shell`. `run_web_tests.py` can only run `content_shell`.
281. `wptrunner` can communicate with the binary via WebDriver (`chromedriver`),
Stephen McGruer16f79432020-10-07 13:11:0529 instead of talking directly to the browser binary.
30
31These differences mean that any feature that works on upstream WPT today (e.g.
Jonathan Leedf7b2af52022-09-27 18:38:3832print-reftests) should work in `wptrunner`, but conversely, features available to
Stephen McGruer16f79432020-10-07 13:11:0533`run_web_tests.py` (e.g. the `internals` API) are not yet available to
34`wptrunner`.
35
36## Running tests locally
37
Jonathan Leedf7b2af52022-09-27 18:38:3838The `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).
40First, build the necessary ninja target:
Stephen McGruer16f79432020-10-07 13:11:0541
Jonathan Lee99259652022-09-27 23:40:0142``` sh
Jonathan Leedf7b2af52022-09-27 18:38:3843autoninja -C out/Release wpt_tests_isolate_content_shell
Stephen McGruer16f79432020-10-07 13:11:0544```
45
Jonathan Leedf7b2af52022-09-27 18:38:3846To run the script, run the command below from `//third_party/blink/tools`:
Stephen McGruer16f79432020-10-07 13:11:0547
Jonathan Lee99259652022-09-27 23:40:0148``` sh
Jonathan Leedf7b2af52022-09-27 18:38:3849./run_wpt_tests.py [test list]
Stephen McGruer16f79432020-10-07 13:11:0550```
51
Jonathan Leedf7b2af52022-09-27 18:38:3852Test 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)).
54For convenience, the `external/wpt/` prefix can be omitted for the [external test
55suite](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 McGruer16f79432020-10-07 13:11:0558
Jonathan Leedf7b2af52022-09-27 18:38:3859`run_wpt_tests.py` also accepts directories, which will run all tests under
60those directories.
61Omitting the test list will run all WPT tests (both internal and external).
62Results from the run are placed under `//out/<target>/layout-test-results/`.
Stephen McGruer16f79432020-10-07 13:11:0563
64Useful flags:
65
Jonathan Leedf7b2af52022-09-27 18:38:3866* `-t/--target`: Select which `//out/` subdirectory to use, e.g. `-t Debug`.
Stephen McGruer16f79432020-10-07 13:11:0567 Defaults to `Release`.
Jonathan Leedf7b2af52022-09-27 18:38:3868* `-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 McGruer16f79432020-10-07 13:11:0573
Jonathan Leedf7b2af52022-09-27 18:38:3874## Experimental Builders
Stephen McGruer16f79432020-10-07 13:11:0575
Jonathan Leedf7b2af52022-09-27 18:38:3876As of Q3 2022, `wptrunner` runs on a handful of experimental FYI CI builders
77(mostly Linux):
Stephen McGruer16f79432020-10-07 13:11:0578
Jonathan Leedf7b2af52022-09-27 18:38:3879* [`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 Zielinski5ce5d372020-12-01 19:19:4787 as well as `external/wpt/infrastructure/testdriver/actions/`
Jonathan Leedf7b2af52022-09-27 18:38:3888* Various
89 [Android](https://ci.chromium.org/p/chromium/g/chromium.android.fyi/console)
90 builders
Stephen McGruer16f79432020-10-07 13:11:0591
Jonathan Leedf7b2af52022-09-27 18:38:3892Each of these builders has an opt-in trybot mirror with the same name.
93To run one of these builders against a CL, click "Choose Tryjobs" in Gerrit,
94then search for the builder name.
Lei Zhang5157b57c2022-10-07 20:54:5395A [`Cq-Include-Trybots:`](https://chromium.googlesource.com/chromium/src/+/main/docs/contributing.md#cl-footer-reference)
Jonathan Leedf7b2af52022-09-27 18:38:3896footer in the CL description can add a `wptrunner` builder to the default CQ
97builder set.
98Results 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 McGruer16f79432020-10-07 13:11:05100
Jonathan Leedf7b2af52022-09-27 18:38:38101## Expectations
Stephen McGruer16f79432020-10-07 13:11:05102
Jonathan Leedf7b2af52022-09-27 18:38:38103[Similar to `run_web_tests.py`](web_test_expectations.md), `wptrunner` allows
104engineers to specify what results to expect and which tests to skip.
105This information is stored in [WPT metadata
106files](https://web-platform-tests.org/tools/wptrunner/docs/expectation.html).
107Each metadata file is checked in with an `.ini` suffix appended to its
108corresponding test file's path:
Stephen McGruer16f79432020-10-07 13:11:05109
110```
111external/wpt/folder/my-test.html
Jonathan Leedf7b2af52022-09-27 18:38:38112external/wpt/folder/my-test-expected.txt <-- run_web_tests.py baseline
113external/wpt/folder/my-test.html.ini <-- wptrunner metadata
Stephen McGruer16f79432020-10-07 13:11:05114```
115
Jonathan Leedf7b2af52022-09-27 18:38:38116A metadata file is roughly equivalent to a `run_web_tests.py` baseline and the
117test's corresponding lines in [web test expectation
118files](web_test_expectations.md#Kinds-of-expectations-files).
119Metadata files record test and subtest expectations in a structured INI-like
120text format:
121
Jonathan Lee99259652022-09-27 23:40:01122```
Jonathan Leedf7b2af52022-09-27 18:38:38123[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
134The brackets `[...]` denote the start of a (sub)test section, which can be
135hierarchically nested with significant indentation.
136Each section can contain `<key>: <value>` pairs.
137Important 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
154test-level status of `OK`, even if some subtests `FAIL`. This is a common
155point 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
162step](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/tools/blinkpy/w3c/wpt_metadata_builder.py).
163Due to lost subtest coverage, we are actively working to deprecate this and use
164checked-in metadata natively in Chromium.
165***
166
167### Conditional Values
168
169`run_web_tests.py` encodes platform- or flag-specific results using [platform
170tags](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)
171in test expectations, separate [`FlagExpectations/*`
172files](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/FlagExpectations/),
173and [baseline fallback](web_test_baseline_fallback.md).
174WPT metadata uses a Python-like [conditional
175syntax](https://web-platform-tests.org/tools/wptrunner/docs/expectation.html#conditional-values)
176instead to store all expectations in one file:
Stephen McGruer16f79432020-10-07 13:11:05177
178```
179[my-test.html]
Jonathan Leedf7b2af52022-09-27 18:38:38180 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 McGruer16f79432020-10-07 13:11:05184```
185
Jonathan Leedf7b2af52022-09-27 18:38:38186To evaluate a conditional value, `wptrunner` takes the right-hand side of the
187first branch where the condition evaluates to a truthy value.
188Conditions can contain arbitrary Python-like boolean expressions that will be
189evaluated against **properties** (*i.e.*, variables) pulled from the [test
190environment](https://firefox-source-docs.mozilla.org/build/buildsystem/mozinfo.html).
191Properties available in Chromium are shown below:
192
Jonathan Lee99259652022-09-27 23:40:01193| 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 Leedf7b2af52022-09-27 18:38:38201
202### Test Parameterization
203
204The WPT suite supports forms of test parameterization where a test file on disk
205may map to more than one test ID: [multiglobal `.any.js`
206tests](https://web-platform-tests.org/writing-tests/testharness.html#tests-for-other-or-multiple-globals-any-js)
207and [test
208variants](https://web-platform-tests.org/writing-tests/testharness.html#variants).
209The metadata for these parameterizations live in the same file (test file path
210with the `.ini` suffix), but under different top-level sections.
211For 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`.
214Then, a file named `external/wpt/a.any.js.ini` stores expectations for all
215parameterizations:
216
Jonathan Lee99259652022-09-27 23:40:01217```
Jonathan Leedf7b2af52022-09-27 18:38:38218[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
233To set expectations or disable tests under a directory without editing an `.ini`
234file for every test, place a file named `__dir__.ini` under the desired
235directory with contents like:
236
Jonathan Lee99259652022-09-27 23:40:01237```
Jonathan Leedf7b2af52022-09-27 18:38:38238expected:
239 if os == "linux": CRASH
240disabled:
241 if flag_specific == "highdpi": skip highdpi for these non-rendering tests
242```
243
244Note that there is no section heading `[my-test.html]`, but the keys work
245exactly the same as for per-test metadata.
246
247Metadata closer to affected test files take higher precedence.
248For example, expectations set by `a/b/test.html.ini` override those of
249`a/b/__dir__.ini`, which overrides `a/__dir__.ini`.
250
251The special value `disabled: @False` can selectively reenable child tests or
252directories that would have been disabled by a parent `__dir__.ini`.
253
254### Tooling
255
256To 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)
258has an
259[`update-metadata`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/tools/blinkpy/tool/commands/update_metadata.py)
260subcommand 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)).
263Example invocation:
264
Jonathan Lee99259652022-09-27 23:40:01265``` sh
Jonathan Leedf7b2af52022-09-27 18:38:38266./blink_tool.py update-metadata --verbose --bug=123 \
267 --build=linux-wpt-content-shell-fyi-rel:30 css/
268```
269
270This will update the `expected` statuses for `external/wpt/css/` (sub)tests that
271ran 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).
273Any updated test section will be annotated with `bug: crbug.com/123`.
Stephen McGruer16f79432020-10-07 13:11:05274
275## Known issues
276
Stephen McGruer16f79432020-10-07 13:11:05277* 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 Leedf7b2af52022-09-27 18:38:38279 support hooking up `gdb` to test runs.
Stephen McGruer16f79432020-10-07 13:11:05280* 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
283Please [file bugs and feature requests](https://crbug.com/new) against
Jonathan Leedf7b2af52022-09-27 18:38:38284`Blink>Infra`, tagging the title with `[wptrunner]`.