예제 #1
0
    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)
예제 #2
0
    def test_rebaseline_multiple_builders_and_tests_command_line(self):
        old_exact_matches = builders._exact_matches
        try:
            builders._exact_matches = {
                "MOCK builder": {"port_name": "test-mac-leopard", "specifiers": set(["mock-specifier"])},
                "MOCK builder2": {"port_name": "test-mac-snowleopard", "specifiers": set(["mock-specifier2"])},
                "MOCK builder3": {"port_name": "test-mac-snowleopard", "specifiers": set(["mock-specifier2"])},
            }

            command = Rebaseline()
            tool = MockTool()
            command.bind_to_tool(tool)

            for port_name in tool.port_factory.all_port_names():
                port = tool.port_factory.get(port_name)
                for path in port.expectations_files():
                    tool.filesystem.write_text_file(path, '')

            tool.executive = MockExecutive(should_log=True)

            expected_stdout = """rebaseline-json: {'mock/path/to/test.html': {'MOCK builder2': ['wav', 'txt', 'png'], 'MOCK builder': ['wav', 'txt', 'png'], 'MOCK builder3': ['wav', 'txt', 'png']}, 'mock/path/to/test2.html': {'MOCK builder2': ['wav', 'txt', 'png'], 'MOCK builder': ['wav', 'txt', 'png'], 'MOCK builder3': ['wav', 'txt', 'png']}}
"""

            expected_stderr = """MOCK run_command: ['echo', 'rebaseline-test-internal', '--suffixes', 'wav,txt,png', '--builder', 'MOCK builder2', '--test', 'mock/path/to/test.html'], cwd=/mock-checkout
MOCK run_command: ['echo', 'rebaseline-test-internal', '--suffixes', 'wav,txt,png', '--builder', 'MOCK builder', '--test', 'mock/path/to/test.html'], cwd=/mock-checkout
MOCK run_command: ['echo', 'rebaseline-test-internal', '--suffixes', 'wav,txt,png', '--builder', 'MOCK builder2', '--test', 'mock/path/to/test2.html'], cwd=/mock-checkout
MOCK run_command: ['echo', 'rebaseline-test-internal', '--suffixes', 'wav,txt,png', '--builder', 'MOCK builder', '--test', 'mock/path/to/test2.html'], cwd=/mock-checkout
MOCK run_command: ['echo', 'optimize-baselines', '--suffixes', 'wav,txt,png', 'mock/path/to/test.html'], cwd=/mock-checkout
MOCK run_command: ['echo', 'optimize-baselines', '--suffixes', 'wav,txt,png', 'mock/path/to/test2.html'], cwd=/mock-checkout
"""

            OutputCapture().assert_outputs(self, command.execute, [MockOptions(optimize=True, builders=["MOCK builder,MOCK builder2", "MOCK builder3"], suffixes=["txt,png", "png,wav,txt"], verbose=True), ["mock/path/to/test.html", "mock/path/to/test2.html"], tool], expected_stdout=expected_stdout, expected_stderr=expected_stderr)

        finally:
            builders._exact_matches = old_exact_matches
    def test_start_cmd(self):
        # Fails on win - see https://bugs.webkit.org/show_bug.cgi?id=84726
        if sys.platform in ('cygwin', 'win32'):
            return

        def fake_pid(_):
            host.filesystem.write_text_file('/tmp/WebKit/httpd.pid', '42')
            return True

        host = MockHost()
        host.executive = MockExecutive(should_log=True)
        test_port = test.TestPort(host)
        host.filesystem.write_text_file(
            test_port._path_to_apache_config_file(), '')

        server = LayoutTestApacheHttpd(test_port, "/mock/output_dir")
        server._check_that_all_ports_are_available = lambda: True
        server._is_server_running_on_all_ports = lambda: True
        server._wait_for_action = fake_pid
        oc = OutputCapture()
        try:
            oc.capture_output()
            server.start()
            server.stop()
        finally:
            _, _, logs = oc.restore_output()
        self.assertTrue(host.filesystem.exists("/mock/output_dir/httpd.conf"))
