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