Tools/Scripts: eliminate find_test_files from Port class.
[WebKit-https.git] / Tools / Scripts / webkitpy / layout_tests / port / chromium_gpu_unittest.py
1 #!/usr/bin/env python
2 # Copyright (C) 2010 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #     * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 #     * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 import sys
28 import unittest
29
30 import chromium_gpu
31
32 from webkitpy.tool.mocktool import MockOptions
33 from webkitpy.common.host_mock import MockHost
34 from webkitpy.layout_tests.port import port_testcase
35 from webkitpy.common.system.filesystem_mock import MockFileSystem
36
37
38 class ChromiumGpuTest(unittest.TestCase):
39     def integration_test_chromium_gpu_linux(self):
40         self.assert_port_works('chromium-gpu-linux')
41         self.assert_port_works('chromium-gpu-linux', 'chromium-gpu', 'linux2')
42         self.assert_port_works('chromium-gpu-linux', 'chromium-gpu', 'linux3')
43
44     def integration_test_chromium_gpu_mac(self):
45         self.assert_port_works('chromium-gpu-cg-mac')
46         self.assert_port_works('chromium-gpu-mac')
47         # For now, chromium-gpu on Mac defaults to the chromium-gpu-cg-mac port.
48         self.assert_port_works('chromium-gpu-cg-mac', 'chromium-gpu', 'darwin')
49
50     def integration_test_chromium_gpu_win(self):
51         self.assert_port_works('chromium-gpu-win')
52         self.assert_port_works('chromium-gpu-win', 'chromium-gpu', 'win32')
53         self.assert_port_works('chromium-gpu-win', 'chromium-gpu', 'cygwin')
54
55     def assert_port_works(self, port_name, input_name=None, platform=None):
56         host = MockHost()
57         host.filesystem = FileSystem()  # FIXME: This test should not use a real filesystem!
58
59         # test that we got the right port
60         mock_options = MockOptions(accelerated_2d_canvas=None,
61                                    accelerated_video=None,
62                                    builder_name='foo',
63                                    child_processes=None)
64         if input_name and platform:
65             port = chromium_gpu.get(host, platform=platform, port_name=input_name, options=mock_options)
66         else:
67             port = chromium_gpu.get(host, port_name=port_name, options=mock_options)
68         self.assertTrue(port._options.accelerated_2d_canvas)
69         self.assertTrue(port._options.accelerated_video)
70         self.assertTrue(port._options.experimental_fully_parallel)
71         self.assertEqual(port._options.builder_name, 'foo - GPU')
72
73         self.assertTrue(port.name().startswith(port_name))
74
75         # test that it has the right directories in front of the search path.
76         paths = port.baseline_search_path()
77         self.assertEqual(port._webkit_baseline_path(port_name), paths[0])
78         if port_name == 'chromium-gpu-linux':
79             self.assertEqual(port._webkit_baseline_path('chromium-gpu-win'), paths[1])
80             self.assertEqual(port._webkit_baseline_path('chromium-gpu'), paths[2])
81         else:
82             self.assertEqual(port._webkit_baseline_path('chromium-gpu'), paths[1])
83
84         # Test that we're limiting to the correct directories.
85         # These two tests are picked mostly at random, but we make sure they
86         # exist separately from being filtered out by the port.
87
88         # Note that this is using a real filesystem.
89         files = port.tests(None)
90
91         path = 'fast/html/keygen.html'
92         self.assertTrue(port._filesystem.exists(port.abspath_for_test(path)))
93         self.assertFalse(path in files)
94         if port_name.startswith('chromium-gpu-cg-mac'):
95             path = 'fast/canvas/set-colors.html'
96             self.assertTrue(port._filesystem.exists(port.abspath_for_test(path)))
97             self.assertFalse(path in files)
98
99     def _assert_baseline_path(self, port_name, baseline_path):
100         host = MockHost()
101         port = host.port_factory.get(port_name)
102         self.assertEquals(port.name(), port_name)
103         self.assertEquals(port.baseline_path(), port._webkit_baseline_path(baseline_path))
104
105     def test_baseline_paths(self):
106         self._assert_baseline_path('chromium-gpu-win-vista', 'chromium-gpu-win')
107         self._assert_baseline_path('chromium-gpu-win-xp', 'chromium-gpu-win')
108         self._assert_baseline_path('chromium-gpu-win-win7', 'chromium-gpu-win')
109         self._assert_baseline_path('chromium-gpu-cg-mac-leopard', 'chromium-gpu-cg-mac')
110         self._assert_baseline_path('chromium-gpu-cg-mac-snowleopard', 'chromium-gpu-cg-mac')
111
112     def test_graphics_type(self):
113         host = MockHost()
114         port = host.port_factory.get('chromium-gpu-cg-mac')
115         self.assertEquals('gpu-cg', port.graphics_type())
116         port = host.port_factory.get('chromium-gpu-mac')
117         self.assertEquals('gpu', port.graphics_type())
118
119     def test_default_tests_paths(self):
120         host = MockHost()
121
122         def test_paths(port_name):
123             return chromium_gpu._default_tests_paths(host.port_factory.get(port_name))
124
125         self.assertEqual(test_paths('chromium-gpu-linux'), ['media', 'fast/canvas', 'canvas/philip'])
126         self.assertEqual(test_paths('chromium-gpu-mac-leopard'), ['fast/canvas', 'canvas/philip'])
127         self.assertEqual(test_paths('chromium-gpu-cg-mac-leopard'), ['fast/html'])
128
129     def test_test_files(self):
130         host = MockHost()
131         files = {
132             '/mock-checkout/LayoutTests/canvas/philip/test.html': '',
133             '/mock-checkout/LayoutTests/fast/canvas/test.html': '',
134             '/mock-checkout/LayoutTests/fast/html/test.html': '',
135             '/mock-checkout/LayoutTests/media/test.html': '',
136             '/mock-checkout/LayoutTests/foo/bar.html': '',
137         }
138         host.filesystem = MockFileSystem(files)
139
140         def test_paths(port_name):
141             return host.port_factory.get(port_name).tests([])
142
143         self.assertEqual(test_paths('chromium-gpu-linux'), set(['canvas/philip/test.html', 'fast/canvas/test.html', 'media/test.html']))
144         self.assertEqual(test_paths('chromium-gpu-mac-leopard'), set(['canvas/philip/test.html', 'fast/canvas/test.html']))
145         self.assertEqual(test_paths('chromium-gpu-cg-mac-leopard'), set(['fast/html/test.html']))
146
147
148 if __name__ == '__main__':
149     port_testcase.main()