Commit 5f74e543 authored by Ned Nguyen's avatar Ned Nguyen Committed by Commit Bot

Automatically pick a target directory which exists for run_web_tests.py script

This also updates how we compute the default for 'configuration'. First, we try to look for the
configuration definition (args.gn) & use that value. If that doesn't succeed, we guess the
value of configuration using the target value.

Reviewers: the main change is in third_party/blink/tools/blinkpy/web_tests/port/base.py, the rest are followed by.


Bug: 893618
Change-Id: I578c977bcaccd6294596f8cf7079748809698db6
Reviewed-on: https://chromium-review.googlesource.com/c/1281043Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Reviewed-by: default avatarRobert Ma <robertma@chromium.org>
Commit-Queue: Ned Nguyen <nednguyen@google.com>
Cr-Commit-Position: refs/heads/master@{#600760}
parent bd379426
...@@ -42,7 +42,8 @@ _log = logging.getLogger(__name__) ...@@ -42,7 +42,8 @@ _log = logging.getLogger(__name__)
def lint(host, options): def lint(host, options):
ports_to_lint = [host.port_factory.get(name) for name in host.port_factory.all_port_names(options.platform)] ports_to_lint = [host.port_factory.get(name)
for name in host.port_factory.all_port_names(options.platform)]
files_linted = set() files_linted = set()
# In general, the set of TestExpectation files should be the same for # In general, the set of TestExpectation files should be the same for
...@@ -80,7 +81,7 @@ def lint(host, options): ...@@ -80,7 +81,7 @@ def lint(host, options):
def check_virtual_test_suites(host, options): def check_virtual_test_suites(host, options):
port = host.port_factory.get(options=options) port = host.port_factory.get()
fs = host.filesystem fs = host.filesystem
layout_tests_dir = port.layout_tests_dir() layout_tests_dir = port.layout_tests_dir()
virtual_suites = port.virtual_test_suites() virtual_suites = port.virtual_test_suites()
...@@ -99,7 +100,7 @@ def check_virtual_test_suites(host, options): ...@@ -99,7 +100,7 @@ def check_virtual_test_suites(host, options):
def check_smoke_tests(host, options): def check_smoke_tests(host, options):
port = host.port_factory.get(options=options) port = host.port_factory.get()
smoke_tests_file = host.filesystem.join(port.layout_tests_dir(), 'SmokeTests') smoke_tests_file = host.filesystem.join(port.layout_tests_dir(), 'SmokeTests')
failures = [] failures = []
if not host.filesystem.exists(smoke_tests_file): if not host.filesystem.exists(smoke_tests_file):
......
...@@ -171,7 +171,7 @@ class CheckVirtualSuiteTest(unittest.TestCase): ...@@ -171,7 +171,7 @@ class CheckVirtualSuiteTest(unittest.TestCase):
host = MockHost() host = MockHost()
options = optparse.Values({'platform': 'test', 'debug_rwt_logging': False}) options = optparse.Values({'platform': 'test', 'debug_rwt_logging': False})
orig_get = host.port_factory.get orig_get = host.port_factory.get
host.port_factory.get = lambda options: orig_get('test', options=options) host.port_factory.get = lambda : orig_get('test', options=options)
res = lint_test_expectations.check_virtual_test_suites(host, options) res = lint_test_expectations.check_virtual_test_suites(host, options)
self.assertTrue(res) self.assertTrue(res)
......
...@@ -242,12 +242,13 @@ class AndroidPort(base.Port): ...@@ -242,12 +242,13 @@ class AndroidPort(base.Port):
def __init__(self, host, port_name, **kwargs): def __init__(self, host, port_name, **kwargs):
_import_android_packages_if_necessary() _import_android_packages_if_necessary()
self._driver_details = ContentShellDriverDetails()
self._host_port = factory.PortFactory(host).get(**kwargs)
super(AndroidPort, self).__init__(host, port_name, **kwargs) super(AndroidPort, self).__init__(host, port_name, **kwargs)
self._operating_system = 'android' self._operating_system = 'android'
self._version = 'kitkat' self._version = 'kitkat'
self._host_port = factory.PortFactory(host).get(**kwargs)
self.server_process_constructor = self._android_server_process_constructor self.server_process_constructor = self._android_server_process_constructor
if not self.get_option('disable_breakpad'): if not self.get_option('disable_breakpad'):
...@@ -256,7 +257,6 @@ class AndroidPort(base.Port): ...@@ -256,7 +257,6 @@ class AndroidPort(base.Port):
if self.driver_name() != self.CONTENT_SHELL_NAME: if self.driver_name() != self.CONTENT_SHELL_NAME:
raise AssertionError('Layout tests on Android only support content_shell as the driver.') raise AssertionError('Layout tests on Android only support content_shell as the driver.')
self._driver_details = ContentShellDriverDetails()
# Initialize the AndroidDevices class which tracks available devices. # Initialize the AndroidDevices class which tracks available devices.
default_devices = None default_devices = None
......
...@@ -94,7 +94,8 @@ class AndroidPortTest(port_testcase.PortTestCase): ...@@ -94,7 +94,8 @@ class AndroidPortTest(port_testcase.PortTestCase):
def test_check_build(self): def test_check_build(self):
host = MockSystemHost() host = MockSystemHost()
port = self.make_port(host=host, options=optparse.Values({'child_processes': 1})) port = self.make_port(host=host, options=optparse.Values(
{'child_processes': 1, 'target': 'Release'}))
# Checking the devices is not tested in this unit test. # Checking the devices is not tested in this unit test.
port._check_devices = lambda _: None port._check_devices = lambda _: None
host.filesystem.exists = lambda p: True host.filesystem.exists = lambda p: True
...@@ -107,12 +108,14 @@ class AndroidPortTest(port_testcase.PortTestCase): ...@@ -107,12 +108,14 @@ class AndroidPortTest(port_testcase.PortTestCase):
# Test that content_shell currently is the only supported driver. # Test that content_shell currently is the only supported driver.
def test_non_content_shell_driver(self): def test_non_content_shell_driver(self):
with self.assertRaises(Exception): with self.assertRaises(Exception):
self.make_port(options=optparse.Values({'driver_name': 'foobar'})) self.make_port(options=optparse.Values({'driver_name': 'foobar', 'target': 'Release'}))
# Test that the number of child processes to create depends on the devices. # Test that the number of child processes to create depends on the devices.
def test_default_child_processes(self): def test_default_child_processes(self):
port_default = self.make_port(device_count=5) port_default = self.make_port(device_count=5)
port_fixed_device = self.make_port(device_count=5, options=optparse.Values({'adb_devices': ['123456789ABCDEF9']})) port_fixed_device = self.make_port(
device_count=5,
options=optparse.Values({'adb_devices': ['123456789ABCDEF9'], 'target': 'Release'}))
self.assertEquals(6, port_default.default_child_processes()) self.assertEquals(6, port_default.default_child_processes())
self.assertEquals(1, port_fixed_device.default_child_processes()) self.assertEquals(1, port_fixed_device.default_child_processes())
...@@ -123,8 +126,8 @@ class AndroidPortTest(port_testcase.PortTestCase): ...@@ -123,8 +126,8 @@ class AndroidPortTest(port_testcase.PortTestCase):
# Tests the default timeouts for Android, which are different than the rest of Chromium. # Tests the default timeouts for Android, which are different than the rest of Chromium.
def test_default_timeout_ms(self): def test_default_timeout_ms(self):
self.assertEqual(self.make_port(options=optparse.Values({'configuration': 'Release'})).default_timeout_ms(), 10000) self.assertEqual(self.make_port(options=optparse.Values({'target': 'Release'})).default_timeout_ms(), 10000)
self.assertEqual(self.make_port(options=optparse.Values({'configuration': 'Debug'})).default_timeout_ms(), 10000) self.assertEqual(self.make_port(options=optparse.Values({'target': 'Debug'})).default_timeout_ms(), 10000)
def test_path_to_apache_config_file(self): def test_path_to_apache_config_file(self):
port = self.make_port() port = self.make_port()
...@@ -149,7 +152,9 @@ class ChromiumAndroidDriverTest(unittest.TestCase): ...@@ -149,7 +152,9 @@ class ChromiumAndroidDriverTest(unittest.TestCase):
'devil.android.perf.perf_control.PerfControl') 'devil.android.perf.perf_control.PerfControl')
self._mock_perf_control.start() self._mock_perf_control.start()
self._port = android.AndroidPort(MockSystemHost(executive=MockExecutive()), 'android') self._port = android.AndroidPort(
MockSystemHost(executive=MockExecutive()), 'android',
options=optparse.Values({'target': 'Release'}))
self._driver = android.ChromiumAndroidDriver( self._driver = android.ChromiumAndroidDriver(
self._port, self._port,
worker_number=0, worker_number=0,
...@@ -199,7 +204,8 @@ class ChromiumAndroidDriverTwoDriversTest(unittest.TestCase): ...@@ -199,7 +204,8 @@ class ChromiumAndroidDriverTwoDriversTest(unittest.TestCase):
self._mock_perf_control.stop() self._mock_perf_control.stop()
def test_two_drivers(self): def test_two_drivers(self):
port = android.AndroidPort(MockSystemHost(executive=MockExecutive()), 'android') options = optparse.Values({'target': 'Release'})
port = android.AndroidPort(MockSystemHost(executive=MockExecutive()), 'android', options=options)
driver0 = android.ChromiumAndroidDriver(port, worker_number=0, driver0 = android.ChromiumAndroidDriver(port, worker_number=0,
driver_details=android.ContentShellDriverDetails(), android_devices=port._devices) driver_details=android.ContentShellDriverDetails(), android_devices=port._devices)
driver1 = android.ChromiumAndroidDriver(port, worker_number=1, driver1 = android.ChromiumAndroidDriver(port, worker_number=1,
...@@ -235,10 +241,12 @@ class ChromiumAndroidTwoPortsTest(unittest.TestCase): ...@@ -235,10 +241,12 @@ class ChromiumAndroidTwoPortsTest(unittest.TestCase):
def test_options_with_two_ports(self): def test_options_with_two_ports(self):
port0 = android.AndroidPort( port0 = android.AndroidPort(
MockSystemHost(executive=MockExecutive()), 'android', MockSystemHost(executive=MockExecutive()), 'android',
options=optparse.Values({'additional_driver_flag': ['--foo=bar']})) options=optparse.Values(
{'additional_driver_flag': ['--foo=bar'], 'target': 'Release'}))
port1 = android.AndroidPort( port1 = android.AndroidPort(
MockSystemHost(executive=MockExecutive()), 'android', MockSystemHost(executive=MockExecutive()), 'android',
options=optparse.Values({'driver_name': 'content_shell'})) options=optparse.Values(
{'driver_name': 'content_shell', 'target': 'Release'}))
self.assertEqual(1, port0.driver_cmd_line().count('--foo=bar')) self.assertEqual(1, port0.driver_cmd_line().count('--foo=bar'))
self.assertEqual(0, port1.driver_cmd_line().count('--create-stdin-fifo')) self.assertEqual(0, port1.driver_cmd_line().count('--create-stdin-fifo'))
...@@ -258,7 +266,9 @@ class ChromiumAndroidDriverTombstoneTest(unittest.TestCase): ...@@ -258,7 +266,9 @@ class ChromiumAndroidDriverTombstoneTest(unittest.TestCase):
return_value={'level': 100}) return_value={'level': 100})
self._mock_battery.start() self._mock_battery.start()
self._port = android.AndroidPort(MockSystemHost(executive=MockExecutive()), 'android') self._port = android.AndroidPort(
MockSystemHost(executive=MockExecutive()), 'android',
options=optparse.Values({'target': 'Release'}))
self._driver = android.ChromiumAndroidDriver( self._driver = android.ChromiumAndroidDriver(
self._port, self._port,
worker_number=0, worker_number=0,
......
...@@ -58,6 +58,7 @@ from blinkpy.web_tests.models.test_run_results import TestRunException ...@@ -58,6 +58,7 @@ from blinkpy.web_tests.models.test_run_results import TestRunException
from blinkpy.web_tests.port import driver from blinkpy.web_tests.port import driver
from blinkpy.web_tests.port import server_process from blinkpy.web_tests.port import server_process
from blinkpy.web_tests.port.factory import PortFactory from blinkpy.web_tests.port.factory import PortFactory
from blinkpy.web_tests.port.factory import check_configuration_and_target
from blinkpy.web_tests.servers import apache_http from blinkpy.web_tests.servers import apache_http
from blinkpy.web_tests.servers import pywebsocket from blinkpy.web_tests.servers import pywebsocket
from blinkpy.web_tests.servers import wptserve from blinkpy.web_tests.servers import wptserve
...@@ -217,11 +218,10 @@ class Port(object): ...@@ -217,11 +218,10 @@ class Port(object):
self.server_process_constructor = server_process.ServerProcess # This can be overridden for testing. self.server_process_constructor = server_process.ServerProcess # This can be overridden for testing.
self._http_lock = None # FIXME: Why does this live on the port object? self._http_lock = None # FIXME: Why does this live on the port object?
self._dump_reader = None self._dump_reader = None
if not hasattr(options, 'configuration') or not options.configuration:
self.set_option_default('configuration', self.default_configuration())
if not hasattr(options, 'target') or not options.target: if not hasattr(options, 'target') or not options.target:
self.set_option_default('target', self._options.configuration) self.set_option_default('target', self.default_target())
self.check_configuration_and_target()
self._test_configuration = None self._test_configuration = None
self._reftest_list = {} self._reftest_list = {}
self._results_directory = None self._results_directory = None
...@@ -1448,8 +1448,25 @@ class Port(object): ...@@ -1448,8 +1448,25 @@ class Port(object):
"""Returns the repository path for the chromium code base.""" """Returns the repository path for the chromium code base."""
return self._path_from_chromium_base('build') return self._path_from_chromium_base('build')
def default_configuration(self): def default_target(self):
return 'Release' runnable_targets = []
for possible_target in ('Release', 'Default', 'Debug'):
if self._filesystem.exists(self._path_to_driver(possible_target)):
runnable_targets.append(possible_target)
if len(runnable_targets) == 0:
_log.error('Driver cannot be found in common build directories.')
sys.exit(1)
elif len(runnable_targets) == 1:
_log.info('Automatically picked a target: %s', runnable_targets[0])
return runnable_targets[0]
else:
_log.error('Multiple runnable targets are found: %s. '
'Specify the exact target with --target flag.',
', '.join(repr(runnable_targets)))
sys.exit(1)
def check_configuration_and_target(self):
check_configuration_and_target(self._filesystem, self._options)
def clobber_old_port_specific_results(self): def clobber_old_port_specific_results(self):
pass pass
...@@ -1753,7 +1770,10 @@ class Port(object): ...@@ -1753,7 +1770,10 @@ class Port(object):
def _build_path(self, *comps): def _build_path(self, *comps):
"""Returns a path from the build directory.""" """Returns a path from the build directory."""
return self._build_path_with_target(self._options.target, *comps) target = None
if 'target' in comps:
target = comps.pop('target')
return self._build_path_with_target(target, *comps)
def _build_path_with_target(self, target, *comps): def _build_path_with_target(self, target, *comps):
target = target or self.get_option('target') target = target or self.get_option('target')
......
...@@ -49,8 +49,10 @@ MOCK_WEB_TESTS = '/mock-checkout/' + RELATIVE_WEB_TESTS ...@@ -49,8 +49,10 @@ MOCK_WEB_TESTS = '/mock-checkout/' + RELATIVE_WEB_TESTS
class PortTest(LoggingTestCase): class PortTest(LoggingTestCase):
def make_port(self, executive=None, with_tests=False, port_name=None, **kwargs): def make_port(self, executive=None, with_tests=False, port_name=None, host=None, **kwargs):
host = MockSystemHost() if not 'options' in kwargs:
kwargs['options'] = optparse.Values({'target': 'Release', 'configuration': 'Release'})
host = host or MockSystemHost()
if executive: if executive:
host.executive = executive host.executive = executive
if with_tests: if with_tests:
...@@ -74,6 +76,7 @@ class PortTest(LoggingTestCase): ...@@ -74,6 +76,7 @@ class PortTest(LoggingTestCase):
def test_get_option__set(self): def test_get_option__set(self):
options, _ = optparse.OptionParser().parse_args([]) options, _ = optparse.OptionParser().parse_args([])
options.foo = 'bar' options.foo = 'bar'
options.target = 'Release'
port = self.make_port(options=options) port = self.make_port(options=options)
self.assertEqual(port.get_option('foo'), 'bar') self.assertEqual(port.get_option('foo'), 'bar')
...@@ -85,6 +88,30 @@ class PortTest(LoggingTestCase): ...@@ -85,6 +88,30 @@ class PortTest(LoggingTestCase):
port = self.make_port() port = self.make_port()
self.assertEqual(port.get_option('foo', 'bar'), 'bar') self.assertEqual(port.get_option('foo', 'bar'), 'bar')
def test_get_option__default_target(self):
temp_port = self.make_port(options=optparse.Values(
{'target': 'Default', 'configuration': 'Release'}))
fake_driver_path = temp_port._path_to_driver()
host = MockSystemHost()
host.filesystem.write_binary_file(fake_driver_path, 'DeathStar')
options, _ = optparse.OptionParser().parse_args([])
port = self.make_port(host=host, options=options)
self.assertEqual(port.get_option('target'), 'Default')
def test_get_option__default_configuration(self):
temp_port = self.make_port(
options=optparse.Values({'target': 'Default', 'configuration': 'Debug'}))
fake_driver_path = temp_port._path_to_driver()
host = MockSystemHost()
host.filesystem.write_binary_file(fake_driver_path, 'DeathStar')
fake_arg_gn_path = host.filesystem.normpath(
host.filesystem.join(fake_driver_path, '..', 'args.gn'))
host.filesystem.write_text_file(fake_arg_gn_path, 'is_debug=True')
options, _ = optparse.OptionParser().parse_args([])
port = self.make_port(host=host, options=options)
self.assertEqual(port.get_option('target'), 'Default')
self.assertEqual(port.get_option('configuration'), 'Debug')
def test_output_filename(self): def test_output_filename(self):
port = self.make_port() port = self.make_port()
...@@ -365,11 +392,13 @@ class PortTest(LoggingTestCase): ...@@ -365,11 +392,13 @@ class PortTest(LoggingTestCase):
# --additional-driver-flag. additional_driver_flags() excludes primary_driver_flag(). # --additional-driver-flag. additional_driver_flags() excludes primary_driver_flag().
port_a = self.make_port(options=optparse.Values( port_a = self.make_port(options=optparse.Values(
{'additional_driver_flag': []})) {'additional_driver_flag': [], 'target': 'Release', 'configuration': 'Release'}))
port_b = self.make_port(options=optparse.Values( port_b = self.make_port(options=optparse.Values(
{'additional_driver_flag': ['--bb']})) {'additional_driver_flag': ['--bb'], 'target': 'Release',
'configuration': 'Release'}))
port_c = self.make_port(options=optparse.Values( port_c = self.make_port(options=optparse.Values(
{'additional_driver_flag': ['--bb', '--cc']})) {'additional_driver_flag': ['--bb', '--cc'], 'target': 'Release',
'configuration': 'Release'}))
self.assertEqual(port_a.primary_driver_flag(), None) self.assertEqual(port_a.primary_driver_flag(), None)
self.assertEqual(port_b.primary_driver_flag(), '--bb') self.assertEqual(port_b.primary_driver_flag(), '--bb')
...@@ -396,7 +425,9 @@ class PortTest(LoggingTestCase): ...@@ -396,7 +425,9 @@ class PortTest(LoggingTestCase):
['--cc'] + default_flags) ['--cc'] + default_flags)
def test_additional_env_var(self): def test_additional_env_var(self):
port = self.make_port(options=optparse.Values({'additional_env_var': ['FOO=BAR', 'BAR=FOO']})) port = self.make_port(options=optparse.Values(
{'additional_env_var': ['FOO=BAR', 'BAR=FOO'], 'target': 'Release',
'configuration': 'Release'}))
self.assertEqual(port.get_option('additional_env_var'), ['FOO=BAR', 'BAR=FOO']) self.assertEqual(port.get_option('additional_env_var'), ['FOO=BAR', 'BAR=FOO'])
environment = port.setup_environ_for_server() environment = port.setup_environ_for_server()
self.assertTrue(('FOO' in environment) & ('BAR' in environment)) self.assertTrue(('FOO' in environment) & ('BAR' in environment))
...@@ -604,12 +635,14 @@ class PortTest(LoggingTestCase): ...@@ -604,12 +635,14 @@ class PortTest(LoggingTestCase):
def test_should_run_as_pixel_test_with_no_pixel_tests_in_args(self): def test_should_run_as_pixel_test_with_no_pixel_tests_in_args(self):
# With the --no-pixel-tests flag, no tests should run as pixel tests. # With the --no-pixel-tests flag, no tests should run as pixel tests.
options = optparse.Values({'pixel_tests': False}) options = optparse.Values(
{'pixel_tests': False, 'target': 'Release', 'configuration': 'Release'})
port = self.make_port(options=options) port = self.make_port(options=options)
self.assertFalse(port.should_run_as_pixel_test('fast/css/001.html')) self.assertFalse(port.should_run_as_pixel_test('fast/css/001.html'))
def test_should_run_as_pixel_test_default(self): def test_should_run_as_pixel_test_default(self):
options = optparse.Values({'pixel_tests': True}) options = optparse.Values(
{'pixel_tests': True, 'target': 'Release', 'configuration': 'Release'})
port = self.make_port(options=options) port = self.make_port(options=options)
self.assertFalse(port.should_run_as_pixel_test('external/wpt/dom/interfaces.html')) self.assertFalse(port.should_run_as_pixel_test('external/wpt/dom/interfaces.html'))
self.assertFalse(port.should_run_as_pixel_test('virtual/a-name/external/wpt/dom/interfaces.html')) self.assertFalse(port.should_run_as_pixel_test('virtual/a-name/external/wpt/dom/interfaces.html'))
...@@ -791,11 +824,13 @@ class PortTest(LoggingTestCase): ...@@ -791,11 +824,13 @@ class PortTest(LoggingTestCase):
def test_build_path(self): def test_build_path(self):
# Test for a protected method - pylint: disable=protected-access # Test for a protected method - pylint: disable=protected-access
# Test that optional paths are used regardless of whether they exist. # Test that optional paths are used regardless of whether they exist.
options = optparse.Values({'configuration': 'Release', 'build_directory': 'xcodebuild'}) options = optparse.Values({'target': 'Release', 'build_directory': 'xcodebuild',
'configuration': 'Release'})
self.assertEqual(self.make_port(options=options)._build_path(), '/mock-checkout/xcodebuild/Release') self.assertEqual(self.make_port(options=options)._build_path(), '/mock-checkout/xcodebuild/Release')
# Test that "out" is used as the default. # Test that "out" is used as the default.
options = optparse.Values({'configuration': 'Release', 'build_directory': None}) options = optparse.Values({'target': 'Release', 'build_directory': None,
'configuration': 'Release'})
self.assertEqual(self.make_port(options=options)._build_path(), '/mock-checkout/out/Release') self.assertEqual(self.make_port(options=options)._build_path(), '/mock-checkout/out/Release')
def test_dont_require_http_server(self): def test_dont_require_http_server(self):
...@@ -803,7 +838,8 @@ class PortTest(LoggingTestCase): ...@@ -803,7 +838,8 @@ class PortTest(LoggingTestCase):
self.assertEqual(port.requires_http_server(), False) self.assertEqual(port.requires_http_server(), False)
def test_can_load_actual_virtual_test_suite_file(self): def test_can_load_actual_virtual_test_suite_file(self):
port = Port(SystemHost(), 'baseport') port = Port(SystemHost(), 'baseport', options=optparse.Values(
{'target': 'Release', 'configuration': 'Release'}))
# If this call returns successfully, we found and loaded the LayoutTests/VirtualTestSuites. # If this call returns successfully, we found and loaded the LayoutTests/VirtualTestSuites.
_ = port.virtual_test_suites() _ = port.virtual_test_suites()
...@@ -845,7 +881,10 @@ class PortTest(LoggingTestCase): ...@@ -845,7 +881,10 @@ class PortTest(LoggingTestCase):
self.assertEqual(port.default_results_directory(), '/mock-checkout/out/Default/layout-test-results') self.assertEqual(port.default_results_directory(), '/mock-checkout/out/Default/layout-test-results')
def test_results_directory(self): def test_results_directory(self):
port = self.make_port(options=optparse.Values({'results_directory': 'some-directory/results'})) options = options=optparse.Values({
'results_directory': 'some-directory/results', 'target': 'Release',
'configuration': 'Release'})
port = self.make_port(options=options)
# A results directory can be given as an option, and it is relative to current working directory. # A results directory can be given as an option, and it is relative to current working directory.
self.assertEqual(port.host.filesystem.cwd, '/') self.assertEqual(port.host.filesystem.cwd, '/')
self.assertEqual(port.results_directory(), '/some-directory/results') self.assertEqual(port.results_directory(), '/some-directory/results')
......
...@@ -42,14 +42,15 @@ class _BrowserTestTestCaseMixin(object): ...@@ -42,14 +42,15 @@ class _BrowserTestTestCaseMixin(object):
self.assertTrue(self.make_port()._path_to_driver().endswith(self.driver_name_endswith)) self.assertTrue(self.make_port()._path_to_driver().endswith(self.driver_name_endswith))
def test_default_timeout_ms(self): def test_default_timeout_ms(self):
self.assertEqual(self.make_port(options=optparse.Values({'configuration': 'Release'})).default_timeout_ms(), options = optparse.Values({'target': 'Release', 'configuration': 'Release'})
self.timeout_ms) self.assertEqual(self.make_port(options=options).default_timeout_ms(), self.timeout_ms)
self.assertEqual(self.make_port(options=optparse.Values({'configuration': 'Debug'})).default_timeout_ms(), options = optparse.Values({'target': 'Debug', 'configuration': 'Debug'})
3 * self.timeout_ms) self.assertEqual(self.make_port(options=options).default_timeout_ms(), 3 * self.timeout_ms)
def test_driver_type(self): def test_driver_type(self):
self.assertTrue(isinstance(self.make_port(options=optparse.Values({'driver_name': 'browser_tests'}) port = self.make_port(options=optparse.Values(
).create_driver(1), browser_test_driver.BrowserTestDriver)) {'driver_name': 'browser_tests', 'target': 'Release', 'configuration': 'Release'}))
self.assertTrue(isinstance(port.create_driver(1), browser_test_driver.BrowserTestDriver))
def test_layout_tests_dir(self): def test_layout_tests_dir(self):
self.assertTrue(self.make_port().layout_tests_dir().endswith('chrome/test/data/printing/layout_tests')) self.assertTrue(self.make_port().layout_tests_dir().endswith('chrome/test/data/printing/layout_tests'))
...@@ -90,5 +91,7 @@ class BrowserTestMacTest(_BrowserTestTestCaseMixin, port_testcase.PortTestCase): ...@@ -90,5 +91,7 @@ class BrowserTestMacTest(_BrowserTestTestCaseMixin, port_testcase.PortTestCase):
timeout_ms = 20 * 1000 timeout_ms = 20 * 1000
def test_driver_path(self): def test_driver_path(self):
test_port = self.make_port(options=optparse.Values({'driver_name': 'browser_tests'})) options = optparse.Values(
{'driver_name': 'browser_tests', 'target': 'Release', 'configuration': 'Release'})
test_port = self.make_port(options=options)
self.assertNotIn('.app/Contents/MacOS', test_port._path_to_driver()) self.assertNotIn('.app/Contents/MacOS', test_port._path_to_driver())
...@@ -38,7 +38,8 @@ from blinkpy.web_tests.port.server_process_mock import MockServerProcess ...@@ -38,7 +38,8 @@ from blinkpy.web_tests.port.server_process_mock import MockServerProcess
class DriverTest(unittest.TestCase): class DriverTest(unittest.TestCase):
def make_port(self): def make_port(self):
return Port(MockSystemHost(), 'test', optparse.Values({'configuration': 'Release'})) return Port(MockSystemHost(), 'test',
optparse.Values({'configuration': 'Release', 'target': 'Release'}))
def _assert_wrapper(self, wrapper_string, expected_wrapper): def _assert_wrapper(self, wrapper_string, expected_wrapper):
wrapper = Driver(self.make_port(), None)._command_wrapper(wrapper_string) wrapper = Driver(self.make_port(), None)._command_wrapper(wrapper_string)
......
...@@ -59,15 +59,19 @@ class PortFactory(object): ...@@ -59,15 +59,19 @@ class PortFactory(object):
return 'win' return 'win'
raise NotImplementedError('unknown platform: %s' % platform) raise NotImplementedError('unknown platform: %s' % platform)
def _default_options(self):
return optparse.Values({'configuration': 'Release', 'target': 'Release'})
def get(self, port_name=None, options=None, **kwargs): def get(self, port_name=None, options=None, **kwargs):
"""Returns an object implementing the Port interface. """Returns an object implementing the Port interface.
If port_name is None, this routine attempts to guess at the most If port_name is None, this routine attempts to guess at the most
appropriate port on this platform. appropriate port on this platform.
""" """
options = options or self._default_options()
port_name = port_name or self._default_port() port_name = port_name or self._default_port()
_check_configuration_and_target(self._host.filesystem, options) check_configuration_and_target(self._host.filesystem, options)
if 'browser_test' in port_name: if 'browser_test' in port_name:
module_name, class_name = port_name.rsplit('.', 1) module_name, class_name = port_name.rsplit('.', 1)
...@@ -130,28 +134,29 @@ def configuration_options(): ...@@ -130,28 +134,29 @@ def configuration_options():
def _builder_options(builder_name): def _builder_options(builder_name):
configuration = 'Debug' if re.search(r'[d|D](ebu|b)g', builder_name) else 'Release'
return optparse.Values({ return optparse.Values({
'builder_name': builder_name, 'builder_name': builder_name,
'configuration': 'Debug' if re.search(r'[d|D](ebu|b)g', builder_name) else 'Release', 'configuration': configuration,
'target': None, 'target': configuration,
}) })
def _check_configuration_and_target(host, options): def check_configuration_and_target(host, options):
"""Updates options.configuration based on options.target.""" """Updates options.configuration based on options.target."""
if not options or not getattr(options, 'target', None): if not options or not getattr(options, 'target', None):
return return
gn_configuration = _read_configuration_from_gn(host, options) gn_configuration = _read_configuration_from_gn(host, options)
if gn_configuration: if gn_configuration:
expected_configuration = getattr(options, 'configuration') expected_configuration = getattr(options, 'configuration', None)
if expected_configuration not in (None, gn_configuration): if expected_configuration not in (None, gn_configuration):
raise ValueError('Configuration does not match the GN build args. ' raise ValueError('Configuration does not match the GN build args. '
'Expected "%s" but got "%s".' % (gn_configuration, expected_configuration)) 'Expected "%s" but got "%s".' % (gn_configuration, expected_configuration))
options.configuration = gn_configuration options.configuration = gn_configuration
return return
if options.target in ('Debug', 'Debug_x64'): if options.target in ('Default', 'Debug', 'Debug_x64'):
options.configuration = 'Debug' options.configuration = 'Debug'
elif options.target in ('Release', 'Release_x64'): elif options.target in ('Release', 'Release_x64'):
options.configuration = 'Release' options.configuration = 'Release'
......
...@@ -45,7 +45,7 @@ class FactoryTest(unittest.TestCase): ...@@ -45,7 +45,7 @@ class FactoryTest(unittest.TestCase):
# instead of passing generic "options". # instead of passing generic "options".
def setUp(self): def setUp(self):
self.webkit_options = optparse.Values({'pixel_tests': False}) self.webkit_options = optparse.Values({'pixel_tests': False, 'configuration': 'Release'})
def assert_port(self, port_name=None, os_name=None, os_version=None, options=None, cls=None): def assert_port(self, port_name=None, os_name=None, os_version=None, options=None, cls=None):
host = MockHost(os_name=os_name, os_version=os_version) host = MockHost(os_name=os_name, os_version=os_version)
...@@ -98,32 +98,35 @@ class FactoryTest(unittest.TestCase): ...@@ -98,32 +98,35 @@ class FactoryTest(unittest.TestCase):
return factory.PortFactory(host).get(options=options) return factory.PortFactory(host).get(options=options)
def test_default_target_and_configuration(self): def test_default_target_and_configuration(self):
port = self.get_port() # Generate a fake 'content shell' binary in 'Debug' target
self.assertEqual(port._options.configuration, 'Release') temp_port = self.get_port(target='Debug', configuration='Debug')
self.assertEqual(port._options.target, 'Release') path_to_fake_driver = temp_port._path_to_driver()
port = self.get_port(files={path_to_fake_driver: 'blah'})
self.assertEqual(port._options.configuration, 'Debug')
self.assertEqual(port._options.target, 'Debug')
def test_debug_configuration(self): def test_debug_configuration(self):
port = self.get_port(configuration='Debug') port = self.get_port(target='Debug', configuration='Debug')
self.assertEqual(port._options.configuration, 'Debug') self.assertEqual(port._options.configuration, 'Debug')
self.assertEqual(port._options.target, 'Debug') self.assertEqual(port._options.target, 'Debug')
def test_release_configuration(self): def test_release_configuration(self):
port = self.get_port(configuration='Release') port = self.get_port(target='Release', configuration='Release')
self.assertEqual(port._options.configuration, 'Release') self.assertEqual(port._options.configuration, 'Release')
self.assertEqual(port._options.target, 'Release') self.assertEqual(port._options.target, 'Release')
def test_debug_target(self): def test_debug_target(self):
port = self.get_port(target='Debug') port = self.get_port(target='Debug', configuration='Debug')
self.assertEqual(port._options.configuration, 'Debug') self.assertEqual(port._options.configuration, 'Debug')
self.assertEqual(port._options.target, 'Debug') self.assertEqual(port._options.target, 'Debug')
def test_debug_x64_target(self): def test_debug_x64_target(self):
port = self.get_port(target='Debug_x64') port = self.get_port(target='Debug_x64', configuration='Debug')
self.assertEqual(port._options.configuration, 'Debug') self.assertEqual(port._options.configuration, 'Debug')
self.assertEqual(port._options.target, 'Debug_x64') self.assertEqual(port._options.target, 'Debug_x64')
def test_release_x64_target(self): def test_release_x64_target(self):
port = self.get_port(target='Release_x64') port = self.get_port(target='Release_x64', configuration='Release')
self.assertEqual(port._options.configuration, 'Release') self.assertEqual(port._options.configuration, 'Release')
self.assertEqual(port._options.target, 'Release_x64') self.assertEqual(port._options.target, 'Release_x64')
...@@ -158,7 +161,7 @@ class FactoryTest(unittest.TestCase): ...@@ -158,7 +161,7 @@ class FactoryTest(unittest.TestCase):
def test_unknown_dir(self): def test_unknown_dir(self):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
self.get_port(target='unknown') self.get_port(target='unknown', configuration='Debug')
def test_both_configuration_and_target_is_an_error(self): def test_both_configuration_and_target_is_an_error(self):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
......
...@@ -79,14 +79,17 @@ class LinuxPortTest(port_testcase.PortTestCase, LoggingTestCase): ...@@ -79,14 +79,17 @@ class LinuxPortTest(port_testcase.PortTestCase, LoggingTestCase):
# FIXME: Check that, for now, these are illegal port names. # FIXME: Check that, for now, these are illegal port names.
# Eventually we should be able to do the right thing here. # Eventually we should be able to do the right thing here.
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
linux.LinuxPort(MockSystemHost(), port_name='linux-x86') linux.LinuxPort(
MockSystemHost(), port_name='linux-x86',
options=optparse.Values({'configuration': 'Release', 'target': 'Release'}))
def test_operating_system(self): def test_operating_system(self):
self.assertEqual('linux', self.make_port().operating_system()) self.assertEqual('linux', self.make_port().operating_system())
def test_driver_name_option(self): def test_driver_name_option(self):
self.assertTrue(self.make_port()._path_to_driver().endswith('content_shell')) self.assertTrue(self.make_port()._path_to_driver().endswith('content_shell'))
port = self.make_port(options=optparse.Values({'driver_name': 'OtherDriver'})) port = self.make_port(options=optparse.Values(
{'driver_name': 'OtherDriver', 'configuration': 'Release', 'target': 'Release'}))
self.assertTrue(port._path_to_driver().endswith('OtherDriver')) # pylint: disable=protected-access self.assertTrue(port._path_to_driver().endswith('OtherDriver')) # pylint: disable=protected-access
def test_path_to_image_diff(self): def test_path_to_image_diff(self):
......
...@@ -48,7 +48,8 @@ class MacPortTest(port_testcase.PortTestCase): ...@@ -48,7 +48,8 @@ class MacPortTest(port_testcase.PortTestCase):
def test_driver_name_option(self): def test_driver_name_option(self):
self.assertTrue(self.make_port()._path_to_driver().endswith('Content Shell')) self.assertTrue(self.make_port()._path_to_driver().endswith('Content Shell'))
port = self.make_port(options=optparse.Values(dict(driver_name='OtherDriver'))) port = self.make_port(options=optparse.Values(
{'driver_name': 'OtherDriver', 'configuration': 'Release', 'target': 'Release'}))
self.assertTrue(port._path_to_driver().endswith('OtherDriver')) # pylint: disable=protected-access self.assertTrue(port._path_to_driver().endswith('OtherDriver')) # pylint: disable=protected-access
def test_path_to_image_diff(self): def test_path_to_image_diff(self):
......
...@@ -41,7 +41,8 @@ from blinkpy.web_tests.port.factory import PortFactory ...@@ -41,7 +41,8 @@ from blinkpy.web_tests.port.factory import PortFactory
class MockDRTPortTest(port_testcase.PortTestCase): class MockDRTPortTest(port_testcase.PortTestCase):
def make_port(self, host=None, options=optparse.Values({'configuration': 'Release'})): def make_port(self, host=None,
options=optparse.Values({'configuration': 'Release', 'target': 'Release'})):
host = host or MockSystemHost() host = host or MockSystemHost()
test.add_unit_tests_to_mock_filesystem(host.filesystem) test.add_unit_tests_to_mock_filesystem(host.filesystem)
return mock_drt.MockDRTPort(host, port_name='mock-mac', options=options) return mock_drt.MockDRTPort(host, port_name='mock-mac', options=options)
......
...@@ -66,7 +66,9 @@ class PortTestCase(LoggingTestCase): ...@@ -66,7 +66,9 @@ class PortTestCase(LoggingTestCase):
def make_port(self, host=None, port_name=None, options=None, os_name=None, os_version=None, **kwargs): 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)) 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'}) options = options or optparse.Values(
{'target': 'Release', 'configuration': 'Release'})
port_name = port_name or self.port_name port_name = port_name or self.port_name
port_name = self.port_maker.determine_full_port_name(host, options, 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) return self.port_maker(host, port_name, options=options, **kwargs)
...@@ -117,14 +119,18 @@ class PortTestCase(LoggingTestCase): ...@@ -117,14 +119,18 @@ class PortTestCase(LoggingTestCase):
self.assertEqual(port.default_max_locked_shards(), 1) self.assertEqual(port.default_max_locked_shards(), 1)
def test_default_timeout_ms(self): def test_default_timeout_ms(self):
self.assertEqual(self.make_port(options=optparse.Values({'configuration': 'Release'})).default_timeout_ms(), 6000) options = optparse.Values({'configuration': 'Release', 'target': 'Release'})
self.assertEqual(self.make_port(options=optparse.Values({'configuration': 'Debug'})).default_timeout_ms(), 18000) self.assertEqual(self.make_port(options=options).default_timeout_ms(), 6000)
options = optparse.Values({'configuration': 'Debug', 'target': 'Debug'})
self.assertEqual(self.make_port(options=options).default_timeout_ms(), 18000)
def test_driver_cmd_line(self): def test_driver_cmd_line(self):
port = self.make_port() port = self.make_port()
self.assertTrue(len(port.driver_cmd_line())) self.assertTrue(len(port.driver_cmd_line()))
options = optparse.Values(dict(additional_driver_flag=['--foo=bar', '--foo=baz'])) options = optparse.Values({
'additional_driver_flag': ['--foo=bar', '--foo=baz'],
'configuration': 'Release', 'target': 'Release'})
port = self.make_port(options=options) port = self.make_port(options=options)
cmd_line = port.driver_cmd_line() cmd_line = port.driver_cmd_line()
self.assertTrue('--foo=bar' in cmd_line) self.assertTrue('--foo=bar' in cmd_line)
...@@ -261,7 +267,9 @@ class PortTestCase(LoggingTestCase): ...@@ -261,7 +267,9 @@ class PortTestCase(LoggingTestCase):
ordered_dict = port.expectations_dict() ordered_dict = port.expectations_dict()
self.assertEqual(port.path_to_generic_test_expectations_file(), ordered_dict.keys()[0]) self.assertEqual(port.path_to_generic_test_expectations_file(), ordered_dict.keys()[0])
options = optparse.Values(dict(additional_expectations=['/tmp/foo', '/tmp/bar'])) options = optparse.Values(
{'additional_expectations': ['/tmp/foo', '/tmp/bar'],
'configuration': 'Release', 'target': 'Release'})
port = self.make_port(options=options) port = self.make_port(options=options)
for path in port.expectations_files(): for path in port.expectations_files():
port.host.filesystem.write_text_file(path, '') port.host.filesystem.write_text_file(path, '')
...@@ -294,7 +302,9 @@ class PortTestCase(LoggingTestCase): ...@@ -294,7 +302,9 @@ class PortTestCase(LoggingTestCase):
self.assertEqual(port.path_to_apache_config_file(), '/existing/httpd.conf') self.assertEqual(port.path_to_apache_config_file(), '/existing/httpd.conf')
def test_additional_platform_directory(self): def test_additional_platform_directory(self):
port = self.make_port(options=optparse.Values(dict(additional_platform_directory=['/tmp/foo']))) port = self.make_port(options=optparse.Values(
{'additional_platform_directory': ['/tmp/foo'],
'configuration': 'Release', 'target': 'Release'}))
self.assertEqual(port.baseline_search_path()[0], '/tmp/foo') self.assertEqual(port.baseline_search_path()[0], '/tmp/foo')
def test_virtual_test_suites(self): def test_virtual_test_suites(self):
......
...@@ -447,9 +447,10 @@ class TestPort(Port): ...@@ -447,9 +447,10 @@ class TestPort(Port):
'linux': ['precise', 'trusty'] 'linux': ['precise', 'trusty']
} }
def _path_to_driver(self): def _path_to_driver(self, target=None):
# This routine shouldn't normally be called, but it is called by # This routine shouldn't normally be called, but it is called by
# the mock_drt Driver. We return something, but make sure it's useless. # the mock_drt Driver. We return something, but make sure it's useless.
del target # Unused
return 'MOCK _path_to_driver' return 'MOCK _path_to_driver'
def default_child_processes(self): def default_child_processes(self):
...@@ -461,9 +462,13 @@ class TestPort(Port): ...@@ -461,9 +462,13 @@ class TestPort(Port):
def check_sys_deps(self, needs_http): def check_sys_deps(self, needs_http):
return exit_codes.OK_EXIT_STATUS return exit_codes.OK_EXIT_STATUS
def default_configuration(self): def default_target(self):
return 'Release' return 'Release'
def check_configuration_and_target(self):
if not getattr(self._options, 'configuration', None):
self._options.configuration = 'Release'
def diff_image(self, expected_contents, actual_contents): def diff_image(self, expected_contents, actual_contents):
diffed = actual_contents != expected_contents diffed = actual_contents != expected_contents
if not actual_contents and not expected_contents: if not actual_contents and not expected_contents:
......
...@@ -105,8 +105,9 @@ class WinPortTest(port_testcase.PortTestCase): ...@@ -105,8 +105,9 @@ class WinPortTest(port_testcase.PortTestCase):
def test_driver_name_option(self): def test_driver_name_option(self):
self.assertTrue(self.make_port()._path_to_driver().endswith('content_shell.exe')) self.assertTrue(self.make_port()._path_to_driver().endswith('content_shell.exe'))
self.assertTrue( port = self.make_port(options=optparse.Values(
self.make_port(options=optparse.Values({'driver_name': 'OtherDriver'}))._path_to_driver().endswith('OtherDriver.exe')) {'driver_name': 'OtherDriver', 'configuration': 'Release', 'target': 'Release'}))
self.assertTrue(port._path_to_driver().endswith('OtherDriver.exe'))
def test_path_to_image_diff(self): def test_path_to_image_diff(self):
self.assertEqual(self.make_port()._path_to_image_diff(), '/mock-checkout/out/Release/image_diff.exe') self.assertEqual(self.make_port()._path_to_image_diff(), '/mock-checkout/out/Release/image_diff.exe')
......
...@@ -544,7 +544,7 @@ def _set_up_derived_options(port, options, args): ...@@ -544,7 +544,7 @@ def _set_up_derived_options(port, options, args):
'WEBKIT_TEST_MAX_LOCKED_SHARDS', str(port.default_max_locked_shards()))) 'WEBKIT_TEST_MAX_LOCKED_SHARDS', str(port.default_max_locked_shards())))
if not options.configuration: if not options.configuration:
options.configuration = port.default_configuration() options.configuration = 'Release'
if not options.time_out_ms: if not options.time_out_ms:
options.time_out_ms = str(port.default_timeout_ms()) options.time_out_ms = str(port.default_timeout_ms())
......
...@@ -1631,15 +1631,18 @@ class MainTest(unittest.TestCase): ...@@ -1631,15 +1631,18 @@ class MainTest(unittest.TestCase):
stderr = StringIO.StringIO() stderr = StringIO.StringIO()
try: try:
run_webkit_tests._run_tests = interrupting_run run_webkit_tests._run_tests = interrupting_run
res = run_webkit_tests.main([], stdout, stderr) res = run_webkit_tests.main(
['--release', '--target=Release'], stdout, stderr)
self.assertEqual(res, exit_codes.INTERRUPTED_EXIT_STATUS) self.assertEqual(res, exit_codes.INTERRUPTED_EXIT_STATUS)
run_webkit_tests._run_tests = successful_run run_webkit_tests._run_tests = successful_run
res = run_webkit_tests.main(['--platform', 'test'], stdout, stderr) res = run_webkit_tests.main(
['--platform', 'test', '--release', '--target=Release'], stdout, stderr)
self.assertEqual(res, exit_codes.UNEXPECTED_ERROR_EXIT_STATUS) self.assertEqual(res, exit_codes.UNEXPECTED_ERROR_EXIT_STATUS)
run_webkit_tests._run_tests = exception_raising_run run_webkit_tests._run_tests = exception_raising_run
res = run_webkit_tests.main([], stdout, stderr) res = run_webkit_tests.main(
['--release', '--target=Release'], stdout, stderr)
self.assertEqual(res, exit_codes.UNEXPECTED_ERROR_EXIT_STATUS) self.assertEqual(res, exit_codes.UNEXPECTED_ERROR_EXIT_STATUS)
finally: finally:
run_webkit_tests._run_tests = orig_run_fn run_webkit_tests._run_tests = orig_run_fn
...@@ -61,6 +61,9 @@ def main(server_constructor, input_fn=None, argv=None, description=None, **kwarg ...@@ -61,6 +61,9 @@ def main(server_constructor, input_fn=None, argv=None, description=None, **kwarg
logger.setLevel(logging.DEBUG if options.verbose else logging.INFO) logger.setLevel(logging.DEBUG if options.verbose else logging.INFO)
host = Host() host = Host()
# Constructing a port requires explicitly setting the configuration & target.
options.configuration = 'Release'
options.target = 'Release'
port_obj = host.port_factory.get(options=options) port_obj = host.port_factory.get(options=options)
if not options.output_dir: if not options.output_dir:
options.output_dir = port_obj.default_results_directory() options.output_dir = port_obj.default_results_directory()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment