Debian Codegraph @

testing/web-platform/mach_commands_base.py

raw
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 import sys
6
7 from mozlog import handlers
8 from mozlog.structuredlog import log_levels
9
10
11 def create_parser_wpt():
12 from wptrunner import wptcommandline
13
14 result = wptcommandline.create_parser()
15
16 result.add_argument(
17 "--no-install",
18 action="store_true",
19 default=False,
20 help="Do not install test runner application",
21 )
22 return result
23
24
25 class CriticalLogBuffer(handlers.BaseHandler):
26 """
27 Buffer critical log entries
28 """
29
30 def __init__(self):
31 self.log_entries = []
32
33 def __call__(self, data):
34 if (
35 data["action"] == "log"
36 and log_levels[data["level"]] <= log_levels["CRITICAL"]
37 ):
38 self.log_entries.append(data)
39
40
41 class WebPlatformTestsRunner:
42 """Run web platform tests."""
43
44 def __init__(self, setup):
45 self.setup = setup
46
47 def setup_logging(self, **kwargs):
48 from tools.wpt import run
49
50 return run.setup_logging(
51 kwargs,
52 {self.setup.default_log_type: sys.stdout},
53 formatter_defaults={"screenshot": True},
54 )
55
56 def run(self, logger, **kwargs):
57 from mozbuild.base import BinaryNotFoundException
58 from wptrunner import wptrunner
59
60 if kwargs["manifest_update"] is not False:
61 self.update_manifest(logger)
62 kwargs["manifest_update"] = False
63
64 if kwargs["product"] == "firefox":
65 try:
66 kwargs = self.setup.kwargs_firefox(kwargs)
67 except BinaryNotFoundException as e:
68 logger.error(e)
69 logger.info(e.help())
70 return 1
71 elif kwargs["product"] == "firefox_android":
72 kwargs = self.setup.kwargs_firefox_android(kwargs)
73 else:
74 kwargs = self.setup.kwargs_wptrun(kwargs)
75
76 log_buffer = CriticalLogBuffer()
77 logger.add_handler(log_buffer)
78
79 result = 1
80 try:
81 result = wptrunner.start(**kwargs)
82 finally:
83 if int(result) != 0:
84 self._process_log_errors(logger, log_buffer, kwargs)
85 logger.remove_handler(log_buffer)
86 return int(result)
87
88 def _process_log_errors(self, logger, log_buffer, kwargs):
89 for item in log_buffer.log_entries:
90 if (
91 kwargs["webdriver_binary"] is None
92 and "webdriver" in item["message"]
93 and self.setup.topobjdir
94 ):
95 print(
96 "ERROR: Couldn't find geckodriver binary required to run wdspec tests, consider `ac_add_options --enable-geckodriver` in your build configuration"
97 )
98
99 def update_manifest(self, logger, **kwargs):
100 import manifestupdate
101
102 return manifestupdate.run(
103 logger=logger,
104 src_root=self.setup.topsrcdir,
105 obj_root=self.setup.topobjdir,
106 **kwargs
107 )