66 lines · python
1import re2import lldb3import lldbsuite.test.lldbutil as lldbutil4from lldbsuite.test.lldbtest import *5from lldbsuite.test.decorators import *6from os.path import exists7 8 9def get_os_version():10 try:11 os_version_str = subprocess.check_output(["sysctl", "kern.osversion"]).decode(12 "utf-8"13 )14 except subprocess.CalledProcessError:15 return None16 m = re.match(r"kern\.osversion: (\w+)", os_version_str)17 if m:18 return m.group(1)19 return None20 21 22def rosetta_debugserver_installed():23 return exists("/Library/Apple/usr/libexec/oah/debugserver")24 25 26def has_rosetta_shared_cache(os_version):27 if not os_version:28 return False29 macos_device_support = os.path.join(30 os.path.expanduser("~"), "Library", "Developer", "Xcode", "macOS DeviceSupport"31 )32 for _, subdirs, _ in os.walk(macos_device_support):33 for subdir in subdirs:34 if os_version in subdir:35 return True36 return False37 38 39class TestRosetta(TestBase):40 NO_DEBUG_INFO_TESTCASE = True41 42 @skipUnlessAppleSilicon43 @skipIfLLVMTargetMissing("X86")44 @skipIfDarwinEmbedded45 def test_rosetta(self):46 """There can be many tests in a test case - describe this test here."""47 self.build()48 self.main_source_file = lldb.SBFileSpec("main.c")49 50 if rosetta_debugserver_installed():51 broadcaster = self.dbg.GetBroadcaster()52 listener = lldbutil.start_listening_from(53 broadcaster, lldb.SBDebugger.eBroadcastBitWarning54 )55 56 target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(57 self, "Set a breakpoint here", self.main_source_file58 )59 60 event = lldb.SBEvent()61 os_version = get_os_version()62 if not has_rosetta_shared_cache(os_version):63 self.assertTrue(listener.GetNextEvent(event))64 else:65 self.assertFalse(listener.GetNextEvent(event))66