Skip to content

Commit

Permalink
[lldb/test] Update lldbutil.fetch_next_event to match broadcaster class
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
medismailben committed Apr 25, 2023
1 parent e31d0c2 commit 34bd157
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lldb/packages/Python/lldbsuite/test/lldbutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down

0 comments on commit 34bd157

Please sign in to comment.