TestSimulatorPlatform.py
7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import json
import unittest2
@skipIfDarwin # rdar://problem/64552748
class TestSimulatorPlatformLaunching(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
def check_load_commands(self, expected_load_command):
"""sanity check the built binary for the expected number of load commands"""
load_cmds = subprocess.check_output(
['otool', '-l', self.getBuildArtifact()]
).decode("utf-8")
found = 0
for line in load_cmds.split('\n'):
if expected_load_command in line:
found += 1
self.assertEquals(found, 1, "wrong load command")
def check_debugserver(self, log, expected_platform, expected_version):
"""scan the debugserver packet log"""
logfile = open(log, "r")
dylib_info = None
response = False
for line in logfile:
if response:
while line[0] != '$':
line = line[1:]
line = line[1:]
# Unescape '}'.
dylib_info = json.loads(line.replace('}]','}')[:-4])
response = False
if 'send packet: $jGetLoadedDynamicLibrariesInfos:{' in line:
response = True
self.assertTrue(dylib_info)
aout_info = None
for image in dylib_info['images']:
if image['pathname'].endswith('a.out'):
aout_info = image
self.assertTrue(aout_info)
self.assertEquals(aout_info['min_version_os_name'], expected_platform)
if expected_version:
self.assertEquals(aout_info['min_version_os_sdk'], expected_version)
def run_with(self, arch, os, vers, env, expected_load_command):
self.build(dictionary={'TRIPLE': arch+'-apple-'+os+vers+'-'+env})
self.check_load_commands(expected_load_command)
log = self.getBuildArtifact('packets.log')
self.expect("log enable gdb-remote packets -f "+log)
lldbutil.run_to_source_breakpoint(self, "break here",
lldb.SBFileSpec("hello.c"))
self.expect('image list -b -t',
patterns=['a\.out '+arch+'-apple-'+os+vers+'.*-'+env])
self.check_debugserver(log, os+env, vers)
@skipUnlessDarwin
@skipIfDarwinEmbedded
@apple_simulator_test('iphone')
def test_ios(self):
"""Test running an iOS simulator binary"""
self.run_with(arch=self.getArchitecture(),
os='ios', vers='', env='simulator',
expected_load_command='LC_BUILD_VERSION')
@skipUnlessDarwin
@skipIfDarwinEmbedded
@apple_simulator_test('appletv')
def test_tvos(self):
"""Test running an tvOS simulator binary"""
self.run_with(arch=self.getArchitecture(),
os='tvos', vers='', env='simulator',
expected_load_command='LC_BUILD_VERSION')
@skipUnlessDarwin
@skipIfDarwinEmbedded
@apple_simulator_test('watch')
@skipIfDarwin # rdar://problem/64552748
@skipIf(archs=['arm64','arm64e'])
def test_watchos_i386(self):
"""Test running a 32-bit watchOS simulator binary"""
self.run_with(arch='i386',
os='watchos', vers='', env='simulator',
expected_load_command='LC_BUILD_VERSION')
@skipUnlessDarwin
@skipIfDarwinEmbedded
@apple_simulator_test('watch')
@skipIfDarwin # rdar://problem/64552748
@skipIf(archs=['i386','x86_64'])
def test_watchos_armv7k(self):
"""Test running a 32-bit watchOS simulator binary"""
self.run_with(arch='armv7k',
os='watchos', vers='', env='simulator',
expected_load_command='LC_BUILD_VERSION')
#
# Back-deployment tests.
#
# Older Mach-O versions used less expressive load commands, such
# as LC_VERSION_MIN_IPHONEOS that wouldn't distinguish between ios
# and ios-simulator. When targeting a simulator on Apple Silicon
# macOS, however, these legacy load commands are never generated.
#
@skipUnlessDarwin
@skipIfDarwinEmbedded
@apple_simulator_test('iphone')
@skipIf(archs=['arm64','arm64e'])
def test_lc_version_min_iphoneos(self):
"""Test running a back-deploying iOS simulator binary
with a legacy iOS load command"""
self.run_with(arch=self.getArchitecture(),
os='ios', vers='11.0', env='simulator',
expected_load_command='LC_VERSION_MIN_IPHONEOS')
@skipUnlessDarwin
@skipIfDarwinEmbedded
@apple_simulator_test('iphone')
@skipIf(archs=['arm64','arm64e'])
def test_ios_backdeploy_x86(self):
"""Test running a back-deploying iOS simulator binary
with a legacy iOS load command"""
self.run_with(arch=self.getArchitecture(),
os='ios', vers='13.0', env='simulator',
expected_load_command='LC_BUILD_VERSION')
@skipUnlessDarwin
@skipIfDarwinEmbedded
@apple_simulator_test('iphone')
@skipIf(archs=['i386','x86_64'])
def test_ios_backdeploy_apple_silicon(self):
"""Test running a back-deploying iOS simulator binary"""
self.run_with(arch=self.getArchitecture(),
os='ios', vers='11.0', env='simulator',
expected_load_command='LC_BUILD_VERSION')
@skipUnlessDarwin
@skipIfDarwinEmbedded
@apple_simulator_test('appletv')
@skipIf(archs=['arm64','arm64e'])
def test_lc_version_min_tvos(self):
"""Test running a back-deploying tvOS simulator binary
with a legacy tvOS load command"""
self.run_with(arch=self.getArchitecture(),
os='tvos', vers='11.0', env='simulator',
expected_load_command='LC_VERSION_MIN_TVOS')
@skipUnlessDarwin
@skipIfDarwinEmbedded
@apple_simulator_test('appletv')
@skipIf(archs=['i386','x86_64'])
def test_tvos_backdeploy_apple_silicon(self):
"""Test running a back-deploying tvOS simulator binary"""
self.run_with(arch=self.getArchitecture(),
os='tvos', vers='11.0', env='simulator',
expected_load_command='LC_BUILD_VERSION')
@skipUnlessDarwin
@skipIfDarwinEmbedded
@apple_simulator_test('watch')
@skipIf(archs=['arm64','arm64e'])
@skipIfDarwin # rdar://problem/64552748
def test_lc_version_min_watchos(self):
"""Test running a back-deploying watchOS simulator binary
with a legacy watchOS load command"""
self.run_with(arch='i386',
os='watchos', vers='4.0', env='simulator',
expected_load_command='LC_VERSION_MIN_WATCHOS')
@skipUnlessDarwin
@skipIfDarwinEmbedded
@apple_simulator_test('watch')
@skipIf(archs=['arm64','arm64e'])
@skipIfDarwin # rdar://problem/64552748
def test_watchos_backdeploy_apple_silicon(self):
"""Test running a back-deploying watchOS simulator binary"""
self.run_with(arch='armv7k',
os='watchos', vers='4.0', env='simulator',
expected_load_command='LC_BUILD_VERSION')