NFC test if rosetta debugserver exists before testing rosetta
authorJason Molenda <jason@molenda.com>
Tue, 15 Nov 2022 22:33:50 +0000 (14:33 -0800)
committerJason Molenda <jason@molenda.com>
Tue, 15 Nov 2022 22:35:02 +0000 (14:35 -0800)
A fresh install of macOS does not have Rosetta 2 installed by
default; the CI bots are often in this state, resulting in a
test failure.  debugserver already hardcodes the filepath of
the Rosetta 2 debugserver; test if that file exists before
running the Rosetta test.

lldb/test/API/macosx/rosetta/TestRosetta.py

index 8836db9..4146fc3 100644 (file)
@@ -3,6 +3,7 @@ import lldb
 import lldbsuite.test.lldbutil as lldbutil
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test.decorators import *
+from os.path import exists
 
 
 def get_os_version():
@@ -16,6 +17,8 @@ def get_os_version():
         return m.group(1)
     return None
 
+def rosetta_debugserver_installed():
+    return exists("/Library/Apple/usr/libexec/oah/debugserver")
 
 def has_rosetta_shared_cache(os_version):
     if not os_version:
@@ -41,16 +44,17 @@ class TestRosetta(TestBase):
         self.build()
         self.main_source_file = lldb.SBFileSpec("main.c")
 
-        broadcaster = self.dbg.GetBroadcaster()
-        listener = lldbutil.start_listening_from(
-            broadcaster, lldb.SBDebugger.eBroadcastBitWarning)
+        if rosetta_debugserver_installed():
+          broadcaster = self.dbg.GetBroadcaster()
+          listener = lldbutil.start_listening_from(
+              broadcaster, lldb.SBDebugger.eBroadcastBitWarning)
 
-        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
-            self, "Set a breakpoint here", self.main_source_file)
+          target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
+              self, "Set a breakpoint here", self.main_source_file)
 
-        event = lldb.SBEvent()
-        os_version = get_os_version()
-        if not has_rosetta_shared_cache(os_version):
-            self.assertTrue(listener.GetNextEvent(event))
-        else:
-            self.assertFalse(listener.GetNextEvent(event))
+          event = lldb.SBEvent()
+          os_version = get_os_version()
+          if not has_rosetta_shared_cache(os_version):
+              self.assertTrue(listener.GetNextEvent(event))
+          else:
+              self.assertFalse(listener.GetNextEvent(event))