Access expectations path through apple_additions
[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 import time
24
25 from webkitpy.port.ios_simulator import IOSSimulatorPort
26 from webkitpy.port import ios_testcase
27 from webkitpy.port import port_testcase
28 from webkitpy.common.system.outputcapture import OutputCapture
29 from webkitpy.tool.mocktool import MockOptions
30 from webkitpy.common.system.executive_mock import MockExecutive2, ScriptError
31
32
33 class IOSSimulatorTest(ios_testcase.IOSTest):
34     # FIXME: https://bugs.webkit.org/show_bug.cgi?id=173107
35     os_name = 'mac'
36     os_version = ''
37     port_name = 'ios-simulator'
38     port_maker = IOSSimulatorPort
39
40     def make_port(self, host=None, port_name=None, options=None, os_name=None, os_version=None, **kwargs):
41         port = super(IOSSimulatorTest, self).make_port(host=host, port_name=port_name, options=options, os_name=os_name, s_version=os_version, kwargs=kwargs)
42         port.set_option('child_processes', 1)
43         return port
44
45     def test_setup_environ_for_server(self):
46         port = self.make_port(options=MockOptions(leaks=True, guard_malloc=True))
47         env = port.setup_environ_for_server(port.driver_name())
48         self.assertEqual(env['MallocStackLogging'], '1')
49         self.assertEqual(env['MallocScribble'], '1')
50         self.assertEqual(env['DYLD_INSERT_LIBRARIES'], '/usr/lib/libgmalloc.dylib')
51
52     def test_operating_system(self):
53         self.assertEqual('ios-simulator', self.make_port().operating_system())
54
55     def test_32bit(self):
56         port = self.make_port(options=MockOptions(architecture='x86'))
57
58         def run_script(script, args=None, env=None):
59             self.args = args
60
61         port._run_script = run_script
62         self.assertEqual(port.architecture(), 'x86')
63         port._build_driver()
64         self.assertEqual(self.args, ['ARCHS=i386', '--sdk', 'iphonesimulator'])
65
66     def test_64bit(self):
67         # Apple Mac port is 64-bit by default
68         port = self.make_port()
69         self.assertEqual(port.architecture(), 'x86_64')
70
71         def run_script(script, args=None, env=None):
72             self.args = args
73
74         port._run_script = run_script
75         port._build_driver()
76         self.assertEqual(self.args, ['--sdk', 'iphonesimulator'])
77
78     def test_sdk_name(self):
79         port = self.make_port()
80         self.assertEqual(port.SDK, 'iphonesimulator')
81
82     def test_xcrun(self):
83         def throwing_run_command(args):
84             print args
85             raise ScriptError("MOCK script error")
86
87         port = self.make_port()
88         port._executive = MockExecutive2(run_command_fn=throwing_run_command)
89         expected_stdout = "['xcrun', '--sdk', 'iphonesimulator', '-find', 'test']\n"
90         OutputCapture().assert_outputs(self, port.xcrun_find, args=['test', 'falling'], expected_stdout=expected_stdout)
91
92     def test_layout_test_searchpath_with_apple_additions(self):
93         with port_testcase.bind_mock_apple_additions():
94             search_path = self.make_port().default_baseline_search_path()
95         self.assertEqual(search_path[0], '/additional_testing_path/ios-simulator-add-8-wk1')
96         self.assertEqual(search_path[1], '/mock-checkout/LayoutTests/platform/ios-simulator-8-wk1')
97         self.assertEqual(search_path[2], '/additional_testing_path/ios-simulator-add-8')
98         self.assertEqual(search_path[3], '/mock-checkout/LayoutTests/platform/ios-simulator-8')
99         self.assertEqual(search_path[4], '/additional_testing_path/ios-simulator-wk1')
100         self.assertEqual(search_path[5], '/mock-checkout/LayoutTests/platform/ios-simulator-wk1')
101         self.assertEqual(search_path[6], '/additional_testing_path/ios-simulator')
102         self.assertEqual(search_path[7], '/mock-checkout/LayoutTests/platform/ios-simulator')
103         self.assertEqual(search_path[8], '/additional_testing_path/ios-add-8')
104         self.assertEqual(search_path[9], '/mock-checkout/LayoutTests/platform/ios-8')
105         self.assertEqual(search_path[10], '/additional_testing_path/ios-wk1')
106         self.assertEqual(search_path[11], '/mock-checkout/LayoutTests/platform/ios-wk1')