1import contextlib 2import os 3from os.path import exists 4import lldb 5from lldbsuite.test.decorators import * 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test import lldbutil 8 9 10def haswell(): 11 features = subprocess.check_output(["sysctl", "machdep.cpu"]) 12 return "AVX2" in features.decode("utf-8") 13 14 15def apple_silicon(): 16 features = subprocess.check_output(["sysctl", "machdep.cpu"]) 17 return "Apple M" in features.decode("utf-8") 18 19 20def rosetta_debugserver_installed(): 21 return exists("/Library/Apple/usr/libexec/oah/debugserver") 22 23 24class TestLaunchProcessPosixSpawn(TestBase): 25 NO_DEBUG_INFO_TESTCASE = True 26 27 def no_haswell(self): 28 if not haswell(): 29 return "Current CPU is not Haswell" 30 return None 31 32 def no_apple_silicon(self): 33 if not apple_silicon(): 34 return "Current CPU is not Apple Silicon" 35 return None 36 37 def run_arch(self, exe, arch): 38 self.runCmd("target create -arch {} {}".format(arch, exe)) 39 self.runCmd("run") 40 41 process = self.dbg.GetSelectedTarget().process 42 self.assertState(process.GetState(), lldb.eStateExited) 43 self.assertIn("slice: {}".format(arch), process.GetSTDOUT(1000)) 44 45 @skipUnlessDarwin 46 @skipIfDarwinEmbedded 47 @skipIfLLVMTargetMissing("AArch64") 48 @skipIfLLVMTargetMissing("X86") 49 @skipTestIfFn(no_haswell) 50 def test_haswell(self): 51 self.build() 52 exe = self.getBuildArtifact("fat.out") 53 self.run_arch(exe, "x86_64") 54 self.run_arch(exe, "x86_64h") 55 56 @skipUnlessDarwin 57 @skipIfDarwinEmbedded 58 @skipIfLLVMTargetMissing("AArch64") 59 @skipIfLLVMTargetMissing("X86") 60 @skipTestIfFn(no_apple_silicon) 61 def test_apple_silicon(self): 62 self.build() 63 exe = self.getBuildArtifact("fat.out") 64 if rosetta_debugserver_installed(): 65 self.run_arch(exe, "x86_64") 66 self.run_arch(exe, "arm64") 67