def test_find_log_darwin(self): if not SystemHost().platform.is_mac(): return older_mock_crash_report = make_mock_crash_report_darwin( 'DumpRenderTree', 28528) mock_crash_report = make_mock_crash_report_darwin( 'DumpRenderTree', 28530) newer_mock_crash_report = make_mock_crash_report_darwin( 'DumpRenderTree', 28529) other_process_mock_crash_report = make_mock_crash_report_darwin( 'FooProcess', 28527) misformatted_mock_crash_report = 'Junk that should not appear in a crash report' + \ make_mock_crash_report_darwin('DumpRenderTree', 28526)[200:] files = { '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150718_quadzen.crash': older_mock_crash_report, '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150719_quadzen.crash': mock_crash_report, '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150720_quadzen.crash': newer_mock_crash_report, '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150721_quadzen.crash': None, '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150722_quadzen.crash': other_process_mock_crash_report, '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150723_quadzen.crash': misformatted_mock_crash_report, } filesystem = MockFileSystem(files) crash_logs = CrashLogs(MockSystemHost(filesystem=filesystem)) log = crash_logs.find_newest_log("DumpRenderTree") self.assertMultiLineEqual(log, newer_mock_crash_report) log = crash_logs.find_newest_log("DumpRenderTree", 28529) self.assertMultiLineEqual(log, newer_mock_crash_report) log = crash_logs.find_newest_log("DumpRenderTree", 28530) self.assertMultiLineEqual(log, mock_crash_report) log = crash_logs.find_newest_log("DumpRenderTree", 28531) self.assertIsNone(log) log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0) self.assertIsNone(log) def bad_read(_): raise IOError('IOError: No such file or directory') def bad_mtime(_): raise OSError('OSError: No such file or directory') filesystem.read_text_file = bad_read log = crash_logs.find_newest_log("DumpRenderTree", 28531, include_errors=True) self.assertIn('IOError: No such file or directory', log) filesystem = MockFileSystem(files) crash_logs = CrashLogs(MockSystemHost(filesystem=filesystem)) filesystem.mtime = bad_mtime log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0, include_errors=True) self.assertIn('OSError: No such file or directory', log)
def test_format_docstrings(self): host = MockSystemHost() host.stdin = StringIO.StringIO(''' def f(): """ triple-quoted docstring with multiple lines """ x = """ this is a regular multi-line string, not a docstring """ return x ''') main(host, ['-']) self.assertMultiLineEqual( host.stdout.getvalue(), ''' def f(): """triple-quoted docstring with multiple lines """ x = """ this is a regular multi-line string, not a docstring """ return x ''')
def test_check(self): errors = [] def mock_handle_style_error(line_number, category, confidence, message): error = (line_number, category, confidence, message) errors.append(error) fs = MockFileSystem() file_path = "foo.png" fs.write_binary_file(file_path, "Dummy binary data") errors = [] checker = PNGChecker(file_path, mock_handle_style_error, MockSystemHost(os_name='linux', filesystem=fs)) checker.check() self.assertEqual(len(errors), 0) file_path = "foo-expected.png" fs.write_binary_file(file_path, "Dummy binary data") errors = [] checker = PNGChecker(file_path, mock_handle_style_error, MockSystemHost(os_name='linux', filesystem=fs)) checker.check() self.assertEqual(len(errors), 1) self.assertEqual(errors[0], ( 0, 'image/png', 5, 'Image lacks a checksum. Generate pngs using run-webkit-tests to ensure they have a checksum.' ))
def make_port(self, executive=None, with_tests=False, port_name=None, **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, port_name or 'baseport', **kwargs)
def test_options_with_two_ports(self): port0 = android.AndroidPort( MockSystemHost(executive=MockExecutive()), 'android', options=optparse.Values({'additional_driver_flag': ['--foo=bar']})) port1 = android.AndroidPort( MockSystemHost(executive=MockExecutive()), '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 assert_version_properties(self, port_name, os_version, expected_name, expected_version, driver_file_output=None): host = MockSystemHost(os_name=self.os_name, os_version=(os_version or self.os_version)) host.filesystem.isfile = lambda x: 'content_shell' in x if driver_file_output: host.executive = MockExecutive(driver_file_output) port = self.make_port(host=host, port_name=port_name, os_version=os_version) self.assertEqual(port.name(), expected_name) self.assertEqual(port.version(), expected_version)
def test_setup_test_runs_terminates_if_xvfb_proc_fails(self): def run_command_fake(args): if args[0] == 'xdpyinfo': return 1 return 0 host = MockSystemHost(os_name=self.os_name, os_version=self.os_version) port = self.make_port(host=host) # Xvfb is started via Executive.popen, which returns an object for the # process. Here we set up a fake process object that acts as if it has # exited with return code 1 immediately. proc = MockProcess(stdout='', stderr='', returncode=3) port.host.executive = MockExecutive(run_command_fn=run_command_fake, proc=proc) self.set_logging_level(logging.DEBUG) port.setup_test_run() self.assertEqual(port.host.executive.calls, [[ 'xdpyinfo', '-display', ':99' ], ['Xvfb', ':99', '-screen', '0', '1280x800x24', '-ac', '-dpi', '96'] ]) self.assertLog([ 'DEBUG: Starting Xvfb with display ":99".\n', 'CRITICAL: Failed to start Xvfb on display ":99" (xvfb retcode: 3).\n' ])
def assertTest(self, test_name, pixel_tests, expected_checksum=None, drt_output=None, host=None, expected_text=None): port_name = 'test' host = host or MockSystemHost() test.add_unit_tests_to_mock_filesystem(host.filesystem) port = PortFactory(host).get(port_name) drt_input, drt_output = self.make_input_output( port, test_name, pixel_tests, expected_checksum, drt_output, drt_input=None, expected_text=expected_text) args = ['--run-layout-test', '--platform', port_name, '-'] stdin = io.BytesIO(drt_input) stdout = io.BytesIO() stderr = io.BytesIO() options, args = mock_drt.parse_options(args) drt = self.make_drt(options, args, host, stdin, stdout, stderr) res = drt.run() self.assertEqual(res, 0) self.assertEqual(stdout.getvalue(), ''.join(drt_output)) self.assertEqual(stderr.getvalue(), '#EOF\n')
def setUp(self): self._mock_devices = mock.patch( 'devil.android.device_utils.DeviceUtils.HealthyDevices', return_value=mock_devices()) self._mock_devices.start() self._mock_battery = mock.patch( 'devil.android.battery_utils.BatteryUtils.GetBatteryInfo', return_value={'level': 100}) self._mock_battery.start() self._port = android.AndroidPort( MockSystemHost(executive=MockExecutive()), 'android') self._driver = android.ChromiumAndroidDriver( self._port, worker_number=0, pixel_tests=True, driver_details=android.ContentShellDriverDetails(), android_devices=self._port._devices) # pylint: disable=protected-access self._errors = [] self._driver._log_error = lambda msg: self._errors.append(msg) self._warnings = [] self._driver._log_warning = lambda msg: self._warnings.append(msg)
def test_setup_test_runs_eventually_times_out(self): def run_command_fake(args): if args[0] == 'xdpyinfo': return 1 return 0 host = MockSystemHost(os_name=self.os_name, os_version=self.os_version) port = self.make_port(host=host) port.host.executive = MockExecutive(run_command_fn=run_command_fake) self.set_logging_level(logging.DEBUG) port.setup_test_run() self.assertEqual(port.host.executive.calls, [ ['xdpyinfo', '-display', ':99'], [ 'Xvfb', ':99', '-screen', '0', '1280x800x24', '-ac', '-dpi', '96' ], ] + [['xdpyinfo']] * 51) env = port.setup_environ_for_server() self.assertEqual(env['DISPLAY'], ':99') self.assertLog(['DEBUG: Starting Xvfb with display ":99".\n'] + [ 'WARNING: xdpyinfo check failed with exit code 1 while starting Xvfb on ":99".\n' ] * 51 + [ 'DEBUG: Killing Xvfb process pid 42.\n', 'CRITICAL: Failed to start Xvfb on display ":99" (xvfb retcode: None).\n', ])
def test_check_build(self): host = MockSystemHost() port = self.make_port(host=host, options=optparse.Values({'child_processes': 1})) # Checking the devices is not tested in this unit test. port._check_devices = lambda _: None host.filesystem.exists = lambda p: True port.check_build(needs_http=True, printer=port_testcase.FakePrinter())
def make_port(self, host=None, options=optparse.Values({'configuration': 'Release'})): host = host or MockSystemHost() test.add_unit_tests_to_mock_filesystem(host.filesystem) return mock_drt.MockDRTPort(host, port_name='mock-mac', options=options)
def test_format_docstrings_indentation(self): host = MockSystemHost() host.stdin = StringIO.StringIO(''' def f(): """This is a docstring With extra indentation on this line. """ ''') main(host, ['-']) self.assertMultiLineEqual( host.stdout.getvalue(), ''' def f(): """This is a docstring With extra indentation on this line. """ ''')
def test_files_blink(self): host = MockSystemHost() host.filesystem.files = {'test.py': ACTUAL_INPUT} main(host, ['test.py']) self.assertEqual(host.filesystem.files, { 'test.py': EXPECTED_BLINK_OUTPUT, 'test.py.bak': ACTUAL_INPUT })
def test_init(self): """Test __init__() method.""" def mock_handle_style_error(self): pass checker = PNGChecker("test/config", mock_handle_style_error, MockSystemHost()) self.assertEqual(checker._file_path, "test/config") self.assertEqual(checker._handle_style_error, mock_handle_style_error)
def run_test(self, failures=None, files=None): failures = failures or [] host = MockSystemHost() host.filesystem.files = files or {} port = TestPort(host=host, port_name='test-mac-mac10.11', options=optparse.Values()) actual_output = DriverOutput(text='', image=None, image_hash=None, audio=None) expected_output = DriverOutput(text='', image=None, image_hash=None, audio=None) write_test_result(host.filesystem, port, '/tmp', 'foo.html', actual_output, expected_output, failures) return host.filesystem.written_files
def test_two_drivers(self): port = android.AndroidPort(MockSystemHost(executive=MockExecutive()), 'android') driver0 = android.ChromiumAndroidDriver(port, worker_number=0, pixel_tests=True, driver_details=android.ContentShellDriverDetails(), android_devices=port._devices) driver1 = android.ChromiumAndroidDriver(port, worker_number=1, pixel_tests=True, driver_details=android.ContentShellDriverDetails(), android_devices=port._devices) self.assertEqual(['adb', '-s', '123456789ABCDEF0', 'shell'], driver0.cmd_line(True, [])) self.assertEqual(['adb', '-s', '123456789ABCDEF1', 'shell'], driver1.cmd_line(True, ['anything']))
def get_shards(self, num_workers, fully_parallel, run_singly, test_list=None, max_locked_shards=1): port = TestPort(MockSystemHost()) self.sharder = Sharder(port.split_test, max_locked_shards) test_list = test_list or self.test_list return self.sharder.shard_tests( [self.get_test_input(test) for test in test_list], num_workers, fully_parallel, run_singly)
def test_main(self): host = MockSystemHost() test.add_unit_tests_to_mock_filesystem(host.filesystem) stdin = io.BytesIO() stdout = io.BytesIO() stderr = io.BytesIO() res = mock_drt.main(['--run-layout-test', '--platform', 'test', '-'], host, stdin, stdout, stderr) self.assertEqual(res, 0) self.assertEqual(stdout.getvalue(), '#READY\n') self.assertEqual(stderr.getvalue(), '') self.assertEqual(host.filesystem.written_files, {})
def test_default_profiler_output(self): host = MockSystemHost() self.assertFalse(host.filesystem.exists("/tmp/output")) # Default mocks are Mac, so iprofile should be default. profiler = ProfilerFactory.create_profiler(host, '/bin/executable', '/tmp/output') self.assertTrue(host.filesystem.exists("/tmp/output")) self.assertEqual(profiler._output_path, "/tmp/output/test.dtps") # Linux defaults to perf. host.platform.os_name = 'linux' profiler = ProfilerFactory.create_profiler(host, '/bin/executable', '/tmp/output') self.assertEqual(profiler._output_path, "/tmp/output/test.data")
def make_port(self, host=None, port_name=None, options=None, os_name=None, os_version=None, **kwargs): host = host or MockSystemHost(os_name=(os_name or self.os_name), os_version=(os_version or self.os_version)) options = options or optparse.Values({'configuration': 'Release'}) port_name = port_name or self.port_name port_name = self.port_maker.determine_full_port_name( host, options, port_name) return self.port_maker(host, port_name, options=options, **kwargs)
def test_setup_test_runs_eventually_failes_on_failure(self): def run_command_fake(args): if args[0] == 'xdpyinfo': return 1 return 0 host = MockSystemHost(os_name=self.os_name, os_version=self.os_version) port = self.make_port(host=host) port.host.executive = MockExecutive( run_command_fn=run_command_fake) port.setup_test_run() self.assertEqual( port.host.executive.calls, [ ['xdpyinfo', '-display', ':99'], ['Xvfb', ':99', '-screen', '0', '1280x800x24', '-ac', '-dpi', '96'], ] + [['xdpyinfo']] * 51) env = port.setup_environ_for_server() self.assertEqual(env['DISPLAY'], ':99')
def test_pprof_output_regexp(self): pprof_output = """ sometimes there is junk before the total line Total: 3770 samples 76 2.0% 2.0% 104 2.8% lookup (inline) 60 1.6% 3.6% 60 1.6% FL_SetPrevious (inline) 56 1.5% 5.1% 56 1.5% MaskPtr (inline) 51 1.4% 6.4% 222 5.9% WebCore::HTMLTokenizer::nextToken 42 1.1% 7.6% 47 1.2% WTF::Vector::shrinkCapacity 35 0.9% 8.5% 35 0.9% WTF::RefPtr::get (inline) 33 0.9% 9.4% 43 1.1% append (inline) 29 0.8% 10.1% 67 1.8% WTF::StringImpl::deref (inline) 29 0.8% 10.9% 100 2.7% add (inline) 28 0.7% 11.6% 28 0.7% WebCore::QualifiedName::localName (inline) 25 0.7% 12.3% 27 0.7% WebCore::Private::addChildNodesToDeletionQueue 24 0.6% 12.9% 24 0.6% __memcpy_ssse3_back 23 0.6% 13.6% 23 0.6% intHash (inline) 23 0.6% 14.2% 76 2.0% tcmalloc::FL_Next 23 0.6% 14.8% 95 2.5% tcmalloc::FL_Push 22 0.6% 15.4% 22 0.6% WebCore::MarkupTokenizerBase::InputStreamPreprocessor::peek (inline) """ expected_first_ten_lines = """ 76 2.0% 2.0% 104 2.8% lookup (inline) 60 1.6% 3.6% 60 1.6% FL_SetPrevious (inline) 56 1.5% 5.1% 56 1.5% MaskPtr (inline) 51 1.4% 6.4% 222 5.9% WebCore::HTMLTokenizer::nextToken 42 1.1% 7.6% 47 1.2% WTF::Vector::shrinkCapacity 35 0.9% 8.5% 35 0.9% WTF::RefPtr::get (inline) 33 0.9% 9.4% 43 1.1% append (inline) 29 0.8% 10.1% 67 1.8% WTF::StringImpl::deref (inline) 29 0.8% 10.9% 100 2.7% add (inline) 28 0.7% 11.6% 28 0.7% WebCore::QualifiedName::localName (inline) """ host = MockSystemHost() profiler = GooglePProf(host, '/bin/executable', '/tmp/output') self.assertEqual(profiler._first_ten_lines_of_profile(pprof_output), expected_first_ten_lines)
def setUp(self): self._mock_devices = mock.patch( 'devil.android.device_utils.DeviceUtils.HealthyDevices', return_value=mock_devices()) self._mock_devices.start() self._mock_battery = mock.patch( 'devil.android.battery_utils.BatteryUtils.GetBatteryInfo', return_value={'level': 100}) self._mock_battery.start() self._mock_perf_control = mock.patch( 'devil.android.perf.perf_control.PerfControl') self._mock_perf_control.start() self._port = android.AndroidPort(MockSystemHost(executive=MockExecutive()), 'android') self._driver = android.ChromiumAndroidDriver( self._port, worker_number=0, pixel_tests=True, driver_details=android.ContentShellDriverDetails(), android_devices=self._port._devices) # pylint: disable=protected-access
def setUp(self): self._port = TestPort(MockSystemHost())
def test_stdin_blink(self): host = MockSystemHost() host.stdin = StringIO.StringIO(ACTUAL_INPUT) main(host, ['-']) self.assertMultiLineEqual(host.stdout.getvalue(), EXPECTED_BLINK_OUTPUT)
def test_stdin_chromium(self): host = MockSystemHost() host.stdin = StringIO.StringIO(ACTUAL_INPUT) main(host, ['--chromium', '-']) self.assertMultiLineEqual(host.stdout.getvalue(), EXPECTED_CHROMIUM_OUTPUT)
def test_convert_for_webkit_with_utf8(self): files = {'/file': 'foo', '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in': '', } host = MockSystemHost(filesystem=MockFileSystem(files=files)) convert_for_webkit('', '/file', '', host)
def test_convert_for_webkit_with_utf8(self): files = {'/file': 'foo', } host = MockSystemHost(filesystem=MockFileSystem(files=files)) convert_for_webkit('', '/file', '', host)
def test_stdin_no_changes(self): host = MockSystemHost() host.stdin = StringIO.StringIO(ACTUAL_INPUT) main(host, ['--no-autopep8', '--leave-strings-alone', '-']) self.assertMultiLineEqual(host.stdout.getvalue(), ACTUAL_INPUT)