Need to skip webkitpy.common.checkout.baselineoptimizer_unittest.BaselineOptimizerTes...
[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.tool.mocktool import MockSCM
35
36
37 class TestBaselineOptimizer(BaselineOptimizer):
38     def __init__(self, mock_results_by_directory):
39         BaselineOptimizer.__init__(self, MockSCM(), MockFileSystem())
40         self._mock_results_by_directory = mock_results_by_directory
41
42     # We override this method for testing so we don't have to construct an
43     # elaborate mock file system.
44     def _read_results_by_directory(self, baseline_name):
45         return self._mock_results_by_directory
46
47
48 class BaselineOptimizerTest(unittest.TestCase):
49     def _assertOptimization(self, results_by_directory, expected_new_results_by_directory):
50         baseline_optimizer = TestBaselineOptimizer(results_by_directory)
51         _, new_results_by_directory = baseline_optimizer._find_optimal_result_placement('mock-baseline.png')
52         self.assertEqual(new_results_by_directory, expected_new_results_by_directory)
53
54     def test_move_baselines(self):
55         fs = MockFileSystem()
56         fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-win/another/test-expected.txt', 'result A')
57         fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-cg-mac/another/test-expected.txt', 'result A')
58         fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt', 'result B')
59         baseline_optimizer = BaselineOptimizer(MockSCM(), fs)
60         baseline_optimizer._move_baselines('another/test-expected.txt', {
61             'LayoutTests/platform/chromium-win': 'aaa',
62             'LayoutTests/platform/chromium-cg-mac': 'aaa',
63             'LayoutTests/platform/chromium': 'bbb',
64         }, {
65             'LayoutTests/platform/chromium': 'aaa',
66         })
67         self.assertEqual(fs.read_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt'), 'result A')
68
69     def test_chromium_linux_redundant_with_win(self):
70         self._assertOptimization({
71             'LayoutTests/platform/chromium-win': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
72             'LayoutTests/platform/chromium-linux': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
73         }, {
74             'LayoutTests/platform/chromium-win': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
75         })
76
77     def test_chromium_covers_mac_win_linux(self):
78         self._assertOptimization({
79             'LayoutTests/platform/chromium-cg-mac': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
80             'LayoutTests/platform/chromium-win': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
81             'LayoutTests/platform/chromium-linux': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
82         }, {
83             'LayoutTests/platform/chromium': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
84         })
85
86     def test_chromium_mac_redundant_with_apple_mac(self):
87         self._assertOptimization({
88             'LayoutTests/platform/chromium-cg-mac-snowleopard': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
89             'LayoutTests/platform/mac-snowleopard': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
90         }, {
91             'LayoutTests/platform/mac-snowleopard': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
92         })
93
94     def test_mac_future(self):
95         self._assertOptimization({
96             'LayoutTests/platform/mac-snowleopard': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
97         }, {
98             'LayoutTests/platform/mac-snowleopard': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
99         })
100
101     def test_qt_unknown(self):
102         self._assertOptimization({
103             'LayoutTests/platform/qt': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
104         }, {
105             'LayoutTests/platform/qt': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
106         })
107
108     def test_common_directory_includes_root(self):
109         # Note: The resulting directories are "wrong" in the sense that
110         # enacting this plan would change semantics. However, this test case
111         # demonstrates that we don't throw an exception in this case. :)
112         self._assertOptimization({
113             'LayoutTests/platform/gtk': 'e8608763f6241ddacdd5c1ef1973ba27177d0846',
114             'LayoutTests/platform/qt': 'bcbd457d545986b7abf1221655d722363079ac87',
115             'LayoutTests/platform/chromium-win': '3764ac11e1f9fbadd87a90a2e40278319190a0d3',
116             'LayoutTests/platform/mac': 'e8608763f6241ddacdd5c1ef1973ba27177d0846',
117         }, {
118             'LayoutTests/platform/qt': 'bcbd457d545986b7abf1221655d722363079ac87',
119             'LayoutTests/platform/chromium-win': '3764ac11e1f9fbadd87a90a2e40278319190a0d3',
120             'LayoutTests': 'e8608763f6241ddacdd5c1ef1973ba27177d0846',
121         })
122
123         self._assertOptimization({
124             'LayoutTests/platform/chromium-win': '23a30302a6910f8a48b1007fa36f3e3158341834',
125             'LayoutTests': '9c876f8c3e4cc2aef9519a6c1174eb3432591127',
126             'LayoutTests/platform/chromium-cg-mac': '23a30302a6910f8a48b1007fa36f3e3158341834',
127             'LayoutTests/platform/chromium-mac': '23a30302a6910f8a48b1007fa36f3e3158341834',
128         }, {
129             'LayoutTests/platform/chromium': '23a30302a6910f8a48b1007fa36f3e3158341834',
130             'LayoutTests': '9c876f8c3e4cc2aef9519a6c1174eb3432591127',
131         })
132
133     def test_complex_shadowing(self):
134         # This test relies on OS specific functionality, so it doesn't work on Windows.
135         if sys.platform == 'win32':
136             return
137         self._assertOptimization({
138             'LayoutTests/platform/chromium-win': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
139             'LayoutTests/platform/mac': '5daa78e55f05d9f0d1bb1f32b0cd1bc3a01e9364',
140             'LayoutTests/platform/chromium-win-xp': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
141             'LayoutTests/platform/chromium-cg-mac-leopard': '65e7d42f8b4882b29d46dc77bb879dd41bc074dc',
142             'LayoutTests/platform/mac-leopard': '7ad045ece7c030e2283c5d21d9587be22bcba56e',
143             'LayoutTests/platform/chromium-win-vista': 'f83af9732ce74f702b8c9c4a3d9a4c6636b8d3bd',
144             'LayoutTests/platform/win': '5b1253ef4d5094530d5f1bc6cdb95c90b446bec7',
145             'LayoutTests/platform/chromium-linux': 'f52fcdde9e4be8bd5142171cd859230bd4471036',
146         }, {
147             'LayoutTests/platform/chromium-win': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
148             'LayoutTests/platform/mac': '5daa78e55f05d9f0d1bb1f32b0cd1bc3a01e9364',
149             'LayoutTests/platform/chromium-win-xp': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
150             'LayoutTests/platform/chromium-cg-mac-leopard': '65e7d42f8b4882b29d46dc77bb879dd41bc074dc',
151             'LayoutTests/platform/mac-leopard': '7ad045ece7c030e2283c5d21d9587be22bcba56e',
152             'LayoutTests/platform/chromium-win-vista': 'f83af9732ce74f702b8c9c4a3d9a4c6636b8d3bd',
153             'LayoutTests/platform/win': '5b1253ef4d5094530d5f1bc6cdb95c90b446bec7',
154             'LayoutTests/platform/chromium-linux': 'f52fcdde9e4be8bd5142171cd859230bd4471036'
155         })