74 lines · python
1import contextlib2import os3from os.path import exists4import lldb5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7from lldbsuite.test import lldbutil8 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 import platform22 version = platform.mac_ver()23 # Workaround for an undiagnosed problem on green dragon.24 if version[0] == '15.5':25 return False26 return exists("/Library/Apple/usr/libexec/oah/debugserver")27 28 29class TestLaunchProcessPosixSpawn(TestBase):30 NO_DEBUG_INFO_TESTCASE = True31 32 def no_haswell(self):33 if not haswell():34 return "Current CPU is not Haswell"35 return None36 37 def no_apple_silicon(self):38 if not apple_silicon():39 return "Current CPU is not Apple Silicon"40 return None41 42 def run_arch(self, exe, arch):43 self.runCmd("target create -arch {} {}".format(arch, exe))44 target = self.dbg.GetSelectedTarget()45 launch_info = target.GetLaunchInfo()46 error = lldb.SBError()47 process = target.Launch(launch_info, error)48 self.assertTrue(error.Success(), str(error))49 self.assertState(process.GetState(), lldb.eStateExited)50 self.assertIn("slice: {}".format(arch), process.GetSTDOUT(1000))51 52 @skipUnlessDarwin53 @skipIfDarwinEmbedded54 @skipIfLLVMTargetMissing("AArch64")55 @skipIfLLVMTargetMissing("X86")56 @skipTestIfFn(no_haswell)57 def test_haswell(self):58 self.build()59 exe = self.getBuildArtifact("fat.out")60 self.run_arch(exe, "x86_64")61 self.run_arch(exe, "x86_64h")62 63 @skipUnlessDarwin64 @skipIfDarwinEmbedded65 @skipIfLLVMTargetMissing("AArch64")66 @skipIfLLVMTargetMissing("X86")67 @skipTestIfFn(no_apple_silicon)68 def test_apple_silicon(self):69 self.build()70 exe = self.getBuildArtifact("fat.out")71 if rosetta_debugserver_installed():72 self.run_arch(exe, "x86_64")73 self.run_arch(exe, "arm64")74