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