aboutsummaryrefslogtreecommitdiff
path: root/lldb/packages/Python/lldbsuite/test/lldbutil.py
diff options
context:
space:
mode:
authorMed Ismail Bennani <medismail.bennani@gmail.com>2022-03-23 12:29:47 -0700
committerMed Ismail Bennani <medismail.bennani@gmail.com>2022-03-23 12:30:09 -0700
commit9216baf87d887b75d114e9621cf2ccfa0f19a386 (patch)
tree6b9cfe0192a5062262c3b5c05882b1531aaf8ca5 /lldb/packages/Python/lldbsuite/test/lldbutil.py
parent52f323d0f1a45001c9be65ac42a48d902b903752 (diff)
downloadllvm-9216baf87d887b75d114e9621cf2ccfa0f19a386.zip
llvm-9216baf87d887b75d114e9621cf2ccfa0f19a386.tar.gz
llvm-9216baf87d887b75d114e9621cf2ccfa0f19a386.tar.bz2
[lldb/test] Add events listener helper function to lldbtest
This patch introduces 2 new lldb utility functions: - lldbutil.start_listening_from: This can be called in the test setup to create a listener and set it up for a specific event mask and add it to the user-provided broadcaster's list. - lldbutil.fetch_next_event: This will use fetch a single event from the provided istener and return it if it matches the provided broadcaster. The motivation behind this is to easily test new kinds of events (i.e. Swift type-system progress events). However, this patch also updates `TestProgressReporting.py` and `TestDiagnosticReporting.py` to make use of these new helper functions. Differential Revision: https://reviews.llvm.org/D122193 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/lldbutil.py')
-rw-r--r--lldb/packages/Python/lldbsuite/test/lldbutil.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index 117c624..af2c41d 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1255,6 +1255,29 @@ def expect_state_changes(test, listener, process, states, timeout=30):
lldb.SBProcess.GetStateFromEvent(event),
expected_state)
+def start_listening_from(broadcaster, event_mask):
+ """Creates a listener for a specific event mask and add it to the source broadcaster."""
+
+ listener = lldb.SBListener("lldb.test.listener")
+ broadcaster.AddListener(listener, event_mask)
+ return listener
+
+def fetch_next_event(test, listener, broadcaster, 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
+
+ test.fail("received event '%s' from unexpected broadcaster '%s'." %
+ (event.GetDescription(), event.GetBroadcaster().GetName()))
+
+ test.fail("couldn't fetch an event before reaching the timeout.")
+
+
# ===================================
# Utility functions related to Frames
# ===================================