Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Switch to using mozdebug for debugger arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraham committed Apr 10, 2015
1 parent 2f7f79f commit a0be46b
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 62 deletions.
3 changes: 1 addition & 2 deletions requirements.txt
@@ -1,5 +1,4 @@
html5lib >= 0.99
mozinfo >= 0.7
mozlog >= 2.8
# Unfortunately, just for gdb flags
mozrunner >= 6.1
mozdebug >= 0.1
12 changes: 12 additions & 0 deletions wptrunner/browsers/base.py
Expand Up @@ -41,6 +41,18 @@ def get_free_port(start_port, exclude=None):
finally:
s.close()

def browser_command(binary, args, debug_info):
if debug_info:
if debug_info.requiresEscapedArgs:
args = [item.replace("&", "\\&") for item in args]
debug_args = [debug_info.path] + debug_info.args
else:
debug_args = []

command = [binary] + args

return debug_args, command


class BrowserError(Exception):
pass
Expand Down
26 changes: 13 additions & 13 deletions wptrunner/browsers/firefox.py
Expand Up @@ -12,7 +12,7 @@
from mozrunner import FirefoxRunner
from mozcrash import mozcrash

from .base import get_free_port, Browser, ExecutorBrowser, require_arg, cmd_arg
from .base import get_free_port, Browser, ExecutorBrowser, require_arg, cmd_arg, browser_command
from ..executors import executor_kwargs as base_executor_kwargs
from ..executors.executormarionette import MarionetteTestharnessExecutor, MarionetteRefTestExecutor

Expand All @@ -37,8 +37,7 @@ def check_args(**kwargs):
def browser_kwargs(**kwargs):
return {"binary": kwargs["binary"],
"prefs_root": kwargs["prefs_root"],
"debug_args": kwargs["debug_args"],
"interactive": kwargs["interactive"],
"debug_info": kwargs["debug_info"],
"symbols_path": kwargs["symbols_path"],
"stackwalk_binary": kwargs["stackwalk_binary"],
"certutil_binary": kwargs["certutil_binary"],
Expand All @@ -57,13 +56,14 @@ def env_options():
"external_host": "web-platform.test",
"bind_hostname": "false",
"certificate_domain": "web-platform.test",
"encrypt_after_connect": True}
"encrypt_after_connect": True,
"supports_debugger": True}


class FirefoxBrowser(Browser):
used_ports = set()

