webkitpy: Implement device type specific expected results (Part 2)
[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     DEVICE_TYPE = DeviceType(software_variant='iOS')
43
44     def __init__(self, host, port_name, **kwargs):
45         super(IOSPort, self).__init__(host, port_name, **kwargs)
46         self._test_runner_process_constructor = SimulatorProcess
47         self._printing_cmd_line = False
48
49     def version_name(self):
50         if self._os_version is None:
51             return None
52         return VersionNameMap.map(self.host.platform).to_name(self._os_version, platform=IOSPort.port_name)
53
54     def default_baseline_search_path(self, device_type=None):
55         wk_string = 'wk1'
56         if self.get_option('webkit_test_runner'):
57             wk_string = 'wk2'
58
59         versions_to_fallback = []
60         if self.device_version().major == self.CURRENT_VERSION.major:
61             versions_to_fallback = [self.CURRENT_VERSION]
62         elif self.device_version():
63             temp_version = Version(self.device_version().major)
64             while temp_version != self.CURRENT_VERSION:
65                 versions_to_fallback.append(Version.from_iterable(temp_version))
66                 if temp_version < self.CURRENT_VERSION:
67                     temp_version.major += 1
68                 else:
69                     temp_version.major -= 1
70
71         runtime_type = 'simulator' if 'simulator' in self.SDK else 'device'
72         hardware_family = device_type.hardware_family.lower() if device_type and device_type.hardware_family else None
73         hardware_type = device_type.hardware_type.lower() if device_type and device_type.hardware_type else None
74
75         base_variants = []
76         if hardware_family and hardware_type:
77             base_variants.append('{}-{}-{}'.format(hardware_family, hardware_type, runtime_type))
78         if hardware_family:
79             base_variants.append('{}-{}'.format(hardware_family, runtime_type))
80         base_variants.append('{}-{}'.format(IOSPort.port_name, runtime_type))
81         if hardware_family and hardware_type:
82             base_variants.append('{}-{}'.format(hardware_family, hardware_type))
83         if hardware_family:
84             base_variants.append(hardware_family)
85         base_variants.append(IOSPort.port_name)
86
87         expectations = []
88         for variant in base_variants:
89             for version in versions_to_fallback:
90                 apple_name = None
91                 if apple_additions():
92                     apple_name = VersionNameMap.map(self.host.platform).to_name(version, platform=IOSPort.port_name, table=INTERNAL_TABLE)
93
94                 if apple_name:
95                     expectations.append(self._apple_baseline_path('{}-{}-{}'.format(variant, apple_name.lower().replace(' ', ''), wk_string)))
96                 expectations.append(self._webkit_baseline_path('{}-{}-{}'.format(variant, version.major, wk_string)))
97                 if apple_name:
98                     expectations.append(self._apple_baseline_path('{}-{}'.format(variant, apple_name.lower().replace(' ', ''))))
99                 expectations.append(self._webkit_baseline_path('{}-{}'.format(variant, version.major)))
100
101             if apple_additions():
102                 expectations.append(self._apple_baseline_path('{}-{}'.format(variant, wk_string)))
103             expectations.append(self._webkit_baseline_path('{}-{}'.format(variant, wk_string)))
104             if apple_additions():
105                 expectations.append(self._apple_baseline_path(variant))
106             expectations.append(self._webkit_baseline_path(variant))
107
108         if self.get_option('webkit_test_runner'):
109             expectations.append(self._webkit_baseline_path('wk2'))
110
111         return expectations
112
113     def test_expectations_file_position(self):
114         return 5