ec0de2ddea0122ec83b60075184c26b30c890f37
[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 class MacTest(darwin_testcase.DarwinTest):
40     os_name = 'mac'
41     os_version = 'lion'
42     port_name = 'mac-lion'
43     port_maker = MacPort
44
45     def test_version(self):
46         port = self.make_port()
47         self.assertTrue(port.version())
48
49     def test_versions(self):
50         # Note: these tests don't need to be exhaustive as long as we get path coverage.
51         self.assert_name('mac', 'snowleopard', 'mac-snowleopard')
52         self.assert_name('mac-snowleopard', 'leopard', 'mac-snowleopard')
53         self.assert_name('mac-snowleopard', 'lion', 'mac-snowleopard')
54         self.assert_name('mac', 'lion', 'mac-lion')
55         self.assert_name('mac-lion', 'lion', 'mac-lion')
56         self.assert_name('mac', 'mountainlion', 'mac-mountainlion')
57         self.assert_name('mac-mountainlion', 'lion', 'mac-mountainlion')
58         self.assert_name('mac', 'mavericks', 'mac-mavericks')
59         self.assert_name('mac-mavericks', 'mountainlion', 'mac-mavericks')
60         self.assert_name('mac', 'yosemite', 'mac-yosemite')
61         self.assert_name('mac-yosemite', 'mavericks', 'mac-yosemite')
62         self.assert_name('mac', 'elcapitan', 'mac-elcapitan')
63         self.assert_name('mac-elcapitan', 'mavericks', 'mac-elcapitan')
64         self.assert_name('mac-elcapitan', 'yosemite', 'mac-elcapitan')
65         self.assert_name('mac', 'sierra', 'mac-sierra')
66         self.assert_name('mac-sierra', 'yosemite', 'mac-sierra')
67         self.assert_name('mac-sierra', 'elcapitan', 'mac-sierra')
68         self.assert_name('mac', 'highsierra', 'mac-highsierra')
69         self.assert_name('mac-highsierra', 'elcapitan', 'mac-highsierra')
70         self.assert_name('mac-highsierra', 'sierra', 'mac-highsierra')
71         self.assert_name('mac', 'future', 'mac-future')
72         self.assert_name('mac-future', 'future', 'mac-future')
73         self.assertRaises(AssertionError, self.assert_name, 'mac-tiger', 'leopard', 'mac-leopard')
74
75     def test_setup_environ_for_server(self):
76         port = self.make_port(options=MockOptions(leaks=True, guard_malloc=True))
77         env = port.setup_environ_for_server(port.driver_name())
78         self.assertEqual(env['MallocStackLogging'], '1')
79         self.assertEqual(env['MallocScribble'], '1')
80         self.assertEqual(env['DYLD_INSERT_LIBRARIES'], '/usr/lib/libgmalloc.dylib:/mock-build/libWebCoreTestShim.dylib')
81
82     def test_show_results_html_file(self):
83         port = self.make_port()
84         # Delay setting a should_log executive to avoid logging from MacPort.__init__.
85         port._executive = MockExecutive(should_log=True)
86         expected_logs = "MOCK popen: ['Tools/Scripts/run-safari', '--release', '--no-saved-state', '-NSOpen', 'test.html'], cwd=/mock-checkout\n"
87         OutputCapture().assert_outputs(self, port.show_results_html_file, ["test.html"], expected_logs=expected_logs)
88
89     def test_operating_system(self):
90         self.assertEqual('mac', self.make_port().operating_system())
91
92     def test_default_child_processes(self):
93         port = self.make_port(port_name='mac-lion')
94         # MockPlatformInfo only has 2 mock cores.  The important part is that 2 > 1.
95         self.assertEqual(port.default_child_processes(), 2)
96
97         bytes_for_drt = 200 * 1024 * 1024
98         port.host.platform.total_bytes_memory = lambda: bytes_for_drt
99         expected_logs = "This machine could support 2 child processes, but only has enough memory for 1.\n"
100         child_processes = OutputCapture().assert_outputs(self, port.default_child_processes, (), expected_logs=expected_logs)
101         self.assertEqual(child_processes, 1)
102
103         # Make sure that we always use one process, even if we don't have the memory for it.
104         port.host.platform.total_bytes_memory = lambda: bytes_for_drt - 1
105         expected_logs = "This machine could support 2 child processes, but only has enough memory for 1.\n"
106         child_processes = OutputCapture().assert_outputs(self, port.default_child_processes, (), expected_logs=expected_logs)
107         self.assertEqual(child_processes, 1)
108
109     def test_32bit(self):
110         port = self.make_port(options=MockOptions(architecture='x86'))
111
112         def run_script(script, args=None, env=None):
113             self.args = args
114
115         port._run_script = run_script
116         self.assertEqual(port.architecture(), 'x86')
117         port._build_driver()
118         self.assertEqual(self.args, ['ARCHS=i386'])
119
120     def test_64bit(self):
121         # Apple Mac port is 64-bit by default
122         port = self.make_port()
123         self.assertEqual(port.architecture(), 'x86_64')
124
125         def run_script(script, args=None, env=None):
126             self.args = args
127
128         port._run_script = run_script
129         port._build_driver()
130         self.assertEqual(self.args, [])
131
132     def test_sdk_name(self):
133         port = self.make_port()
134         self.assertEqual(port.SDK, 'macosx')
135
136     def test_xcrun(self):
137         def throwing_run_command(args):
138             print args
139             raise ScriptError("MOCK script error")
140
141         port = self.make_port()
142         port._executive = MockExecutive2(run_command_fn=throwing_run_command)
143         expected_stdout = "['xcrun', '--sdk', 'macosx', '-find', 'test']\n"
144         OutputCapture().assert_outputs(self, port.xcrun_find, args=['test', 'falling'], expected_stdout=expected_stdout)
145
146     def test_layout_test_searchpath_with_apple_additions(self):
147         with port_testcase.bind_mock_apple_additions():
148             search_path = self.make_port().default_baseline_search_path()
149         self.assertEqual(search_path[0], '/additional_testing_path/mac-add-lion-wk1')
150         self.assertEqual(search_path[1], '/mock-checkout/LayoutTests/platform/mac-lion-wk1')
151         self.assertEqual(search_path[2], '/additional_testing_path/mac-add-lion')
152         self.assertEqual(search_path[3], '/mock-checkout/LayoutTests/platform/mac-lion')
153         self.assertEqual(search_path[4], '/additional_testing_path/mac-add-mountainlion-wk1')
154         self.assertEqual(search_path[5], '/mock-checkout/LayoutTests/platform/mac-mountainlion-wk1')