xref: /llvm-project/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py (revision 7e9bab6ad51af1cab0c7457e4323166af3ac797c)
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@skipIfDarwin # rdar://problem/64552748
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        self.build(dictionary={'TRIPLE': arch+'-apple-'+os+vers+'-'+env})
45        self.check_load_commands(expected_load_command)
46        log = self.getBuildArtifact('packets.log')
47        self.expect("log enable gdb-remote packets -f "+log)
48        lldbutil.run_to_source_breakpoint(self, "break here",
49                                          lldb.SBFileSpec("hello.c"))
50        self.expect('image list -b -t',
51                    patterns=['a\.out '+arch+'-apple-'+os+vers+'.*-'+env])
52        self.check_debugserver(log, os+env, vers)
53
54    @skipUnlessDarwin
55    @skipIfDarwinEmbedded
56    @apple_simulator_test('iphone')
57    def test_ios(self):
58        """Test running an iOS simulator binary"""
59        self.run_with(arch=self.getArchitecture(),
60                      os='ios', vers='', env='simulator',
61                      expected_load_command='LC_BUILD_VERSION')
62
63    @skipUnlessDarwin
64    @skipIfDarwinEmbedded
65    @apple_simulator_test('appletv')
66    def test_tvos(self):
67        """Test running an tvOS simulator binary"""
68        self.run_with(arch=self.getArchitecture(),
69                      os='tvos', vers='', env='simulator',
70                      expected_load_command='LC_BUILD_VERSION')
71
72    @skipUnlessDarwin
73    @skipIfDarwinEmbedded
74    @apple_simulator_test('watch')
75    @skipIfDarwin # rdar://problem/64552748
76    @skipIf(archs=['arm64','arm64e'])
77    def test_watchos_i386(self):
78        """Test running a 32-bit watchOS simulator binary"""
79        self.run_with(arch='i386',
80                      os='watchos', vers='', env='simulator',
81                      expected_load_command='LC_BUILD_VERSION')
82
83    @skipUnlessDarwin
84    @skipIfDarwinEmbedded
85    @apple_simulator_test('watch')
86    @skipIfDarwin # rdar://problem/64552748
87    @skipIf(archs=['i386','x86_64'])
88    def test_watchos_armv7k(self):
89        """Test running a 32-bit watchOS simulator binary"""
90        self.run_with(arch='armv7k',
91                      os='watchos', vers='', env='simulator',
92                      expected_load_command='LC_BUILD_VERSION')
93
94
95    #
96    # Back-deployment tests.
97    #
98    # Older Mach-O versions used less expressive load commands, such
99    # as LC_VERSION_MIN_IPHONEOS that wouldn't distinguish between ios
100    # and ios-simulator.  When targeting a simulator on Apple Silicon
101    # macOS, however, these legacy load commands are never generated.
102    #
103
104    @skipUnlessDarwin
105    @skipIfDarwinEmbedded
106    @apple_simulator_test('iphone')
107    @skipIf(archs=['arm64','arm64e'])
108    def test_lc_version_min_iphoneos(self):
109        """Test running a back-deploying iOS simulator binary
110           with a legacy iOS load command"""
111        self.run_with(arch=self.getArchitecture(),
112                      os='ios', vers='11.0', env='simulator',
113                      expected_load_command='LC_VERSION_MIN_IPHONEOS')
114
115    @skipUnlessDarwin
116    @skipIfDarwinEmbedded
117    @apple_simulator_test('iphone')
118    @skipIf(archs=['arm64','arm64e'])
119    def test_ios_backdeploy_x86(self):
120        """Test running a back-deploying iOS simulator binary
121           with a legacy iOS load command"""
122        self.run_with(arch=self.getArchitecture(),
123                      os='ios', vers='13.0', env='simulator',
124                      expected_load_command='LC_BUILD_VERSION')
125
126    @skipUnlessDarwin
127    @skipIfDarwinEmbedded
128    @apple_simulator_test('iphone')
129    @skipIf(archs=['i386','x86_64'])
130    def test_ios_backdeploy_apple_silicon(self):
131        """Test running a back-deploying iOS simulator binary"""
132        self.run_with(arch=self.getArchitecture(),
133                      os='ios', vers='11.0', env='simulator',
134                      expected_load_command='LC_BUILD_VERSION')
135
136    @skipUnlessDarwin
137    @skipIfDarwinEmbedded
138    @apple_simulator_test('appletv')
139    @skipIf(archs=['arm64','arm64e'])
140    def test_lc_version_min_tvos(self):
141        """Test running a back-deploying tvOS simulator binary
142           with a legacy tvOS load command"""
143        self.run_with(arch=self.getArchitecture(),
144                      os='tvos', vers='11.0', env='simulator',
145                      expected_load_command='LC_VERSION_MIN_TVOS')
146
147    @skipUnlessDarwin
148    @skipIfDarwinEmbedded
149    @apple_simulator_test('appletv')
150    @skipIf(archs=['i386','x86_64'])
151    def test_tvos_backdeploy_apple_silicon(self):
152        """Test running a back-deploying tvOS simulator binary"""
153        self.run_with(arch=self.getArchitecture(),
154                      os='tvos', vers='11.0', env='simulator',
155                      expected_load_command='LC_BUILD_VERSION')
156
157    @skipUnlessDarwin
158    @skipIfDarwinEmbedded
159    @apple_simulator_test('watch')
160    @skipIf(archs=['arm64','arm64e'])
161    @skipIfDarwin # rdar://problem/64552748
162    def test_lc_version_min_watchos(self):
163        """Test running a back-deploying watchOS simulator binary
164           with a legacy watchOS load command"""
165        self.run_with(arch='i386',
166                      os='watchos', vers='4.0', env='simulator',
167                      expected_load_command='LC_VERSION_MIN_WATCHOS')
168
169    @skipUnlessDarwin
170    @skipIfDarwinEmbedded
171    @apple_simulator_test('watch')
172    @skipIf(archs=['arm64','arm64e'])
173    @skipIfDarwin # rdar://problem/64552748
174    def test_watchos_backdeploy_apple_silicon(self):
175        """Test running a back-deploying watchOS simulator binary"""
176        self.run_with(arch='armv7k',
177                      os='watchos', vers='4.0', env='simulator',
178                      expected_load_command='LC_BUILD_VERSION')
179