9ba6ff1f21b89f6e6e37875fbffa61e3ff5a1857
[WebKit-https.git] / Tools / Scripts / webkitpy / common / checkout / baselineoptimizer_unittest.py
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 sys
30 import unittest
31
32 from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer
33 from webkitpy.common.system.filesystem_mock import MockFileSystem
34 from webkitpy.common.host_mock import MockHost
35
36
37 class TestBaselineOptimizer(BaselineOptimizer):
38     def __init__(self, mock_results_by_directory):
39         host = MockHost()
40         BaselineOptimizer.__init__(self, host)
41         self._mock_results_by_directory = mock_results_by_directory
42
43     # We override this method for testing so we don't have to construct an
44     # elaborate mock file system.
45     def _read_results_by_directory(self, baseline_name):
46         return self._mock_results_by_directory
47
48
49 class BaselineOptimizerTest(unittest.TestCase):
50     def _assertOptimization(self, results_by_directory, expected_new_results_by_directory):
51         baseline_optimizer = TestBaselineOptimizer(results_by_directory)
52         _, new_results_by_directory = baseline_optimizer._find_optimal_result_placement('mock-baseline.png')
53         self.assertEqual(new_results_by_directory, expected_new_results_by_directory)
54
55     def test_move_baselines(self):
56         host = MockHost()
57         host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-win/another/test-expected.txt', 'result A')
58         host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-mac/another/test-expected.txt', 'result A')
59         host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt', 'result B')
60         baseline_optimizer = BaselineOptimizer(host)
61         baseline_optimizer._move_baselines('another/test-expected.txt', {
62             'LayoutTests/platform/chromium-win': 'aaa',
63             'LayoutTests/platform/chromium-mac': 'aaa',
64             'LayoutTests/platform/chromium': 'bbb',
65         }, {
66             'LayoutTests/platform/chromium': 'aaa',
67         })
68         self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt'), 'result A')
69
70     def test_chromium_linux_redundant_with_win(self):
71         self._assertOptimization({
72             'LayoutTests/platform/chromium-win': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
73             'LayoutTests/platform/chromium-linux': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
74         }, {
75             'LayoutTests/platform/chromium-win': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
76         })
77
78     def test_no_add_mac_future(self):
79         self._assertOptimization({
80             'LayoutTests/platform/mac': '29a1715a6470d5dd9486a142f609708de84cdac8',
81             'LayoutTests/platform/win-xp': '453e67177a75b2e79905154ece0efba6e5bfb65d',
82             'LayoutTests/platform/mac-lion': 'c43eaeb358f49d5e835236ae23b7e49d7f2b089f',
83             'LayoutTests/platform/chromium-mac': 'a9ba153c700a94ae1b206d8e4a75a621a89b4554',
84         }, {
85             'LayoutTests/platform/mac': '29a1715a6470d5dd9486a142f609708de84cdac8',
86             'LayoutTests/platform/win-xp': '453e67177a75b2e79905154ece0efba6e5bfb65d',
87             'LayoutTests/platform/mac-lion': 'c43eaeb358f49d5e835236ae23b7e49d7f2b089f',
88             'LayoutTests/platform/chromium-mac': 'a9ba153c700a94ae1b206d8e4a75a621a89b4554',
89         })
90
91     def test_chromium_covers_mac_win_linux(self):
92         self._assertOptimization({
93             'LayoutTests/platform/chromium-mac': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
94             'LayoutTests/platform/chromium-win': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
95             'LayoutTests/platform/chromium-linux': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
96         }, {
97             'LayoutTests/platform/chromium': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
98         })
99
100     def test_chromium_mac_redundant_with_apple_mac(self):
101         self._assertOptimization({
102             'LayoutTests/platform/chromium-mac': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
103             'LayoutTests/platform/mac': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
104         }, {
105             'LayoutTests/platform/mac': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
106         })
107
108     def test_mac_future(self):
109         self._assertOptimization({
110             'LayoutTests/platform/mac-lion': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
111         }, {
112             'LayoutTests/platform/mac-lion': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
113         })
114
115     def test_qt_unknown(self):
116         self._assertOptimization({
117             'LayoutTests/platform/qt': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
118         }, {
119             'LayoutTests/platform/qt': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
120         })
121
122     def test_win_does_not_drop_to_win_7sp0(self):
123         self._assertOptimization({
124             'LayoutTests/platform/win': '1',
125             'LayoutTests/platform/mac': '2',
126             'LayoutTests/platform/gtk': '3',
127             'LayoutTests/platform/qt': '4',
128             'LayoutTests/platform/chromium': '5',
129         }, {
130             'LayoutTests/platform/win': '1',
131             'LayoutTests/platform/mac': '2',
132             'LayoutTests/platform/gtk': '3',
133             'LayoutTests/platform/qt': '4',
134             'LayoutTests/platform/chromium': '5',
135         })
136
137     def test_common_directory_includes_root(self):
138         # Note: The resulting directories are "wrong" in the sense that
139         # enacting this plan would change semantics. However, this test case
140         # demonstrates that we don't throw an exception in this case. :)
141         self._assertOptimization({
142             'LayoutTests/platform/gtk': 'e8608763f6241ddacdd5c1ef1973ba27177d0846',
143             'LayoutTests/platform/qt': 'bcbd457d545986b7abf1221655d722363079ac87',
144             'LayoutTests/platform/chromium-win': '3764ac11e1f9fbadd87a90a2e40278319190a0d3',
145             'LayoutTests/platform/mac': 'e8608763f6241ddacdd5c1ef1973ba27177d0846',
146         }, {
147             'LayoutTests/platform/qt': 'bcbd457d545986b7abf1221655d722363079ac87',
148             'LayoutTests/platform/chromium-win': '3764ac11e1f9fbadd87a90a2e40278319190a0d3',
149             'LayoutTests': 'e8608763f6241ddacdd5c1ef1973ba27177d0846',
150         })
151
152         self._assertOptimization({
153             'LayoutTests/platform/chromium-win': '23a30302a6910f8a48b1007fa36f3e3158341834',
154             'LayoutTests': '9c876f8c3e4cc2aef9519a6c1174eb3432591127',
155             'LayoutTests/platform/chromium-mac': '23a30302a6910f8a48b1007fa36f3e3158341834',
156             'LayoutTests/platform/chromium': '1',
157         }, {
158             'LayoutTests/platform/chromium': '23a30302a6910f8a48b1007fa36f3e3158341834',
159             'LayoutTests': '9c876f8c3e4cc2aef9519a6c1174eb3432591127',
160         })
161
162     def test_complex_shadowing(self):
163         # This test relies on OS specific functionality, so it doesn't work on Windows.
164         # FIXME: What functionality does this rely on?  When can we remove this if?
165         if sys.platform == 'win32':
166             return
167         self._assertOptimization({
168             'LayoutTests/platform/chromium-win': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
169             'LayoutTests/platform/mac': '5daa78e55f05d9f0d1bb1f32b0cd1bc3a01e9364',
170             'LayoutTests/platform/chromium-win-xp': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
171             'LayoutTests/platform/mac-lion': '7ad045ece7c030e2283c5d21d9587be22bcba56e',
172             'LayoutTests/platform/chromium-win': 'f83af9732ce74f702b8c9c4a3d9a4c6636b8d3bd',
173             'LayoutTests/platform/win-xp': '5b1253ef4d5094530d5f1bc6cdb95c90b446bec7',
174             'LayoutTests/platform/chromium-linux': 'f52fcdde9e4be8bd5142171cd859230bd4471036',
175         }, {
176             'LayoutTests/platform/chromium-win': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
177             'LayoutTests/platform/mac': '5daa78e55f05d9f0d1bb1f32b0cd1bc3a01e9364',
178             'LayoutTests/platform/chromium-win-xp': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
179             'LayoutTests/platform/mac-lion': '7ad045ece7c030e2283c5d21d9587be22bcba56e',
180             'LayoutTests/platform/chromium-win': 'f83af9732ce74f702b8c9c4a3d9a4c6636b8d3bd',
181             'LayoutTests/platform/win-xp': '5b1253ef4d5094530d5f1bc6cdb95c90b446bec7',
182             'LayoutTests/platform/chromium-linux': 'f52fcdde9e4be8bd5142171cd859230bd4471036'
183         })