xref: /llvm-project/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py (revision 116b1033738f9a409e502e270dbf1c9e04f5b1ad)
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
27    def run_with(self, arch, os, env, expected_load_command):
28        self.build(dictionary={'TRIPLE': arch+'-apple-'+os+'-'+env})
29        lldbutil.run_to_source_breakpoint(self, "break here",
30                                          lldb.SBFileSpec("hello.c"))
31        self.check_load_commands(expected_load_command)
32        self.expect('image list -b -t',
33                    patterns=['a\.out '+arch+'-apple-'+os+'.*-'+env])
34
35    @skipUnlessDarwin
36    @skipIfDarwinEmbedded
37    @apple_simulator_test('iphone')
38    def test_ios(self):
39        """Test running an iOS simulator binary"""
40        self.run_with(arch=self.getArchitecture(),
41                      os='ios', env='simulator',
42                      expected_load_command='LC_BUILD_VERSION')
43
44    @skipUnlessDarwin
45    @skipIfDarwinEmbedded
46    @apple_simulator_test('appletv')
47    def test_tvos(self):
48        """Test running an tvOS simulator binary"""
49        self.run_with(arch=self.getArchitecture(),
50                      os='tvos', env='simulator',
51                      expected_load_command='LC_BUILD_VERSION')
52
53    @skipUnlessDarwin
54    @skipIfDarwinEmbedded
55    @apple_simulator_test('watch')
56    @skipIfDarwin # rdar://problem/64552748
57    @skipIf(archs=['arm64','arm64e'])
58    def test_watchos_i386(self):
59        """Test running a 32-bit watchOS simulator binary"""
60        self.run_with(arch='i386',
61                      os='watchos', env='simulator',
62                      expected_load_command='LC_BUILD_VERSION')
63
64    @skipUnlessDarwin
65    @skipIfDarwinEmbedded
66    @apple_simulator_test('watch')
67    @skipIfDarwin # rdar://problem/64552748
68    @skipIf(archs=['i386','x86_64'])
69    def test_watchos_armv7k(self):
70        """Test running a 32-bit watchOS simulator binary"""
71        self.run_with(arch='armv7k',
72                      os='watchos', env='simulator',
73                      expected_load_command='LC_BUILD_VERSION')
74
75
76    #
77    # Back-deployment tests.
78    #
79    # Older Mach-O versions used less expressive load commands, such
80    # as LC_VERSION_MIN_IPHONEOS that wouldn't distinguish between ios
81    # and ios-simulator.  When targeting a simulator on Apple Silicon
82    # macOS, however, these legacy load commands are never generated.
83    #
84
85    @skipUnlessDarwin
86    @skipIfDarwinEmbedded
87    @apple_simulator_test('iphone')
88    @skipIf(archs=['arm64','arm64e'])
89    def test_lc_version_min_iphoneos(self):
90        """Test running a back-deploying iOS simulator binary
91           with a legacy iOS load command"""
92        self.run_with(arch=self.getArchitecture(),
93                      os='ios11.0', env='simulator',
94                      expected_load_command='LC_VERSION_MIN_IPHONEOS')
95
96    @skipUnlessDarwin
97    @skipIfDarwinEmbedded
98    @apple_simulator_test('iphone')
99    @skipIf(archs=['i386','x86_64'])
100    def test_ios_backdeploy_apple_silicon(self):
101        """Test running a back-deploying iOS simulator binary"""
102        self.run_with(arch=self.getArchitecture(),
103                      os='ios11.0', env='simulator',
104                      expected_load_command='LC_BUILD_VERSION')
105
106    @skipUnlessDarwin
107    @skipIfDarwinEmbedded
108    @apple_simulator_test('appletv')
109    @skipIf(archs=['arm64','arm64e'])
110    def test_lc_version_min_tvos(self):
111        """Test running a back-deploying tvOS simulator binary
112           with a legacy tvOS load command"""
113        self.run_with(arch=self.getArchitecture(),
114                      os='tvos11.0', env='simulator',
115                      expected_load_command='LC_VERSION_MIN_TVOS')
116
117    @skipUnlessDarwin
118    @skipIfDarwinEmbedded
119    @apple_simulator_test('appletv')
120    @skipIf(archs=['i386','x86_64'])
121    def test_tvos_backdeploy_apple_silicon(self):
122        """Test running a back-deploying tvOS simulator binary"""
123        self.run_with(arch=self.getArchitecture(),
124                      os='tvos11.0', env='simulator',
125                      expected_load_command='LC_BUILD_VERSION')
126
127    @skipUnlessDarwin
128    @skipIfDarwinEmbedded
129    @apple_simulator_test('watch')
130    @skipIf(archs=['arm64','arm64e'])
131    @skipIfDarwin # rdar://problem/64552748
132    def test_lc_version_min_watchos(self):
133        """Test running a back-deploying watchOS simulator binary
134           with a legacy watchOS load command"""
135        self.run_with(arch='i386',
136                      os='watchos4.0', env='simulator',
137                      expected_load_command='LC_VERSION_MIN_WATCHOS')
138
139    @skipUnlessDarwin
140    @skipIfDarwinEmbedded
141    @apple_simulator_test('watch')
142    @skipIf(archs=['arm64','arm64e'])
143    @skipIfDarwin # rdar://problem/64552748
144    def test_watchos_backdeploy_apple_silicon(self):
145        """Test running a back-deploying watchOS simulator binary"""
146        self.run_with(arch='armv7k',
147                      os='watchos4.0', env='simulator',
148                      expected_load_command='LC_BUILD_VERSION')
149