[Lldb-commits] [lldb] d62a343 - Add a test for adding and removing Listeners from a BroadcasterManager.
Jim Ingham via lldb-commits
lldb-commits at lists.llvm.org
Fri Feb 7 17:54:35 PST 2020
Author: Jim Ingham
Date: 2020-02-07T17:54:25-08:00
New Revision: d62a343db23b7e8c3b5f2a0284bcacc10141a49e
URL: https://github.com/llvm/llvm-project/commit/d62a343db23b7e8c3b5f2a0284bcacc10141a49e
DIFF: https://github.com/llvm/llvm-project/commit/d62a343db23b7e8c3b5f2a0284bcacc10141a49e.diff
LOG: Add a test for adding and removing Listeners from a BroadcasterManager.
Reid found a bug in removing Listeners from a BroadcasterManager:
https://reviews.llvm.org/D74010
The bug didn't affect the case where there was only one Listener
signed up for a BroadcasterManager, which was all the extant test
case tests. The driver also only uses one listener (the debugger)
for everything, so neither the test nor anything you do with lldb
command line would have triggered the bug.
This adds a couple more tests using more listeners, and adding and
removing them in a different way, which triggers a separate code path.
Added:
Modified:
lldb/packages/Python/lldbsuite/test/api/listeners/TestListener.py
Removed:
################################################################################
diff --git a/lldb/packages/Python/lldbsuite/test/api/listeners/TestListener.py b/lldb/packages/Python/lldbsuite/test/api/listeners/TestListener.py
index 480041b3e1fc..a71ced961c05 100644
--- a/lldb/packages/Python/lldbsuite/test/api/listeners/TestListener.py
+++ b/lldb/packages/Python/lldbsuite/test/api/listeners/TestListener.py
@@ -2,8 +2,6 @@
Test that we can listen to modules loaded events.
"""
-
-
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
@@ -11,12 +9,45 @@
import six
-
class ListenToModuleLoadedEvents (TestBase):
mydir = TestBase.compute_mydir(__file__)
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def test_clearing_listener(self):
+ """Make sure we also clear listerers from the hook up for event type manager"""
+ self.build()
+
+ my_first_listener = lldb.SBListener("bonus_listener")
+ my_listener = lldb.SBListener("test_listener")
+ my_third_listener = lldb.SBListener("extra_bonus_listener")
- def test_receiving_breakpoint_added(self):
+ my_listener.StartListeningForEventClass(
+ self.dbg,
+ lldb.SBTarget.GetBroadcasterClassName(),
+ lldb.SBTarget.eBroadcastBitBreakpointChanged)
+ my_first_listener.StartListeningForEventClass(
+ self.dbg,
+ lldb.SBTarget.GetBroadcasterClassName(),
+ lldb.SBTarget.eBroadcastBitWatchpointChanged)
+ my_third_listener.StartListeningForEventClass(
+ self.dbg,
+ lldb.SBTarget.GetBroadcasterClassName(),
+ lldb.SBTarget.eBroadcastBitModulesUnloaded)
+
+ exe = self.getBuildArtifact("a.out")
+
+ my_listener.Clear()
+
+ target = self.dbg.CreateTarget(exe)
+
+ bkpt = target.BreakpointCreateByName("main")
+
+ event = lldb.SBEvent()
+ my_listener.WaitForEvent(1, event)
+ self.assertTrue(not event.IsValid(), "We don't get events we aren't listening to.")
+
+ def test_receiving_breakpoint_added_from_debugger(self):
"""Test that we get breakpoint added events, waiting on event classes on the debugger"""
self.build()
@@ -47,7 +78,6 @@ def test_receiving_breakpoint_added(self):
"It is our breakpoint.")
# Now make sure if we stop listening for events we don't get them:
-
my_listener.StopListeningForEventClass(
self.dbg,
lldb.SBTarget.GetBroadcasterClassName(),
@@ -55,9 +85,47 @@ def test_receiving_breakpoint_added(self):
my_listener.StopListeningForEvents(
target.GetBroadcaster(),
lldb.SBTarget.eBroadcastBitBreakpointChanged)
-
+
bkpt2 = target.BreakpointCreateByName("main")
my_listener.WaitForEvent(1, event)
+ self.assertTrue(not event.IsValid(), "We don't get events we aren't listening to.")
+
+ def test_recieving_breakpoint_added_from_target(self):
+ """Test that we get breakpoint added events, waiting on event classes on the debugger"""
+ self.build()
+
+ my_listener = lldb.SBListener("test_listener")
+ my_listener.StartListeningForEventClass(
+ self.dbg,
+ lldb.SBTarget.GetBroadcasterClassName(),
+ lldb.SBTarget.eBroadcastBitBreakpointChanged)
+
+ exe = self.getBuildArtifact("a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ result = target.GetBroadcaster().AddListener(my_listener,
+ lldb.SBTarget.eBroadcastBitBreakpointChanged)
+ self.assertEqual(result, lldb.SBTarget.eBroadcastBitBreakpointChanged,"Got our bit")
+
+ bkpt = target.BreakpointCreateByName("main")
+
+ event = lldb.SBEvent()
+ my_listener.WaitForEvent(1, event)
+
+ self.assertTrue(event.IsValid(), "Got a valid event.")
+ self.assertTrue(
+ lldb.SBBreakpoint.EventIsBreakpointEvent(event),
+ "It is a breakpoint event.")
+ self.assertTrue(lldb.SBBreakpoint.GetBreakpointEventTypeFromEvent(
+ event) == lldb.eBreakpointEventTypeAdded, "It is a breakpoint added event.")
self.assertTrue(
- not event.IsValid(),
- "We don't get events we aren't listening to.")
+ bkpt == lldb.SBBreakpoint.GetBreakpointFromEvent(event),
+ "It is our breakpoint.")
+
+ # Now make sure if we stop listening for events we don't get them:
+ target.GetBroadcaster().RemoveListener(my_listener)
+
+ bkpt2 = target.BreakpointCreateByName("main")
+ my_listener.WaitForEvent(1, event)
+ self.assertTrue(not event.IsValid(), "We don't get events we aren't listening to.")
+
More information about the lldb-commits
mailing list