1#!/usr/bin/env vpython
2# Copyright 2018 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Runs WPT as an isolate bundle.
7
8This script maps flags supported by run_isolate_script_test.py to flags that are
9understood by WPT.
10
11Here's the mapping [isolate script flag] : [wpt flag]
12--isolated-script-test-output : --log-chromium
13--total-shards : --total-chunks
14--shard-index : -- this-chunk
15"""
16
17import json
18import os
19import sys
20
21import common
22
23BLINK_TOOLS_DIR = os.path.join(common.SRC_DIR, 'third_party', 'blink', 'tools')
24WPT_METADATA_DIR = "../../wpt_expectations_metadata/"
25WPT_OVERRIDE_EXPECTATIONS_PATH = (
26    "../../third_party/blink/web_tests/WPTOverrideExpectations")
27
28class WPTTestAdapter(common.BaseIsolatedScriptArgsAdapter):
29
30    def generate_test_output_args(self, output):
31        return ['--log-chromium', output]
32
33    def generate_sharding_args(self, total_shards, shard_index):
34        return ['--total-chunks=%d' % total_shards,
35                # shard_index is 0-based but WPT's this-chunk to be 1-based
36                '--this-chunk=%d' % (shard_index + 1)]
37
38    @property
39    def rest_args(self):
40        rest_args = super(WPTTestAdapter, self).rest_args
41        # Here we add all of the arguments required to run WPT tests on Chrome.
42        rest_args.extend([
43            "../../third_party/blink/web_tests/external/wpt/wpt",
44            "--venv=../../",
45            "--skip-venv-setup",
46            "run",
47            "chrome",
48            "--binary=../../out/Release/chrome",
49            "--binary-arg=--host-resolver-rules="
50                "MAP nonexistent.*.test ~NOTFOUND, MAP *.test 127.0.0.1",
51            "--binary-arg=--enable-experimental-web-platform-features",
52            "--binary-arg=--enable-blink-features=MojoJS,MojoJSTest",
53            "--webdriver-binary=../../out/Release/chromedriver",
54            "--headless",
55            "--no-capture-stdio",
56            "--no-manifest-download",
57            "--no-pause-after-test",
58            # Exclude webdriver tests for now. They are run separately on the CI
59            "--exclude=webdriver",
60            "--exclude=infrastructure/webdriver",
61            # Setting --no-fail-on-unexpected makes the return code of wpt 0
62            # even if there were test failures. The CQ doesn't like this since
63            # it uses the exit code to determine which shards to retry (ie:
64            # those that had non-zero exit codes).
65            #"--no-fail-on-unexpected",
66            "--metadata",
67            WPT_METADATA_DIR,
68            # By specifying metadata above, WPT will try to find manifest in the
69            # metadata directory. So here we point it back to the correct path
70            # for the manifest.
71            # TODO(lpz): Allowing WPT to rebuild its own manifest temporarily to
72            # gauge performance impact. Issue with specifying the base manifest
73            # below is that it can get stale if tests are renamed, and requires
74            # a lengthy import/export cycle to refresh. So we allow WPT to
75            # update the manifest in cast it's stale.
76            #"--no-manifest-update",
77            "--manifest=../../third_party/blink/web_tests/external/"
78                "WPT_BASE_MANIFEST_7.json",
79            # (crbug.com/1023835) The flags below are temporary to aid debugging
80            "--log-mach=-",
81            "--log-mach-verbose",
82            # See if multi-processing affects timeouts.
83            # TODO(lpz): Consider removing --processes and compute automatically
84            # from multiprocessing.cpu_count()
85            #"--processes=5",
86        ])
87        return rest_args
88
89
90def main():
91    # First, generate WPT metadata files.
92    common.run_command([
93        sys.executable,
94        os.path.join(BLINK_TOOLS_DIR, 'build_wpt_metadata.py'),
95        "--metadata-output-dir",
96        WPT_METADATA_DIR,
97        "--additional-expectations",
98        WPT_OVERRIDE_EXPECTATIONS_PATH
99    ])
100
101    adapter = WPTTestAdapter()
102    return adapter.run_test()
103
104
105# This is not really a "script test" so does not need to manually add
106# any additional compile targets.
107def main_compile_targets(args):
108    json.dump([], args.output)
109
110
111if __name__ == '__main__':
112    # Conform minimally to the protocol defined by ScriptTest.
113    if 'compile_targets' in sys.argv:
114        funcs = {
115            'run': None,
116            'compile_targets': main_compile_targets,
117        }
118        sys.exit(common.run_script(sys.argv[1:], funcs))
119    sys.exit(main())
120