Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 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.baseline_optimizer import BaselineOptimizer |
| 32 from webkitpy.common.host_mock import MockHost | 32 from webkitpy.common.host_mock import MockHost |
| 33 from webkitpy.common.webkit_finder import WebKitFinder | 33 from webkitpy.common.webkit_finder import WebKitFinder |
| 34 | 34 |
| 35 | 35 |
| 36 class BaselineOptimizerTest(unittest.TestCase): | 36 class BaselineOptimizerTest(unittest.TestCase): |
| 37 | 37 |
| 38 # 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 |
| 39 def test_move_baselines(self): | 39 def test_move_baselines(self): |
| 40 host = MockHost() | 40 host = MockHost() |
| 41 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', '[]') |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 }, | 78 }, |
| 79 { | 79 { |
| 80 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux': 'bbb', | 80 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux': 'bbb', |
| 81 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', | 81 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa', |
| 82 }) | 82 }) |
| 83 self.assertEqual( | 83 self.assertEqual( |
| 84 host.filesystem.read_binary_file( | 84 host.filesystem.read_binary_file( |
| 85 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expe cted.txt'), | 85 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expe cted.txt'), |
| 86 'result A') | 86 'result A') |
| 87 | 87 |
| 88 def _assertOptimization(self, results_by_directory, expected_new_results_by_ directory, | 88 def _assert_optimization( |
| 89 baseline_dirname='', host=None): | 89 self, |
| 90 results_by_directory, | |
| 91 directory_to_new_results, | |
| 92 baseline_dirname='', host=None): | |
| 90 if not host: | 93 if not host: |
| 91 host = MockHost() | 94 host = MockHost() |
| 92 fs = host.filesystem | 95 fs = host.filesystem |
| 93 webkit_base = WebKitFinder(fs).webkit_base() | 96 webkit_base = WebKitFinder(fs).webkit_base() |
| 94 baseline_name = 'mock-baseline-expected.txt' | 97 baseline_name = 'mock-baseline-expected.txt' |
| 95 fs.write_text_file(fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuite s'), | 98 fs.write_text_file(fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuite s'), |
| 96 '[{"prefix": "gpu", "base": "fast/canvas", "args": [" --foo"]}]') | 99 '[{"prefix": "gpu", "base": "fast/canvas", "args": [" --foo"]}]') |
| 97 | 100 |
| 98 for dirname, contents in results_by_directory.items(): | 101 for dirname, contents in results_by_directory.items(): |
| 99 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) | 102 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) |
| 100 fs.write_binary_file(path, contents) | 103 fs.write_binary_file(path, contents) |
| 101 | 104 |
| 102 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get( | 105 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get( |
| 103 ), host.port_factory.all_port_names()) | 106 ), host.port_factory.all_port_names()) |
| 104 self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, ba seline_name))) | 107 self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, ba seline_name))) |
| 105 | 108 |
| 106 for dirname, contents in expected_new_results_by_directory.items(): | 109 for dirname, contents in directory_to_new_results.items(): |
| 107 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) | 110 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name) |
| 108 if contents is not None: | 111 if contents is not None: |
| 109 self.assertEqual(fs.read_binary_file(path), contents) | 112 self.assertEqual(fs.read_binary_file(path), contents) |
| 110 | 113 |
| 111 def test_linux_redundant_with_win(self): | 114 def test_linux_redundant_with_win(self): |
| 112 self._assertOptimization( | 115 self._assert_optimization( |
| 113 { | 116 { |
| 114 'platform/win': '1', | 117 'platform/win': '1', |
| 115 'platform/linux': '1', | 118 'platform/linux': '1', |
| 116 }, | 119 }, |
| 117 { | 120 { |
| 118 'platform/win': '1', | 121 'platform/win': '1', |
| 119 }) | 122 }) |
| 120 | 123 |
| 121 def test_covers_mac_win_linux(self): | 124 def test_covers_mac_win_linux(self): |
| 122 self._assertOptimization( | 125 self._assert_optimization( |
| 123 { | 126 { |
| 124 'platform/mac': '1', | 127 'platform/mac': '1', |
| 125 'platform/win': '1', | 128 'platform/win': '1', |
| 126 'platform/linux': '1', | 129 'platform/linux': '1', |
| 127 '': None, | 130 '': None, |
| 128 }, | 131 }, |
| 129 { | 132 { |
| 130 '': '1', | 133 '': '1', |
| 131 }) | 134 }) |
| 132 | 135 |
| 133 def test_overwrites_root(self): | 136 def test_overwrites_root(self): |
| 134 self._assertOptimization( | 137 self._assert_optimization( |
| 135 { | 138 { |
| 136 'platform/mac': '1', | 139 'platform/mac': '1', |
| 137 'platform/win': '1', | 140 'platform/win': '1', |
| 138 'platform/linux': '1', | 141 'platform/linux': '1', |
| 139 '': '2', | 142 '': '2', |
| 140 }, | 143 }, |
| 141 { | 144 { |
| 142 '': '1', | 145 '': '1', |
| 143 }) | 146 }) |
| 144 | 147 |
| 145 def test_no_new_common_directory(self): | 148 def test_no_new_common_directory(self): |
| 146 self._assertOptimization( | 149 self._assert_optimization( |
| 147 { | 150 { |
| 148 'platform/mac': '1', | 151 'platform/mac': '1', |
| 149 'platform/linux': '1', | 152 'platform/linux': '1', |
| 150 '': '2', | 153 '': '2', |
| 151 }, | 154 }, |
| 152 { | 155 { |
| 153 'platform/mac': '1', | 156 'platform/mac': '1', |
| 154 'platform/linux': '1', | 157 'platform/linux': '1', |
| 155 '': '2', | 158 '': '2', |
| 156 }) | 159 }) |
| 157 | 160 |
| 158 def test_local_optimization(self): | 161 def test_local_optimization(self): |
| 159 self._assertOptimization( | 162 self._assert_optimization( |
| 160 { | 163 { |
| 161 'platform/mac': '1', | 164 'platform/mac': '1', |
| 162 'platform/linux': '1', | 165 'platform/linux': '1', |
| 163 'platform/linux-precise': '1', | 166 'platform/linux-precise': '1', |
| 164 }, | 167 }, |
| 165 { | 168 { |
| 166 'platform/mac': '1', | 169 'platform/mac': '1', |
| 167 'platform/linux': '1', | 170 'platform/linux': '1', |
| 168 }) | 171 }) |
| 169 | 172 |
| 170 def test_local_optimization_skipping_a_port_in_the_middle(self): | 173 def test_local_optimization_skipping_a_port_in_the_middle(self): |
| 171 self._assertOptimization( | 174 self._assert_optimization( |
| 172 { | 175 { |
| 173 'platform/mac-snowleopard': '1', | 176 'platform/mac-snowleopard': '1', |
| 174 'platform/win': '1', | 177 'platform/win': '1', |
| 175 'platform/linux': '1', | 178 'platform/linux': '1', |
| 176 'platform/linux-precise': '1', | 179 'platform/linux-precise': '1', |
| 177 }, | 180 }, |
| 178 { | 181 { |
| 179 'platform/mac-snowleopard': '1', | 182 'platform/mac-snowleopard': '1', |
| 180 'platform/win': '1', | 183 'platform/win': '1', |
| 181 }) | 184 }) |
| 182 | 185 |
| 183 def test_baseline_redundant_with_root(self): | 186 def test_baseline_redundant_with_root(self): |
| 184 self._assertOptimization( | 187 self._assert_optimization( |
| 185 { | 188 { |
| 186 'platform/mac': '1', | 189 'platform/mac': '1', |
| 187 'platform/win': '2', | 190 'platform/win': '2', |
| 188 '': '2', | 191 '': '2', |
| 189 }, | 192 }, |
| 190 { | 193 { |
| 191 'platform/mac': '1', | 194 'platform/mac': '1', |
| 192 '': '2', | 195 '': '2', |
| 193 }) | 196 }) |
| 194 | 197 |
| 195 def test_root_baseline_unused(self): | 198 def test_root_baseline_unused(self): |
| 196 self._assertOptimization( | 199 self._assert_optimization( |
| 197 { | 200 { |
| 198 'platform/mac': '1', | 201 'platform/mac': '1', |
| 199 'platform/win': '2', | 202 'platform/win': '2', |
| 200 '': '3', | 203 '': '3', |
| 201 }, | 204 }, |
| 202 { | 205 { |
| 203 'platform/mac': '1', | 206 'platform/mac': '1', |
| 204 'platform/win': '2', | 207 'platform/win': '2', |
| 205 }) | 208 }) |
| 206 | 209 |
| 207 def test_root_baseline_unused_and_non_existant(self): | 210 def test_root_baseline_unused_and_non_existant(self): |
| 208 self._assertOptimization( | 211 self._assert_optimization( |
| 209 { | 212 { |
| 210 'platform/mac': '1', | 213 'platform/mac': '1', |
| 211 'platform/win': '2', | 214 'platform/win': '2', |
| 212 }, | 215 }, |
| 213 { | 216 { |
| 214 'platform/mac': '1', | 217 'platform/mac': '1', |
| 215 'platform/win': '2', | 218 'platform/win': '2', |
| 216 }) | 219 }) |
| 217 | 220 |
| 218 def test_virtual_root_redundant_with_actual_root(self): | 221 def test_virtual_root_redundant_with_actual_root(self): |
| 219 self._assertOptimization( | 222 self._assert_optimization( |
| 220 { | 223 { |
| 221 'virtual/gpu/fast/canvas': '2', | 224 'virtual/gpu/fast/canvas': '2', |
| 222 'fast/canvas': '2', | 225 'fast/canvas': '2', |
| 223 }, | 226 }, |
| 224 { | 227 { |
| 225 'virtual/gpu/fast/canvas': None, | 228 'virtual/gpu/fast/canvas': None, |
| 226 'fast/canvas': '2', | 229 'fast/canvas': '2', |
| 227 }, | 230 }, |
| 228 baseline_dirname='virtual/gpu/fast/canvas') | 231 baseline_dirname='virtual/gpu/fast/canvas') |
| 229 | 232 |
| 230 def test_virtual_root_redundant_with_ancestors(self): | 233 def test_virtual_root_redundant_with_ancestors(self): |
| 231 self._assertOptimization( | 234 self._assert_optimization( |
| 232 { | 235 { |
| 233 'virtual/gpu/fast/canvas': '2', | 236 'virtual/gpu/fast/canvas': '2', |
| 234 'platform/mac/fast/canvas': '2', | 237 'platform/mac/fast/canvas': '2', |
| 235 'platform/win/fast/canvas': '2', | 238 'platform/win/fast/canvas': '2', |
| 236 }, | 239 }, |
| 237 { | 240 { |
| 238 'virtual/gpu/fast/canvas': None, | 241 'virtual/gpu/fast/canvas': None, |
| 239 'fast/canvas': '2', | 242 'fast/canvas': '2', |
| 240 }, | 243 }, |
| 241 baseline_dirname='virtual/gpu/fast/canvas') | 244 baseline_dirname='virtual/gpu/fast/canvas') |
| 242 | 245 |
| 243 def test_virtual_root_redundant_with_ancestors_skip_scm_commands(self): | |
| 244 self._assertOptimization( | |
| 245 { | |
| 246 'virtual/gpu/fast/canvas': '2', | |
| 247 'platform/mac/fast/canvas': '2', | |
| 248 'platform/win/fast/canvas': '2', | |
| 249 }, | |
| 250 { | |
| 251 'virtual/gpu/fast/canvas': None, | |
| 252 'fast/canvas': '2', | |
| 253 }, | |
| 254 baseline_dirname='virtual/gpu/fast/canvas') | |
| 255 | |
| 256 def test_virtual_root_redundant_with_ancestors_skip_scm_commands_with_file_n ot_in_scm(self): | |
| 257 self._assertOptimization( | |
| 258 { | |
| 259 'virtual/gpu/fast/canvas': '2', | |
| 260 'platform/mac/fast/canvas': '2', | |
| 261 'platform/win/fast/canvas': '2', | |
| 262 }, | |
| 263 { | |
| 264 'virtual/gpu/fast/canvas': None, | |
| 265 'fast/canvas': '2', | |
| 266 }, | |
| 267 baseline_dirname='virtual/gpu/fast/canvas', | |
| 268 host=MockHost()) | |
| 269 | |
|
qyearsley
2016/12/17 18:58:57
As far as I can tell, these methods were both redu
Dirk Pranke
2016/12/18 02:46:41
Acknowledged.
| |
| 270 def test_virtual_root_not_redundant_with_ancestors(self): | 246 def test_virtual_root_not_redundant_with_ancestors(self): |
| 271 self._assertOptimization( | 247 self._assert_optimization( |
| 272 { | 248 { |
| 273 'virtual/gpu/fast/canvas': '2', | 249 'virtual/gpu/fast/canvas': '2', |
| 274 'platform/mac/fast/canvas': '1', | 250 'platform/mac/fast/canvas': '1', |
| 275 }, | 251 }, |
| 276 { | 252 { |
| 277 'virtual/gpu/fast/canvas': '2', | 253 'virtual/gpu/fast/canvas': '2', |
| 278 'platform/mac/fast/canvas': '1', | 254 'platform/mac/fast/canvas': '1', |
| 279 }, | 255 }, |
| 280 baseline_dirname='virtual/gpu/fast/canvas') | 256 baseline_dirname='virtual/gpu/fast/canvas') |
| OLD | NEW |