Пример #1
0
 def test_main(self):
     host = MockSystemHost()
     test.add_unit_tests_to_mock_filesystem(host.filesystem)
     stdin = newstringio.StringIO()
     stdout = newstringio.StringIO()
     stderr = newstringio.StringIO()
     res = mock_drt.main(['--platform', 'test'] + self.extra_args(False),
                         host, stdin, stdout, stderr)
     self.assertEqual(res, 0)
     self.assertEqual(stdout.getvalue(), '')
     self.assertEqual(stderr.getvalue(), '')
     self.assertEqual(host.filesystem.written_files, {})
Пример #2
0
 def test_test_expectations(self):
     # Check that we read the expectations file
     host = MockSystemHost()
     host.filesystem.write_text_file(
         '/mock-checkout/LayoutTests/platform/testwebkitport/TestExpectations',
         'BUG_TESTEXPECTATIONS SKIP : fast/html/article-element.html = TEXT\n'
     )
     port = TestWebKitPort(host=host)
     self.assertEqual(
         ''.join(port.expectations_dict().values()),
         'BUG_TESTEXPECTATIONS SKIP : fast/html/article-element.html = TEXT\n'
     )
Пример #3
0
    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
        driver._xvfb_screen_depth = lambda: '24'
        driver._environment = port.setup_environ_for_server(port.driver_name())
        return driver
Пример #4
0
    def test_helper_starts(self):
        host = MockSystemHost(MockExecutive())
        port = self.make_port(host)
        oc = OutputCapture()
        oc.capture_output()
        host.executive._proc = MockProcess('ready\n')
        port.start_helper()
        port.stop_helper()
        oc.restore_output()

        # make sure trying to stop the helper twice is safe.
        port.stop_helper()
Пример #5
0
    def test_two_drivers(self):
        mock_adb = MockAndroidDebugBridge(2)
        mock_executive = MockExecutive2(run_command_fn=mock_adb.run_command)

        port = android.AndroidPort(MockSystemHost(executive=mock_executive), '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']))
Пример #6
0
 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)
Пример #7
0
 def make_driver(self, worker_number=0, xorg_running=False, executive=None):
     port = Port(MockSystemHost(log_executive=True, executive=executive),
                 'headlessdrivertestport',
                 options=MockOptions(configuration='Release'))
     port._config.build_directory = lambda configuration: '/mock-build'
     port._server_process_constructor = MockServerProcess
     driver = HeadlessDriver(port,
                             worker_number=worker_number,
                             pixel_tests=True)
     driver._startup_delay_secs = 0
     driver._environment = port.setup_environ_for_server(port.driver_name())
     return driver
Пример #8
0
 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)
Пример #9
0
    def test_get_timestamp_from_logs_darwin(self):
        if not SystemHost().platform.is_mac():
            return

        crash_report = make_mock_crash_report_darwin('DumpRenderTree', 28528)
        crash_logs = CrashLogs(MockSystemHost(), CrashLogsTest.DARWIN_MOCK_CRASH_DIRECTORY)
        crash_timestamp = crash_logs.get_timestamp_from_log(crash_report)
        self.assertIn('2011-12-07 13:27:34.816', str(crash_timestamp))

        crash_report = crash_report.replace("Date/Time", "")
        crash_timestamp = crash_logs.get_timestamp_from_log(crash_report)
        self.assertIsNone(crash_timestamp)
 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, {})
Пример #11
0
    def test_basic(self):
        host = MockSystemHost()
        self.assertFalse(host.filesystem.exists("/tmp/output"))
        profiler = ProfilerFactory.create_profiler(host, '/bin/executable',
                                                   '/tmp/output')
        self.assertTrue(host.filesystem.exists("/tmp/output"))
        self.assertEquals(profiler._output_path, "/tmp/output/test.trace")

        host.platform.os_name = 'linux'
        profiler = ProfilerFactory.create_profiler(host, '/bin/executable',
                                                   '/tmp/output')
        self.assertEquals(profiler._output_path, "/tmp/output/test.pprof")
Пример #12
0
 def test_pixeltest__fails(self):
     host = MockSystemHost()
     url = '#URL:file://'
     if sys.platform == 'win32':
         host = MockSystemHost(os_name='win', os_version='xp')
         url = '#URL:file:///'
     url = url + '%s/failures/expected/checksum.html' % PortFactory(
         host).get('test').layout_tests_dir()
     self.assertTest('failures/expected/checksum.html',
                     pixel_tests=True,
                     expected_checksum='wrong-checksum',
                     drt_output=[
                         url + '\n', '#MD5:checksum-checksum\n',
                         'checksum-txt', '\n', '#EOF\n'
                     ],
                     host=host)
     self.assertEquals(
         host.filesystem.written_files, {
             '/tmp/png_result0.png':
             'checksum\x8a-pngtEXtchecksum\x00checksum-checksum'
         })
