[lldb/test] Update lldbutil.fetch_next_event to match broadcaster class
authorMed Ismail Bennani <medismail.bennani@gmail.com>
Tue, 25 Apr 2023 18:24:02 +0000 (11:24 -0700)
committerMed Ismail Bennani <medismail.bennani@gmail.com>
Tue, 25 Apr 2023 22:03:45 +0000 (15:03 -0700)
This patch updates the `lldbutil.fetch_next_event` helper function to
either match a specific broadcaster or match a whole broadcaster class.

This is very handy when testing process events for interactive scripted
process debugging.

This also fixes a bug in the failing case, where `SBEvent.GetDescription`
expects a `SBStream` argument. We never took that code path in the
original implementation so we didn't hit that bug.

Differential Revision: https://reviews.llvm.org/D149175

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
lldb/packages/Python/lldbsuite/test/lldbutil.py

index d174c5af069b8837d39ef91f0b6e94c1a8885b17..309b51baae9bebddd7e4e8e01777e97c6dfe3187 100644 (file)
@@ -1202,18 +1202,25 @@ def start_listening_from(broadcaster, event_mask):
     broadcaster.AddListener(listener, event_mask)
     return listener
 
-def fetch_next_event(test, listener, broadcaster, timeout=10):
+def fetch_next_event(test, listener, broadcaster, match_class=False, timeout=10):
     """Fetch one event from the listener and return it if it matches the provided broadcaster.
+    If `match_class` is set to True, this will match an event with an entire broadcaster class.
     Fails otherwise."""
 
     event = lldb.SBEvent()
 
     if listener.WaitForEvent(timeout, event):
-        if event.BroadcasterMatchesRef(broadcaster):
-            return event
+        if match_class:
+            if event.GetBroadcasterClass() == broadcaster:
+                return event
+        else:
+            if event.BroadcasterMatchesRef(broadcaster):
+                return event
 
+        stream = lldb.SBStream()
+        event.GetDescription(stream)
         test.fail("received event '%s' from unexpected broadcaster '%s'." %
-                  (event.GetDescription(), event.GetBroadcaster().GetName()))
+                  (stream.GetData(), event.GetBroadcaster().GetName()))
 
     test.fail("couldn't fetch an event before reaching the timeout.")