diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py --- a/lldb/packages/Python/lldbsuite/test/lldbutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py @@ -1619,3 +1619,51 @@ expect_dylib_info_response = True return dylib_info + +# ================================================== +# Utility functions to setup a progress event listener +# ================================================== + +import threading + +class ProgressEventListener: + + eBroadcastBitStopProgressThread = (1 << 0) + + progress_events = [] + + def __fetch_events__(self): + event = lldb.SBEvent() + + done = False + while not done: + if self.listener.WaitForEvent(1, event): + event_mask = event.GetType(); + if event.BroadcasterMatchesRef(self.broadcaster): + if event_mask & self.eBroadcastBitStopProgressThread: + done = True; + elif event.BroadcasterMatchesRef(self.src_broadcaster): + ret_args = lldb.SBDebugger().GetProgressFromEvent(event); + if not len(ret_args): + continue + + message = ret_args[0] + if message: + self.progress_events.append((message, event)) + + def start(self, src_broadcaster, event_mask, callback=self.__fetch_events__): + self.src_broadcaster = src_broadcaster + self.broadcaster = lldb.SBBroadcaster('lldb.progress.broadcaster') + self.listener = lldb.SBListener("lldb.progress.listener") + self.listener.StartListeningForEvents(self.test_broadcaster, + self.eBroadcastBitStopProgressThread) + + src_broadcaster.AddListener(self.listener, event_mask) + + self.listener_thread = threading.Thread(target=callback) + self.listener_thread.start() + + def stop(self): + self.broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread) + self.listener_thread.join() + return self.progress_events diff --git a/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py b/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py --- a/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py +++ b/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py @@ -5,54 +5,23 @@ from lldbsuite.test.lldbtest import * from lldbsuite.test.decorators import * import lldbsuite.test.lldbutil as lldbutil -import threading class TestProgressReporting(TestBase): mydir = TestBase.compute_mydir(__file__) - eBroadcastBitStopProgressThread = (1 << 0) - def setUp(self): TestBase.setUp(self) - self.progress_events = [] - - def fetch_events(self): - event = lldb.SBEvent() - - done = False - while not done: - if self.listener.WaitForEvent(1, event): - event_mask = event.GetType(); - if event.BroadcasterMatchesRef(self.test_broadcaster): - if event_mask & self.eBroadcastBitStopProgressThread: - done = True; - elif event.BroadcasterMatchesRef(self.progress_broadcaster): - ret_args = lldb.SBDebugger().GetProgressFromEvent(event); - self.assertGreater(len(ret_args), 1) - - message = ret_args[0] - if message: - self.progress_events.append((message, event)) def test_dwarf_symbol_loading_progress_report(self): """Test that we are able to fetch dwarf symbol loading progress events""" self.build() - self.listener = lldb.SBListener("lldb.progress.listener") - self.test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test') - self.listener.StartListeningForEvents(self.test_broadcaster, - self.eBroadcastBitStopProgressThread) - - self.progress_broadcaster = self.dbg.GetBroadcaster() - self.progress_broadcaster.AddListener(self.listener, lldb.SBDebugger.eBroadcastBitProgress) - - listener_thread = threading.Thread(target=self.fetch_events) - listener_thread.start() + progress_events_listener = lldbutil.ProgressEventListener() + progress_events_listener.start(self.dbg.GetBroadcaster(), + lldb.SBDebugger.eBroadcastBitProgress) lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c')) - self.test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread) - listener_thread.join() - - self.assertGreater(len(self.progress_events), 0) + progress_events = progress_events_listener.stop() + self.assertGreater(len(progress_events), 0)