def __init__(self, logger, binary, prefs_root, debug_args=None, interactive=None,
def __init__(self, logger, binary, prefs_root, debug_info=None,
symbols_path=None, stackwalk_binary=None, certutil_binary=None,
ca_certificate_path=None):
Browser.__init__(self, logger)
Expand All @@ -72,8 +72,7 @@ def __init__(self, logger, binary, prefs_root, debug_args=None, interactive=None
self.marionette_port = None
self.used_ports.add(self.marionette_port)
self.runner = None
self.debug_args = debug_args
self.interactive = interactive
self.debug_info = debug_info
self.profile = None
self.symbols_path = symbols_path
self.stackwalk_binary = stackwalk_binary
Expand All @@ -84,9 +83,6 @@ def start(self):
self.marionette_port = get_free_port(2828, exclude=self.used_ports)

env = os.environ.copy()
env["MOZ_CRASHREPORTER"] = "1"
env["MOZ_CRASHREPORTER_SHUTDOWN"] = "1"
env["MOZ_CRASHREPORTER_NO_REPORT"] = "1"
env["MOZ_DISABLE_NONLOCAL_CONNECTIONS"] = "1"

locations = ServerLocations(filename=os.path.join(here, "server-locations.txt"))
Expand All @@ -107,15 +103,19 @@ def start(self):
if self.ca_certificate_path is not None:
self.setup_ssl()

debug_args, cmd = browser_command(self.binary, [cmd_arg("marionette"), "about:blank"],
self.debug_info)

self.runner = FirefoxRunner(profile=self.profile,
binary=self.binary,
cmdargs=[cmd_arg("marionette"), "about:blank"],
binary=cmd[0],
cmdargs=cmd[1:],
env=env,
process_class=ProcessHandler,
process_args={"processOutputLine": [self.on_output]})

self.logger.debug("Starting Firefox")
self.runner.start(debug_args=self.debug_args, interactive=self.interactive)

self.runner.start(debug_args=debug_args, interactive=self.debug_info and self.debug_info.interactive)
self.logger.debug("Firefox Started")

def load_prefs(self):
Expand Down
11 changes: 6 additions & 5 deletions wptrunner/browsers/servo.py
Expand Up @@ -26,7 +26,7 @@ def check_args(**kwargs):

def browser_kwargs(**kwargs):
return {"binary": kwargs["binary"],
"debug_args": kwargs["debug_args"],
"debug_info": kwargs["debug_info"],
"interactive": kwargs["interactive"]}


Expand All @@ -39,17 +39,18 @@ def executor_kwargs(test_type, server_config, cache_manager, **kwargs):
def env_options():
return {"host": "localhost",
"bind_hostname": "true",
"testharnessreport": "testharnessreport-servo.js"}
"testharnessreport": "testharnessreport-servo.js",
"supports_debugger": True}


class ServoBrowser(NullBrowser):
def __init__(self, logger, binary, debug_args=None, interactive=False):
def __init__(self, logger, binary, debug_info=None, interactive=False):
NullBrowser.__init__(self, logger)
self.binary = binary
self.debug_args = debug_args
self.debug_info = debug_info
self.interactive = interactive

def executor_browser(self):
return ExecutorBrowser, {"binary": self.binary,
"debug_args": self.debug_args,
"debug_info": self.debug_info,
"interactive": self.interactive}
14 changes: 13 additions & 1 deletion wptrunner/environment.py
Expand Up @@ -5,6 +5,7 @@
import json
import os
import multiprocessing
import signal
import socket
import sys
import time
Expand Down Expand Up @@ -90,7 +91,7 @@ def __call__(self, request, response):


class TestEnvironment(object):
def __init__(self, test_paths, ssl_env, pause_after_test, options):
def __init__(self, test_paths, ssl_env, pause_after_test, debug_info, options):
"""Context manager that owns the test environment i.e. the http and
websockets servers"""
self.test_paths = test_paths
Expand All @@ -100,11 +101,13 @@ def __init__(self, test_paths, ssl_env, pause_after_test, options):
self.external_config = None
self.pause_after_test = pause_after_test
self.test_server_port = options.pop("test_server_port", True)
self.debug_info = debug_info
self.options = options if options is not None else {}

self.cache_manager = multiprocessing.Manager()
self.routes = self.get_routes()


def __enter__(self):
self.ssl_env.__enter__()
self.cache_manager.__enter__()
Expand All @@ -113,16 +116,25 @@ def __enter__(self):
serve.set_computed_defaults(self.config)
self.external_config, self.servers = serve.start(self.config, self.ssl_env,
self.routes)
if self.options.get("supports_debugger") and self.debug_info and self.debug_info.interactive:
self.ignore_interrupts()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.process_interrupts()
self.cache_manager.__exit__(exc_type, exc_val, exc_tb)
self.ssl_env.__exit__(exc_type, exc_val, exc_tb)

for scheme, servers in self.servers.iteritems():
for port, server in servers:
server.kill()

def ignore_interrupts(self):
signal.signal(signal.SIGINT, signal.SIG_IGN)

def process_interrupts(self):
signal.signal(signal.SIGINT, signal.SIG_DFL)

def load_config(self):
default_config_path = os.path.join(serve_path(self.test_paths), "config.default.json")
local_config_path = os.path.join(here, "config.json")
Expand Down
10 changes: 5 additions & 5 deletions wptrunner/executors/base.py
Expand Up @@ -21,7 +21,7 @@ def executor_kwargs(test_type, server_config, cache_manager, **kwargs):

executor_kwargs = {"server_config": server_config,
"timeout_multiplier": timeout_multiplier,
"debug_args": kwargs["debug_args"]}
"debug_info": kwargs["debug_info"]}

