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