def __init__(self, port_name=None, user=None, filesystem=None, **kwargs): if not port_name or port_name == 'test': port_name = 'test-mac-leopard' user = user or mocktool.MockUser() filesystem = filesystem or unit_test_filesystem() Port.__init__(self, port_name=port_name, filesystem=filesystem, user=user, **kwargs) self._results_directory = None assert filesystem._tests self._tests = filesystem._tests self._operating_system = 'mac' if port_name.startswith('test-win'): self._operating_system = 'win' elif port_name.startswith('test-linux'): self._operating_system = 'linux' version_map = { 'test-win-xp': 'xp', 'test-win-win7': 'win7', 'test-win-vista': 'vista', 'test-mac-leopard': 'leopard', 'test-mac-snowleopard': 'snowleopard', 'test-linux-x86_64': 'lucid', } self._version = version_map[port_name] self._expectations_path = LAYOUT_TEST_DIR + '/platform/test/test_expectations.txt'
def __init__(self, host, port_name=None, **kwargs): Port.__init__(self, host, port_name or TestPort.default_port_name, **kwargs) self._tests = unit_test_list() self._flakes = set() # FIXME: crbug.com/279494. This needs to be in the "real layout tests # dir" in a mock filesystem, rather than outside of the checkout, so # that tests that want to write to a TestExpectations file can share # this between "test" ports and "real" ports. This is the result of # rebaseline_unittest.py having tests that refer to "real" port names # and real builders instead of fake builders that point back to the # test ports. rebaseline_unittest.py needs to not mix both "real" ports # and "test" ports self._generic_expectations_path = '/mock-checkout/LayoutTests/TestExpectations' self._results_directory = None self._operating_system = 'mac' if self._name.startswith('test-win'): self._operating_system = 'win' elif self._name.startswith('test-linux'): self._operating_system = 'linux' version_map = { 'test-win-xp': 'xp', 'test-win-win7': 'win7', 'test-mac-leopard': 'leopard', 'test-mac-snowleopard': 'snowleopard', 'test-linux-x86_64': 'lucid', } self._version = version_map[self._name]
def __init__(self, host, port_name=None, **kwargs): # FIXME: Consider updating all of the callers to pass in a port_name so it can be a # required parameter like all of the other Port objects. port_name = port_name or 'test-mac-leopard' Port.__init__(self, host, port_name, **kwargs) self._tests = unit_test_list() self._flakes = set() self._expectations_path = LAYOUT_TEST_DIR + '/platform/test/TestExpectations' self._results_directory = None self._operating_system = 'mac' if port_name.startswith('test-win'): self._operating_system = 'win' elif port_name.startswith('test-linux'): self._operating_system = 'linux' version_map = { 'test-win-xp': 'xp', 'test-win-win7': 'win7', 'test-win-vista': 'vista', 'test-mac-leopard': 'leopard', 'test-mac-snowleopard': 'snowleopard', 'test-linux-x86_64': 'lucid', } self._version = version_map[port_name]
def __init__(self, host, port_name=None, **kwargs): # FIXME: Consider updating all of the callers to pass in a port_name so it can be a # required parameter like all of the other Port objects. port_name = port_name or "test-mac-leopard" Port.__init__(self, host, port_name, **kwargs) self._tests = unit_test_list() self._flakes = set() self._expectations_path = LAYOUT_TEST_DIR + "/platform/test/TestExpectations" self._results_directory = None self._operating_system = "mac" if port_name.startswith("test-win"): self._operating_system = "win" elif port_name.startswith("test-linux"): self._operating_system = "linux" version_map = { "test-win-xp": "xp", "test-win-win7": "win7", "test-win-vista": "vista", "test-mac-leopard": "leopard", "test-mac-snowleopard": "snowleopard", "test-linux-x86_64": "lucid", } self._version = version_map[port_name]
def __init__(self, host=None, port_name=None, **kwargs): if not port_name or port_name == 'test': port_name = 'test-mac-leopard' host = host or MockHost() filesystem = self._set_default_overriding_none(kwargs, 'filesystem', unit_test_filesystem()) Port.__init__(self, host, port_name=port_name, **kwargs) self._results_directory = None assert filesystem._tests self._tests = filesystem._tests self._operating_system = 'mac' if port_name.startswith('test-win'): self._operating_system = 'win' elif port_name.startswith('test-linux'): self._operating_system = 'linux' version_map = { 'test-win-xp': 'xp', 'test-win-win7': 'win7', 'test-win-vista': 'vista', 'test-mac-leopard': 'leopard', 'test-mac-snowleopard': 'snowleopard', 'test-linux-x86_64': 'lucid', } self._version = version_map[port_name] self._expectations_path = LAYOUT_TEST_DIR + '/platform/test/test_expectations.txt'
def __init__(self, host, port_name=None, **kwargs): if not port_name or port_name == 'test': port_name = 'test-mac-leopard' self._tests = unit_test_list() self._expectations_path = LAYOUT_TEST_DIR + '/platform/test/test_expectations.txt' self._results_directory = None Port.__init__(self, host, port_name=port_name, **kwargs) self._operating_system = 'mac' if port_name.startswith('test-win'): self._operating_system = 'win' elif port_name.startswith('test-linux'): self._operating_system = 'linux' version_map = { 'test-win-xp': 'xp', 'test-win-win7': 'win7', 'test-win-vista': 'vista', 'test-mac-leopard': 'leopard', 'test-mac-snowleopard': 'snowleopard', 'test-linux-x86_64': 'lucid', } self._version = version_map[port_name]
def test_uses_test_expectations_file(self): filesystem = MockFileSystem() port = Port(port_name='foo', filesystem=filesystem) port.path_to_test_expectations_file = lambda: '/mock-results/test_expectations.txt' self.assertFalse(port.uses_test_expectations_file()) port._filesystem = MockFileSystem({'/mock-results/test_expectations.txt': ''}) self.assertTrue(port.uses_test_expectations_file())
def make_driver(self, worker_number=0, xorg_running=False): port = Port(host=MockSystemHost(log_executive=True), config=MockConfig()) port._server_process_constructor = MockServerProcess if xorg_running: port._executive._running_pids['Xorg'] = 108 driver = XvfbDriver(port, worker_number=worker_number, pixel_tests=True) return driver
def test_test_to_uri(self): port = Port() layout_test_dir = port.layout_tests_dir() test = 'foo/bar.html' path = port._filesystem.join(layout_test_dir, test) if sys.platform == 'win32': path = path.replace("\\", "/") self.assertEqual(port.test_to_uri(test), abspath_to_uri(path))
def __init__(self, host, port_name=None, **kwargs): Port.__init__(self, host, port_name=port_name, **kwargs) # FIXME: Disable pixel tests until they are run by default on build.webkit.org. self.set_option_default("pixel_tests", False) # WebKit ports expect a 35s timeout, or 350s timeout when running with -g/--guard-malloc. # FIXME: --guard-malloc is only supported on Mac, so this logic should be in mac.py. default_time_out_seconds = 350 if self.get_option('guard_malloc') else 35 self.set_option_default("time_out_ms", default_time_out_seconds * 1000)
def __init__(self, host, **kwargs): Port.__init__(self, host, **kwargs) # FIXME: Disable pixel tests until they are run by default on build.webkit.org. self.set_option_default("pixel_tests", False) # WebKit ports expect a 35s timeout, or 350s timeout when running with -g/--guard-malloc. # FIXME: --guard-malloc is only supported on Mac, so this logic should be in mac.py. default_time_out_seconds = 350 if self.get_option('guard_malloc') else 35 self.set_option_default("time_out_ms", default_time_out_seconds * 1000)
def make_driver(self, worker_number=0, xorg_running=False, executive=None): port = Port(MockSystemHost(log_executive=True, executive=executive), 'xvfbdrivertestport', options=MockOptions(configuration='Release')) port._config.build_directory = lambda configuration: "/mock-build" port._server_process_constructor = MockServerProcess if xorg_running: port._executive._running_pids['Xorg'] = 108 driver = XvfbDriver(port, worker_number=worker_number, pixel_tests=True) driver._startup_delay_secs = 0 return driver
def test_pretty_patch_script_error(self): # FIXME: This is some ugly white-box test hacking ... port = Port(executive=executive_mock.MockExecutive2(exception=ScriptError)) port._pretty_patch_available = True self.assertEqual(port.pretty_patch_text("patch.txt"), port._pretty_patch_error_html) # This tests repeated calls to make sure we cache the result. self.assertEqual(port.pretty_patch_text("patch.txt"), port._pretty_patch_error_html)
def test_additional_platform_directory(self): filesystem = MockFileSystem() port = Port(port_name='foo', filesystem=filesystem) port.baseline_search_path = lambda: ['LayoutTests/platform/foo'] layout_test_dir = port.layout_tests_dir() test_file = 'fast/test.html' # No additional platform directory self.assertEqual( port.expected_baselines(test_file, '.txt'), [(None, 'fast/test-expected.txt')]) self.assertEqual(port.baseline_path(), 'LayoutTests/platform/foo') # Simple additional platform directory port._options.additional_platform_directory = ['/tmp/local-baselines'] filesystem.files = { '/tmp/local-baselines/fast/test-expected.txt': 'foo', } self.assertEqual( port.expected_baselines(test_file, '.txt'), [('/tmp/local-baselines', 'fast/test-expected.txt')]) self.assertEqual(port.baseline_path(), '/tmp/local-baselines') # Multiple additional platform directories port._options.additional_platform_directory = ['/foo', '/tmp/local-baselines'] self.assertEqual( port.expected_baselines(test_file, '.txt'), [('/tmp/local-baselines', 'fast/test-expected.txt')]) self.assertEqual(port.baseline_path(), '/foo')
def test_pretty_patch_os_error(self): port = Port(executive=executive_mock.MockExecutive2(exception=OSError)) oc = outputcapture.OutputCapture() oc.capture_output() self.assertEqual(port.pretty_patch_text("patch.txt"), port._pretty_patch_error_html) # This tests repeated calls to make sure we cache the result. self.assertEqual(port.pretty_patch_text("patch.txt"), port._pretty_patch_error_html) oc.restore_output()
def test_wdiff_command(self): port = Port() port._path_to_wdiff = lambda: "/path/to/wdiff" command = port._wdiff_command("/actual/path", "/expected/path") expected_command = [ "/path/to/wdiff", "--start-delete=##WDIFF_DEL##", "--end-delete=##WDIFF_END##", "--start-insert=##WDIFF_ADD##", "--end-insert=##WDIFF_END##", "/actual/path", "/expected/path", ] self.assertEqual(command, expected_command)
def test_parse_reftest_list(self): port = self.make_port(with_tests=True) port.host.filesystem.files["bar/reftest.list"] = "\n".join( [ "== test.html test-ref.html", "", "# some comment", "!= test-2.html test-notref.html # more comments", "== test-3.html test-ref.html", "== test-3.html test-ref2.html", "!= test-3.html test-notref.html", ] ) reftest_list = Port._parse_reftest_list(port.host.filesystem, "bar") self.assertEqual( reftest_list, { "bar/test.html": [("==", "bar/test-ref.html")], "bar/test-2.html": [("!=", "bar/test-notref.html")], "bar/test-3.html": [ ("==", "bar/test-ref.html"), ("==", "bar/test-ref2.html"), ("!=", "bar/test-notref.html"), ], }, )
def make_port(self, executive=None, with_tests=False, **kwargs): host = MockSystemHost() if executive: host.executive = executive if with_tests: add_unit_tests_to_mock_filesystem(host.filesystem) return TestPort(host, **kwargs) return Port(host, **kwargs)
def __init__(self, host, port_name=None, **kwargs): Port.__init__(self, host, port_name or TestPort.default_port_name, **kwargs) self._tests = unit_test_list() self._flakes = set() self._generic_expectations_path = LAYOUT_TEST_DIR + '/TestExpectations' self._results_directory = None self._operating_system = 'mac' if self._name.startswith('test-win'): self._operating_system = 'win' elif self._name.startswith('test-linux'): self._operating_system = 'linux' version_map = { 'test-win-xp': 'xp', 'test-win-win7': 'win7', 'test-mac-leopard': 'leopard', 'test-mac-snowleopard': 'snowleopard', 'test-linux-x86_64': 'lucid', } self._version = version_map[self._name]
def __init__(self, host, port_name=None, **kwargs): Port.__init__(self, host, port_name or TestPort.default_port_name, **kwargs) self._tests = unit_test_list() self._flakes = set() self._expectations_path = LAYOUT_TEST_DIR + '/platform/test/TestExpectations' self._results_directory = None self._operating_system = 'mac' if self._name.startswith('test-win'): self._operating_system = 'win' elif self._name.startswith('test-linux'): self._operating_system = 'linux' version_map = { 'test-win-xp': 'xp', 'test-win-win7': 'win7', 'test-win-vista': 'vista', 'test-mac-leopard': 'leopard', 'test-mac-snowleopard': 'snowleopard', 'test-linux-x86_64': 'lucid', } self._version = version_map[self._name]
def __init__(self, host, port_name=None, **kwargs): Port.__init__(self, host, port_name or TestPort.default_port_name, **kwargs) self._tests = unit_test_list() self._flakes = set() self._generic_expectations_path = LAYOUT_TEST_DIR + "/TestExpectations" self._results_directory = None self._operating_system = "mac" if self._name.startswith("test-win"): self._operating_system = "win" elif self._name.startswith("test-linux"): self._operating_system = "linux" version_map = { "test-win-xp": "xp", "test-win-win7": "win7", "test-win-vista": "vista", "test-mac-leopard": "leopard", "test-mac-snowleopard": "snowleopard", "test-linux-x86_64": "lucid", } self._version = version_map[self._name]
def run_test(self, test_input): if self._current_test_batch is None: self._current_test_batch = [] test_batches.append(self._current_test_batch) test_name = test_input.test_name # In case of reftest, one test calls the driver's run_test() twice. # We should not add a reference html used by reftests to tests unless include_reference_html parameter # is explicitly given. filesystem = self._port.host.filesystem dirname, filename = filesystem.split(test_name) if include_reference_html or not Port.is_reference_html_file(filesystem, dirname, filename): self._current_test_batch.append(test_name) return TestDriver.run_test(self, test_input)
def test_parse_reftest_list(self): port = self.make_port(with_tests=True) port.host.filesystem.files['bar/reftest.list'] = "\n".join(["== test.html test-ref.html", "", "# some comment", "!= test-2.html test-notref.html # more comments", "== test-3.html test-ref.html", "== test-3.html test-ref2.html", "!= test-3.html test-notref.html"]) reftest_list = Port._parse_reftest_list(port.host.filesystem, 'bar') self.assertEqual(reftest_list, {'bar/test.html': [('==', 'bar/test-ref.html')], 'bar/test-2.html': [('!=', 'bar/test-notref.html')], 'bar/test-3.html': [('==', 'bar/test-ref.html'), ('==', 'bar/test-ref2.html'), ('!=', 'bar/test-notref.html')]})
def test_parse_reftest_list(self): port = self.make_port(with_tests=True) port.host.filesystem.files['bar/reftest.list'] = "\n".join(["== test.html test-ref.html", "", "# some comment", "!= test-2.html test-notref.html # more comments", "== test-3.html test-ref.html", "== test-3.html test-ref2.html", "!= test-3.html test-notref.html", "fuzzy(80,500) == test-3 test-ref.html"]) # Note that we don't support the syntax in the last line; the code should ignore it, rather than crashing. reftest_list = Port._parse_reftest_list(port.host.filesystem, 'bar') self.assertEqual(reftest_list, {'bar/test.html': [('==', 'bar/test-ref.html')], 'bar/test-2.html': [('!=', 'bar/test-notref.html')], 'bar/test-3.html': [('==', 'bar/test-ref.html'), ('==', 'bar/test-ref2.html'), ('!=', 'bar/test-notref.html')]})
def test_stop(self): filesystem = MockFileSystem(files={'/tmp/.X42-lock': '1234\n'}) port = Port(MockSystemHost(log_executive=True, filesystem=filesystem), 'xvfbdrivertestport', options=MockOptions(configuration='Release')) port._executive.kill_process = lambda x: _log.info("MOCK kill_process pid: " + str(x)) driver = XvfbDriver(port, worker_number=0, pixel_tests=True) class FakeXvfbProcess(object): pid = 1234 driver._xvfb_process = FakeXvfbProcess() driver._lock_file = '/tmp/.X42-lock' expected_logs = "MOCK kill_process pid: 1234\n" OutputCapture().assert_outputs(self, driver.stop, [], expected_logs=expected_logs) self.assertIsNone(driver._xvfb_process) self.assertFalse(port._filesystem.exists(driver._lock_file))
def test_virtual_methods(self): port = Port(MockSystemHost()) self.assertVirtual(port.baseline_path) self.assertVirtual(port.baseline_search_path) self.assertVirtual(port.check_build, None) self.assertVirtual(port.check_image_diff) self.assertVirtual(port.create_driver, 0) self.assertVirtual(port.diff_image, None, None) self.assertVirtual(port.default_results_directory) self.assertVirtual(port._path_to_apache) self.assertVirtual(port._path_to_apache_config_file) self.assertVirtual(port._path_to_driver) self.assertVirtual(port._path_to_helper) self.assertVirtual(port._path_to_image_diff) self.assertVirtual(port._path_to_lighttpd) self.assertVirtual(port._path_to_lighttpd_modules) self.assertVirtual(port._path_to_lighttpd_php) self.assertVirtual(port._path_to_wdiff)
def test_stop(self): filesystem = MockFileSystem(files={'/tmp/.X42-lock': '1234\n'}) port = Port(host=MockSystemHost(log_executive=True, filesystem=filesystem), config=MockConfig()) port._executive.kill_process = lambda x: log("MOCK kill_process pid: " + str(x)) driver = XvfbDriver(port, worker_number=0, pixel_tests=True) class FakeXvfbProcess(object): pid = 1234 driver._xvfb_process = FakeXvfbProcess() driver._lock_file = '/tmp/.X42-lock' expected_stderr = "MOCK kill_process pid: 1234\n" OutputCapture().assert_outputs(self, driver.stop, [], expected_stderr=expected_stderr) self.assertEqual(driver._xvfb_process, None) self.assertFalse(port._filesystem.exists(driver._lock_file))
def test_layout_tests_skipping(self): port = Port() port.skipped_layout_tests = lambda: ['foo/bar.html', 'media'] self.assertTrue(port.skips_layout_test('foo/bar.html')) self.assertTrue(port.skips_layout_test('media/video-zoom.html')) self.assertFalse(port.skips_layout_test('foo/foo.html'))
def test_get_option__default(self): port = Port() self.assertEqual(port.get_option('foo', 'bar'), 'bar')
def test_get_option__unset(self): port = Port() self.assertEqual(port.get_option('foo'), None)
def test_get_option__set(self): options, args = optparse.OptionParser().parse_args([]) options.foo = 'bar' port = Port(options=options) self.assertEqual(port.get_option('foo'), 'bar')
def test_is_test_file(self): filesystem = MockFileSystem() self.assertTrue(Port._is_test_file(filesystem, '', 'foo.html')) self.assertTrue(Port._is_test_file(filesystem, '', 'foo.shtml')) self.assertTrue(Port._is_test_file(filesystem, '', 'foo.svg')) self.assertTrue(Port._is_test_file(filesystem, '', 'test-ref-test.html')) self.assertFalse(Port._is_test_file(filesystem, '', 'foo.png')) self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected.html')) self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected.svg')) self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected.xht')) self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected-mismatch.html')) self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected-mismatch.svg')) self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected-mismatch.xhtml')) self.assertFalse(Port._is_test_file(filesystem, '', 'foo-ref.html')) self.assertFalse(Port._is_test_file(filesystem, '', 'foo-notref.html')) self.assertFalse(Port._is_test_file(filesystem, '', 'foo-notref.xht')) self.assertFalse(Port._is_test_file(filesystem, '', 'foo-ref.xhtml')) self.assertFalse(Port._is_test_file(filesystem, '', 'ref-foo.html')) self.assertFalse(Port._is_test_file(filesystem, '', 'notref-foo.xhr'))
def test_test_dirs(self): port = Port() dirs = port.test_dirs() self.assertTrue('canvas' in dirs) self.assertTrue('css2.1' in dirs)
def test_setup_test_run(self): port = Port() # This routine is a no-op. We just test it for coverage. port.setup_test_run()
def test_can_load_actual_virtual_test_suite_file(self): port = Port(SystemHost(), 'baseport') # If this call returns successfully, we found and loaded the LayoutTests/VirtualTestSuites. _ = port.virtual_test_suites()
def test_name__set(self): port = Port(port_name='foo') self.assertEqual(port.name(), 'foo')
def test_name__unset(self): port = Port() self.assertEqual(port.name(), None)