webkitpy: Implement device type specific expected results (Part 2)
[WebKit-https.git] / Tools / Scripts / webkitpy / port / ios_simulator.py
1 # Copyright (C) 2014-2018 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 logging
24
25 from webkitpy.common.memoized import memoized
26 from webkitpy.common.version import Version
27 from webkitpy.port.config import apple_additions
28 from webkitpy.port.ios import IOSPort
29 from webkitpy.xcode.device_type import DeviceType
30 from webkitpy.xcode.simulated_device import SimulatedDeviceManager
31
32
33 _log = logging.getLogger(__name__)
34
35
36 class IOSSimulatorPort(IOSPort):
37     port_name = "ios-simulator"
38
39     FUTURE_VERSION = 'future'
40     ARCHITECTURES = ['x86_64', 'i386']
41     DEFAULT_ARCHITECTURE = 'x86_64'
42
43     DEVICE_MANAGER = SimulatedDeviceManager
44
45     DEFAULT_DEVICE_TYPES = [
46         DeviceType(hardware_family='iPhone', hardware_type='SE'),
47         DeviceType(hardware_family='iPad', hardware_type='(5th generation)'),
48         DeviceType(hardware_family='iPhone', hardware_type='7'),
49     ]
50     SDK = apple_additions().get_sdk('iphonesimulator') if apple_additions() else 'iphonesimulator'
51
52     @staticmethod
53     def _version_from_name(name):
54         if len(name.split('-')) > 2 and name.split('-')[2].isdigit():
55             return Version.from_string(name.split('-')[2])
56         return None
57
58     @memoized
59     def device_version(self):
60         if self.get_option('version'):
61             return Version.from_string(self.get_option('version'))
62         return IOSSimulatorPort._version_from_name(self._name) if IOSSimulatorPort._version_from_name(self._name) else self.host.platform.xcode_sdk_version('iphonesimulator')
63
64     def clean_up_test_run(self):
65         super(IOSSimulatorPort, self).clean_up_test_run()
66         _log.debug("clean_up_test_run")
67
68         SimulatedDeviceManager.tear_down(self.host)
69
70     def environment_for_api_tests(self):
71         no_prefix = super(IOSSimulatorPort, self).environment_for_api_tests()
72         result = {}
73         SIMCTL_ENV_PREFIX = 'SIMCTL_CHILD_'
74         for value in no_prefix:
75             if not value.startswith(SIMCTL_ENV_PREFIX):
76                 result[SIMCTL_ENV_PREFIX + value] = no_prefix[value]
77             else:
78                 result[value] = no_prefix[value]
79         return result
80
81     def setup_environ_for_server(self, server_name=None):
82         _log.debug("setup_environ_for_server")
83         env = super(IOSSimulatorPort, self).setup_environ_for_server(server_name)
84         if server_name == self.driver_name():
85             if self.get_option('leaks'):
86                 env['MallocStackLogging'] = '1'
87                 env['__XPC_MallocStackLogging'] = '1'
88                 env['MallocScribble'] = '1'
89                 env['__XPC_MallocScribble'] = '1'
90         return env
91
92     def operating_system(self):
93         return 'ios-simulator'
94
95     def reset_preferences(self):
96         _log.debug("reset_preferences")
97         SimulatedDeviceManager.tear_down(self.host)
98
99     def nm_command(self):
100         return self.xcrun_find('nm')
101
102     @property
103     @memoized
104     def developer_dir(self):
105         return self._executive.run_command(['xcode-select', '--print-path']).rstrip()
106
107     def logging_patterns_to_strip(self):
108         return []
109
110     def stderr_patterns_to_strip(self):
111         return []