예제 #4
0
    def __init__(self,
                 log_executive=False,
                 os_name=None,
                 os_version=None,
                 executive=None,
                 filesystem=None,
                 time_return_val=123):
        self.executable = 'python'
        self.executive = executive or MockExecutive(should_log=log_executive)
        self.filesystem = filesystem or MockFileSystem()
        self.user = MockUser()
        self.platform = MockPlatformInfo()
        if os_name:
            self.platform.os_name = os_name
        if os_version:
            self.platform.os_version = os_version

        # FIXME: Should this take pointers to the filesystem and the executive?
        self.workspace = MockWorkspace()

        self.stdin = StringIO()
        self.stdout = StringIO()
        self.stderr = StringIO()
        self.environ = {
            'MOCK_ENVIRON_COPY': '1',
            'PATH': '/bin:/mock/bin'
        }
        self.time_return_val = time_return_val
예제 #5
0
    def test_rebaseline_all(self):
        old_exact_matches = builders._exact_matches
        builders._exact_matches = {
            "MOCK builder": {"port_name": "test-mac-leopard", "specifiers": set(["mock-specifier"])},
            "MOCK builder (Debug)": {"port_name": "test-mac-leopard", "specifiers": set(["mock-specifier", "debug"])},
        }

        command = RebaselineJson()
        tool = MockTool()
        options = MockOptions()
        options.optimize = True
        command.bind_to_tool(tool)
        tool.executive = MockExecutive(should_log=True)

        expected_stderr = """MOCK run_command: ['echo', 'rebaseline-test-internal', '--suffixes', 'txt,png', '--builder', 'MOCK builder', '--test', 'user-scripts/another-test.html'], cwd=/mock-checkout
MOCK run_command: ['echo', 'optimize-baselines', '--suffixes', 'txt,png', 'user-scripts/another-test.html'], cwd=/mock-checkout
"""
        OutputCapture().assert_outputs(self, command._rebaseline, [options, {"user-scripts/another-test.html":{"MOCK builder": ["txt", "png"]}}], expected_stderr=expected_stderr)

        expected_stderr = """MOCK run_command: ['echo', 'rebaseline-test-internal', '--suffixes', 'txt,png', '--builder', 'MOCK builder (Debug)', '--test', 'user-scripts/another-test.html'], cwd=/mock-checkout
MOCK run_command: ['echo', 'optimize-baselines', '--suffixes', 'txt,png', 'user-scripts/another-test.html'], cwd=/mock-checkout
"""
        OutputCapture().assert_outputs(self, command._rebaseline, [options, {"user-scripts/another-test.html":{"MOCK builder (Debug)": ["txt", "png"]}}], expected_stderr=expected_stderr)

        expected_stderr = """MOCK run_command: ['echo', 'rebaseline-test-internal', '--suffixes', 'txt', '--builder', 'MOCK builder', '--test', 'user-scripts/another-test.html'], cwd=/mock-checkout
MOCK run_command: ['echo', 'optimize-baselines', '--suffixes', 'txt', 'user-scripts/another-test.html'], cwd=/mock-checkout
"""
        OutputCapture().assert_outputs(self, command._rebaseline, [options, {"user-scripts/another-test.html":{"MOCK builder (Debug)": ["txt", "png"], "MOCK builder": ["txt"]}}], expected_stderr=expected_stderr)

        builders._exact_matches = old_exact_matches
예제 #6
0
 def test_run(self):
     host = MockHost()
     host.executive = MockExecutive(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']])
예제 #7
0
    def setUp(self):
        super(TestRebaselineUpdatesExpectationsFiles, self).setUp()
        self.tool.executive = MockExecutive()

        def mock_run_command(*args, **kwargs):  # pylint: disable=unused-argument
            return '{"add": [], "remove-lines": [{"test": "userscripts/first-test.html", "port_name": "test-mac-mac10.11"}]}\n'
        self.tool.executive.run_command = mock_run_command
예제 #8
0
    def test_setup_test_runs_multiple_checks_when_slow_to_start(self):
        count = [0]

        def run_command_fake(args):
            if args[0] == 'xdpyinfo':
                if '-display' in args:
                    return 1
                if count[0] < 3:
                    count[0] += 1
                    return 1
            return 0

        port = self.make_port()
        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'],
                ['xdpyinfo'],
                ['xdpyinfo'],
                ['xdpyinfo'],
            ])
        env = port.setup_environ_for_server()
        self.assertEqual(env['DISPLAY'], ':99')