Пример #13
0
 def __init__(self,
              port_name=None,
              expectations_file=None,
              skips_file=None,
              host=None,
              config=None,
              **kwargs):
     port_name = port_name or TestWebKitPort.port_name
     host = host or MockSystemHost()
     super(TestWebKitPort, self).__init__(host,
                                          port_name=port_name,
                                          **kwargs)
Пример #14
0
    def test_helper_fails_to_stop(self):
        host = MockSystemHost(MockExecutive())
        host.executive._proc = MockProcess()

        def bad_waiter():
            raise IOError('failed to wait')
        host.executive._proc.wait = bad_waiter

        port = self.make_port(host)
        with OutputCapture():
            port.start_helper()
            port.stop_helper()
Пример #15
0
    def mock_host_for_simctl():
        simctl_json = json.loads(
            simctl_json_output
        )  # Construct enough of a filesystem for all our simctl code to work.
        filesystem_map = {}
        runtime_name_to_id = {}

        # Runtime mapping
        for runtime_group in simctl_json['runtimes']:
            runtime_name_to_id[
                runtime_group['name']] = runtime_group['identifier']

        # Device type mapping
        device_type_name_to_id = {}
        for device_type in simctl_json['devicetypes']:
            device_type_name_to_id[
                device_type['name']] = device_type['identifier']

        for runtime, device_groups in simctl_json['devices'].iteritems():
            for device in device_groups:
                file_path = '/Users/mock' + SimulatedDeviceManager.simulator_device_path[
                    1:] + '/' + device['udid'] + '/device.plist'
                # We're taking advantage the fact that the names of the devices match the names of their runtimes in the
                # provided JSON ouput. This is not generally true, which is why we're only using this fact to build up
                # a mock filesystem that is used by the actual simctl parsing code.
                filesystem_map[
                    file_path] = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "{}">
<plist version="1.0">
<dict>
    <key>UDID</key>
    <string>{}</string>
    <key>deviceType</key>
    <string>{}</string>
    <key>name</key>
    <string>{}</string>
    <key>runtime</key>
    <string>{}</string>
    <key>state</key>
    <integer>{}</integer>
