webkitpy: Refactor port code for devices
[WebKit-https.git] / Tools / Scripts / webkitpy / port / ios_simulator_unittest.py
1 # Copyright (C) 2014-2016 Apple 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
5 # are met:
6 # 1.  Redistributions of source code must retain the above copyright
7 #     notice, this list of conditions and the following disclaimer.
8 # 2.  Redistributions in binary form must reproduce the above copyright
9 #     notice, this list of conditions and the following disclaimer in the
10 #     documentation and/or other materials provided with the distribution.
11 #
12 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
13 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
16 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
23 from webkitpy.port.ios_simulator import IOSSimulatorPort
24 from webkitpy.port import ios_testcase
25 from webkitpy.port import port_testcase
26 from webkitpy.common.system.outputcapture import OutputCapture
27 from webkitpy.common.version import Version
28 from webkitpy.tool.mocktool import MockOptions
29 from webkitpy.common.system.executive_mock import MockExecutive2, ScriptError
30
31
32 class IOSSimulatorTest(ios_testcase.IOSTest):
33     # FIXME: https://bugs.webkit.org/show_bug.cgi?id=173107
34     os_name = 'mac'
35     os_version = None
36     port_name = 'ios-simulator'
37     port_maker = IOSSimulatorPort
38
39     def make_port(self, host=None, port_name=None, options=None, os_name=None, os_version=Version(11), **kwargs):
40         port = super(IOSSimulatorTest, self).make_port(host=host, port_name=port_name, options=options, os_name=os_name, os_version=os_version, kwargs=kwargs)
41         port.set_option('child_processes', 1)
42         return port
43
44     def test_setup_environ_for_server(self):
45         port = self.make_port(options=MockOptions(leaks=True, guard_malloc=True))
46         env = port.setup_environ_for_server(port.driver_name())
47         self.assertEqual(env['MallocStackLogging'], '1')
48         self.assertEqual(env['MallocScribble'], '1')
49         self.assertEqual(env['DYLD_INSERT_LIBRARIES'], '/usr/lib/libgmalloc.dylib')
50
51     def test_operating_system(self):
52         self.assertEqual('ios-simulator', self.make_port().operating_system())
53
54     def test_32bit(self):
55         port = self.make_port(options=MockOptions(architecture='i386'))
56
57         def run_script(script, args=None, env=None):
58             self.args = args
59
60         port._run_script = run_script
61         self.assertEqual(port.architecture(), 'i386')
62         port._build_driver()
63         self.assertEqual(self.args, ['--sdk', 'iphonesimulator', 'ARCHS=i386'])
64
65     def test_64bit(self):
66         # Apple Mac port is 64-bit by default
67         port = self.make_port()
68         self.assertEqual(port.architecture(), 'x86_64')
69
70         def run_script(script, args=None, env=None):
71             self.args = args
72
73         port._run_script = run_script
74         port._build_driver()
75         self.assertEqual(self.args, ['--sdk', 'iphonesimulator', 'ARCHS=x86_64'])
76
77     def test_sdk_name(self):
78         port = self.make_port()
79         self.assertEqual(port.SDK, 'iphonesimulator')
80
81     def test_xcrun(self):
82         def throwing_run_command(args):
83             print(args)
84             raise ScriptError("MOCK script error")
85
86         port = self.make_port()
87         port._executive = MockExecutive2(run_command_fn=throwing_run_command)
88         expected_stdout = "['xcrun', '--sdk', 'iphonesimulator', '-find', 'test']\n"
89         OutputCapture().assert_outputs(self, port.xcrun_find, args=['test', 'falling'], expected_stdout=expected_stdout)
90
91     def test_layout_test_searchpath_with_apple_additions(self):
92         with port_testcase.bind_mock_apple_additions():
93             search_path = self.make_port().default_baseline_search_path()
94         self.assertEqual(search_path[0], '/additional_testing_path/ios-simulator-add-ios11-wk1')
95         self.assertEqual(search_path[1], '/mock-checkout/LayoutTests/platform/ios-simulator-11-wk1')
96         self.assertEqual(search_path[2], '/additional_testing_path/ios-simulator-add-ios11')
97         self.assertEqual(search_path[3], '/mock-checkout/LayoutTests/platform/ios-simulator-11')
98         self.assertEqual(search_path[4], '/additional_testing_path/ios-simulator-wk1')
99         self.assertEqual(search_path[5], '/mock-checkout/LayoutTests/platform/ios-simulator-wk1')
100         self.assertEqual(search_path[6], '/additional_testing_path/ios-simulator')
101         self.assertEqual(search_path[7], '/mock-checkout/LayoutTests/platform/ios-simulator')
102         self.assertEqual(search_path[8], '/additional_testing_path/ios-add-ios11')
103         self.assertEqual(search_path[9], '/mock-checkout/LayoutTests/platform/ios-11')
104         self.assertEqual(search_path[10], '/additional_testing_path/ios-wk1')
105         self.assertEqual(search_path[11], '/mock-checkout/LayoutTests/platform/ios-wk1')
106
107     def test_layout_test_searchpath_without_apple_additions(self):
108         search_path = self.make_port(port_name='ios-simulator-wk2', os_version=Version(12)).default_baseline_search_path()
109
110         self.assertEqual(search_path[0], '/mock-checkout/LayoutTests/platform/ios-simulator-12-wk2')
111         self.assertEqual(search_path[1], '/mock-checkout/LayoutTests/platform/ios-simulator-12')
112         self.assertEqual(search_path[2], '/mock-checkout/LayoutTests/platform/ios-simulator-wk2')
113         self.assertEqual(search_path[3], '/mock-checkout/LayoutTests/platform/ios-simulator')
114         self.assertEqual(search_path[4], '/mock-checkout/LayoutTests/platform/ios-12')
115         self.assertEqual(search_path[5], '/mock-checkout/LayoutTests/platform/ios-wk2')
116         self.assertEqual(search_path[6], '/mock-checkout/LayoutTests/platform/ios')
117         self.assertEqual(search_path[7], '/mock-checkout/LayoutTests/platform/wk2')