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 @skipUnlessDarwin 56 @skipIfDarwinEmbedded 57 @apple_simulator_test('iphone') 58 @skipIfOutOfTreeDebugserver 59 def test_ios(self): 60 """Test running an iOS simulator binary""" 61 self.run_with(arch=self.getArchitecture(), 62 os='ios', vers='', env='simulator', 63 expected_load_command='LC_BUILD_VERSION') 64 65 @skipUnlessDarwin 66 @skipIfDarwinEmbedded 67 @apple_simulator_test('appletv') 68 @skipIfOutOfTreeDebugserver 69 def test_tvos(self): 70 """Test running an tvOS simulator binary""" 71 self.run_with(arch=self.getArchitecture(), 72 os='tvos', vers='', env='simulator', 73 expected_load_command='LC_BUILD_VERSION') 74 75 @skipUnlessDarwin 76 @skipIfDarwinEmbedded 77 @apple_simulator_test('watch') 78 @skipIfDarwin # rdar://problem/64552748 79 @skipIf(archs=['arm64','arm64e']) 80 @skipIfOutOfTreeDebugserver 81 def test_watchos_i386(self): 82 """Test running a 32-bit watchOS simulator binary""" 83 self.run_with(arch='i386', 84 os='watchos', vers='', env='simulator', 85 expected_load_command='LC_BUILD_VERSION') 86 87 @skipUnlessDarwin 88 @skipIfDarwinEmbedded 89 @apple_simulator_test('watch') 90 @skipIfDarwin # rdar://problem/64552748 91 @skipIf(archs=['i386','x86_64']) 92 @skipIfOutOfTreeDebugserver 93 def test_watchos_armv7k(self): 94 """Test running a 32-bit watchOS simulator binary""" 95 self.run_with(arch='armv7k', 96 os='watchos', vers='', env='simulator', 97 expected_load_command='LC_BUILD_VERSION') 98 99 100 # 101 # Back-deployment tests. 102 # 103 # Older Mach-O versions used less expressive load commands, such 104 # as LC_VERSION_MIN_IPHONEOS that wouldn't distinguish between ios 105 # and ios-simulator. When targeting a simulator on Apple Silicon 106 # macOS, however, these legacy load commands are never generated. 107 # 108 109 @skipUnlessDarwin 110 @skipIfDarwinEmbedded 111 @skipIfOutOfTreeDebugserver 112 def test_lc_version_min_macosx(self): 113 """Test running a back-deploying non-simulator MacOS X binary""" 114 self.run_with(arch=self.getArchitecture(), 115 os='macosx', vers='10.9', env='', 116 expected_load_command='LC_VERSION_MIN_MACOSX') 117 @skipUnlessDarwin 118 @skipIfDarwinEmbedded 119 @apple_simulator_test('iphone') 120 @skipIf(archs=['arm64','arm64e']) 121 @skipIfOutOfTreeDebugserver 122 def test_lc_version_min_iphoneos(self): 123 """Test running a back-deploying iOS simulator binary 124 with a legacy iOS load command""" 125 self.run_with(arch=self.getArchitecture(), 126 os='ios', vers='11.0', env='simulator', 127 expected_load_command='LC_VERSION_MIN_IPHONEOS') 128 129 @skipUnlessDarwin 130 @skipIfDarwinEmbedded 131 @apple_simulator_test('iphone') 132 @skipIf(archs=['arm64','arm64e']) 133 @skipIfOutOfTreeDebugserver 134 def test_ios_backdeploy_x86(self): 135 """Test running a back-deploying iOS simulator binary 136 with a legacy iOS load command""" 137 self.run_with(arch=self.getArchitecture(), 138 os='ios', vers='13.0', env='simulator', 139 expected_load_command='LC_BUILD_VERSION') 140 141 @skipUnlessDarwin 142 @skipIfDarwinEmbedded 143 @apple_simulator_test('iphone') 144 @skipIf(archs=['i386','x86_64']) 145 @skipIfOutOfTreeDebugserver 146 def test_ios_backdeploy_apple_silicon(self): 147 """Test running a back-deploying iOS simulator binary""" 148 self.run_with(arch=self.getArchitecture(), 149 os='ios', vers='11.0', env='simulator', 150 expected_load_command='LC_BUILD_VERSION') 151 152 @skipUnlessDarwin 153 @skipIfDarwinEmbedded 154 @apple_simulator_test('appletv') 155 @skipIf(archs=['arm64','arm64e']) 156 @skipIfOutOfTreeDebugserver 157 def test_lc_version_min_tvos(self): 158 """Test running a back-deploying tvOS simulator binary 159 with a legacy tvOS load command""" 160 self.run_with(arch=self.getArchitecture(), 161 os='tvos', vers='11.0', env='simulator', 162 expected_load_command='LC_VERSION_MIN_TVOS') 163 164 @skipUnlessDarwin 165 @skipIfDarwinEmbedded 166 @apple_simulator_test('appletv') 167 @skipIf(archs=['i386','x86_64']) 168 @skipIfOutOfTreeDebugserver 169 def test_tvos_backdeploy_apple_silicon(self): 170 """Test running a back-deploying tvOS simulator binary""" 171 self.run_with(arch=self.getArchitecture(), 172 os='tvos', vers='11.0', env='simulator', 173 expected_load_command='LC_BUILD_VERSION') 174 175 @skipUnlessDarwin 176 @skipIfDarwinEmbedded 177 @apple_simulator_test('watch') 178 @skipIf(archs=['arm64','arm64e']) 179 @skipIfDarwin # rdar://problem/64552748 180 @skipIfOutOfTreeDebugserver 181 def test_lc_version_min_watchos(self): 182 """Test running a back-deploying watchOS simulator binary 183 with a legacy watchOS load command""" 184 self.run_with(arch='i386', 185 os='watchos', vers='4.0', env='simulator', 186 expected_load_command='LC_VERSION_MIN_WATCHOS') 187 188 @skipUnlessDarwin 189 @skipIfDarwinEmbedded 190 @apple_simulator_test('watch') 191 @skipIf(archs=['arm64','arm64e']) 192 @skipIfDarwin # rdar://problem/64552748 193 @skipIfOutOfTreeDebugserver 194 def test_watchos_backdeploy_apple_silicon(self): 195 """Test running a back-deploying watchOS simulator binary""" 196 self.run_with(arch='armv7k', 197 os='watchos', vers='4.0', env='simulator', 198 expected_load_command='LC_BUILD_VERSION') 199