if test_type == "reftest":
executor_kwargs["screenshot_cache"] = cache_manager.dict()
Expand Down Expand Up @@ -81,7 +81,7 @@ class TestExecutor(object):
convert_result = None

def __init__(self, browser, server_config, timeout_multiplier=1,
debug_args=None):
debug_info=None):
"""Abstract Base class for object that actually executes the tests in a
specific browser. Typically there will be a different TestExecutor
subclass for each test type and method of executing tests.
Expand All @@ -97,7 +97,7 @@ def __init__(self, browser, server_config, timeout_multiplier=1,
self.browser = browser
self.server_config = server_config
self.timeout_multiplier = timeout_multiplier
self.debug_args = debug_args
self.debug_info = debug_info
self.last_environment = {"protocol": "http",
"prefs": []}
self.protocol = None # This must be set in subclasses
Expand Down Expand Up @@ -182,10 +182,10 @@ class RefTestExecutor(TestExecutor):
convert_result = reftest_result_converter

def __init__(self, browser, server_config, timeout_multiplier=1, screenshot_cache=None,
debug_args=None):
debug_info=None):
TestExecutor.__init__(self, browser, server_config,
timeout_multiplier=timeout_multiplier,
debug_args=debug_args)
debug_info=debug_info)

self.screenshot_cache = screenshot_cache

Expand Down
14 changes: 7 additions & 7 deletions wptrunner/executors/executormarionette.py
Expand Up @@ -62,7 +62,7 @@ def setup(self, runner):
while True:
success = self.marionette.wait_for_port(60)
#When running in a debugger wait indefinitely for firefox to start
if success or self.executor.debug_args is None:
if success or self.executor.debug_info is None:
break

session_started = False
Expand Down Expand Up @@ -271,11 +271,11 @@ def _run(self):

class MarionetteTestharnessExecutor(TestharnessExecutor):
def __init__(self, browser, server_config, timeout_multiplier=1, close_after_done=True,
debug_args=None):
debug_info=None):
"""Marionette-based executor for testharness.js tests"""
TestharnessExecutor.__init__(self, browser, server_config,
timeout_multiplier=timeout_multiplier,
debug_args=debug_args)
debug_info=debug_info)

self.protocol = MarionetteProtocol(self, browser)
self.script = open(os.path.join(here, "testharness_marionette.js")).read()
Expand All @@ -297,7 +297,7 @@ def on_environment_change(self, new_environment):
self.protocol.load_runner(new_environment["protocol"])

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

success, data = MarionetteRun(self.logger,
Expand Down Expand Up @@ -331,14 +331,14 @@ def do_testharness(self, marionette, url, timeout):

class MarionetteRefTestExecutor(RefTestExecutor):
def __init__(self, browser, server_config, timeout_multiplier=1,
screenshot_cache=None, close_after_done=True, debug_args=None):
screenshot_cache=None, close_after_done=True, debug_info=None):
"""Marionette-based executor for reftests"""
RefTestExecutor.__init__(self,
browser,
server_config,
screenshot_cache=screenshot_cache,
timeout_multiplier=timeout_multiplier,
debug_args=debug_args)
debug_info=debug_info)
self.protocol = MarionetteProtocol(self, browser)
self.implementation = RefTestImplementation(self)
self.close_after_done = close_after_done
Expand Down Expand Up @@ -373,7 +373,7 @@ def do_test(self, test):
return self.convert_result(test, result)

def screenshot(self, test):
timeout = self.timeout_multiplier * test.timeout if self.debug_args is None else None
timeout = test.timeout if self.debug_info is None else None

test_url = self.test_url(test)

Expand Down
8 changes: 4 additions & 4 deletions wptrunner/executors/executorselenium.py
Expand Up @@ -165,11 +165,11 @@ def _run(self):

class SeleniumTestharnessExecutor(TestharnessExecutor):
def __init__(self, browser, server_config, timeout_multiplier=1,
close_after_done=True, capabilities=None, debug_args=None):
close_after_done=True, capabilities=None, debug_info=None):
"""Selenium-based executor for testharness.js tests"""
TestharnessExecutor.__init__(self, browser, server_config,
timeout_multiplier=timeout_multiplier,
debug_args=debug_args)
debug_info=debug_info)
self.protocol = SeleniumProtocol(self, browser, capabilities)
with open(os.path.join(here, "testharness_webdriver.js")) as f:
self.script = f.read()
Expand Down Expand Up @@ -206,14 +206,14 @@ def do_testharness(self, webdriver, url, timeout):
class SeleniumRefTestExecutor(RefTestExecutor):
def __init__(self, browser, server_config, timeout_multiplier=1,
screenshot_cache=None, close_after_done=True,
debug_args=None, capabilities=None):
debug_info=None, capabilities=None):
"""Selenium WebDriver-based executor for reftests"""
RefTestExecutor.__init__(self,
browser,
server_config,
screenshot_cache=screenshot_cache,
timeout_multiplier=timeout_multiplier,
debug_args=debug_args)
debug_info=debug_info)
self.protocol = SeleniumProtocol(self, browser,
capabilities=capabilities)
self.implementation = RefTestImplementation(self)
Expand Down
19 changes: 11 additions & 8 deletions wptrunner/executors/executorservo.py
Expand Up @@ -21,6 +21,7 @@
testharness_result_converter,
reftest_result_converter)
from .process import ProcessTestExecutor
from ..executors.base import browser_command

hosts_text = """127.0.0.1 web-platform.test
127.0.0.1 www.web-platform.test
Expand All @@ -39,11 +40,11 @@ def make_hosts_file():
class ServoTestharnessExecutor(ProcessTestExecutor):
convert_result = testharness_result_converter