예제 #9
0
 def test_setup_environ_for_server(self):
     port = self.make_port()
     port._executive = MockExecutive(should_log=True)
     output = output_capture.OutputCapture()
     orig_environ = port.host.environ.copy()
     env = output.assert_outputs(self, port.setup_environ_for_server)
     self.assertEqual(orig_environ['PATH'], port.host.environ.get('PATH'))
예제 #10
0
    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'
        ])
예제 #11
0
    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',
        ])
예제 #12
0
    def test_setup_test_runs_multiple_checks_when_slow_to_start(self):
        count = [0]

        def run_command_fake(args):
            if args[0:2] == ['xdpyinfo', '-display']:
                return 1
            # The variable `count` is a list rather than an int so that this
            # function can increment the value.
            if args == ['xdpyinfo'] and count[0] < 3:
                count[0] += 1
                return 1
            return 0

        port = self.make_port()
        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'],
            ['xdpyinfo'],
            ['xdpyinfo'],
            ['xdpyinfo'],
        ])
        env = port.setup_environ_for_server()
        self.assertEqual(env['DISPLAY'], ':99')
    def test_creates_pull_request_for_earliest_commit(self):
        host = MockHost()

        def mock_command(args):
            canned_git_outputs = {
                'show':
                'newer fake text' if 'cafedad5' in args else 'older fake text',
                'rev-list': 'facebeef\ncafedad5',
                'footers': 'fake-cr-position',
                'remote': 'github',
                'format-patch': 'fake patch',
                'diff': 'fake patch diff',
                'diff-tree': 'fake\n\files\nchanged',
            }
            return canned_git_outputs.get(args[1], '')

        host.executive = MockExecutive(run_command_fn=mock_command)
        wpt_github = MockWPTGitHub(pull_requests=[])

        TestExporter(host, wpt_github).run()

        self.assertEqual(wpt_github.calls,
                         ['in_flight_pull_requests', 'create_pr'])
        self.assertEqual(
            wpt_github.pull_requests_created,
            [('chromium-export-try', 'older fake text', 'older fake text')])
예제 #14
0
    def test_creates_pull_request_for_earliest_commit(self):
        host = MockHost()

        def mock_command(args):
            canned_git_outputs = {
                'show':
                'newer fake text' if 'add087a97844f4b9e307d9a216940582d96db306'
                in args else 'older fake text',
                'rev-list':
                'c881563d734a86f7d9cd57ac509653a61c45c240\nadd087a97844f4b9e307d9a216940582d96db306',
                'footers':
                'fake-cr-position',
                'remote':
                'github',
                'format-patch':
                'fake patch',
                'diff':
                'fake patch diff',
                'diff-tree':
                'fake\n\files\nchanged',
                'crrev-parse':
                'c881563d734a86f7d9cd57ac509653a61c45c240',
            }
            return canned_git_outputs.get(args[1], '')

        host.executive = MockExecutive(run_command_fn=mock_command)
        test_exporter = TestExporter(host, 'gh-username', 'gh-token')
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[])
        test_exporter.run()

        self.assertEqual(test_exporter.wpt_github.calls,
                         ['in_flight_pull_requests', 'create_pr'])
        self.assertEqual(
            test_exporter.wpt_github.pull_requests_created,
            [('chromium-export-try', 'older fake text', 'older fake text')])
