Skip to content

Commit bd278f4

Browse files
mukilanjdm
authored andcommitted
wpt: Have ServoRefTestExecutor inherit from RefTestExecutor
Since `ProcessTestExecutor` is only used by Servo and doesn't add much on top of `ServoExecutor`, merge the former into the latter. Also make `ServoExecutor` a mixin so that the derived classes can inherit from upstream `wptrunner`'s classes and avoid the diamond inheritance of `TestExecutor` base class. Another issue is that new changes in the `RefTestImplementation.get_screenshot_list` method upstream conflicts with the assumptions in Servo's executor: - The `dpi` argument is used as an `int` although it is a string - The `viewport_size` argument is treated as a tuple of ints but it is in fact a string of the format `WxH`. It also treats the viewport dimensions as being specified in device pixel coordinates while Servo treats it as logical coordinates and will scale it by `dpi`. These issues need to discussed with upstream and patched in `RefTestImplementation`. Finally, add back `**kwargs` argument to `ServoCrashtestExecutor`'s constructor to fix #40322. Fixes #40288, #40322 Signed-off-by: Mukilan Thiyagarajan <[email protected]>
1 parent a169963 commit bd278f4

File tree

2 files changed

+54
-63
lines changed

2 files changed

+54
-63
lines changed

tools/wptrunner/wptrunner/executors/executorservo.py

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313

1414
from tools.serve.serve import make_hosts_file
1515

