Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py

Issue 2578213005: Use underscores to separate words in filenames in webkitpy. (Closed)
Patch Set: Fix check for attribute in output_capture.py. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright (C) 2011 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
28
29 import unittest
30
31 from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer
32 from webkitpy.common.host_mock import MockHost
33 from webkitpy.common.webkit_finder import WebKitFinder
34
35
36 class BaselineOptimizerTest(unittest.TestCase):
37
38 # Protected method _move_baselines is tested below - pylint: disable=protect ed-access
39 def test_move_baselines(self):
40 host = MockHost()
41 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou tTests/VirtualTestSuites', '[]')
42 host.filesystem.write_binary_file(
43 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/ test-expected.txt', 'result A')
44 host.filesystem.write_binary_file(
45 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/ test-expected.txt', 'result A')
46 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/another/test-expected.txt', 'result B')
47 baseline_optimizer = BaselineOptimizer(
48 host, host.port_factory.get(), host.port_factory.all_port_names())
49 baseline_optimizer._move_baselines(
50 'another/test-expected.txt',
51 {
52 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'a aa',
53 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'a aa',
54 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb',
55 },
56 {
57 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa',
58 })
59 self.assertEqual(host.filesystem.read_binary_file(
60 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expected .txt'), 'result A')
61
62 def test_move_baselines_skip_scm_commands(self):
63 host = MockHost()
64 host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/Layou tTests/VirtualTestSuites', '[]')
65 host.filesystem.write_binary_file(
66 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win/another/ test-expected.txt', 'result A')
67 host.filesystem.write_binary_file(
68 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac/another/ test-expected.txt', 'result A')
69 host.filesystem.write_binary_file('/mock-checkout/third_party/WebKit/Lay outTests/another/test-expected.txt', 'result B')
70 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get(
71 ), host.port_factory.all_port_names())
72 baseline_optimizer._move_baselines(
73 'another/test-expected.txt',
74 {
75 '/mock-checkout/third_party/WebKit/LayoutTests/platform/win': 'a aa',
76 '/mock-checkout/third_party/WebKit/LayoutTests/platform/mac': 'a aa',
77 '/mock-checkout/third_party/WebKit/LayoutTests': 'bbb',
78 },
79 {
80 '/mock-checkout/third_party/WebKit/LayoutTests/platform/linux': 'bbb',
81 '/mock-checkout/third_party/WebKit/LayoutTests': 'aaa',
82 })
83 self.assertEqual(
84 host.filesystem.read_binary_file(
85 '/mock-checkout/third_party/WebKit/LayoutTests/another/test-expe cted.txt'),
86 'result A')
87
88 def _assertOptimization(self, results_by_directory, expected_new_results_by_ directory,
89 baseline_dirname='', host=None):
90 if not host:
91 host = MockHost()
92 fs = host.filesystem
93 webkit_base = WebKitFinder(fs).webkit_base()
94 baseline_name = 'mock-baseline-expected.txt'
95 fs.write_text_file(fs.join(webkit_base, 'LayoutTests', 'VirtualTestSuite s'),
96 '[{"prefix": "gpu", "base": "fast/canvas", "args": [" --foo"]}]')
97
98 for dirname, contents in results_by_directory.items():
99 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name)
100 fs.write_binary_file(path, contents)
101
102 baseline_optimizer = BaselineOptimizer(host, host.port_factory.get(
103 ), host.port_factory.all_port_names())
104 self.assertTrue(baseline_optimizer.optimize(fs.join(baseline_dirname, ba seline_name)))
105
106 for dirname, contents in expected_new_results_by_directory.items():
107 path = fs.join(webkit_base, 'LayoutTests', dirname, baseline_name)
108 if contents is not None:
109 self.assertEqual(fs.read_binary_file(path), contents)
110
111 def test_linux_redundant_with_win(self):
112 self._assertOptimization(
113 {
114 'platform/win': '1',
115 'platform/linux': '1',
116 },
117 {
118 'platform/win': '1',
119 })
120
121 def test_covers_mac_win_linux(self):
122 self._assertOptimization(
123 {
124 'platform/mac': '1',
125 'platform/win': '1',
126 'platform/linux': '1',
127 '': None,
128 },
129 {
130 '': '1',
131 })
132
133 def test_overwrites_root(self):
134 self._assertOptimization(
135 {
136 'platform/mac': '1',
137 'platform/win': '1',
138 'platform/linux': '1',
139 '': '2',
140 },
141 {
142 '': '1',
143 })
144
145 def test_no_new_common_directory(self):
146 self._assertOptimization(
147 {
148 'platform/mac': '1',
149 'platform/linux': '1',
150 '': '2',
151 },
152 {
153 'platform/mac': '1',
154 'platform/linux': '1',
155 '': '2',
156 })
157
158 def test_local_optimization(self):
159 self._assertOptimization(
160 {
161 'platform/mac': '1',
162 'platform/linux': '1',
163 'platform/linux-precise': '1',
164 },
165 {
166 'platform/mac': '1',
167 'platform/linux': '1',
168 })
169
170 def test_local_optimization_skipping_a_port_in_the_middle(self):
171 self._assertOptimization(
172 {
173 'platform/mac-snowleopard': '1',
174 'platform/win': '1',
175 'platform/linux': '1',
176 'platform/linux-precise': '1',
177 },
178 {
179 'platform/mac-snowleopard': '1',
180 'platform/win': '1',
181 })
182
183 def test_baseline_redundant_with_root(self):
184 self._assertOptimization(
185 {
186 'platform/mac': '1',
187 'platform/win': '2',
188 '': '2',
189 },
190 {
191 'platform/mac': '1',
192 '': '2',
193 })
194
195 def test_root_baseline_unused(self):
196 self._assertOptimization(
197 {
198 'platform/mac': '1',
199 'platform/win': '2',
200 '': '3',
201 },
202 {
203 'platform/mac': '1',
204 'platform/win': '2',
205 })
206
207 def test_root_baseline_unused_and_non_existant(self):
208 self._assertOptimization(
209 {
210 'platform/mac': '1',
211 'platform/win': '2',
212 },
213 {
214 'platform/mac': '1',
215 'platform/win': '2',
216 })
217
218 def test_virtual_root_redundant_with_actual_root(self):
219 self._assertOptimization(
220 {
221 'virtual/gpu/fast/canvas': '2',
222 'fast/canvas': '2',
223 },
224 {
225 'virtual/gpu/fast/canvas': None,
226 'fast/canvas': '2',
227 },
228 baseline_dirname='virtual/gpu/fast/canvas')
229
230 def test_virtual_root_redundant_with_ancestors(self):
231 self._assertOptimization(
232 {
233 'virtual/gpu/fast/canvas': '2',
234 'platform/mac/fast/canvas': '2',
235 'platform/win/fast/canvas': '2',
236 },
237 {
238 'virtual/gpu/fast/canvas': None,
239 'fast/canvas': '2',
240 },
241 baseline_dirname='virtual/gpu/fast/canvas')
242
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
270 def test_virtual_root_not_redundant_with_ancestors(self):
271 self._assertOptimization(
272 {
273 'virtual/gpu/fast/canvas': '2',
274 'platform/mac/fast/canvas': '1',
275 },
276 {
277 'virtual/gpu/fast/canvas': '2',
278 'platform/mac/fast/canvas': '1',
279 },
280 baseline_dirname='virtual/gpu/fast/canvas')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698