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 logfile = open(log, "r") 29 dylib_info = None 30 process_info_ostype = None 31 expect_dylib_info_response = False 32 expect_process_info_response = False 33 for line in logfile: 34 if expect_dylib_info_response: 35 while line[0] != '$': 36 line = line[1:] 37 line = line[1:] 38 # Unescape '}'. 39 dylib_info = json.loads(line.replace('}]','}')[:-4]) 40 expect_dylib_info_response = False 41 if 'send packet: $jGetLoadedDynamicLibrariesInfos:{' in line: 42 expect_dylib_info_response = True 43 if expect_process_info_response: 44 for pair in line.split(';'): 45 keyval = pair.split(':') 46 if len(keyval) == 2 and keyval[0] == 'ostype': 47 process_info_ostype = keyval[1] 48 if 'send packet: $qProcessInfo#' in line: 49 expect_process_info_response = True 50 51 self.assertEquals(process_info_ostype, expected_platform) 52 self.assertTrue(dylib_info) 53 aout_info = None 54 for image in dylib_info['images']: 55 if image['pathname'].endswith('a.out'): 56 aout_info = image 57 self.assertTrue(aout_info) 58 self.assertEquals(aout_info['min_version_os_name'], expected_platform) 59 if expected_version: 60 self.assertEquals(aout_info['min_version_os_sdk'], expected_version) 61 62 63 def run_with(self, arch, os, vers, env, expected_load_command): 64 self.build(dictionary={'TRIPLE': arch+'-apple-'+os+vers+'-'+env}) 65 self.check_load_commands(expected_load_command) 66 log = self.getBuildArtifact('packets.log') 67 self.expect("log enable gdb-remote packets -f "+log) 68 lldbutil.run_to_source_breakpoint(self, "break here", 69 lldb.SBFileSpec("hello.c")) 70 self.expect('image list -b -t', 71 patterns=['a\.out '+arch+'-apple-'+os+vers+'.*-'+env]) 72 self.check_debugserver(log, os+env, vers) 73 74 @skipUnlessDarwin 75 @skipIfDarwinEmbedded 76 @apple_simulator_test('iphone') 77 def test_ios(self): 78 """Test running an iOS simulator binary""" 79 self.run_with(arch=self.getArchitecture(), 80 os='ios', vers='', env='simulator', 81 expected_load_command='LC_BUILD_VERSION') 82 83 @skipUnlessDarwin 84 @skipIfDarwinEmbedded 85 @apple_simulator_test('appletv') 86 def test_tvos(self): 87 """Test running an tvOS simulator binary""" 88 self.run_with(arch=self.getArchitecture(), 89 os='tvos', vers='', env='simulator', 90 expected_load_command='LC_BUILD_VERSION') 91 92 @skipUnlessDarwin 93 @skipIfDarwinEmbedded 94 @apple_simulator_test('watch') 95 @skipIfDarwin # rdar://problem/64552748 96 @skipIf(archs=['arm64','arm64e']) 97 def test_watchos_i386(self): 98 """Test running a 32-bit watchOS simulator binary""" 99 self.run_with(arch='i386', 100 os='watchos', vers='', env='simulator', 101 expected_load_command='LC_BUILD_VERSION') 102 103 @skipUnlessDarwin 104 @skipIfDarwinEmbedded 105 @apple_simulator_test('watch') 106 @skipIfDarwin # rdar://problem/64552748 107 @skipIf(archs=['i386','x86_64']) 108 def test_watchos_armv7k(self): 109 """Test running a 32-bit watchOS simulator binary""" 110 self.run_with(arch='armv7k', 111 os='watchos', vers='', env='simulator', 112 expected_load_command='LC_BUILD_VERSION') 113 114 115 # 116 # Back-deployment tests. 117 # 118 # Older Mach-O versions used less expressive load commands, such 119 # as LC_VERSION_MIN_IPHONEOS that wouldn't distinguish between ios 120 # and ios-simulator. When targeting a simulator on Apple Silicon 121 # macOS, however, these legacy load commands are never generated. 122 # 123 124 @skipUnlessDarwin 125 @skipIfDarwinEmbedded 126 @apple_simulator_test('iphone') 127 @skipIf(archs=['arm64','arm64e']) 128 def test_lc_version_min_iphoneos(self): 129 """Test running a back-deploying iOS simulator binary 130 with a legacy iOS load command""" 131 self.run_with(arch=self.getArchitecture(), 132 os='ios', vers='11.0', env='simulator', 133 expected_load_command='LC_VERSION_MIN_IPHONEOS') 134 135 @skipUnlessDarwin 136 @skipIfDarwinEmbedded 137 @apple_simulator_test('iphone') 138 @skipIf(archs=['arm64','arm64e']) 139 def test_ios_backdeploy_x86(self): 140 """Test running a back-deploying iOS simulator binary 141 with a legacy iOS load command""" 142 self.run_with(arch=self.getArchitecture(), 143 os='ios', vers='13.0', env='simulator', 144 expected_load_command='LC_BUILD_VERSION') 145 146 @skipUnlessDarwin 147 @skipIfDarwinEmbedded 148 @apple_simulator_test('iphone') 149 @skipIf(archs=['i386','x86_64']) 150 def test_ios_backdeploy_apple_silicon(self): 151 """Test running a back-deploying iOS simulator binary""" 152 self.run_with(arch=self.getArchitecture(), 153 os='ios', vers='11.0', env='simulator', 154 expected_load_command='LC_BUILD_VERSION') 155 156 @skipUnlessDarwin 157 @skipIfDarwinEmbedded 158 @apple_simulator_test('appletv') 159 @skipIf(archs=['arm64','arm64e']) 160 def test_lc_version_min_tvos(self): 161 """Test running a back-deploying tvOS simulator binary 162 with a legacy tvOS load command""" 163 self.run_with(arch=self.getArchitecture(), 164 os='tvos', vers='11.0', env='simulator', 165 expected_load_command='LC_VERSION_MIN_TVOS') 166 167 @skipUnlessDarwin 168 @skipIfDarwinEmbedded 169 @apple_simulator_test('appletv') 170 @skipIf(archs=['i386','x86_64']) 171 def test_tvos_backdeploy_apple_silicon(self): 172 """Test running a back-deploying tvOS simulator binary""" 173 self.run_with(arch=self.getArchitecture(), 174 os='tvos', vers='11.0', env='simulator', 175 expected_load_command='LC_BUILD_VERSION') 176 177 @skipUnlessDarwin 178 @skipIfDarwinEmbedded 179 @apple_simulator_test('watch') 180 @skipIf(archs=['arm64','arm64e']) 181 @skipIfDarwin # rdar://problem/64552748 182 def test_lc_version_min_watchos(self): 183 """Test running a back-deploying watchOS simulator binary 184 with a legacy watchOS load command""" 185 self.run_with(arch='i386', 186 os='watchos', vers='4.0', env='simulator', 187 expected_load_command='LC_VERSION_MIN_WATCHOS') 188 189 @skipUnlessDarwin 190 @skipIfDarwinEmbedded 191 @apple_simulator_test('watch') 192 @skipIf(archs=['arm64','arm64e']) 193 @skipIfDarwin # rdar://problem/64552748 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