예제 #15
0
    def test_build_driver(self):
        output = OutputCapture()
        port = TestWebKitPort()
        # Delay setting _executive to avoid logging during construction
        port._executive = MockExecutive(should_log=True)
        port._options = MockOptions(
            configuration="Release"
        )  # This should not be necessary, but I think TestWebKitPort is actually reading from disk (and thus detects the current configuration).
        expected_stderr = "MOCK run_command: ['Tools/Scripts/build-dumprendertree', '--release'], cwd=/mock-checkout, env={'LC_ALL': 'C', 'MOCK_ENVIRON_COPY': '1'}\n"
        self.assertTrue(
            output.assert_outputs(self,
                                  port._build_driver,
                                  expected_stderr=expected_stderr,
                                  expected_logs=''))

        # Make sure when passed --webkit-test-runner we build the right tool.
        port._options = MockOptions(webkit_test_runner=True,
                                    configuration="Release")
        expected_stderr = "MOCK run_command: ['Tools/Scripts/build-dumprendertree', '--release'], cwd=/mock-checkout, env={'LC_ALL': 'C', 'MOCK_ENVIRON_COPY': '1'}\nMOCK run_command: ['Tools/Scripts/build-webkittestrunner', '--release'], cwd=/mock-checkout, env={'LC_ALL': 'C', 'MOCK_ENVIRON_COPY': '1'}\n"
        self.assertTrue(
            output.assert_outputs(self,
                                  port._build_driver,
                                  expected_stderr=expected_stderr,
                                  expected_logs=''))

        # Make sure we show the build log when --verbose is passed, which we simulate by setting the logging level to DEBUG.
        output.set_log_level(logging.DEBUG)
        port._options = MockOptions(configuration="Release")
        expected_stderr = "MOCK run_command: ['Tools/Scripts/build-dumprendertree', '--release'], cwd=/mock-checkout, env={'LC_ALL': 'C', 'MOCK_ENVIRON_COPY': '1'}\n"
        expected_logs = "Output of ['Tools/Scripts/build-dumprendertree', '--release']:\nMOCK output of child process\n"
        self.assertTrue(
            output.assert_outputs(self,
                                  port._build_driver,
                                  expected_stderr=expected_stderr,
                                  expected_logs=expected_logs))
        output.set_log_level(logging.INFO)

        # Make sure that failure to build returns False.
        port._executive = MockExecutive(should_log=True, should_throw=True)
        # Because WK2 currently has to build both webkittestrunner and DRT, if DRT fails, that's the only one it tries.
        expected_stderr = "MOCK run_command: ['Tools/Scripts/build-dumprendertree', '--release'], cwd=/mock-checkout, env={'LC_ALL': 'C', 'MOCK_ENVIRON_COPY': '1'}\n"
        expected_logs = "MOCK ScriptError\n\nMOCK output of child process\n"
        self.assertFalse(
            output.assert_outputs(self,
                                  port._build_driver,
                                  expected_stderr=expected_stderr,
                                  expected_logs=expected_logs))
예제 #16
0
 def test_show_results_html_file(self):
     port = self.make_port()
     port._executive = MockExecutive(should_log=True)
     expected_logs = "MOCK run_command: ['Tools/Scripts/run-launcher', '--release', '--qt', 'file://test.html'], cwd=/mock-checkout\n"
     OutputCapture().assert_outputs(self,
                                    port.show_results_html_file,
                                    ["test.html"],
                                    expected_logs=expected_logs)
예제 #17
0
    def test_last_wpt_exported_commit_not_found(self):
        host = MockHost()
        host.executive = MockExecutive(run_command_fn=lambda _: '')
        host.filesystem = MockFileSystem()
        local_wpt = LocalWPT(host, 'token')

        commit = local_wpt.most_recent_chromium_commit()
        self.assertEqual(commit, (None, None))
예제 #18
0
 def test_cl_description_moves_noexport_tag(self):
     host = MockHost()
     host.executive = MockExecutive(output='Summary\n\nNo-Export: true\n\n')
     importer = TestImporter(host)
     description = importer._cl_description(directory_owners={})
     self.assertIn(
         'No-Export: true',
         description)
