def _assertOptimization(self, results_by_directory, expected_new_results_by_directory, baseline_dirname='', expected_files_to_delete=None, host=None): if not host: host = MockHost() fs = host.filesystem webkit_base = WebKitFinder(fs).webkit_base() baseline_name = 'mock-baseline-expected.txt' for dirname, contents in results_by_directory.items(): path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) fs.write_binary_file(path, contents) baseline_optimizer = BaselineOptimizer(host, host.port_factory.all_port_names(), skip_scm_commands=expected_files_to_delete is not None) self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, baseline_name))) for dirname, contents in expected_new_results_by_directory.items(): path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) if contents is None: self.assertTrue(not fs.exists(path) or path in baseline_optimizer._files_to_delete) else: self.assertEqual(fs.read_binary_file(path), contents) # Check that the files that were in the original set have been deleted where necessary. for dirname in results_by_directory: path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) if not dirname in expected_new_results_by_directory: self.assertTrue(not fs.exists(path) or path in baseline_optimizer._files_to_delete) if expected_files_to_delete: self.assertEqual(baseline_optimizer._files_to_delete, expected_files_to_delete)
def test_move_baselines(self): host = MockHost(scm=ExcludingMockSCM([ '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/test-expected.txt' ])) host.filesystem.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/test-expected.txt', 'result A') host.filesystem.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/test-expected.txt', 'result A') host.filesystem.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt', 'result B') baseline_optimizer = BaselineOptimizer( host, host.port_factory.all_port_names(), skip_scm_commands=False) baseline_optimizer._move_baselines( 'another/test-expected.txt', { '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', }, { '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', }) self.assertEqual( host.filesystem.read_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt' ), 'result A')
def test_move_baselines_skip_scm_commands(self): host = MockHost() host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/LayoutTests/VirtualTestSuites', '[]') host.filesystem.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/test-expected.txt', 'result A') host.filesystem.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/test-expected.txt', 'result A') host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt', 'result B') baseline_optimizer = BaselineOptimizer(host, host.port_factory.get( ), host.port_factory.all_port_names()) baseline_optimizer._move_baselines( 'another/test-expected.txt', { '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', }, { '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux': 'bbb', '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', }) self.assertEqual( host.filesystem.read_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt'), 'result A')
def _assertOptimization(self, results_by_directory, expected_new_results_by_directory, baseline_dirname=''): host = MockHost() fs = host.filesystem webkit_base = WebKitFinder(fs).webkit_base() baseline_name = 'mock-baseline-expected.txt' for dirname, contents in results_by_directory.items(): path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) fs.write_binary_file(path, contents) baseline_optimizer = BaselineOptimizer( host, host.port_factory.all_port_names()) self.assertTrue( baseline_optimizer.optimize( fs.join(baseline_dirname, baseline_name))) for dirname, contents in expected_new_results_by_directory.items(): path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) if contents is None: self.assertFalse(fs.exists(path)) else: self.assertEqual(fs.read_binary_file(path), contents) # Check that the files that were in the original set have been deleted where necessary. for dirname in results_by_directory: path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) if not dirname in expected_new_results_by_directory: self.assertFalse(fs.exists(path))
def test_move_baselines_skip_scm_commands(self): host = MockHost() host.filesystem.write_text_file( '/mock-checkout/third_party/WebKit/LayoutTests/VirtualTestSuites', '[]') host.filesystem.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/test-expected.txt', 'result A') host.filesystem.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/test-expected.txt', 'result A') host.filesystem.write_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt', 'result B') baseline_optimizer = BaselineOptimizer( host, host.port_factory.get(), host.port_factory.all_port_names()) baseline_optimizer._move_baselines( 'another/test-expected.txt', { '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', }, { '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux': 'bbb', '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', }) self.assertEqual( host.filesystem.read_binary_file( '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt' ), 'result A')
def _assertOptimization(self, results_by_directory, expected_new_results_by_directory, baseline_dirname='', expected_files_to_delete=None, host=None): if not host: host = MockHost() fs = host.filesystem webkit_base = WebKitFinder(fs).webkit_base() baseline_name = 'mock-baseline-expected.txt' fs.write_text_file(fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuites'), '[{"prefix": "gpu", "base": "fast/canvas", "args": ["--foo"]}]') for dirname, contents in results_by_directory.items(): path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) fs.write_binary_file(path, contents) baseline_optimizer = BaselineOptimizer(host, host.port_factory.get(), host.port_factory.all_port_names(), skip_scm_commands=expected_files_to_delete is not None) self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, baseline_name))) for dirname, contents in expected_new_results_by_directory.items(): path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) if contents is None: self.assertTrue(not fs.exists(path) or path in baseline_optimizer._files_to_delete) else: self.assertEqual(fs.read_binary_file(path), contents) # Check that the files that were in the original set have been deleted where necessary. for dirname in results_by_directory: path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) if not dirname in expected_new_results_by_directory: self.assertTrue(not fs.exists(path) or path in baseline_optimizer._files_to_delete) if expected_files_to_delete: self.assertEqual(sorted(baseline_optimizer._files_to_delete), sorted(expected_files_to_delete))
def _assertOptimization(self, results_by_directory, expected_new_results_by_directory, baseline_dirname='', host=None): if not host: host = MockHost() fs = host.filesystem webkit_base = WebKitFinder(fs).webkit_base() baseline_name = 'mock-baseline-expected.txt' fs.write_text_file( fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuites'), '[{"prefix": "gpu", "base": "fast/canvas", "args": ["--foo"]}]') for dirname, contents in results_by_directory.items(): path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) fs.write_binary_file(path, contents) baseline_optimizer = BaselineOptimizer( host, host.port_factory.get(), host.port_factory.all_port_names()) self.assertTrue( baseline_optimizer.optimize( fs.join(baseline_dirname, baseline_name))) for dirname, contents in expected_new_results_by_directory.items(): path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) if contents is not None: self.assertEqual(fs.read_binary_file(path), contents)
def test_move_baselines(self): host = MockHost() host.filesystem.write_binary_file( "/mock-checkout/LayoutTests/platform/chromium-win/another/test-expected.txt", "result A" ) host.filesystem.write_binary_file( "/mock-checkout/LayoutTests/platform/chromium-mac/another/test-expected.txt", "result A" ) host.filesystem.write_binary_file( "/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt", "result B" ) baseline_optimizer = BaselineOptimizer(host) baseline_optimizer._move_baselines( "another/test-expected.txt", { "LayoutTests/platform/chromium-win": "aaa", "LayoutTests/platform/chromium-mac": "aaa", "LayoutTests/platform/chromium": "bbb", }, {"LayoutTests/platform/chromium": "aaa"}, ) self.assertEqual( host.filesystem.read_binary_file("/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt"), "result A", )
def test_move_baselines(self): host = MockHost() host.filesystem.write_binary_file( '/mock-checkout/LayoutTests/platform/mac-lion/another/test-expected.txt', 'result A') host.filesystem.write_binary_file( '/mock-checkout/LayoutTests/platform/mac-lion-wk2/another/test-expected.txt', 'result A') host.filesystem.write_binary_file( '/mock-checkout/LayoutTests/platform/mac/another/test-expected.txt', 'result B') baseline_optimizer = BaselineOptimizer( host, host.port_factory.all_port_names()) baseline_optimizer._move_baselines( 'another/test-expected.txt', { 'LayoutTests/platform/mac-lion': 'aaa', 'LayoutTests/platform/mac-lion-wk2': 'aaa', 'LayoutTests/platform/mac': 'bbb', }, { 'LayoutTests/platform/mac': 'aaa', }) self.assertEqual( host.filesystem.read_binary_file( '/mock-checkout/LayoutTests/platform/mac/another/test-expected.txt' ), 'result A')
def __init__(self, mock_results_by_directory, create_mock_files, baseline_name): host = MockHost() BaselineOptimizer.__init__(self, host, host.port_factory.all_port_names()) self._mock_results_by_directory = mock_results_by_directory self._filesystem = host.filesystem self._port_factory = host.port_factory self._created_mock_files = create_mock_files self._baseline_name = baseline_name self._create_mock_files(mock_results_by_directory)
def test_move_baselines(self): host = MockHost() host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-win/another/test-expected.txt', 'result A') host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-mac/another/test-expected.txt', 'result A') host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt', 'result B') baseline_optimizer = BaselineOptimizer(host) baseline_optimizer._move_baselines('another/test-expected.txt', { 'LayoutTests/platform/chromium-win': 'aaa', 'LayoutTests/platform/chromium-mac': 'aaa', 'LayoutTests/platform/chromium': 'bbb', }, { 'LayoutTests/platform/chromium': 'aaa', }) self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt'), 'result A')
def test_move_baselines(self): host = MockHost() host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/mac-lion/another/test-expected.txt', 'result A') host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/mac-lion-wk2/another/test-expected.txt', 'result A') host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/mac/another/test-expected.txt', 'result B') baseline_optimizer = BaselineOptimizer(host, host.port_factory.all_port_names()) baseline_optimizer._move_baselines('another/test-expected.txt', { 'LayoutTests/platform/mac-lion': 'aaa', 'LayoutTests/platform/mac-lion-wk2': 'aaa', 'LayoutTests/platform/mac': 'bbb', }, { 'LayoutTests/platform/mac': 'aaa', }) self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/LayoutTests/platform/mac/another/test-expected.txt'), 'result A')
def test_move_baselines(self): fs = MockFileSystem() fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-win/another/test-expected.txt', 'result A') fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-cg-mac/another/test-expected.txt', 'result A') fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt', 'result B') baseline_optimizer = BaselineOptimizer(MockSCM(), fs) baseline_optimizer._move_baselines('another/test-expected.txt', { 'LayoutTests/platform/chromium-win': 'aaa', 'LayoutTests/platform/chromium-cg-mac': 'aaa', 'LayoutTests/platform/chromium': 'bbb', }, { 'LayoutTests/platform/chromium': 'aaa', }) self.assertEqual(fs.read_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt'), 'result A')
def test_move_baselines(self): host = MockHost(scm=ExcludingMockSCM(['/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/test-expected.txt'])) host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/test-expected.txt', 'result A') host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/test-expected.txt', 'result A') host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt', 'result B') baseline_optimizer = BaselineOptimizer(host, host.port_factory.all_port_names(), skip_scm_commands=False) baseline_optimizer._move_baselines('another/test-expected.txt', { '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'aaa', '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', }, { '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', }) self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected.txt'), 'result A')
def execute(self, options, args, tool): self._baseline_optimizer = BaselineOptimizer(tool) self._port = tool.port_factory.get( "chromium-win-win7") # FIXME: This should be selectable. for test_name in self._port.tests(args): self._analyze_baseline(test_name)
def execute(self, options, args, tool): self._baseline_suffix_list = options.suffixes.split(',') self._baseline_optimizer = BaselineOptimizer(tool) self._port = tool.port_factory.get("chromium-win-win7") # FIXME: This should be selectable. for test_name in self._port.tests(args): print "Optimizing %s." % test_name self._optimize_baseline(test_name)
def execute(self, options, args, tool): self._baseline_optimizer = BaselineOptimizer(tool.scm(), tool.filesystem) self._port = factory.get( "chromium-win-win7") # FIXME: This should be selectable. for test_name in map(self._to_test_name, test_files.find(self._port, args)): self._analyze_baseline(test_name)
def test_move_baselines(self): fs = MockFileSystem() fs.write_binary_file("/mock-checkout/LayoutTests/platform/chromium-win/another/test-expected.txt", "result A") fs.write_binary_file( "/mock-checkout/LayoutTests/platform/chromium-cg-mac/another/test-expected.txt", "result A" ) fs.write_binary_file("/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt", "result B") baseline_optimizer = BaselineOptimizer(MockSCM(), fs) baseline_optimizer._move_baselines( "another/test-expected.txt", { "LayoutTests/platform/chromium-win": "aaa", "LayoutTests/platform/chromium-cg-mac": "aaa", "LayoutTests/platform/chromium": "bbb", }, {"LayoutTests/platform/chromium": "aaa"}, ) self.assertEqual( fs.read_binary_file("/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt"), "result A" )
def execute(self, options, args, tool): self._baseline_suffix_list = options.suffixes.split(',') port_names = tool.port_factory.all_port_names(options.platform) if not port_names: print "No port names match '%s'" % options.platform return optimizer = BaselineOptimizer(tool, port_names) port = tool.port_factory.get(port_names[0]) for test_name in port.tests(args): _log.info("Optimizing %s" % test_name) self._optimize_baseline(optimizer, test_name)
def execute(self, options, args, tool): self._tool = tool self._baseline_suffix_list = options.suffixes.split(',') port_names = tool.port_factory.all_port_names(options.platform) if not port_names: _log.error("No port names match '%s'", options.platform) return port = tool.port_factory.get(port_names[0]) optimizer = BaselineOptimizer(tool, port, port_names) tests = port.tests(args) for test_name in tests: self._optimize_baseline(optimizer, test_name)
def _assertOptimization(self, results_by_directory, expected_new_results_by_directory, baseline_dirname='', host=None): if not host: host = MockHost() fs = host.filesystem webkit_base = WebKitFinder(fs).webkit_base() baseline_name = 'mock-baseline-expected.txt' fs.write_text_file(fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuites'), '[{"prefix": "gpu", "base": "fast/canvas", "args": ["--foo"]}]') for dirname, contents in results_by_directory.items(): path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) fs.write_binary_file(path, contents) baseline_optimizer = BaselineOptimizer(host, host.port_factory.get( ), host.port_factory.all_port_names()) self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, baseline_name))) for dirname, contents in expected_new_results_by_directory.items(): path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) if contents is not None: self.assertEqual(fs.read_binary_file(path), contents)
def execute(self, options, args, tool): self._baseline_suffix_list = options.suffixes.split(',') port_names = tool.port_factory.all_port_names(options.platform) if not port_names: print "No port names match '%s'" % options.platform return port = tool.port_factory.get(port_names[0]) optimizer = BaselineOptimizer(tool, port, port_names, skip_scm_commands=options.no_modify_scm) tests = port.tests(args) for test_name in tests: files_to_delete, files_to_add = self._optimize_baseline(optimizer, test_name) for path in files_to_delete: self._delete_from_scm_later(path) for path in files_to_add: self._add_to_scm_later(path) print json.dumps(self._scm_changes)
def execute(self, options, args, tool): self._tool = tool self._baseline_suffix_list = options.suffixes.split(',') port_names = tool.port_factory.all_port_names(options.platform) if not port_names: _log.error("No port names match '%s'", options.platform) return port = tool.port_factory.get(port_names[0]) optimizer = BaselineOptimizer(tool, port, port_names, skip_scm_commands=options.no_modify_scm) tests = port.tests(args) for test_name in tests: files_to_delete, files_to_add = self._optimize_baseline( optimizer, test_name) for path in files_to_delete: self._scm_changes.delete_file(path) for path in files_to_add: self._scm_changes.add_file(path) self._print_scm_changes()
def __init__(self, mock_results_by_directory): BaselineOptimizer.__init__(self, MockSCM(), MockFileSystem()) self._mock_results_by_directory = mock_results_by_directory
def __init__(self, mock_results_by_directory): host = MockHost() BaselineOptimizer.__init__(self, host, host.port_factory.all_port_names()) self._mock_results_by_directory = mock_results_by_directory
def __init__(self, mock_results_by_directory): host = MockHost() BaselineOptimizer.__init__(self, host) self._mock_results_by_directory = mock_results_by_directory