def test_python3_command(self): def run_command_fn(valid_python, args): if args[0] != valid_python: raise WindowsError('%s != %s' % (valid_python, args[0])) return 0 with mock.patch('os.getenv', return_value='.BAT;.EXE;.COM'): # Simple case: one of the extensions match. port = self.make_port() port._executive = MockExecutive(run_command_fn=functools.partial( run_command_fn, 'python3.EXE')) self.assertEqual('python3.EXE', port.python3_command()) # Ensure that the code checks for python3 without an extension. port = self.make_port() port._executive = MockExecutive( run_command_fn=functools.partial(run_command_fn, 'python3')) self.assertEqual('python3', port.python3_command()) # If there are no matches, a WindowsError should be raised. port = self.make_port() port._executive = MockExecutive( run_command_fn=functools.partial(run_command_fn, None)) with self.assertRaises(WindowsError): port.python3_command()
def test_check_sys_deps(self): port = self.make_port() port._executive = MockExecutive(exit_code=0) # pylint: disable=protected-access self.assertEqual(port.check_sys_deps(needs_http=False), exit_codes.OK_EXIT_STATUS) port._executive = MockExecutive(exit_code=1, output='testing output failure') # pylint: disable=protected-access self.assertEqual(port.check_sys_deps(needs_http=False), exit_codes.SYS_DEPS_EXIT_STATUS)
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 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) self.assertIsNone(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_setup_test_runs_finds_free_display(self): def run_command_fake(args): if args == ['xdpyinfo', '-display', ':102']: return 1 return 0 port = self.make_port() port.host.filesystem.files['/tmp/.X99-lock'] = '' port.host.executive = MockExecutive(run_command_fn=run_command_fake) self.assertIsNone(port.setup_test_run()) self.assertEqual( port.host.executive.calls, [ # Do not call `xdpyinfo -display :99` because the lock exists. ['xdpyinfo', '-display', ':100'], ['xdpyinfo', '-display', ':101'], ['xdpyinfo', '-display', ':102'], [ 'Xvfb', ':102', '-screen', '0', '1280x800x24', '-ac', '-dpi', '96' ], ['xdpyinfo'], ]) env = port.setup_environ_for_server() self.assertEqual(env['DISPLAY'], ':102')
def test_diff_image_crashed(self): port = self.make_port() port._executive = MockExecutive(exit_code=2) # pylint: disable=protected-access self.assertEqual(port.diff_image('EXPECTED', 'ACTUAL'), ( None, 'Image diff returned an exit code of 2. See http://crbug.com/278596' ))
def test_wait_for_try_jobs_done(self): host = MockHost() host.executive = MockExecutive(output='lgtm') git_cl = GitCL(host) git_cl.fetch_raw_try_job_results = lambda **_: [ { 'builder_name': 'some-builder', 'status': 'COMPLETED', 'result': 'FAILURE', 'tags': [ 'build_address:luci.chromium.try/chromium_presubmit/100', ], 'url': 'http://ci.chromium.org/b/8931586523737389552', }, ] self.assertEqual( git_cl.wait_for_try_jobs(), CLStatus( status='lgtm', try_job_results={ Build('some-builder', 100): TryJobStatus('COMPLETED', 'FAILURE'), } ) ) self.assertEqual( host.stdout.getvalue(), 'Waiting for try jobs, timeout: 7200 seconds.\n')
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) self.assertEqual(port.setup_test_run(), SYS_DEPS_EXIT_STATUS) 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 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_wait_for_try_jobs_done(self): host = MockHost() host.executive = MockExecutive(output='lgtm') git_cl = GitCL(host) git_cl._host.web = MockWeb(responses=[{ 'status_code': 200, 'body': SEARCHBUILDS_RESPONSE_PREFIX + b"""{ "builds": [ { "status": "FAILURE", "builder": { "builder": "some-builder" }, "number": 100 } ] }""" }]) self.assertEqual( git_cl.wait_for_try_jobs(), CLStatus(status='lgtm', try_job_results={ Build('some-builder', 100): TryJobStatus('COMPLETED', 'FAILURE'), })) self.assertEqual(host.stdout.getvalue(), 'Waiting for try jobs, timeout: 7200 seconds.\n')
def test_wait_for_try_jobs_cl_closed(self): host = MockHost() host.executive = MockExecutive(output='closed') git_cl = GitCL(host) git_cl._host.web = MockWeb(responses=[{ 'status_code': 200, 'body': SEARCHBUILDS_RESPONSE_PREFIX + b"""{ "builds": [ { "status": "STARTED", "builder": { "builder": "some-builder" } } ] }""" }]) self.assertEqual( git_cl.wait_for_try_jobs(), CLStatus( status='closed', try_job_results={ Build('some-builder', None): TryJobStatus('STARTED', None), }, )) self.assertEqual(host.stdout.getvalue(), 'Waiting for try jobs, timeout: 7200 seconds.\n')
def test_start_cmd(self): # Fails on win - see https://bugs.webkit.org/show_bug.cgi?id=84726 if sys.platform == '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 = ApacheHTTP(test_port, '/mock/output_dir', additional_dirs=[], number_of_servers=4) 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.assertIn('StartServers 4', logs) self.assertIn('MinSpareServers 4', logs) self.assertIn('MaxSpareServers 4', logs)
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) self.assertEqual(port.setup_test_run(), SYS_DEPS_EXIT_STATUS) 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_is_wpt_notify_enabled_error(self): self.host.executive = MockExecutive(output='error') extractor = DirectoryOwnersExtractor(self.host) self.assertFalse( extractor.is_wpt_notify_enabled(ABS_WPT_BASE + '/foo/DIR_METADATA'))
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)
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']])
def test_extract_component_with_dir_metadata(self): data = ( '{"dirs":{"a/b":{"monorail":' '{"component":"foo"},"teamEmail":"bar","wpt":{"notify":"YES"}}}}') self.host.executive = MockExecutive(output=data) extractor = DirectoryOwnersExtractor(self.host) self.assertEqual( extractor.extract_component(MOCK_WEB_TESTS + 'a/b/OWNERS'), 'foo')
def test_check_is_functional_cdb_not_found(self): host = MockHost() host.executive = MockExecutive(should_throw=True) build_dir = "/mock-checkout/out/Debug" host.filesystem.maybe_make_directory(build_dir) dump_reader = DumpReaderWin(host, build_dir) self.assertFalse(dump_reader.check_is_functional())
def test_two_drivers(self): port = android.AndroidPort(MockSystemHost(executive=MockExecutive()), 'android') driver0 = android.ChromiumAndroidDriver(port, worker_number=0, driver_details=android.ContentShellDriverDetails(), android_devices=port._devices) driver1 = android.ChromiumAndroidDriver(port, worker_number=1, driver_details=android.ContentShellDriverDetails(), android_devices=port._devices) self.assertEqual(['adb', '-s', '123456789ABCDEF0', 'shell'], driver0.cmd_line([])) self.assertEqual(['adb', '-s', '123456789ABCDEF1', 'shell'], driver1.cmd_line(['anything']))
def test_is_wpt_notify_enabled_false(self): data = ( '{"dirs":{"third_party/blink/web_tests/a/b":{"monorail":' '{"component":"foo"},"teamEmail":"bar","wpt":{"notify":"NO"}}}}') self.host.executive = MockExecutive(output=data) extractor = DirectoryOwnersExtractor(self.host) self.assertFalse( extractor.is_wpt_notify_enabled(MOCK_WEB_TESTS + 'a/b/DIR_METADATA'))
def test_is_wpt_notify_enabled_true(self): data = ( '{"dirs":{"a/b":{"monorail":' '{"component":"foo"},"teamEmail":"bar","wpt":{"notify":"YES"}}}}') self.host.executive = MockExecutive(output=data) extractor = DirectoryOwnersExtractor(self.host) self.assertTrue( extractor.is_wpt_notify_enabled(MOCK_WEB_TESTS + 'a/b/DIR_METADATA'))
def test_extract_component(self): data = ( '{"dirs":{"third_party/blink/web_tests/a/b":{"monorail":' '{"component":"foo"},"teamEmail":"bar","wpt":{"notify":"YES"}}}}') self.host.executive = MockExecutive(output=data) extractor = DirectoryOwnersExtractor(self.host) self.assertEqual( extractor.extract_component(MOCK_WEB_TESTS + 'a/b/DIR_METADATA'), 'foo')