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 50 version_min = '' 51 if vers: 52 if env == 'simulator': 53 version_min = '-m{}-simulator-version-min={}'.format(os, vers) 54 elif os == 'macosx': 55 version_min = '-m{}-version-min={}'.format(os, vers) 56 57 sdk = lldbutil.get_xcode_sdk(os, env) 58 sdk_root = lldbutil.get_xcode_sdk_root(sdk) 59 60 self.build( 61 dictionary={ 62 'ARCH': arch, 63 'ARCH_CFLAGS': '-target {} {}'.format(triple, version_min), 64 'SDKROOT': sdk_root 65 }) 66 67 self.check_load_commands(expected_load_command) 68 log = self.getBuildArtifact('packets.log') 69 self.expect("log enable gdb-remote packets -f "+log) 70 lldbutil.run_to_source_breakpoint(self, "break here", 71 lldb.SBFileSpec("hello.c")) 72 triple_re = '-'.join([arch, 'apple', os + vers+'.*'] + env_list) 73 self.expect('image list -b -t', patterns=['a\.out '+triple_re]) 74 self.check_debugserver(log, os+env, vers) 75 76 @skipIfAsan 77 @skipUnlessDarwin 78 @skipIfDarwinEmbedded 79 @apple_simulator_test('iphone') 80 @skipIfOutOfTreeDebugserver 81 def test_ios(self): 82 """Test running an iOS simulator binary""" 83 self.run_with(arch=self.getArchitecture(), 84 os='ios', vers='', env='simulator', 85 expected_load_command='LC_BUILD_VERSION') 86 87 @skipIfAsan 88 @skipUnlessDarwin 89 @skipIfDarwinEmbedded 90 @apple_simulator_test('appletv') 91 @skipIfOutOfTreeDebugserver 92 def test_tvos(self): 93 """Test running an tvOS simulator binary""" 94 self.run_with(arch=self.getArchitecture(), 95 os='tvos', vers='', env='simulator', 96 expected_load_command='LC_BUILD_VERSION') 97 98 @skipIfAsan 99 @skipUnlessDarwin 100 @skipIfDarwinEmbedded 101 @apple_simulator_test('watch') 102 @skipIfDarwin # rdar://problem/64552748 103 @skipIf(archs=['arm64','arm64e']) 104 @skipIfOutOfTreeDebugserver 105 def test_watchos_i386(self): 106 """Test running a 32-bit watchOS simulator binary""" 107 self.run_with(arch='i386', 108 os='watchos', vers='', env='simulator', 109 expected_load_command='LC_BUILD_VERSION') 110 111 @skipIfAsan 112 @skipUnlessDarwin 113 @skipIfDarwinEmbedded 114 @apple_simulator_test('watch') 115 @skipIfDarwin # rdar://problem/64552748 116 @skipIf(archs=['i386','x86_64']) 117 @skipIfOutOfTreeDebugserver 118 def test_watchos_armv7k(self): 119 """Test running a 32-bit watchOS simulator binary""" 120 self.run_with(arch='armv7k', 121 os='watchos', vers='', env='simulator', 122 expected_load_command='LC_BUILD_VERSION') 123 124 125 # 126 # Back-deployment tests. 127 # 128 # Older Mach-O versions used less expressive load commands, such 129 # as LC_VERSION_MIN_IPHONEOS that wouldn't distinguish between ios 130 # and ios-simulator. When targeting a simulator on Apple Silicon 131 # macOS, however, these legacy load commands are never generated. 132 # 133 134 @skipUnlessDarwin 135 @skipIfDarwinEmbedded 136 @skipIfOutOfTreeDebugserver 137 def test_lc_version_min_macosx(self): 138 """Test running a back-deploying non-simulator MacOS X binary""" 139 self.run_with(arch=self.getArchitecture(), 140 os='macosx', vers='10.9', env='', 141 expected_load_command='LC_VERSION_MIN_MACOSX') 142 @skipIfAsan 143 @skipUnlessDarwin 144 @skipIfDarwinEmbedded 145 @apple_simulator_test('iphone') 146 @skipIf(archs=['arm64','arm64e']) 147 @skipIfOutOfTreeDebugserver 148 def test_lc_version_min_iphoneos(self): 149 """Test running a back-deploying iOS simulator binary 150 with a legacy iOS load command""" 151 self.run_with(arch=self.getArchitecture(), 152 os='ios', vers='11.0', env='simulator', 153 expected_load_command='LC_VERSION_MIN_IPHONEOS') 154 155 @skipIfAsan 156 @skipUnlessDarwin 157 @skipIfDarwinEmbedded 158 @apple_simulator_test('iphone') 159 @skipIf(archs=['arm64','arm64e']) 160 @skipIfOutOfTreeDebugserver 161 def test_ios_backdeploy_x86(self): 162 """Test running a back-deploying iOS simulator binary 163 with a legacy iOS load command""" 164 self.run_with(arch=self.getArchitecture(), 165 os='ios', vers='13.0', env='simulator', 166 expected_load_command='LC_BUILD_VERSION') 167 168 @skipIfAsan 169 @skipUnlessDarwin 170 @skipIfDarwinEmbedded 171 @apple_simulator_test('iphone') 172 @skipIf(archs=['i386','x86_64']) 173 @skipIfOutOfTreeDebugserver 174 def test_ios_backdeploy_apple_silicon(self): 175 """Test running a back-deploying iOS simulator binary""" 176 self.run_with(arch=self.getArchitecture(), 177 os='ios', vers='11.0', env='simulator', 178 expected_load_command='LC_BUILD_VERSION') 179 180 @skipIfAsan 181 @skipUnlessDarwin 182 @skipIfDarwinEmbedded 183 @apple_simulator_test('appletv') 184 @skipIf(archs=['arm64','arm64e']) 185 @skipIfOutOfTreeDebugserver 186 def test_lc_version_min_tvos(self): 187 """Test running a back-deploying tvOS simulator binary 188 with a legacy tvOS load command""" 189 self.run_with(arch=self.getArchitecture(), 190 os='tvos', vers='11.0', env='simulator', 191 expected_load_command='LC_VERSION_MIN_TVOS') 192 193 @skipIfAsan 194 @skipUnlessDarwin 195 @skipIfDarwinEmbedded 196 @apple_simulator_test('appletv') 197 @skipIf(archs=['i386','x86_64']) 198 @skipIfOutOfTreeDebugserver 199 def test_tvos_backdeploy_apple_silicon(self): 200 """Test running a back-deploying tvOS simulator binary""" 201 self.run_with(arch=self.getArchitecture(), 202 os='tvos', vers='11.0', env='simulator', 203 expected_load_command='LC_BUILD_VERSION') 204 205 @skipIfAsan 206 @skipUnlessDarwin 207 @skipIfDarwinEmbedded 208 @apple_simulator_test('watch') 209 @skipIf(archs=['arm64','arm64e']) 210 @skipIfDarwin # rdar://problem/64552748 211 @skipIfOutOfTreeDebugserver 212 def test_lc_version_min_watchos(self): 213 """Test running a back-deploying watchOS simulator binary 214 with a legacy watchOS load command""" 215 self.run_with(arch='i386', 216 os='watchos', vers='4.0', env='simulator', 217 expected_load_command='LC_VERSION_MIN_WATCHOS') 218 219 @skipIfAsan 220 @skipUnlessDarwin 221 @skipIfDarwinEmbedded 222 @apple_simulator_test('watch') 223 @skipIf(archs=['arm64','arm64e']) 224 @skipIfDarwin # rdar://problem/64552748 225 @skipIfOutOfTreeDebugserver 226 def test_watchos_backdeploy_apple_silicon(self): 227 """Test running a back-deploying watchOS simulator binary""" 228 self.run_with(arch='armv7k', 229 os='watchos', vers='4.0', env='simulator', 230 expected_load_command='LC_BUILD_VERSION') 231