Chromium Code Reviews| Index: Tools/Scripts/webkitpy/layout_tests/port/mock_drt.py |
| diff --git a/Tools/Scripts/webkitpy/layout_tests/port/mock_drt.py b/Tools/Scripts/webkitpy/layout_tests/port/mock_drt.py |
| index 7992a00a12c4de6e34bfb1de0f14b921ab517659..4591f5605eef5fb2a11f51c2eca2e89071fccf50 100644 |
| --- a/Tools/Scripts/webkitpy/layout_tests/port/mock_drt.py |
| +++ b/Tools/Scripts/webkitpy/layout_tests/port/mock_drt.py |
| @@ -41,6 +41,7 @@ import logging |
| import optparse |
| import os |
| import sys |
| +import types |
| # Since we execute this script directly as part of the unit tests, we need to ensure |
| # that Tools/Scripts is in sys.path for the next imports to work correctly. |
| @@ -48,6 +49,7 @@ script_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os. |
| if script_dir not in sys.path: |
| sys.path.append(script_dir) |
| +from webkitpy.common import read_checksum_from_png |
| from webkitpy.common.system.systemhost import SystemHost |
| from webkitpy.layout_tests.port.driver import DriverInput, DriverOutput |
| from webkitpy.layout_tests.port.factory import PortFactory |
| @@ -64,6 +66,8 @@ class MockDRTPort(object): |
| def __init__(self, host, port_name, **kwargs): |
| self.__delegate = PortFactory(host).get(port_name.replace('mock-', ''), **kwargs) |
| + self.__delegate_driver_class = self.__delegate._driver_class |
| + self.__delegate._driver_class = types.MethodType(self._driver_class, self.__delegate) |
| def __getattr__(self, name): |
| return getattr(self.__delegate, name) |
| @@ -74,18 +78,17 @@ class MockDRTPort(object): |
| def check_sys_deps(self, needs_http): |
| return True |
| - def _driver_class(self): |
| + def _driver_class(self, delegate): |
| return self._mocked_driver_maker |
| - @staticmethod |
| - def _mocked_driver_maker(port, worker_number, pixel_tests, no_timeout=False): |
| - path_to_this_file = port.host.filesystem.abspath(__file__.replace('.pyc', '.py')) |
| - driver = port.__delegate._driver_class()(port, worker_number, pixel_tests, no_timeout) |
| - driver.cmd_line = port._overriding_cmd_line(driver.cmd_line, |
| - port.__delegate._path_to_driver(), |
| + def _mocked_driver_maker(self, port, worker_number, pixel_tests, no_timeout=False): |
| + path_to_this_file = self.host.filesystem.abspath(__file__.replace('.pyc', '.py')) |
| + driver = self.__delegate_driver_class()(self, worker_number, pixel_tests, no_timeout) |
| + driver.cmd_line = self._overriding_cmd_line(driver.cmd_line, |
| + self.__delegate._path_to_driver(), |
| sys.executable, |
| path_to_this_file, |
| - port.__delegate.name()) |
| + self.__delegate.name()) |
| return driver |
| @staticmethod |
| @@ -122,47 +125,46 @@ class MockDRTPort(object): |
| def release_http_lock(self): |
| pass |
| - def show_results_html_file(self, results_filename): |
| - pass |
| - |
| def _make_wdiff_available(self): |
| self.__delegate._wdiff_available = True |
| + def setup_environ_for_server(self, server_name): |
| + env = self.__delegate.setup_environ_for_server() |
| + # We need to propagate PATH down so the python code can find the checkout. |
| + env['PATH'] = os.environ['PATH'] |
| + return env |
| + |
| + def lookup_virtual_test_args(self, test_name): |
| + suite = self.__delegate.lookup_virtual_suite(test_name) |
| + return suite.args + ['--virtual-test-suite-name', suite.name, '--virtual-test-suite-base', suite.base] |
| def main(argv, host, stdin, stdout, stderr): |
| """Run the tests.""" |
| options, args = parse_options(argv) |
| - if options.test_shell: |
| - drt = MockTestShell(options, args, host, stdin, stdout, stderr) |
| - else: |
| - drt = MockDRT(options, args, host, stdin, stdout, stderr) |
| + drt = MockDRT(options, args, host, stdin, stdout, stderr) |
| return drt.run() |
| def parse_options(argv): |
| - # FIXME: We have to do custom arg parsing instead of using the optparse |
| - # module. First, Chromium and non-Chromium DRTs have a different argument |
| - # syntax. Chromium uses --pixel-tests=<path>, and non-Chromium uses |
| - # --pixel-tests as a boolean flag. Second, we don't want to have to list |
| - # every command line flag DRT accepts, but optparse complains about |
| - # unrecognized flags. At some point it might be good to share a common |
| - # DRT options class between this file and webkit.py and chromium.py |
| - # just to get better type checking. |
| - platform_index = argv.index('--platform') |
| - platform = argv[platform_index + 1] |
| - |
| - pixel_tests = False |
| - pixel_path = None |
| - test_shell = '--test-shell' in argv |
| - if test_shell: |
| - for arg in argv: |
| - if arg.startswith('--pixel-tests'): |
| - pixel_tests = True |
| - pixel_path = arg[len('--pixel-tests='):] |
| - else: |
| - pixel_tests = '--pixel-tests' in argv |
| - options = optparse.Values({'test_shell': test_shell, 'platform': platform, 'pixel_tests': pixel_tests, 'pixel_path': pixel_path}) |
| + # We do custom arg parsing instead of using the optparse module |
| + # because we don't want to have to list every command line flag DRT |
| + # accepts, and optparse complains about unrecognized flags. |
| + |
| + def get_arg(arg_name): |
| + if arg_name in argv: |
| + index = argv.index(arg_name) |
| + return argv[index + 1] |
| + return None |
| + |
| + platform = get_arg('--platform') |
| + actual_directory = get_arg('--actual_directory') |
| + virtual_test_suite_name = get_arg('--virtual-test-suite-name') |
| + virtual_test_suite_base = get_arg('--virtual-test-suite-base') |
| + options = optparse.Values({'actual_directory': actual_directory, |
|
bungeman-chromium
2013/09/20 22:35:17
Arg, my OCD! Any reason these are in a different o
Dirk Pranke
2013/09/20 22:41:00
No good reason. Will fix.
|
| + 'platform': platform, |
| + 'virtual_test_suite_base': virtual_test_suite_base, |
| + 'virtual_test_suite_name': virtual_test_suite_name}) |
| return (options, argv) |
| @@ -195,21 +197,28 @@ class MockDRT(object): |
| def input_from_line(self, line): |
| vals = line.strip().split("'") |
| - if len(vals) == 1: |
| - uri = vals[0] |
| - checksum = None |
| - else: |
| - uri = vals[0] |
| - checksum = vals[1] |
| + uri = vals[0] |
| + checksum = None |
| + should_run_pixel_tests = False |
| + if len(vals) == 2 and vals[1] == '--pixel-test': |
| + should_run_pixel_tests = True |
| + elif len(vals) == 3 and vals[1] == '--pixel-test': |
| + should_run_pixel_tests = True |
| + checksum = vals[2] |
| + elif len(vals) != 1: |
| + raise NotImplementedError |
| + |
| if uri.startswith('http://') or uri.startswith('https://'): |
| test_name = self._driver.uri_to_test(uri) |
| else: |
| test_name = self._port.relative_test_filename(uri) |
| - return DriverInput(test_name, 0, checksum, self._options.pixel_tests) |
| + return DriverInput(test_name, 0, checksum, should_run_pixel_tests) |
| def output_for_test(self, test_input, is_reftest): |
| port = self._port |
| + if self._options.virtual_test_suite_name: |
| + test_input.test_name = test_input.test_name.replace(self._options.virtual_test_suite_base, self._options.virtual_test_suite_name) |
| actual_text = port.expected_text(test_input.test_name) |
| actual_audio = port.expected_audio(test_input.test_name) |
| actual_image = None |
| @@ -223,10 +232,25 @@ class MockDRT(object): |
| actual_text = 'not reference text\n' |
| actual_checksum = 'not-mock-checksum' |
| actual_image = 'not blank' |
| - elif self._options.pixel_tests and test_input.image_hash: |
| + elif test_input.should_run_pixel_test and test_input.image_hash: |
| actual_checksum = port.expected_checksum(test_input.test_name) |
| actual_image = port.expected_image(test_input.test_name) |
| + if self._options.actual_directory: |
| + actual_path = port._filesystem.join(self._options.actual_directory, test_input.test_name) |
| + root, _ = port._filesystem.splitext(actual_path) |
| + text_path = root + '-actual.txt' |
| + if port._filesystem.exists(text_path): |
| + actual_text = port._filesystem.read_binary_file(text_path) |
| + audio_path = root + '-actual.wav' |
| + if port._filesystem.exists(audio_path): |
| + actual_audio = port._filesystem.read_binary_file(audio_path) |
| + image_path = root + '-actual.png' |
| + if port._filesystem.exists(image_path): |
| + actual_image = port._filesystem.read_binary_file(image_path) |
| + with port._filesystem.open_binary_file_for_reading(image_path) as filehandle: |
| + actual_checksum = read_checksum_from_png.read_checksum(filehandle) |
| + |
| return DriverOutput(actual_text, actual_image, actual_checksum, actual_audio) |
| def write_test_output(self, test_input, output, is_reftest): |
| @@ -234,6 +258,7 @@ class MockDRT(object): |
| self._stdout.write('Content-Type: audio/wav\n') |
| self._stdout.write('Content-Transfer-Encoding: base64\n') |
| self._stdout.write(base64.b64encode(output.audio)) |
| + self._stdout.write('\n') |
| else: |
| self._stdout.write('Content-Type: text/plain\n') |
| # FIXME: Note that we don't ensure there is a trailing newline! |
| @@ -243,7 +268,7 @@ class MockDRT(object): |
| self._stdout.write('#EOF\n') |
| - if self._options.pixel_tests and output.image_hash: |
| + if test_input.should_run_pixel_test and output.image_hash: |
|
bungeman-chromium
2013/09/20 22:35:17
I think I added ' or is_reftest' here in my origin
Dirk Pranke
2013/09/20 22:41:00
Yeah, you needed to add it to work around the call
|
| self._stdout.write('\n') |
| self._stdout.write('ActualHash: %s\n' % output.image_hash) |
| self._stdout.write('ExpectedHash: %s\n' % test_input.image_hash) |
| @@ -257,43 +282,6 @@ class MockDRT(object): |
| self._stderr.flush() |
| -class MockTestShell(MockDRT): |
| - def input_from_line(self, line): |
| - vals = line.strip().split() |
| - if len(vals) == 3: |
| - uri, timeout, checksum = vals |
| - else: |
| - uri, timeout = vals |
| - checksum = None |
| - |
| - test_name = self._driver.uri_to_test(uri) |
| - return DriverInput(test_name, timeout, checksum, self._options.pixel_tests) |
| - |
| - def output_for_test(self, test_input, is_reftest): |
| - # FIXME: This is a hack to make virtual tests work. Need something more general. |
| - original_test_name = test_input.test_name |
| - if '--enable-accelerated-2d-canvas' in self._args and 'canvas' in test_input.test_name: |
| - test_input.test_name = 'platform/chromium/virtual/gpu/' + test_input.test_name |
| - output = super(MockTestShell, self).output_for_test(test_input, is_reftest) |
| - test_input.test_name = original_test_name |
| - return output |
| - |
| - def write_test_output(self, test_input, output, is_reftest): |
| - self._stdout.write("#URL:%s\n" % self._driver.test_to_uri(test_input.test_name)) |
| - if self._options.pixel_tests and output.image_hash: |
| - self._stdout.write("#MD5:%s\n" % output.image_hash) |
| - if output.image: |
| - self._host.filesystem.maybe_make_directory(self._host.filesystem.dirname(self._options.pixel_path)) |
| - self._host.filesystem.write_binary_file(self._options.pixel_path, output.image) |
| - if output.text: |
| - self._stdout.write(output.text) |
| - |
| - if output.text and not output.text.endswith('\n'): |
| - self._stdout.write('\n') |
| - self._stdout.write('#EOF\n') |
| - self._stdout.flush() |
| - |
| - |
| if __name__ == '__main__': |
| # Note that the Mock in MockDRT refers to the fact that it is emulating a |
| # real DRT, and as such, it needs access to a real SystemHost, not a MockSystemHost. |