</dict>
</plist>""".format(
                        file_path, device['udid'],
                        device_type_name_to_id[device['name']], device['name'],
                        runtime_name_to_id[runtime],
                        SimulatedDevice.NAME_FOR_STATE.index(
                            device['state'].upper()))

        return MockSystemHost(
            executive=MockExecutive2(output=simctl_json_output),
            filesystem=MockFileSystem(files=filesystem_map),
        )
Пример #16
0
    def setUp(self):
        self._mock_adb = MockAndroidDebugBridge(1)
        self._mock_executive = MockExecutive2(run_command_fn=self._mock_adb.run_command)

        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)

        self._errors = []
        self._driver._log_error = lambda msg: self._errors.append(msg)

        self._warnings = []
        self._driver._log_warning = lambda msg: self._warnings.append(msg)
Пример #17
0
    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")
Пример #18
0
 def make_port(self, options=mock_options):
     host = MockSystemHost()
     test.add_unit_tests_to_mock_filesystem(host.filesystem)
     if sys.platform == 'win32':
         # We use this because the 'win' port doesn't work yet.
         host.platform.os_name = 'win'
         host.platform.os_version = 'xp'
         return mock_drt.MockDRTPort(host,
                                     port_name='mock-chromium-win',
                                     options=options)
     return mock_drt.MockDRTPort(host,
                                 port_name='mock-mac',
                                 options=options)
Пример #19
0
    def make_driver(self, worker_number=0, xorg_running=False, executive=None):
        port = Port(host=MockSystemHost(log_executive=True,
                                        executive=executive),
                    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)
        driver._startup_delay_secs = 0
        return driver
Пример #20
0
    def test_wdiff_text_fails(self):
        host = MockSystemHost(os_name=self.os_name, os_version=self.os_version)
        host.executive = MockExecutive(should_throw=True)
        port = self.make_port(host=host)
        port._executive = host.executive  # AndroidPortTest.make_port sets its own executive, so reset that as well.

        # This should raise a ScriptError that gets caught and turned into the
        # error text, and also mark wdiff as not available.
        self.make_wdiff_available(port)
        self.assertTrue(port.wdiff_available())
        diff_txt = port.wdiff_text("/tmp/foo.html", "/tmp/bar.html")
        self.assertEqual(diff_txt, port._wdiff_error_html)
        self.assertFalse(port.wdiff_available())
Пример #21
0
 def setUp(self):
     host = MockSystemHost()
     options = MockOptions(configuration='Release',
                           additional_drt_flag=['--test-shell'])
     config = MockConfig(filesystem=host.filesystem,
                         default_configuration='Release')
     self.port = chromium_mac.ChromiumMacPort(host,
                                              'chromium-mac-snowleopard',
                                              options=options,
                                              config=config)
     self.driver = chromium.ChromiumDriver(self.port,
                                           worker_number=0,
                                           pixel_tests=True)
Пример #22
0
 def __init__(self,
              port_name=None,
              symbols_string=None,
              expectations_file=None,
              skips_file=None,
              host=None,
              config=None,
              **kwargs):
     port_name = port_name or TestWebKitPort.port_name
     self.symbols_string = symbols_string  # Passing "" disables all staticly-detectable features.
     host = host or MockSystemHost()
     super(TestWebKitPort, self).__init__(host,
                                          port_name=port_name,
                                          **kwargs)
Пример #23
0
    def test_stop(self):
        port = Port(MockSystemHost(log_executive=True), '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()

        expected_logs = "MOCK kill_process pid: 1234\n"
        OutputCapture().assert_outputs(self, driver.stop, [], expected_logs=expected_logs)

        self.assertIsNone(driver._xvfb_process)
 def test_pixeltest__fails(self):
     host = MockSystemHost()
     url = '#URL:file://'
     url = url + '%s/failures/expected/image_checksum.html' % PortFactory(host).get('test').layout_tests_dir()
     self.assertTest('failures/expected/image_checksum.html', pixel_tests=True,
         expected_checksum='image_checksum',
         drt_output=[url + '\n',
                     '#MD5:image_checksum-checksum\n',
                     'image_checksum-txt',
                     '\n',
                     '#EOF\n'],
         host=host)
     self.assertEqual(host.filesystem.written_files,
         {'/tmp/png_result0.png': 'image_checksum\x8a-pngtEXtchecksum\x00image_checksum-checksum'})
    def test_two_drivers(self):
        mock_run_command = MockRunCommand()
        mock_run_command.mock_two_devices()
        port = chromium_android.ChromiumAndroidPort(
                MockSystemHost(executive=MockExecutive2(run_command_fn=mock_run_command.mock_run_command_fn)),
                'chromium-android')
        driver0 = chromium_android.ChromiumAndroidDriver(port, worker_number=0, pixel_tests=True)
        driver1 = chromium_android.ChromiumAndroidDriver(port, worker_number=1, pixel_tests=True)

        cmd_line0 = driver0.cmd_line(True, ['anything'])
        self.assertEquals(['adb', '-s', mock_run_command._mock_devices[0], 'shell'], cmd_line0)

        cmd_line1 = driver1.cmd_line(True, ['anything'])
        self.assertEquals(['adb', '-s', mock_run_command._mock_devices[1], 'shell'], cmd_line1)
Пример #26
0
    def make_driver(self):
        port = Port(MockSystemHost(log_executive=True),
                    'westondrivertestport',
                    options=MockOptions(configuration='Release'))
        port._config.build_directory = lambda configuration: "/mock_build"
        port._test_runner_process_constructor = MockServerProcess

        driver = WestonDriver(port, worker_number=0, pixel_tests=True)
        driver._startup_delay_secs = 0
        driver._expected_xvfbdisplay = 23
        driver._xvfbdriver = WestonXvfbDriverDisplayTest(
            driver._expected_xvfbdisplay)
        driver._environment = port.setup_environ_for_server(port.driver_name())
        return driver
Пример #27
0
    def make_driver(self, worker_number=0, xorg_running=False, executive=None):
        port = Port(host=MockSystemHost(log_executive=True,
                                        executive=executive),
                    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
Пример #28
0
    def test_check(self):
        errors = []

        def mock_handle_style_error(line_number, category, confidence, message):
            error = (line_number, category, confidence, message)
            errors.append(error)

        file_path = ''

        fs = MockFileSystem()

        scm = MockSCMDetector('svn')
        checker = PNGChecker(file_path, mock_handle_style_error, scm, MockSystemHost(filesystem=fs))
        checker.check()
        self.assertEquals(len(errors), 1)
        self.assertEquals(errors[0],
                          (0, 'image/png', 5, 'Set the svn:mime-type property (svn propset svn:mime-type image/png ).'))

        files = {'/Users/mock/.subversion/config': 'enable-auto-props = yes\n*.png = svn:mime-type=image/png'}
        fs = MockFileSystem(files)
        scm = MockSCMDetector('git')
        errors = []
        checker = PNGChecker("config", mock_handle_style_error, scm, MockSystemHost(os_name='linux', filesystem=fs))
        checker.check()
        self.assertEquals(len(errors), 0)

        files = {'/Users/mock/.subversion/config': '#enable-auto-props = yes'}
        fs = MockFileSystem(files)
        scm = MockSCMDetector('git')
        errors = []
        checker = PNGChecker("config", mock_handle_style_error, scm, MockSystemHost(os_name='linux', filesystem=fs))
        checker.check()
        self.assertEquals(len(errors), 1)

        files = {'/Users/mock/.subversion/config': 'enable-auto-props = yes\n#enable-auto-props = yes\n*.png = svn:mime-type=image/png'}
        fs = MockFileSystem(files)
        scm = MockSCMDetector('git')
        errors = []
        checker = PNGChecker("config", mock_handle_style_error, scm, MockSystemHost(os_name='linux', filesystem=fs))
        checker.check()
        self.assertEquals(len(errors), 0)

        files = {'/Users/mock/.subversion/config': '#enable-auto-props = yes\nenable-auto-props = yes\n*.png = svn:mime-type=image/png'}
        fs = MockFileSystem(files)
        scm = MockSCMDetector('git')
        errors = []
        checker = PNGChecker("config", mock_handle_style_error, scm, MockSystemHost(os_name='linux', filesystem=fs))
        checker.check()
        self.assertEquals(len(errors), 0)

        files = {'/Users/mock/.subversion/config': 'enable-auto-props = no'}
        fs = MockFileSystem(files)
        scm = MockSCMDetector('git')
        errors = []
        checker = PNGChecker("config", mock_handle_style_error, scm, MockSystemHost(os_name='linux', filesystem=fs))
        checker.check()
        self.assertEquals(len(errors), 1)
Пример #29
0
    def create_crash_logs_darwin(self):
        if not SystemHost().platform.is_mac():
            return

        self.older_mock_crash_report = make_mock_crash_report_darwin(
            'DumpRenderTree', 28528)
        self.sandbox_crash_report = make_mock_sandbox_report_darwin(
            'DumpRenderTree', 28530)
        self.mock_crash_report = make_mock_crash_report_darwin(
            'DumpRenderTree', 28530)
        self.newer_mock_crash_report = make_mock_crash_report_darwin(
            'DumpRenderTree', 28529)
        self.other_process_mock_crash_report = make_mock_crash_report_darwin(
            'FooProcess', 28527)
        self.misformatted_mock_crash_report = 'Junk that should not appear in a crash report' + make_mock_crash_report_darwin(
            'DumpRenderTree', 28526)[200:]
        self.files = {}
        self.files[
            '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150715_quadzen.crash'] = self.older_mock_crash_report
        self.files[
            '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150716_quadzen_1.crash'] = self.older_mock_crash_report
        self.files[
            '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150717_quadzen_2.crash'] = self.older_mock_crash_report
        self.files[
            '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150718_quadzen.crash'] = self.sandbox_crash_report
        self.files[
            '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150719_quadzen.crash'] = self.mock_crash_report
        self.files[
            '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150720_quadzen.crash'] = self.newer_mock_crash_report
        self.files[
            '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150721_quadzen.crash'] = None
        self.files[
            '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150722_quadzen.crash'] = self.other_process_mock_crash_report
        self.files[
            '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150723_quadzen.crash'] = self.misformatted_mock_crash_report

        self.files = {
            key: string_utils.encode(value)
            for key, value in self.files.items()
        }

        self.filesystem = MockFileSystem(self.files)
        crash_logs = CrashLogs(MockSystemHost(filesystem=self.filesystem),
                               CrashLogsTest.DARWIN_MOCK_CRASH_DIRECTORY)
        logs = self.filesystem.files_under(
            '/Users/mock/Library/Logs/DiagnosticReports/')
        for path in reversed(sorted(logs)):
            self.assertTrue(path in self.files.keys())
        return crash_logs
Пример #30
0
    def test_determine_architecture_fails(self):
        # Test that we default to 'x86' if the driver doesn't exist.
        port = self.make_port()
        self.assertEqual(port.architecture(), 'x86_64')

        # Test that we default to 'x86' on an unknown architecture.
        host = MockSystemHost()
        host.filesystem.exists = lambda x: True
        host.executive = executive_mock.MockExecutive2('win32')
        port = self.make_port(host=host)
        self.assertEqual(port.architecture(), 'x86_64')

        # Test that we raise errors if something weird happens.
        host.executive = executive_mock.MockExecutive2(exception=AssertionError)
        self.assertRaises(AssertionError, linux.LinuxPort, host, '%s-foo' % self.port_name)