54b81307327cedaa66eab984a1866f1de77539a7
[WebKit-https.git] / Tools / Scripts / webkitpy / port / ios.py
1 # Copyright (C) 2014-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 logging
24 import traceback
25
26 from webkitpy.common.memoized import memoized
27 from webkitpy.common.version import Version
28 from webkitpy.common.version_name_map import VersionNameMap, INTERNAL_TABLE
29 from webkitpy.layout_tests.models.test_configuration import TestConfiguration
30 from webkitpy.port.config import apple_additions
31 from webkitpy.port.device_port import DevicePort
32 from webkitpy.port.simulator_process import SimulatorProcess
33 from webkitpy.xcode.device_type import DeviceType
34
35 _log = logging.getLogger(__name__)
36
37
38 class IOSPort(DevicePort):
39     port_name = "ios"
40
41     CURRENT_VERSION = Version(12)
42     # FIXME: This is not a clear way to do this (although it works) https://bugs.webkit.org/show_bug.cgi?id=192160
43     DEFAULT_DEVICE_TYPE = DeviceType(software_variant='iOS')
44
45     def __init__(self, host, port_name, **kwargs):
46         super(IOSPort, self).__init__(host, port_name, **kwargs)
47         self._test_runner_process_constructor = SimulatorProcess
48         self._printing_cmd_line = False
49
50     def version_name(self):
51         if self._os_version is None:
52             return None
53         return VersionNameMap.map(self.host.platform).to_name(self._os_version, platform=IOSPort.port_name)
54
55     def default_baseline_search_path(self, device_type=None):
56         wk_string = 'wk1'
57         if self.get_option('webkit_test_runner'):
58             wk_string = 'wk2'
59
60         versions_to_fallback = []
61         if self.device_version().major == self.CURRENT_VERSION.major:
62             versions_to_fallback = [self.CURRENT_VERSION]
63         elif self.device_version():
64             temp_version = Version(self.device_version().major)
65             while temp_version != self.CURRENT_VERSION:
66                 versions_to_fallback.append(Version.from_iterable(temp_version))
67                 if temp_version < self.CURRENT_VERSION:
68                     temp_version.major += 1
69                 else:
70                     temp_version.major -= 1
71
72         runtime_type = 'simulator' if 'simulator' in self.SDK else 'device'
73         hardware_family = device_type.hardware_family.lower() if device_type and device_type.hardware_family else None
74         hardware_type = device_type.hardware_type.lower() if device_type and device_type.hardware_type else None
75
76         base_variants = []
77         if hardware_family and hardware_type:
78             base_variants.append('{}-{}-{}'.format(hardware_family, hardware_type, runtime_type))
79         if hardware_family:
80             base_variants.append('{}-{}'.format(hardware_family, runtime_type))
81         base_variants.append('{}-{}'.format(IOSPort.port_name, runtime_type))
82         if hardware_family and hardware_type:
83             base_variants.append('{}-{}'.format(hardware_family, hardware_type))
84         if hardware_family:
85             base_variants.append(hardware_family)
86         base_variants.append(IOSPort.port_name)
87
88         expectations = []
89         for variant in base_variants:
90             for version in versions_to_fallback:
91                 apple_name = None
92                 if apple_additions():
93                     apple_name = VersionNameMap.map(self.host.platform).to_name(version, platform=IOSPort.port_name, table=INTERNAL_TABLE)
94
95                 if apple_name:
96                     expectations.append(self._apple_baseline_path('{}-{}-{}'.format(variant, apple_name.lower().replace(' ', ''), wk_string)))
97                 expectations.append(self._webkit_baseline_path('{}-{}-{}'.format(variant, version.major, wk_string)))
98                 if apple_name:
99                     expectations.append(self._apple_baseline_path('{}-{}'.format(variant, apple_name.lower().replace(' ', ''))))
100                 expectations.append(self._webkit_baseline_path('{}-{}'.format(variant, version.major)))
101
102             if apple_additions():
103                 expectations.append(self._apple_baseline_path('{}-{}'.format(variant, wk_string)))
104             expectations.append(self._webkit_baseline_path('{}-{}'.format(variant, wk_string)))
105             if apple_additions():
106                 expectations.append(self._apple_baseline_path(variant))
107             expectations.append(self._webkit_baseline_path(variant))
108
109         if self.get_option('webkit_test_runner'):
110             expectations.append(self._webkit_baseline_path('wk2'))
111
112         return expectations
113
114     def test_expectations_file_position(self):
115         return 5