def __init__(self, browser, server_config, timeout_multiplier=1, debug_args=None,
def __init__(self, browser, server_config, timeout_multiplier=1, debug_info=None,
pause_after_test=False):
ProcessTestExecutor.__init__(self, browser, server_config,
timeout_multiplier=timeout_multiplier,
debug_args=debug_args)
debug_info=debug_info)
self.pause_after_test = pause_after_test
self.result_data = None
self.result_flag = None
Expand All @@ -61,13 +62,15 @@ def do_test(self, test):
self.result_data = None
self.result_flag = threading.Event()

self.command = [self.binary, "--cpu", "--hard-fail", "-z", self.test_url(test)]
debug_args, command = browser_command(self.binary, ["--cpu", "--hard-fail", "-z", self.test_url(test)],
self.debug_info)

self.command = command

if self.pause_after_test:
self.command.remove("-z")

if self.debug_args:
self.command = list(self.debug_args) + self.command
self.command = debug_args + self.command

env = os.environ.copy()
env["HOST_FILE"] = self.hosts_path
Expand All @@ -83,7 +86,7 @@ def do_test(self, test):
timeout = test.timeout * self.timeout_multiplier

# Now wait to get the output we expect, or until we reach the timeout
if self.debug_args is None and not self.pause_after_test:
if self.debug_info is None and not self.pause_after_test:
wait_timeout = timeout + 5
else:
wait_timeout = None
Expand Down Expand Up @@ -150,13 +153,13 @@ class ServoRefTestExecutor(ProcessTestExecutor):
convert_result = reftest_result_converter

def __init__(self, browser, server_config, binary=None, timeout_multiplier=1,
screenshot_cache=None, debug_args=None, pause_after_test=False):
screenshot_cache=None, debug_info=None, pause_after_test=False):

ProcessTestExecutor.__init__(self,
browser,
server_config,
timeout_multiplier=timeout_multiplier,
debug_args=debug_args)
debug_info=debug_info)

self.protocol = Protocol(self, browser)
self.screenshot_cache = screenshot_cache
Expand Down

0 comments on commit a0be46b

Please sign in to comment.