예제 #19
0
 def test_helper_fails_to_start(self):
     host = MockSystemHost(MockExecutive())
     port = self.make_port(host)
     oc = OutputCapture()
     oc.capture_output()
     port.start_helper()
     port.stop_helper()
     oc.restore_output()
예제 #20
0
 def test_httpd_returns_error_code(self):
     port = self.make_port(executive=MockExecutive(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)
예제 #21
0
    def test_pretty_patch_os_error(self):
        port = self.make_port(executive=MockExecutive(exception=OSError))
        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)
예제 #22
0
 def test_http_server_doesnt_require_http_protocol_options_unsafe(self):
     port = self.make_port(executive=MockExecutive(stderr=(
         "Invalid command 'HttpProtocolOptions', perhaps misspelled or"
         " defined by a module not included in the server configuration\n"
     )))
     port.path_to_apache = lambda: '/usr/sbin/httpd'
     self.assertFalse(
         port.http_server_requires_http_protocol_options_unsafe())
예제 #23
0
 def test_check_httpd_success(self):
     port = self.make_port(executive=MockExecutive())
     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)
예제 #24
0
 def test_create_zip_exception(self):
     workspace = Workspace(None, MockExecutive(should_log=True, should_throw=True))
     expected_stderr = "MOCK run_command: ['zip', '-9', '-r', '/zip/path', '.'], cwd=/source/path\n"
     class MockZipFile(object):
         def __init__(self, path):
             self.filename = path
     archive = OutputCapture().assert_outputs(self, workspace.create_zip, ["/zip/path", "/source/path", MockZipFile], expected_stderr=expected_stderr)
     self.assertEqual(archive, None)
예제 #25
0
    def test_derives_sha_from_position(self):
        host = MockHost()
        host.executive = MockExecutive(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')
예제 #26
0
 def test_cl_description_moves_noexport_tag(self):
     host = MockHost()
     host.executive = MockExecutive(output='Summary\n\nNOEXPORT=true\n\n')
     importer = TestImporter(host)
     description = importer._cl_description(directory_owners={})
     self.assertEqual(description, ('Summary\n\n'
                                    '[email protected]\n'
                                    'NOEXPORT=true'))
예제 #27
0
 def __init__(self, cwd=None, filesystem=None, executive=None, platform=None):
     self.checkout_root = '/mock-checkout'
     self.cwd = cwd or self.checkout_root
     self.added_paths = set()
     self._filesystem = filesystem or MockFileSystem()
     self._executive = executive or MockExecutive()
     self._executable_name = 'git'
     self._local_commits = []
예제 #28
0
 def test_setup_environ_for_server_register_cygwin(self):
     port = self.make_port(options=ChromiumWinTest.RegisterCygwinOption())
     port._executive = MockExecutive(should_log=True)
     expected_stderr = "MOCK run_command: ['/mock-checkout/Source/WebKit/chromium/third_party/cygwin/setup_mount.bat'], cwd=None\n"
     output = outputcapture.OutputCapture()
     output.assert_outputs(self,
                           port.setup_environ_for_server,
                           expected_stderr=expected_stderr)
예제 #29
0
 def test_rollout_updates_working_copy(self):
     rollout = Rollout()
     tool = MockTool()
     tool.executive = MockExecutive(should_log=True)
     expected_stderr = "MOCK run_and_throw_if_fail: ['mock-update-webkit'], cwd=/mock-checkout\n"
     OutputCapture().assert_outputs(self,
                                    rollout._update_working_copy, [tool],
                                    expected_stderr=expected_stderr)
예제 #30
0
 def test_run_with_auth(self):
     host = MockHost()
     host.executive = MockExecutive(output='mock-output')
     git_cl = GitCL(host, auth_refresh_token_json='token.json')
     git_cl.run(['try', '-b', 'win10_blink_rel'])
     self.assertEqual(
         host.executive.calls,
         [['git', 'cl', 'try', '-b', 'win10_blink_rel', '--auth-refresh-token-json', 'token.json']])