16-
from .base import (RefTestImplementation,
16+
from .base import (RefTestExecutor, RefTestImplementation, TestExecutor,
1717
crashtest_result_converter,
1818
testharness_result_converter,
1919
reftest_result_converter,
2020
TimedRunner)
21-
from .process import ProcessTestExecutor
2221
from .protocol import ConnectionlessProtocol
2322
from ..browsers.base import browser_command
2423

@@ -27,14 +26,22 @@
2726
webdriver = None
2827

2928

30-
class ServoExecutor(ProcessTestExecutor):
29+
# A mixin class that includes functionality common to all Servo
30+
# executors that work by spawing a new process. This is intended to
31+
# be used along with either the `TestExecutor` class or its children
32+
# and must be the first in the inheritance list to allow `super`
33+
# to forward the calls to correct base class.
34+
class ServoExecutorMixin:
3135
def __init__(self, logger, browser, server_config, headless,
32-
timeout_multiplier, debug_info,
36+
timeout_multiplier, debug_info,
3337
pause_after_test, reftest_screenshot="unexpected"):
34-
ProcessTestExecutor.__init__(self, logger, browser, server_config,
35-
timeout_multiplier=timeout_multiplier,
36-
debug_info=debug_info,
37-
reftest_screenshot=reftest_screenshot)
38+
super().__init__(logger, browser, server_config,
39+
timeout_multiplier=timeout_multiplier,
40+
debug_info=debug_info,
41+
reftest_screenshot=reftest_screenshot)
42+
self.binary = self.browser.binary
43+
self.interactive = (False if self.debug_info is None
44+
else self.debug_info.interactive)
3845
self.pause_after_test = pause_after_test
3946
self.environment = {}
4047
self.protocol = ConnectionlessProtocol(self, browser)
@@ -44,18 +51,23 @@ def __init__(self, logger, browser, server_config, headless,
4451

4552
hosts_fd, self.hosts_path = tempfile.mkstemp()
4653
with os.fdopen(hosts_fd, "w") as f:
47-
f.write(make_hosts_file(server_config, "127.0.0.1"))
54+
f.write(make_hosts_file(self.server_config, "127.0.0.1"))
4855

4956
self.env_for_tests = os.environ.copy()
5057
self.env_for_tests["HOST_FILE"] = self.hosts_path
5158
self.env_for_tests["RUST_BACKTRACE"] = "1"
5259

60+
def setup(self, runner, protocol=None):
61+
self.runner = runner
62+
self.runner.send_message("init_succeeded")
63+
return True
64+
5365
def teardown(self):
5466
try:
5567
os.unlink(self.hosts_path)
5668
except OSError:
5769
pass
58-
ProcessTestExecutor.teardown(self)
70+
super().teardown()
5971

6072
def on_environment_change(self, new_environment):
6173
self.environment = new_environment
@@ -107,16 +119,17 @@ def build_servo_command(self, test, extra_args=None):
107119
return debug_args + command
108120

109121

110-
class ServoTestharnessExecutor(ServoExecutor):
122+
class ServoTestharnessExecutor(ServoExecutorMixin, TestExecutor):
111123
convert_result = testharness_result_converter
112124

113125
def __init__(self, logger, browser, server_config, headless,
114126
timeout_multiplier=1, debug_info=None,
115127
pause_after_test=False, **kwargs):
116-
ServoExecutor.__init__(self, logger, browser, server_config, headless,
117-
timeout_multiplier=timeout_multiplier,
118-
debug_info=debug_info,
119-
pause_after_test=pause_after_test)
128+
super().__init__(logger, browser, server_config,
129+
headless,
130+
timeout_multiplier=timeout_multiplier,
131+
debug_info=debug_info,
132+
pause_after_test=pause_after_test)
120133
self.result_data = None
121134
self.result_flag = None
122135

@@ -182,7 +195,7 @@ def on_output(self, line):
182195
self.logger.error(f"Could not process test output JSON: {error}")
183196
self.result_flag.set()
184197
else:
185-
ServoExecutor.on_output(self, line)
198+
super().on_output(line)
186199

187200
def on_finish(self):
188201
self.result_flag.set()
@@ -204,21 +217,20 @@ def __exit__(self, *args, **kwargs):
204217
pass
205218

206219

207-
class ServoRefTestExecutor(ServoExecutor):
220+
class ServoRefTestExecutor(ServoExecutorMixin, RefTestExecutor):
208221
convert_result = reftest_result_converter
209222

210223
def __init__(self, logger, browser, server_config, binary=None, timeout_multiplier=1,
211224
screenshot_cache=None, debug_info=None, pause_after_test=False,
212225
reftest_screenshot="unexpected", **kwargs):
213-
ServoExecutor.__init__(self,
214-
logger,
215-
browser,
216-
server_config,
217-
headless=True,
218-
timeout_multiplier=timeout_multiplier,
219-
debug_info=debug_info,
220-
reftest_screenshot=reftest_screenshot,
221-
pause_after_test=pause_after_test)
226+
super().__init__(logger,
227+
browser,
228+
server_config,
229+
headless=True,
230+
timeout_multiplier=timeout_multiplier,
231+
debug_info=debug_info,
232+
reftest_screenshot=reftest_screenshot,
233+
pause_after_test=pause_after_test)
222234

223235
self.screenshot_cache = screenshot_cache
224236
self.reftest_screenshot = reftest_screenshot
@@ -230,7 +242,7 @@ def reset(self):
230242

231243
def teardown(self):
232244
os.rmdir(self.tempdir)
233-
ServoExecutor.teardown(self)
245+
super().teardown()
234246

235247
def screenshot(self, test, viewport_size, dpi, page_ranges):
236248
with TempFilename(self.tempdir) as output_path:
@@ -239,7 +251,7 @@ def screenshot(self, test, viewport_size, dpi, page_ranges):
239251
"--window-size", viewport_size or "800x600"]
240252

241253
if dpi:
242-
extra_args += ["--device-pixel-ratio", dpi]
254+
extra_args += ["--device-pixel-ratio", str(dpi)]
243255

244256
self.command = self.build_servo_command(test, extra_args)
245257

@@ -278,6 +290,11 @@ def screenshot(self, test, viewport_size, dpi, page_ranges):
278290
return True, [base64.b64encode(data).decode()]
279291

280292
def do_test(self, test):
293+
# FIXME: This is a temporary fix until Servo syncs with upstream WPT.
294+
# Once that happens, we can patch the `RefTestImplementation.get_screenshot_list`
295+
# method to cast dpi to integer when using it in arithmetic expressions.
296+
if test.dpi is not None:
297+
test.dpi = int(test.dpi)
281298
self.test = test
282299
result = self.implementation.run_test(test)
283300

@@ -301,23 +318,19 @@ def set_timeout(self):
301318
pass
302319

303320

304-
class ServoCrashtestExecutor(ServoExecutor):
321+
class ServoCrashtestExecutor(ServoExecutorMixin, TestExecutor):
305322
convert_result = crashtest_result_converter
306323

307324
def __init__(self, logger, browser, server_config, headless,
308325
binary=None, timeout_multiplier=1, screenshot_cache=None,
309-
debug_info=None, pause_after_test=False):
310-
ServoExecutor.__init__(self,
311-
logger,
312-
browser,
313-
server_config,
314-
headless,
315-
timeout_multiplier=timeout_multiplier,
316-
debug_info=debug_info,
317-
pause_after_test=pause_after_test)
318-
319-
self.pause_after_test = pause_after_test
320-
self.protocol = ConnectionlessProtocol(self, browser)
326+
debug_info=None, pause_after_test=False, **kwargs):
327+
super().__init__(logger,
328+
browser,
329+
server_config,
330+
headless,
331+
timeout_multiplier=timeout_multiplier,
332+
debug_info=debug_info,
333+
pause_after_test=pause_after_test)
321334

322335
def do_test(self, test):
323336
timeout = (test.timeout * self.timeout_multiplier if self.debug_info is None

tools/wptrunner/wptrunner/executors/process.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)