diff --git a/etc/run_in_headless_android_emulator.py b/etc/run_in_headless_android_emulator.py index 7ee300589d9..d1808f1a197 100755 --- a/etc/run_in_headless_android_emulator.py +++ b/etc/run_in_headless_android_emulator.py @@ -57,6 +57,7 @@ def main(avd_name, apk_path, *args): logcat_args = ["RustAndroidGlueStdouterr:D", "*:S", "-v", "raw"] with terminate_on_exit(adb + ["logcat"] + logcat_args) as logcat: + forward_webdriver(adb, args) logcat.wait() @@ -119,6 +120,28 @@ def write_args(adb, args): check_call(adb + ["shell", "echo %s >> %s" % (shell_quote(arg), params_file)]) +def forward_webdriver(adb, args): + webdriver_port = extract_arg("--webdriver", args) + if webdriver_port is not None: + wait_for_tcp_server(adb, webdriver_port) + port = "tcp:%s" % webdriver_port + check_call(adb + ["forward", port, port]) + sys.stderr.write("Forwarding WebDriver port %s to the emulator\n" % webdriver_port) + + +def extract_arg(name, args): + previous_arg_matches = False + for arg in args: + if previous_arg_matches: + return arg + previous_arg_matches = arg == name + + +def wait_for_tcp_server(adb, port): + while call(adb + ["shell", "nc -z 127.0.0.1 %s" % port]) != 0: + time.sleep(1) + + # Copied from Python 3.3+'s shlex.quote() def shell_quote(arg): # use single quotes, and put single quotes into double quotes diff --git a/tests/wpt/web-platform-tests/tools/wptrunner/wptrunner/executors/executorservodriver.py b/tests/wpt/web-platform-tests/tools/wptrunner/wptrunner/executors/executorservodriver.py index 668f94a398c..1dc5be4bb46 100644 --- a/tests/wpt/web-platform-tests/tools/wptrunner/wptrunner/executors/executorservodriver.py +++ b/tests/wpt/web-platform-tests/tools/wptrunner/wptrunner/executors/executorservodriver.py @@ -57,8 +57,8 @@ class ServoWebDriverProtocol(Protocol): def connect(self): """Connect to browser via WebDriver.""" - # Largish timeout for the case where we're booting an Android emulator. - wait_for_service((self.host, self.port), timeout=120) + # Large timeout for the case where we're booting an Android emulator. + wait_for_service((self.host, self.port), timeout=300) self.session = webdriver.Session(self.host, self.port, extension=ServoCommandExtensions) self.session.start()