def test_diff_image(self): def _path_to_image_diff(): return "/path/to/image_diff" port = self.make_port() port._path_to_image_diff = _path_to_image_diff mock_image_diff = "MOCK Image Diff" def mock_run_command(args): port._filesystem.write_binary_file(args[4], mock_image_diff) return 1 # Images are different. port._executive = MockExecutive2(run_command_fn=mock_run_command) self.assertEqual(mock_image_diff, port.diff_image("EXPECTED", "ACTUAL")[0]) # Images are the same. port._executive = MockExecutive2(exit_code=0) self.assertEqual(None, port.diff_image("EXPECTED", "ACTUAL")[0]) # There was some error running image_diff. port._executive = MockExecutive2(exit_code=2) exception_raised = False try: port.diff_image("EXPECTED", "ACTUAL") except ValueError, e: exception_raised = True
def test_check_sys_deps(self): port = self.make_port() port._executive = MockExecutive2(exit_code=0) self.assertEqual(port.check_sys_deps(needs_http=False), test_run_results.OK_EXIT_STATUS) port._executive = MockExecutive2(exit_code=1, output='testing output failure') self.assertEqual(port.check_sys_deps(needs_http=False), test_run_results.SYS_DEPS_EXIT_STATUS)
def test_options_with_two_ports(self): port0 = android.AndroidPort( MockSystemHost(executive=MockExecutive2()), 'android', options=optparse.Values({'additional_driver_flag': ['--foo=bar']})) port1 = android.AndroidPort( MockSystemHost(executive=MockExecutive2()), 'android', options=optparse.Values({'driver_name': 'content_shell'})) self.assertEqual(1, port0.driver_cmd_line().count('--foo=bar')) self.assertEqual(0, port1.driver_cmd_line().count('--create-stdin-fifo'))
def test_build_path(self): port = self.make_port( executive=MockExecutive2(output='/default-build-path/Debug'), options=optparse.Values({'build_directory': '/my-build-directory/'}), ) self.assertEqual(port._build_path(), '/my-build-directory/Debug') port = self.make_port( executive=MockExecutive2(output='/default-build-path/Debug-embedded-port'), options=optparse.Values({'build_directory': '/my-build-directory/'}), ) self.assertEqual(port._build_path(), '/my-build-directory/Debug-embedded-port')
def test_options_with_two_ports(self): options = MockOptions(additional_drt_flag=['--foo=bar', '--foo=baz']) mock_run_command = MockRunCommand() mock_run_command.mock_two_devices() port0 = chromium_android.ChromiumAndroidPort( MockSystemHost(executive=MockExecutive2(run_command_fn=mock_run_command.mock_run_command_fn)), 'chromium-android', options=options) port1 = chromium_android.ChromiumAndroidPort( MockSystemHost(executive=MockExecutive2(run_command_fn=mock_run_command.mock_run_command_fn)), 'chromium-android', options=options) cmd_line = port1.driver_cmd_line() self.assertEquals(cmd_line.count('--encode-binary'), 1) self.assertEquals(cmd_line.count('--enable-hardware-gpu'), 1)
def test_check_sys_deps(self): port = self.make_port() # Success os.environ['WEBKIT_TESTFONTS'] = '/tmp/foo' port._executive = MockExecutive2(exit_code=0) self.assertTrue(port.check_sys_deps(needs_http=False)) # Failure del os.environ['WEBKIT_TESTFONTS'] port._executive = MockExecutive2(exit_code=1, output='testing output failure') self.assertFalse(port.check_sys_deps(needs_http=False))
def test_diff_image_crashed(self): port = self.make_port() port._executive = MockExecutive2(exit_code=2) self.assertEqual(port.diff_image("EXPECTED", "ACTUAL"), ( None, 'Image diff returned an exit code of 2. See http://crbug.com/278596' ))
def test_get_crash_log(self): port = self.make_port() port._executive = MockExecutive2( run_command_fn=ChromiumAndroidPortTest.mock_run_command_fn) ChromiumAndroidPortTest.mock_logcat = 'logcat contents\n' self.assertEquals( port._get_crash_log('foo', 1234, 'out bar\nout baz\n', 'err bar\nerr baz\n', newer_than=None), (u'crash log for foo (pid 1234):\n' u'STDOUT: out bar\n' u'STDOUT: out baz\n' u'STDOUT: ********* Logcat:\n' u'STDOUT: logcat contents\n' u'STDERR: err bar\n' u'STDERR: err baz\n' u'STDERR: ********* Tombstone file:\n' u'STDERR: -rw------- 1000 1000 45316 2012-04-27 16:33 tombstone_03\n' u'STDERR: /data/tombstones/tombstone_03\n' u'STDERR: mock_contents\n')) self.assertEquals( port._get_crash_log(None, None, None, None, newer_than=None), (u'crash log for <unknown process name> (pid <unknown>):\n' u'STDOUT: ********* Logcat:\n' u'STDOUT: logcat contents\n' u'STDERR: ********* Tombstone file:\n' u'STDERR: -rw------- 1000 1000 45316 2012-04-27 16:33 tombstone_03\n' u'STDERR: /data/tombstones/tombstone_03\n' u'STDERR: mock_contents\n'))
def test_tailspin(self): def logging_run_command(args): print(args) port = self.make_port() port.host.filesystem.files[ '/__im_tmp/tmp_0_/test-42-tailspin-temp.txt'] = 'Temporary tailspin output file' port.host.filesystem.files[ '/__im_tmp/tmp_0_/test-42-tailspin.txt'] = 'Symbolocated tailspin file' port.host.executive = MockExecutive2( run_command_fn=logging_run_command) expected_stdout = """['/usr/bin/tailspin', 'save', '-n', '/__im_tmp/tmp_0_/test-42-tailspin-temp.txt'] ['/usr/sbin/spindump', '-i', '/__im_tmp/tmp_0_/test-42-tailspin-temp.txt', '-file', '/__im_tmp/tmp_0_/test-42-tailspin.txt', '-noBulkSymbolication'] """ OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42], expected_stdout=expected_stdout) self.assertEqual( port.host.filesystem. files['/mock-build/layout-test-results/test-42-tailspin.txt'], 'Symbolocated tailspin file') self.assertIsNone(port.host.filesystem. files['/__im_tmp/tmp_0_/test-42-tailspin-temp.txt']) self.assertIsNone(port.host.filesystem. files['/__im_tmp/tmp_0_/test-42-tailspin.txt'])
def test_rebaseline_test_internal_with_port_that_lacks_buildbot(self): self.tool.executive = MockExecutive2() # FIXME: it's confusing that this is the test- port, and not the regular win port. Really all of the tests should be using the test ports. port = self.tool.port_factory.get('test-win-win7') self._write(port._filesystem.join(port.layout_tests_dir(), 'platform/test-win-win7/failures/expected/image-expected.txt'), 'original win7 result') old_exact_matches = builders._exact_matches oc = OutputCapture() try: builders._exact_matches = { "MOCK XP": {"port_name": "test-win-xp"}, "MOCK Win7": {"port_name": "test-win-win7"}, } options = MockOptions(optimize=True, builder="MOCK Win7", suffixes="txt", verbose=True, test="failures/expected/image.html", results_directory=None) oc.capture_output() self.command.execute(options, [], self.tool) finally: out, _, _ = oc.restore_output() builders._exact_matches = old_exact_matches self.assertMultiLineEqual(self._read(self.tool.filesystem.join(port.layout_tests_dir(), 'platform/test-win-win7/failures/expected/image-expected.txt')), 'MOCK Web result, convert 404 to None=True') self.assertFalse(self.tool.filesystem.exists(self.tool.filesystem.join(port.layout_tests_dir(), 'platform/test-win-xp/failures/expected/image-expected.txt'))) self.assertMultiLineEqual(out, '{"add": [], "remove-lines": [{"test": "failures/expected/image.html", "builder": "MOCK Win7"}]}\n')
def test_no_copy_existing_baseline(self): self.tool.executive = MockExecutive2() # FIXME: it's confusing that this is the test- port, and not the regular win port. Really all of the tests should be using the test ports. port = self.tool.port_factory.get('test-win-win7') self._write(port._filesystem.join(port.layout_tests_dir(), 'platform/test-win-win7/failures/expected/image-expected.txt'), 'original win7 result') old_exact_matches = builders._exact_matches oc = OutputCapture() try: builders._exact_matches = { "MOCK Leopard": {"port_name": "test-mac-leopard", "specifiers": set(["mock-specifier"])}, "MOCK Linux": {"port_name": "test-linux-x86_64", "specifiers": set(["mock-specifier"])}, "MOCK Win7": {"port_name": "test-win-win7", "specifiers": set(["mock-specifier"])}, } options = MockOptions(builder="MOCK Win7", suffixes="txt", verbose=True, test="failures/expected/image.html", results_directory=None) oc.capture_output() self.command.execute(options, [], self.tool) finally: out, _, _ = oc.restore_output() builders._exact_matches = old_exact_matches self.assertMultiLineEqual(self._read(self.tool.filesystem.join(port.layout_tests_dir(), 'platform/test-linux-x86_64/failures/expected/image-expected.txt')), 'original win7 result') self.assertMultiLineEqual(self._read(self.tool.filesystem.join(port.layout_tests_dir(), 'platform/test-win-win7/failures/expected/image-expected.txt')), 'original win7 result') self.assertFalse(self.tool.filesystem.exists(self.tool.filesystem.join(port.layout_tests_dir(), 'platform/mac-leopard/userscripts/another-test-expected.txt'))) self.assertMultiLineEqual(out, '{"add": [], "remove-lines": []}\n')
def test_update_test_expectations(self): host = MockHost() host.executive = MockExecutive2(exception=OSError()) host.filesystem = MockFileSystem( files={ '/mock-checkout/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location-expected.txt': 'e-wk1', '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/dom/events/EventTarget-dispatchEvent-expected.txt': "g", '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-001-expected.txt': "h", '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/html/browsers/windows/browsing-context-expected.txt': "i", '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/url/interfaces-expected.txt': "j-mac-wk2" }) mock_zip = MockZip() with mock.patch( 'webkitpy.common.net.bugzilla.test_expectation_updater.requests.get', MockRequestsGet): updater = TestExpectationUpdater( host, "123456", True, False, MockBugzilla(), lambda content: mock_zip.unzip(content)) updater.do_update() # mac-wk2 expectation self.assertTrue( self._is_matching( host, "imported/w3c/web-platform-tests/fetch/api/redirect/redirect-count-cross-origin-expected.txt", "a")) # no need to add mac-wk1 specific expectation self.assertFalse( self._exists( host, "platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-count-cross-origin-expected.txt" )) # mac-wk1/ios-simulator-wk2 specific expectation self.assertTrue( self._is_matching( host, "platform/mac-wk1/imported/w3c/web-platform-tests/html/browsers/windows/browsing-context-expected.txt", "f-wk1b")) self.assertTrue( self._is_matching( host, "platform/ios-wk2/imported/w3c/web-platform-tests/url/interfaces-expected.txt", "j")) # removal of mac-wk1 expectation since no longer different self.assertFalse( self._exists( host, "platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location-expected.txt" )) # windows specific expectation self.assertTrue( self._is_matching( host, "platform/win/imported/w3c/web-platform-tests/url/interfaces-expected.txt", "j"))
def test_parse_and_print_leaks_detail_incomplete(self): mock_incomplete_valgrind_output = make_mock_incomplete_valgrind_output('DumpRenderTree', 28531, 'e8c7d7b83be411e390c9d43d7e01ba08') files = {} files['/tmp/layout-test-results/drt-28531-e8c7d7b83be411e390c9d43d7e01ba08-leaks.xml'] = mock_incomplete_valgrind_output leakdetector_valgrind = LeakDetectorValgrind(MockExecutive2(), MockFileSystem(files), '/tmp/layout-test-results/') OutputCapture().assert_outputs(self, leakdetector_valgrind.parse_and_print_leaks_detail, [files], expected_logs=make_mock_valgrind_results_incomplete())
def test_detect_version(self): port = self.make_port() def mock_run_command(cmd): self.assertEquals(cmd, ['cmd', '/c', 'ver']) return "6.1.7600" port._executive = MockExecutive2(run_command_fn=mock_run_command) self.assertEquals(port._detect_version(run_on_non_windows_platforms=True), '7sp0') def mock_run_command(cmd): raise ScriptError('Failure') port._executive = MockExecutive2(run_command_fn=mock_run_command) # Failures log to the python error log, but we have no easy way to capture/test that. self.assertEquals(port._detect_version(run_on_non_windows_platforms=True), None)
def test_run(self): host = MockHost() host.executive = MockExecutive2(output='mock-output') git_cl = GitCL(host) output = git_cl.run(['command']) self.assertEqual(output, 'mock-output') self.assertEqual(host.executive.calls, [['git', 'cl', 'command']])
def test_initpy_generation(self): FAKE_FILES = { '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/.gitmodules': '[submodule "tools/resources"]\n path = tools/resources\n url = https://github.com/w3c/testharness.js.git\n ignore = dirty\n', '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/.gitmodules': '[submodule "tools/resources"]\n path = tools/resources\n url = https://github.com/w3c/testharness.js.git\n ignore = dirty\n', } FAKE_FILES.update(FAKE_REPOSITORY) host = MockHost() host.executive = MockExecutive2() host.filesystem = MockFileSystem(files=FAKE_FILES) fs = self.import_downloaded_tests( ['--no-fetch', '--import-all', '-d', 'w3c'], FAKE_FILES) self.assertFalse( fs.exists( '/mock-checkout/LayoutTests/w3c/csswg-tests/__init__.py')) self.assertTrue( fs.exists( '/mock-checkout/LayoutTests/w3c/web-platform-tests/__init__.py' )) self.assertTrue( fs.getsize( '/mock-checkout/LayoutTests/w3c/web-platform-tests/__init__.py' ) > 0)
def test_httpd_returns_error_code(self): port = self.make_port(executive=MockExecutive2(exit_code=1)) port._path_to_apache = lambda: '/usr/sbin/httpd' with OutputCapture() as captured: self.assertFalse(port.check_httpd()) self.assertEqual('httpd seems broken. Cannot run http tests.\n', captured.root.log.getvalue())
def test_rebaseline_test_internal_with_move_overwritten_baselines_to(self): self.tool.executive = MockExecutive2() # FIXME: it's confusing that this is the test- port, and not the regular lion port. Really all of the tests should be using the test ports. port = self.tool.port_factory.get('test-mac-snowleopard') self._write(port._filesystem.join(port.layout_tests_dir(), 'platform/test-mac-snowleopard/failures/expected/image-expected.txt'), 'original snowleopard result') old_exact_matches = builders._exact_matches oc = OutputCapture() try: builders._exact_matches = { "MOCK Leopard": {"port_name": "test-mac-leopard", "specifiers": set(["mock-specifier"])}, "MOCK SnowLeopard": {"port_name": "test-mac-snowleopard", "specifiers": set(["mock-specifier"])}, } options = MockOptions(optimize=True, builder="MOCK SnowLeopard", suffixes="txt", move_overwritten_baselines_to=["test-mac-leopard"], verbose=True, test="failures/expected/image.html", results_directory=None) oc.capture_output() self.command.execute(options, [], self.tool) finally: out, _, _ = oc.restore_output() builders._exact_matches = old_exact_matches self.assertMultiLineEqual(self._read(self.tool.filesystem.join(port.layout_tests_dir(), 'platform/test-mac-leopard/failures/expected/image-expected.txt')), 'original snowleopard result') self.assertMultiLineEqual(out, '{"add": []}\n')
def make_port(self, **kwargs): port = super(ChromiumAndroidPortTest, self).make_port(**kwargs) self.mock_run_command = MockRunCommand() self.mock_run_command.mock_one_device() port._executive = MockExecutive2( run_command_fn=self.mock_run_command.mock_run_command_fn) return port
def test_remove_obsolete_content(self): FAKE_FILES = { '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/temp': '', '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/t/new.html': '<!doctype html><script src="/resources/testharness.js"></script><script src="/resources/testharnessreport.js"></script>', '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/t/w3c-import.log': 'List of files:\n/LayoutTests/w3c/web-platform-tests/t/obsolete.html', '/mock-checkout/LayoutTests/w3c/web-platform-tests/t/obsolete.html': 'obsoleted content', '/mock-checkout/LayoutTests/w3c/web-platform-tests/t/obsolete-expected.txt': 'PASS', } FAKE_FILES.update(FAKE_REPOSITORY) host = MockHost() host.executive = MockExecutive2() host.filesystem = MockFileSystem(files=FAKE_FILES) fs = self.import_downloaded_tests( ['--no-fetch', '--import-all', '-d', 'w3c'], FAKE_FILES) self.assertFalse( fs.exists( '/mock-checkout/LayoutTests/w3c/web-platform-tests/t/obsolete.html' )) self.assertFalse( fs.exists( '/mock-checkout/LayoutTests/w3c/web-platform-tests/t/obsolete-expected.txt' )) self.assertTrue( fs.exists( '/mock-checkout/LayoutTests/w3c/web-platform-tests/t/new.html') )
def test_manual_slow_test(self): tests_options = '{"a": ["slow"]}' FAKE_FILES = { '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/temp': '', '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/t/new-manual.html': '<!doctype html><meta name="timeout" content="long"><script src="/resources/testharness.js"></script><script src="/resources/testharnessreport.js"></script>', '/mock-checkout/LayoutTests/tests-options.json': tests_options } FAKE_FILES.update(FAKE_REPOSITORY) host = MockHost() host.executive = MockExecutive2() host.filesystem = MockFileSystem(files=FAKE_FILES) fs = self.import_downloaded_tests( ['--no-fetch', '--import-all', '-d', 'w3c'], FAKE_FILES) self.assertFalse( fs.exists( '/mock-checkout/LayoutTests/w3c/web-platform-tests/t/new-manual.html' )) self.assertEquals( tests_options, fs.read_text_file('/mock-checkout/LayoutTests/tests-options.json'))
def test_check_sys_deps(self): port = ChromiumPortTestCase.TestLinuxPort() # Success port._executive = MockExecutive2(exit_code=0) self.assertTrue(port.check_sys_deps(needs_http=False)) # Failure port._executive = MockExecutive2(exit_code=1, output='testing output failure') self.assertFalse(port.check_sys_deps(needs_http=False)) self.assertLog([ 'ERROR: System dependencies check failed.\n', 'ERROR: To override, invoke with --nocheck-sys-deps\n', 'ERROR: \n', 'ERROR: testing output failure\n' ])
def setUp(self): self.mock_run_command = MockRunCommand() self.mock_run_command.mock_one_device() self.port = chromium_android.ChromiumAndroidPort( MockSystemHost(executive=MockExecutive2(run_command_fn=self.mock_run_command.mock_run_command_fn)), 'chromium-android') self.driver = chromium_android.ChromiumAndroidDriver(self.port, worker_number=0, pixel_tests=True)
def setUp(self): super(TestRebaselineJson, self).setUp() self.tool.executive = MockExecutive2() self.old_exact_matches = builders._exact_matches builders._exact_matches = { "MOCK builder": {"port_name": "test-mac-snowleopard"}, "MOCK builder (Debug)": {"port_name": "test-mac-snowleopard"}, }
def test_httpd_returns_error_code(self): port = self.make_port(executive=MockExecutive2(exit_code=1)) port._path_to_apache = lambda: '/usr/sbin/httpd' capture = OutputCapture() capture.capture_output() self.assertFalse(port.check_httpd()) _, _, logs = capture.restore_output() self.assertEqual('httpd seems broken. Cannot run http tests.\n', logs)
def test_check_httpd_success(self): port = self.make_port(executive=MockExecutive2()) port._path_to_apache = lambda: '/usr/sbin/httpd' capture = OutputCapture() capture.capture_output() self.assertTrue(port.check_httpd()) _, _, logs = capture.restore_output() self.assertEqual('', logs)
def test_sample_process_throws_exception(self): def throwing_run_command(args): raise ScriptError("MOCK script error") port = self.make_port() port._executive = MockExecutive2(run_command_fn=throwing_run_command) OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42])
def setUp(self): super(TestRebaselineJsonUpdatesExpectationsFiles, self).setUp() self.tool.executive = MockExecutive2() def mock_run_command(*args, **kwargs): # pylint: disable=unused-argument return '{"add": [], "remove-lines": [{"test": "userscripts/first-test.html", "builder": "MOCK Mac10.11"}]}\n' self.tool.executive.run_command = mock_run_command
def setUp(self): self._mock_adb = MockAndroidDebugBridge(1) self._mock_executive = MockExecutive2(run_command_fn=self._mock_adb.run_command) android_commands = android.AndroidCommands(self._mock_executive, '123456789ABCDEF0', debug_logging=False) self._port = android.AndroidPort(MockSystemHost(executive=self._mock_executive), 'android') self._driver = android.ChromiumAndroidDriver(self._port, worker_number=0, pixel_tests=True, driver_details=android.ContentShellDriverDetails(), android_devices=self._port._devices)
def test_derives_sha_from_position(self): host = MockHost() host.executive = MockExecutive2(output='deadbeefcafe') pos = 'Cr-Commit-Position: refs/heads/master@{#789}' chromium_commit = ChromiumCommit(host, position=pos) self.assertEqual(chromium_commit.position, 'refs/heads/master@{#789}') self.assertEqual(chromium_commit.sha, 'deadbeefcafe')