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.
This commit is contained in:
Jim Ingham 2020-02-07 17:48:47 -08:00
parent 84eeee6580
commit d62a343db2
1 changed files with 76 additions and 8 deletions

View File

@ -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 @@ from lldbsuite.test import lldbutil
import six
class ListenToModuleLoadedEvents (TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
def test_receiving_breakpoint_added(self):
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")
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 @@ class ListenToModuleLoadedEvents (TestBase):
"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 @@ class ListenToModuleLoadedEvents (TestBase):
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(
not event.IsValid(),
"We don't get events we aren't listening to.")
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(
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.")