| OLD | NEW |
| 1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import unittest | 29 import unittest |
| 30 | 30 |
| 31 from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer | 31 from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer |
| 32 from webkitpy.common.checkout.scm.scm_mock import MockSCM | |
| 33 from webkitpy.common.host_mock import MockHost | 32 from webkitpy.common.host_mock import MockHost |
| 34 from webkitpy.common.webkit_finder import WebKitFinder | 33 from webkitpy.common.webkit_finder import WebKitFinder |
| 35 | 34 |
| 36 | 35 |
| 37 class ExcludingMockSCM(MockSCM): | |
| 38 | |
| 39 def __init__(self, exclusion_list, filesystem=None, executive=None): | |
| 40 MockSCM.__init__(self, filesystem, executive) | |
| 41 self._exclusion_list = exclusion_list | |
| 42 | |
| 43 def exists(self, path): | |
| 44 if path in self._exclusion_list: | |
| 45 return False | |
| 46 return MockSCM.exists(self, path) | |
| 47 | |
| 48 def delete(self, path): | |
| 49 return self.delete_list([path]) | |
| 50 | |
| 51 def delete_list(self, paths): | |
| 52 for path in paths: | |
| 53 if path in self._exclusion_list: | |
| 54 raise Exception("File is not SCM managed: " + path) | |
| 55 return MockSCM.delete_list(self, paths) | |
| 56 | |
| 57 def move(self, origin, destination): | |
| 58 if origin in self._exclusion_list: | |
| 59 raise Exception("File is not SCM managed: " + origin) | |
| 60 return MockSCM.move(self, origin, destination) | |
| 61 | |
| 62 | |
| 63 class BaselineOptimizerTest(unittest.TestCase): | 36 class BaselineOptimizerTest(unittest.TestCase): |
| 64 | 37 |
| 65 # Protected method _move_baselines is tested below - pylint: disable=protect
ed-access | 38 # Protected method _move_baselines is tested below - pylint: disable=protect
ed-access |
| 66 def test_move_baselines(self): | 39 def test_move_baselines(self): |
| 67 host = MockHost(scm=ExcludingMockSCM( | 40 host = MockHost() |
| 68 ['/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another
/test-expected.txt'])) | |
| 69 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou
tTests/VirtualTestSuites', '[]') | 41 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou
tTests/VirtualTestSuites', '[]') |
| 70 host.filesystem.write_binary_file( | 42 host.filesystem.write_binary_file( |
| 71 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/
test-expected.txt', 'result A') | 43 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/
test-expected.txt', 'result A') |
| 72 host.filesystem.write_binary_file( | 44 host.filesystem.write_binary_file( |
| 73 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/
test-expected.txt', 'result A') | 45 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/
test-expected.txt', 'result A') |
| 74 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/another/test-expected.txt', 'result B') | 46 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/another/test-expected.txt', 'result B') |
| 75 baseline_optimizer = BaselineOptimizer( | 47 baseline_optimizer = BaselineOptimizer( |
| 76 host, host.port_factory.get(), host.port_factory.all_port_names(), s
kip_scm_commands=False) | 48 host, host.port_factory.get(), host.port_factory.all_port_names()) |
| 77 baseline_optimizer._move_baselines( | 49 baseline_optimizer._move_baselines( |
| 78 'another/test-expected.txt', | 50 'another/test-expected.txt', |
| 79 { | 51 { |
| 80 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'a
aa', | 52 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'a
aa', |
| 81 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'a
aa', | 53 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'a
aa', |
| 82 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', | 54 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', |
| 83 }, | 55 }, |
| 84 { | 56 { |
| 85 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', | 57 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', |
| 86 }) | 58 }) |
| 87 self.assertEqual(host.filesystem.read_binary_file( | 59 self.assertEqual(host.filesystem.read_binary_file( |
| 88 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected
.txt'), 'result A') | 60 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected
.txt'), 'result A') |
| 89 | 61 |
| 90 def test_move_baselines_skip_scm_commands(self): | 62 def test_move_baselines_skip_scm_commands(self): |
| 91 host = MockHost(scm=ExcludingMockSCM( | 63 host = MockHost() |
| 92 ['/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another
/test-expected.txt'])) | |
| 93 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou
tTests/VirtualTestSuites', '[]') | 64 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou
tTests/VirtualTestSuites', '[]') |
| 94 host.filesystem.write_binary_file( | 65 host.filesystem.write_binary_file( |
| 95 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/
test-expected.txt', 'result A') | 66 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/
test-expected.txt', 'result A') |
| 96 host.filesystem.write_binary_file( | 67 host.filesystem.write_binary_file( |
| 97 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/
test-expected.txt', 'result A') | 68 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/
test-expected.txt', 'result A') |
| 98 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/another/test-expected.txt', 'result B') | 69 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay
outTests/another/test-expected.txt', 'result B') |
| 99 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get( | 70 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get( |
| 100 ), host.port_factory.all_port_names(), skip_scm_commands=True) | 71 ), host.port_factory.all_port_names()) |
| 101 baseline_optimizer._move_baselines( | 72 baseline_optimizer._move_baselines( |
| 102 'another/test-expected.txt', | 73 'another/test-expected.txt', |
| 103 { | 74 { |
| 104 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'a
aa', | 75 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'a
aa', |
| 105 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'a
aa', | 76 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'a
aa', |
| 106 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', | 77 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb', |
| 107 }, | 78 }, |
| 108 { | 79 { |
| 109 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux':
'bbb', | 80 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux':
'bbb', |
| 110 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', | 81 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', |
| 111 }) | 82 }) |
| 112 self.assertEqual( | 83 self.assertEqual( |
| 113 host.filesystem.read_binary_file( | 84 host.filesystem.read_binary_file( |
| 114 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expe
cted.txt'), | 85 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expe
cted.txt'), |
| 115 'result A') | 86 'result A') |
| 116 | 87 |
| 117 self.assertEqual( | |
| 118 baseline_optimizer._files_to_delete, | |
| 119 [ | |
| 120 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/anot
her/test-expected.txt', | |
| 121 ]) | |
| 122 | |
| 123 self.assertEqual( | |
| 124 baseline_optimizer._files_to_add, | |
| 125 [ | |
| 126 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expe
cted.txt', | |
| 127 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux/an
other/test-expected.txt', | |
| 128 ]) | |
| 129 | |
| 130 def _assertOptimization(self, results_by_directory, expected_new_results_by_
directory, | 88 def _assertOptimization(self, results_by_directory, expected_new_results_by_
directory, |
| 131 baseline_dirname='', expected_files_to_delete=None,
host=None): | 89 baseline_dirname='', host=None): |
| 132 if not host: | 90 if not host: |
| 133 host = MockHost() | 91 host = MockHost() |
| 134 fs = host.filesystem | 92 fs = host.filesystem |
| 135 webkit_base = WebKitFinder(fs).webkit_base() | 93 webkit_base = WebKitFinder(fs).webkit_base() |
| 136 baseline_name = 'mock-baseline-expected.txt' | 94 baseline_name = 'mock-baseline-expected.txt' |
| 137 fs.write_text_file(fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuite
s'), | 95 fs.write_text_file(fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuite
s'), |
| 138 '[{"prefix": "gpu", "base": "fast/canvas", "args": ["
--foo"]}]') | 96 '[{"prefix": "gpu", "base": "fast/canvas", "args": ["
--foo"]}]') |
| 139 | 97 |
| 140 for dirname, contents in results_by_directory.items(): | 98 for dirname, contents in results_by_directory.items(): |
| 141 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) | 99 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) |
| 142 fs.write_binary_file(path, contents) | 100 fs.write_binary_file(path, contents) |
| 143 | 101 |
| 144 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get( | 102 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get( |
| 145 ), host.port_factory.all_port_names(), skip_scm_commands=expected_files_
to_delete is not None) | 103 ), host.port_factory.all_port_names()) |
| 146 self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, ba
seline_name))) | 104 self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, ba
seline_name))) |
| 147 | 105 |
| 148 for dirname, contents in expected_new_results_by_directory.items(): | 106 for dirname, contents in expected_new_results_by_directory.items(): |
| 149 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) | 107 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) |
| 150 if contents is None: | 108 if contents is not None: |
| 151 self.assertTrue(not fs.exists(path) or path in baseline_optimize
r._files_to_delete) | |
| 152 else: | |
| 153 self.assertEqual(fs.read_binary_file(path), contents) | 109 self.assertEqual(fs.read_binary_file(path), contents) |
| 154 | 110 |
| 155 # Check that the files that were in the original set have been deleted w
here necessary. | |
| 156 for dirname in results_by_directory: | |
| 157 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) | |
| 158 if not dirname in expected_new_results_by_directory: | |
| 159 self.assertTrue(not fs.exists(path) or path in baseline_optimize
r._files_to_delete) | |
| 160 | |
| 161 if expected_files_to_delete: | |
| 162 self.assertEqual(sorted(baseline_optimizer._files_to_delete), sorted
(expected_files_to_delete)) | |
| 163 | |
| 164 def test_linux_redundant_with_win(self): | 111 def test_linux_redundant_with_win(self): |
| 165 self._assertOptimization( | 112 self._assertOptimization( |
| 166 { | 113 { |
| 167 'platform/win': '1', | 114 'platform/win': '1', |
| 168 'platform/linux': '1', | 115 'platform/linux': '1', |
| 169 }, | 116 }, |
| 170 { | 117 { |
| 171 'platform/win': '1', | 118 'platform/win': '1', |
| 172 }) | 119 }) |
| 173 | 120 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 self._assertOptimization( | 244 self._assertOptimization( |
| 298 { | 245 { |
| 299 'virtual/gpu/fast/canvas': '2', | 246 'virtual/gpu/fast/canvas': '2', |
| 300 'platform/mac/fast/canvas': '2', | 247 'platform/mac/fast/canvas': '2', |
| 301 'platform/win/fast/canvas': '2', | 248 'platform/win/fast/canvas': '2', |
| 302 }, | 249 }, |
| 303 { | 250 { |
| 304 'virtual/gpu/fast/canvas': None, | 251 'virtual/gpu/fast/canvas': None, |
| 305 'fast/canvas': '2', | 252 'fast/canvas': '2', |
| 306 }, | 253 }, |
| 307 baseline_dirname='virtual/gpu/fast/canvas', | 254 baseline_dirname='virtual/gpu/fast/canvas') |
| 308 expected_files_to_delete=[ | |
| 309 '/mock-checkout/third_party/WebKit/LayoutTests/virtual/gpu/fast/
canvas/mock-baseline-expected.txt', | |
| 310 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/fast
/canvas/mock-baseline-expected.txt', | |
| 311 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/fast
/canvas/mock-baseline-expected.txt', | |
| 312 ]) | |
| 313 | 255 |
| 314 def test_virtual_root_redundant_with_ancestors_skip_scm_commands_with_file_n
ot_in_scm(self): | 256 def test_virtual_root_redundant_with_ancestors_skip_scm_commands_with_file_n
ot_in_scm(self): |
| 315 self._assertOptimization( | 257 self._assertOptimization( |
| 316 { | 258 { |
| 317 'virtual/gpu/fast/canvas': '2', | 259 'virtual/gpu/fast/canvas': '2', |
| 318 'platform/mac/fast/canvas': '2', | 260 'platform/mac/fast/canvas': '2', |
| 319 'platform/win/fast/canvas': '2', | 261 'platform/win/fast/canvas': '2', |
| 320 }, | 262 }, |
| 321 { | 263 { |
| 322 'virtual/gpu/fast/canvas': None, | 264 'virtual/gpu/fast/canvas': None, |
| 323 'fast/canvas': '2', | 265 'fast/canvas': '2', |
| 324 }, | 266 }, |
| 325 baseline_dirname='virtual/gpu/fast/canvas', | 267 baseline_dirname='virtual/gpu/fast/canvas', |
| 326 expected_files_to_delete=[ | 268 host=MockHost()) |
| 327 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/fast
/canvas/mock-baseline-expected.txt', | |
| 328 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/fast
/canvas/mock-baseline-expected.txt', | |
| 329 ], | |
| 330 host=MockHost(scm=ExcludingMockSCM( | |
| 331 ['/mock-checkout/third_party/WebKit/LayoutTests/virtual/gpu/fast
/canvas/mock-baseline-expected.txt']))) | |
| 332 | 269 |
| 333 def test_virtual_root_not_redundant_with_ancestors(self): | 270 def test_virtual_root_not_redundant_with_ancestors(self): |
| 334 self._assertOptimization( | 271 self._assertOptimization( |
| 335 { | 272 { |
| 336 'virtual/gpu/fast/canvas': '2', | 273 'virtual/gpu/fast/canvas': '2', |
| 337 'platform/mac/fast/canvas': '1', | 274 'platform/mac/fast/canvas': '1', |
| 338 }, | 275 }, |
| 339 { | 276 { |
| 340 'virtual/gpu/fast/canvas': '2', | 277 'virtual/gpu/fast/canvas': '2', |
| 341 'platform/mac/fast/canvas': '1', | 278 'platform/mac/fast/canvas': '1', |
| 342 }, | 279 }, |
| 343 baseline_dirname='virtual/gpu/fast/canvas') | 280 baseline_dirname='virtual/gpu/fast/canvas') |
| OLD | NEW |