mib created this revision. mib added reviewers: bulbazord, jingham. mib added a project: LLDB. Herald added a subscriber: JDevlieghere. Herald added a project: All. mib requested review of this revision. Herald added a subscriber: lldb-commits.
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. Signed-off-by: Med Ismail Bennani <medismail.benn...@gmail.com> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D149175 Files: lldb/packages/Python/lldbsuite/test/lldbutil.py Index: lldb/packages/Python/lldbsuite/test/lldbutil.py =================================================================== --- lldb/packages/Python/lldbsuite/test/lldbutil.py +++ lldb/packages/Python/lldbsuite/test/lldbutil.py @@ -1202,18 +1202,24 @@ 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. 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.")
Index: lldb/packages/Python/lldbsuite/test/lldbutil.py =================================================================== --- lldb/packages/Python/lldbsuite/test/lldbutil.py +++ lldb/packages/Python/lldbsuite/test/lldbutil.py @@ -1202,18 +1202,24 @@ 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. 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.")
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits