Access expectations path through apple_additions
[WebKit-https.git] / Tools / Scripts / webkitpy / port / ios_device_unittest.py
1 # Copyright (C) 2017 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.common.system.outputcapture import OutputCapture
26 from webkitpy.common.system.executive_mock import MockExecutive2, ScriptError
27 from webkitpy.port.ios_device import IOSDevicePort
28 from webkitpy.port import ios_testcase
29 from webkitpy.port import port_testcase
30
31
32 class IOSDeviceTest(ios_testcase.IOSTest):
33     os_name = 'ios'
34     os_version = ''
35     port_name = 'ios-device'
36     port_maker = IOSDevicePort
37
38     def make_port(self, host=None, port_name=None, options=None, os_name=None, os_version=None, **kwargs):
39         port = super(IOSDeviceTest, self).make_port(host=host, port_name=port_name, options=options, os_name=os_name, s_version=os_version, kwargs=kwargs)
40         port.set_option('version', '11.0')
41         return port
42
43     def test_operating_system(self):
44         self.assertEqual('ios-device', self.make_port().operating_system())
45
46     def test_crashlog_path(self):
47         port = self.make_port()
48         with self.assertRaises(RuntimeError):
49             port.path_to_crash_logs()
50
51     def test_spindump(self):
52         def logging_run_command(args):
53             print args
54
55         port = self.make_port()
56         port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-spindump.txt'] = 'Spindump file'
57         port.host.executive = MockExecutive2(run_command_fn=logging_run_command)
58         expected_stdout = "['/usr/sbin/spindump', 42, 10, 10, '-file', '/__im_tmp/tmp_0_/test-42-spindump.txt']\n"
59         OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42], expected_stdout=expected_stdout)
60         self.assertEqual(port.host.filesystem.files['/mock-build/layout-test-results/test-42-spindump.txt'], 'Spindump file')
61         self.assertIsNone(port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-spindump.txt'])
62
63     def test_sample_process(self):
64         def logging_run_command(args):
65             if args[0] == '/usr/sbin/spindump':
66                 return 1
67             print args
68             return 0
69
70         port = self.make_port()
71         port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-sample.txt'] = 'Sample file'
72         port.host.executive = MockExecutive2(run_command_fn=logging_run_command)
73         expected_stdout = "['/usr/bin/sample', 42, 10, 10, '-file', '/__im_tmp/tmp_0_/test-42-sample.txt']\n"
74         OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42], expected_stdout=expected_stdout)
75         self.assertEqual(port.host.filesystem.files['/mock-build/layout-test-results/test-42-sample.txt'], 'Sample file')
76         self.assertIsNone(port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-sample.txt'])
77
78     def test_sample_process_exception(self):
79         def throwing_run_command(args):
80             if args[0] == '/usr/sbin/spindump':
81                 return 1
82             raise ScriptError('MOCK script error')
83
84         port = self.make_port()
85         port.host.executive = MockExecutive2(run_command_fn=throwing_run_command)
86         OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42])
87
88     def test_get_crash_log(self):
89         port = self.make_port(port_name=self.port_name)
90         with self.assertRaises(RuntimeError):
91             port._get_crash_log('DumpRenderTree', 1234, None, None, time.time(), wait_for_log=False)
92
93     def test_layout_test_searchpath_with_apple_additions(self):
94         with port_testcase.bind_mock_apple_additions():
95             search_path = self.make_port().default_baseline_search_path()
96         self.assertEqual(search_path[0], '/additional_testing_path/ios-device-add-11-wk1')
97         self.assertEqual(search_path[1], '/mock-checkout/LayoutTests/platform/ios-device-11-wk1')
98         self.assertEqual(search_path[2], '/additional_testing_path/ios-device-add-11')
99         self.assertEqual(search_path[3], '/mock-checkout/LayoutTests/platform/ios-device-11')
100         self.assertEqual(search_path[4], '/additional_testing_path/ios-device-wk1')
101         self.assertEqual(search_path[5], '/mock-checkout/LayoutTests/platform/ios-device-wk1')
102         self.assertEqual(search_path[6], '/additional_testing_path/ios-device')
103         self.assertEqual(search_path[7], '/mock-checkout/LayoutTests/platform/ios-device')
104         self.assertEqual(search_path[8], '/additional_testing_path/ios-add-11')
105         self.assertEqual(search_path[9], '/mock-checkout/LayoutTests/platform/ios-11')
106         self.assertEqual(search_path[10], '/additional_testing_path/ios-wk1')
107         self.assertEqual(search_path[11], '/mock-checkout/LayoutTests/platform/ios-wk1')