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