1 # Copyright (C) 2017 Apple Inc. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
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.
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.
25 from webkitpy.common.system.outputcapture import OutputCapture
26 from webkitpy.common.system.executive_mock import MockExecutive2, ScriptError
27 from webkitpy.common.version import Version
28 from webkitpy.port.ios_device import IOSDevicePort
29 from webkitpy.port import ios_testcase
30 from webkitpy.port import port_testcase
33 class IOSDeviceTest(ios_testcase.IOSTest):
36 port_name = 'ios-device'
37 port_maker = IOSDevicePort
39 def test_operating_system(self):
40 self.assertEqual('ios-device', self.make_port().operating_system())
42 def test_crashlog_path(self):
43 port = self.make_port()
44 with self.assertRaises(RuntimeError):
45 port.path_to_crash_logs()
47 def test_spindump(self):
48 def logging_run_command(args):
51 port = self.make_port()
52 port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-spindump.txt'] = 'Spindump file'
53 port.host.executive = MockExecutive2(run_command_fn=logging_run_command)
54 expected_stdout = "['/usr/sbin/spindump', 42, 10, 10, '-file', '/__im_tmp/tmp_0_/test-42-spindump.txt']\n"
55 OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42], expected_stdout=expected_stdout)
56 self.assertEqual(port.host.filesystem.files['/mock-build/layout-test-results/test-42-spindump.txt'], 'Spindump file')
57 self.assertIsNone(port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-spindump.txt'])
59 def test_sample_process(self):
60 def logging_run_command(args):
61 if args[0] == '/usr/sbin/spindump':
66 port = self.make_port()
67 port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-sample.txt'] = 'Sample file'
68 port.host.executive = MockExecutive2(run_command_fn=logging_run_command)
69 expected_stdout = "['/usr/bin/sample', 42, 10, 10, '-file', '/__im_tmp/tmp_0_/test-42-sample.txt']\n"
70 OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42], expected_stdout=expected_stdout)
71 self.assertEqual(port.host.filesystem.files['/mock-build/layout-test-results/test-42-sample.txt'], 'Sample file')
72 self.assertIsNone(port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-sample.txt'])
74 def test_sample_process_exception(self):
75 def throwing_run_command(args):
76 if args[0] == '/usr/sbin/spindump':
78 raise ScriptError('MOCK script error')
80 port = self.make_port()
81 port.host.executive = MockExecutive2(run_command_fn=throwing_run_command)
82 OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42])
84 def test_get_crash_log(self):
85 port = self.make_port(port_name=self.port_name)
86 with self.assertRaises(RuntimeError):
87 port._get_crash_log('DumpRenderTree', 1234, None, None, time.time(), wait_for_log=False)
89 def test_layout_test_searchpath_with_apple_additions(self):
90 with port_testcase.bind_mock_apple_additions():
91 search_path = self.make_port().default_baseline_search_path()
92 self.assertEqual(search_path[0], '/additional_testing_path/ios-device-add-ios11-wk1')
93 self.assertEqual(search_path[1], '/mock-checkout/LayoutTests/platform/ios-device-11-wk1')
94 self.assertEqual(search_path[2], '/additional_testing_path/ios-device-add-ios11')
95 self.assertEqual(search_path[3], '/mock-checkout/LayoutTests/platform/ios-device-11')
96 self.assertEqual(search_path[4], '/additional_testing_path/ios-device-wk1')
97 self.assertEqual(search_path[5], '/mock-checkout/LayoutTests/platform/ios-device-wk1')
98 self.assertEqual(search_path[6], '/additional_testing_path/ios-device')
99 self.assertEqual(search_path[7], '/mock-checkout/LayoutTests/platform/ios-device')
100 self.assertEqual(search_path[8], '/additional_testing_path/ios-add-ios11')
101 self.assertEqual(search_path[9], '/mock-checkout/LayoutTests/platform/ios-11')
102 self.assertEqual(search_path[10], '/additional_testing_path/ios-wk1')
103 self.assertEqual(search_path[11], '/mock-checkout/LayoutTests/platform/ios-wk1')
105 def test_layout_test_searchpath_without_apple_additions(self):
106 search_path = self.make_port(port_name='ios-device-wk2', os_version=Version(12)).default_baseline_search_path()
108 self.assertEqual(search_path[0], '/mock-checkout/LayoutTests/platform/ios-device-12-wk2')
109 self.assertEqual(search_path[1], '/mock-checkout/LayoutTests/platform/ios-device-12')
110 self.assertEqual(search_path[2], '/mock-checkout/LayoutTests/platform/ios-device-wk2')
111 self.assertEqual(search_path[3], '/mock-checkout/LayoutTests/platform/ios-device')
112 self.assertEqual(search_path[4], '/mock-checkout/LayoutTests/platform/ios-12')
113 self.assertEqual(search_path[5], '/mock-checkout/LayoutTests/platform/ios-wk2')
114 self.assertEqual(search_path[6], '/mock-checkout/LayoutTests/platform/ios')
115 self.assertEqual(search_path[7], '/mock-checkout/LayoutTests/platform/wk2')