fix style failures in webkitpy: expected 2 blank lines found 1
[WebKit-https.git] / Tools / Scripts / webkitpy / port / mac_unittest.py
1 # Copyright (C) 2010 Google Inc. All rights reserved.
2 # Copyright (C) 2014-2016 Apple 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 #    * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 import time
31
32 from webkitpy.port.mac import MacPort
33 from webkitpy.port import darwin_testcase
34 from webkitpy.port import port_testcase
35 from webkitpy.common.system.outputcapture import OutputCapture
36 from webkitpy.tool.mocktool import MockOptions
37 from webkitpy.common.system.executive_mock import MockExecutive, MockExecutive2, ScriptError
38
39
40 class MacTest(darwin_testcase.DarwinTest):
41     os_name = 'mac'
42     os_version = 'lion'
43     port_name = 'mac-lion'
44     port_maker = MacPort
45
46     def test_version(self):
47         port = self.make_port()
48         self.assertTrue(port.version())
49
50     def test_versions(self):
51         # Note: these tests don't need to be exhaustive as long as we get path coverage.
52         self.assert_name('mac', 'snowleopard', 'mac-snowleopard')
53         self.assert_name('mac-snowleopard', 'leopard', 'mac-snowleopard')
54         self.assert_name('mac-snowleopard', 'lion', 'mac-snowleopard')
55         self.assert_name('mac', 'lion', 'mac-lion')
56         self.assert_name('mac-lion', 'lion', 'mac-lion')
57         self.assert_name('mac', 'mountainlion', 'mac-mountainlion')
58         self.assert_name('mac-mountainlion', 'lion', 'mac-mountainlion')
59         self.assert_name('mac', 'mavericks', 'mac-mavericks')
60         self.assert_name('mac-mavericks', 'mountainlion', 'mac-mavericks')
61         self.assert_name('mac', 'yosemite', 'mac-yosemite')
62         self.assert_name('mac-yosemite', 'mavericks', 'mac-yosemite')
63         self.assert_name('mac', 'elcapitan', 'mac-elcapitan')
64         self.assert_name('mac-elcapitan', 'mavericks', 'mac-elcapitan')
65         self.assert_name('mac-elcapitan', 'yosemite', 'mac-elcapitan')
66         self.assert_name('mac', 'sierra', 'mac-sierra')
67         self.assert_name('mac-sierra', 'yosemite', 'mac-sierra')
68         self.assert_name('mac-sierra', 'elcapitan', 'mac-sierra')
69         self.assert_name('mac', 'highsierra', 'mac-highsierra')
70         self.assert_name('mac-highsierra', 'elcapitan', 'mac-highsierra')
71         self.assert_name('mac-highsierra', 'sierra', 'mac-highsierra')
72         self.assert_name('mac', 'future', 'mac-future')
73         self.assert_name('mac-future', 'future', 'mac-future')
74         self.assertRaises(AssertionError, self.assert_name, 'mac-tiger', 'leopard', 'mac-leopard')
75
76     def test_setup_environ_for_server(self):
77         port = self.make_port(options=MockOptions(leaks=True, guard_malloc=True))
78         env = port.setup_environ_for_server(port.driver_name())
79         self.assertEqual(env['MallocStackLogging'], '1')
80         self.assertEqual(env['MallocScribble'], '1')
81         self.assertEqual(env['DYLD_INSERT_LIBRARIES'], '/usr/lib/libgmalloc.dylib:/mock-build/libWebCoreTestShim.dylib')
82
83     def test_show_results_html_file(self):
84         port = self.make_port()
85         # Delay setting a should_log executive to avoid logging from MacPort.__init__.
86         port._executive = MockExecutive(should_log=True)
87         expected_logs = "MOCK popen: ['Tools/Scripts/run-safari', '--release', '--no-saved-state', '-NSOpen', 'test.html'], cwd=/mock-checkout\n"
88         OutputCapture().assert_outputs(self, port.show_results_html_file, ["test.html"], expected_logs=expected_logs)
89
90     def test_operating_system(self):
91         self.assertEqual('mac', self.make_port().operating_system())
92
93     def test_default_child_processes(self):
94         port = self.make_port(port_name='mac-lion')
95         # MockPlatformInfo only has 2 mock cores.  The important part is that 2 > 1.
96         self.assertEqual(port.default_child_processes(), 2)
97
98         bytes_for_drt = 200 * 1024 * 1024
99         port.host.platform.total_bytes_memory = lambda: bytes_for_drt
100         expected_logs = "This machine could support 2 child processes, but only has enough memory for 1.\n"
101         child_processes = OutputCapture().assert_outputs(self, port.default_child_processes, (), expected_logs=expected_logs)
102         self.assertEqual(child_processes, 1)
103
104         # Make sure that we always use one process, even if we don't have the memory for it.
105         port.host.platform.total_bytes_memory = lambda: bytes_for_drt - 1
106         expected_logs = "This machine could support 2 child processes, but only has enough memory for 1.\n"
107         child_processes = OutputCapture().assert_outputs(self, port.default_child_processes, (), expected_logs=expected_logs)
108         self.assertEqual(child_processes, 1)
109
110     def test_32bit(self):
111         port = self.make_port(options=MockOptions(architecture='x86'))
112
113         def run_script(script, args=None, env=None):
114             self.args = args
115
116         port._run_script = run_script
117         self.assertEqual(port.architecture(), 'x86')
118         port._build_driver()
119         self.assertEqual(self.args, ['ARCHS=i386'])
120
121     def test_64bit(self):
122         # Apple Mac port is 64-bit by default
123         port = self.make_port()
124         self.assertEqual(port.architecture(), 'x86_64')
125
126         def run_script(script, args=None, env=None):
127             self.args = args
128
129         port._run_script = run_script
130         port._build_driver()
131         self.assertEqual(self.args, [])
132
133     def test_sdk_name(self):
134         port = self.make_port()
135         self.assertEqual(port.SDK, 'macosx')
136
137     def test_xcrun(self):
138         def throwing_run_command(args):
139             print args
140             raise ScriptError("MOCK script error")
141
142         port = self.make_port()
143         port._executive = MockExecutive2(run_command_fn=throwing_run_command)
144         expected_stdout = "['xcrun', '--sdk', 'macosx', '-find', 'test']\n"
145         OutputCapture().assert_outputs(self, port.xcrun_find, args=['test', 'falling'], expected_stdout=expected_stdout)
146
147     def test_layout_test_searchpath_with_apple_additions(self):
148         with port_testcase.bind_mock_apple_additions():
149             search_path = self.make_port().default_baseline_search_path()
150         self.assertEqual(search_path[0], '/additional_testing_path/mac-add-lion-wk1')
151         self.assertEqual(search_path[1], '/mock-checkout/LayoutTests/platform/mac-lion-wk1')
152         self.assertEqual(search_path[2], '/additional_testing_path/mac-add-lion')
153         self.assertEqual(search_path[3], '/mock-checkout/LayoutTests/platform/mac-lion')
154         self.assertEqual(search_path[4], '/additional_testing_path/mac-add-mountainlion-wk1')
155         self.assertEqual(search_path[5], '/mock-checkout/LayoutTests/platform/mac-mountainlion-wk1')