webkitpy: Refactor port code for devices
[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
34 _log = logging.getLogger(__name__)
35
36
37 class IOSPort(DevicePort):
38     port_name = "ios"
39
40     CURRENT_VERSION = Version(12)
41
42     def __init__(self, host, port_name, **kwargs):
43         super(IOSPort, self).__init__(host, port_name, **kwargs)
44         self._test_runner_process_constructor = SimulatorProcess
45         self._printing_cmd_line = False
46
47     def version_name(self):
48         if self._os_version is None:
49             return None
50         return VersionNameMap.map(self.host.platform).to_name(self._os_version, platform=IOSPort.port_name)
51
52     @memoized
53     def default_baseline_search_path(self):
54         wk_string = 'wk1'
55         if self.get_option('webkit_test_runner'):
56             wk_string = 'wk2'
57
58         versions_to_fallback = []
59         if self.ios_version().major == self.CURRENT_VERSION.major:
60             versions_to_fallback = [self.CURRENT_VERSION]
61         elif self.ios_version():
62             temp_version = Version(self.ios_version().major)
63             while temp_version != self.CURRENT_VERSION:
64                 versions_to_fallback.append(Version.from_iterable(temp_version))
65                 if temp_version < self.CURRENT_VERSION:
66                     temp_version.major += 1
67                 else:
68                     temp_version.major -= 1
69
70         expectations = []
71         for version in versions_to_fallback:
72             apple_name = None
73             if apple_additions():
74                 apple_name = VersionNameMap.map(self.host.platform).to_name(version, platform=IOSPort.port_name, table=INTERNAL_TABLE)
75
76             if apple_name:
77                 expectations.append(self._apple_baseline_path('{}-{}-{}'.format(self.port_name, apple_name.lower().replace(' ', ''), wk_string)))
78             expectations.append(self._webkit_baseline_path('{}-{}-{}'.format(self.port_name, version.major, wk_string)))
79             if apple_name:
80                 expectations.append(self._apple_baseline_path('{}-{}'.format(self.port_name, apple_name.lower().replace(' ', ''))))
81             expectations.append(self._webkit_baseline_path('{}-{}'.format(self.port_name, version.major)))
82
83         if apple_additions():
84             expectations.append(self._apple_baseline_path('{}-{}'.format(self.port_name, wk_string)))
85         expectations.append(self._webkit_baseline_path('{}-{}'.format(self.port_name, wk_string)))
86         if apple_additions():
87             expectations.append(self._apple_baseline_path(self.port_name))
88         expectations.append(self._webkit_baseline_path(self.port_name))
89
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             if apple_name:
95                 expectations.append(self._apple_baseline_path('{}-{}'.format(IOSPort.port_name, apple_name.lower().replace(' ', ''))))
96             expectations.append(self._webkit_baseline_path('{}-{}'.format(IOSPort.port_name, version.major)))
97
98         if apple_additions():
99             expectations.append(self._apple_baseline_path('{}-{}'.format(IOSPort.port_name, wk_string)))
100         expectations.append(self._webkit_baseline_path('{}-{}'.format(IOSPort.port_name, wk_string)))
101         if apple_additions():
102             expectations.append(self._apple_baseline_path(IOSPort.port_name))
103         expectations.append(self._webkit_baseline_path(IOSPort.port_name))
104
105         if self.get_option('webkit_test_runner'):
106             expectations.append(self._webkit_baseline_path('wk2'))
107
108         return expectations
109
110     def test_expectations_file_position(self):
111         return 4
112
113     def ios_version(self):
114         raise NotImplementedError