Skip to content

Commit

Permalink
[wptrunner] Add debugger support for content_shell
Browse files Browse the repository at this point in the history
Prefix the `content_shell` command with a debugger wrapper command, and
set an indefinite test timeout for interactive debuggers.

Tested upstream with:

```sh
./run_wpt_test.py -t Default external/wpt/badging -vv --wrapper='time -o /dev/null'
```
  • Loading branch information
jonathan-j-lee committed Sep 15, 2023
1 parent 82e584d commit 42bf85b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
14 changes: 14 additions & 0 deletions tools/wptrunner/wptrunner/browsers/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
"timeout_multiplier": "get_timeout_multiplier",}


def debug_args(debug_info):
if debug_info.interactive:
# Keep in sync with:
# https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/tools/debug_renderer
return [
"--no-sandbox",
"--disable-hang-monitor",
"--wait-for-debugger-on-navigation",
]
return []


def check_args(**kwargs):
require_arg(kwargs, "webdriver_binary")

Expand Down Expand Up @@ -148,6 +160,8 @@ def env_extras(**kwargs):


def env_options():
# TODO(crbug.com/1440021): Support text-based debuggers for `chrome` through
# `chromedriver`.
return {"server_host": "127.0.0.1"}


Expand Down
17 changes: 13 additions & 4 deletions tools/wptrunner/wptrunner/browsers/content_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
Browser,
ExecutorBrowser,
OutputHandler,
browser_command,
)
from .base import get_timeout_multiplier # noqa: F401
from .chrome import debug_args
from ..executors import executor_kwargs as base_executor_kwargs
from ..executors.executorcontentshell import ( # noqa: F401
ContentShellCrashtestExecutor,
Expand Down Expand Up @@ -57,6 +59,9 @@ def browser_kwargs(logger, test_type, run_info_data, config, subsuite, **kwargs)
if not kwargs["headless"]:
args.append("--disable-headless-mode")

if kwargs["debug_info"]:
args.extend(debug_args(kwargs["debug_info"]))

# `--run-web-tests -` are specific to content_shell - they activate web
# test protocol mode.
args.append("--run-web-tests")
Expand All @@ -76,7 +81,8 @@ def browser_kwargs(logger, test_type, run_info_data, config, subsuite, **kwargs)
args.append("-")

return {"binary": kwargs["binary"],
"binary_args": args}
"binary_args": args,
"debug_info": kwargs["debug_info"]}


def executor_kwargs(logger, test_type, test_environment, run_info_data,
Expand All @@ -96,7 +102,8 @@ def env_extras(**kwargs):

def env_options():
return {"server_host": "127.0.0.1",
"testharnessreport": "testharnessreport-content-shell.js"}
"testharnessreport": "testharnessreport-content-shell.js",
"supports_debugger": True}


def update_properties():
Expand All @@ -119,9 +126,11 @@ class ContentShellBrowser(Browser):
# https://chromium.googlesource.com/chromium/src/+/b175d48d3ea4ea66eea35c88c11aa80d233f3bee/third_party/blink/tools/blinkpy/web_tests/port/base.py#476
termination_timeout: float = 3

def __init__(self, logger, binary="content_shell", binary_args=[], **kwargs):
def __init__(self, logger, binary="content_shell", binary_args=None,
debug_info=None, **kwargs):
super().__init__(logger)
self._args = [binary] + binary_args
debug_cmd_prefix, browser_cmd = browser_command(binary, binary_args or [], debug_info)
self._args = [*debug_cmd_prefix, *browser_cmd]
self._output_handler = None
self._proc = None

Expand Down
17 changes: 11 additions & 6 deletions tools/wptrunner/wptrunner/executors/executorcontentshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ def _convert_exception(test, exception, errors):
raise exception


def timeout_for_test(executor, test):
if executor.debug_info and executor.debug_info.interactive:
return None
return test.timeout * executor.timeout_multiplier


class ContentShellCrashtestExecutor(CrashtestExecutor):
def __init__(self, logger, browser, server_config, timeout_multiplier=1, debug_info=None,
**kwargs):
Expand All @@ -232,7 +238,8 @@ def __init__(self, logger, browser, server_config, timeout_multiplier=1, debug_i

def do_test(self, test):
try:
_ = self.protocol.content_shell_test.do_test(self.test_url(test), test.timeout * self.timeout_multiplier)
_ = self.protocol.content_shell_test.do_test(self.test_url(test),
timeout_for_test(self, test))
self.protocol.content_shell_errors.read_errors()
return self.convert_result(test, {"status": "PASS", "message": None})
except BaseException as exception:
Expand Down Expand Up @@ -275,12 +282,11 @@ def screenshot(self, test, viewport_size, dpi, page_ranges):
# source tree (i.e., without looking at a reference). This is not
# possible in `wpt`, so pass an empty hash here to force a dump.
command += "''print"
_, image = self.protocol.content_shell_test.do_test(
command, test.timeout * self.timeout_multiplier)

_, image = self.protocol.content_shell_test.do_test(command,
timeout_for_test(self, test))
if not image:
return False, ("ERROR", self.protocol.content_shell_errors.read_errors())

return True, b64encode(image).decode()


Expand All @@ -303,8 +309,7 @@ def __init__(self, logger, browser, server_config, timeout_multiplier=1, debug_i
def do_test(self, test):
try:
text, _ = self.protocol.content_shell_test.do_test(self.test_url(test),
test.timeout * self.timeout_multiplier)

timeout_for_test(self, test))
errors = self.protocol.content_shell_errors.read_errors()
if not text:
return (test.result_cls("ERROR", errors), [])
Expand Down
2 changes: 1 addition & 1 deletion tools/wptrunner/wptrunner/executors/executorwebdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ class WebDriverCrashtestExecutor(CrashtestExecutor):
def __init__(self, logger, browser, server_config, timeout_multiplier=1,
screenshot_cache=None, close_after_done=True,
debug_info=None, capabilities=None, **kwargs):
"""WebDriver-based executor for reftests"""
"""WebDriver-based executor for crashtests"""
CrashtestExecutor.__init__(self,
logger,
browser,
Expand Down

0 comments on commit 42bf85b

Please sign in to comment.