forked from OSchip/llvm-project
Fixed python API event test cases.
Issues were: 1 - It isn't good to have more than one listener for the process events, just supply a listener at launch instead of making a one then have the process broadcaster add a new listener 2 - run in async mode llvm-svn: 220113
This commit is contained in:
parent
9b3d7366d4
commit
a6cffdecde
|
@ -67,6 +67,8 @@ class EventAPITestCase(TestBase):
|
|||
"""Create a listener and use SBEvent API to print the events received."""
|
||||
exe = os.path.join(os.getcwd(), "a.out")
|
||||
|
||||
self.dbg.SetAsync(True)
|
||||
|
||||
# Create a target by the debugger.
|
||||
target = self.dbg.CreateTarget(exe)
|
||||
self.assertTrue(target, VALID_TARGET)
|
||||
|
@ -74,22 +76,26 @@ class EventAPITestCase(TestBase):
|
|||
# Now create a breakpoint on main.c by name 'c'.
|
||||
breakpoint = target.BreakpointCreateByName('c', 'a.out')
|
||||
|
||||
# Now launch the process, and do not stop at the entry point.
|
||||
process = target.LaunchSimple (None, None, self.get_process_working_directory())
|
||||
self.assertTrue(process.GetState() == lldb.eStateStopped,
|
||||
PROCESS_STOPPED)
|
||||
listener = lldb.SBListener("my listener")
|
||||
|
||||
# Get a handle on the process's broadcaster.
|
||||
broadcaster = process.GetBroadcaster()
|
||||
# Now launch the process, and do not stop at the entry point.
|
||||
error = lldb.SBError()
|
||||
process = target.Launch (listener,
|
||||
None, # argv
|
||||
None, # envp
|
||||
None, # stdin_path
|
||||
None, # stdout_path
|
||||
None, # stderr_path
|
||||
None, # working directory
|
||||
0, # launch flags
|
||||
False, # Stop at entry
|
||||
error) # error
|
||||
|
||||
self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED)
|
||||
|
||||
# Create an empty event object.
|
||||
event = lldb.SBEvent()
|
||||
|
||||
# Create a listener object and register with the broadcaster.
|
||||
listener = lldb.SBListener("my listener")
|
||||
rc = broadcaster.AddListener(listener, lldb.SBProcess.eBroadcastBitStateChanged)
|
||||
self.assertTrue(rc, "AddListener successfully retruns")
|
||||
|
||||
traceOn = self.TraceOn()
|
||||
if traceOn:
|
||||
lldbutil.print_stacktraces(process)
|
||||
|
@ -104,10 +110,7 @@ class EventAPITestCase(TestBase):
|
|||
while not count > 3:
|
||||
if traceOn:
|
||||
print "Try wait for event..."
|
||||
if listener.WaitForEventForBroadcasterWithType(5,
|
||||
broadcaster,
|
||||
lldb.SBProcess.eBroadcastBitStateChanged,
|
||||
event):
|
||||
if listener.WaitForEvent(5, event):
|
||||
if traceOn:
|
||||
desc = lldbutil.get_description(event)
|
||||
print "Event description:", desc
|
||||
|
@ -139,6 +142,8 @@ class EventAPITestCase(TestBase):
|
|||
"""Get the listener associated with the debugger and exercise WaitForEvent API."""
|
||||
exe = os.path.join(os.getcwd(), "a.out")
|
||||
|
||||
self.dbg.SetAsync(True)
|
||||
|
||||
# Create a target by the debugger.
|
||||
target = self.dbg.CreateTarget(exe)
|
||||
self.assertTrue(target, VALID_TARGET)
|
||||
|
@ -155,13 +160,18 @@ class EventAPITestCase(TestBase):
|
|||
|
||||
# Now launch the process, and do not stop at entry point.
|
||||
error = lldb.SBError()
|
||||
process = target.Launch (listener, None, None, None, None, None, None, 0, False, error)
|
||||
process = target.Launch (listener,
|
||||
None, # argv
|
||||
None, # envp
|
||||
None, # stdin_path
|
||||
None, # stdout_path
|
||||
None, # stderr_path
|
||||
None, # working directory
|
||||
0, # launch flags
|
||||
False, # Stop at entry
|
||||
error) # error
|
||||
self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
|
||||
|
||||
# Get a handle on the process's broadcaster.
|
||||
broadcaster = process.GetBroadcaster()
|
||||
self.assertTrue(broadcaster, "Process with valid broadcaster")
|
||||
|
||||
# Create an empty event object.
|
||||
event = lldb.SBEvent()
|
||||
self.assertFalse(event, "Event should not be valid initially")
|
||||
|
@ -201,6 +211,8 @@ class EventAPITestCase(TestBase):
|
|||
"""Get the broadcaster associated with the process and wait for broadcaster events."""
|
||||
exe = os.path.join(os.getcwd(), "a.out")
|
||||
|
||||
self.dbg.SetAsync(True)
|
||||
|
||||
# Create a target by the debugger.
|
||||
target = self.dbg.CreateTarget(exe)
|
||||
self.assertTrue(target, VALID_TARGET)
|
||||
|
@ -212,23 +224,25 @@ class EventAPITestCase(TestBase):
|
|||
breakpoint.GetNumLocations() == 1,
|
||||
VALID_BREAKPOINT)
|
||||
|
||||
# Now launch the process, and do not stop at the entry point.
|
||||
process = target.LaunchSimple (None, None, self.get_process_working_directory())
|
||||
self.assertTrue(process.GetState() == lldb.eStateStopped,
|
||||
PROCESS_STOPPED)
|
||||
listener = lldb.SBListener("my listener")
|
||||
|
||||
# Get a handle on the process's broadcaster.
|
||||
broadcaster = process.GetBroadcaster()
|
||||
self.assertTrue(broadcaster, "Process with valid broadcaster")
|
||||
# Now launch the process, and do not stop at the entry point.
|
||||
error = lldb.SBError()
|
||||
process = target.Launch (listener,
|
||||
None, # argv
|
||||
None, # envp
|
||||
None, # stdin_path
|
||||
None, # stdout_path
|
||||
None, # stderr_path
|
||||
None, # working directory
|
||||
0, # launch flags
|
||||
False, # Stop at entry
|
||||
error) # error
|
||||
|
||||
# Create an empty event object.
|
||||
event = lldb.SBEvent()
|
||||
self.assertFalse(event, "Event should not be valid initially")
|
||||
|
||||
# Create a listener object and register with the broadcaster.
|
||||
listener = lldb.SBListener("TestEvents.listener")
|
||||
rc = broadcaster.AddListener(listener, lldb.SBProcess.eBroadcastBitStateChanged)
|
||||
self.assertTrue(rc, "AddListener successfully retruns")
|
||||
|
||||
# The finite state machine for our custom listening thread, with an
|
||||
# initail state of 0, which means a "running" event is expected.
|
||||
|
@ -250,10 +264,7 @@ class EventAPITestCase(TestBase):
|
|||
# Let's only try at most 6 times to retrieve our events.
|
||||
count = 0
|
||||
while True:
|
||||
if listener.WaitForEventForBroadcasterWithType(5,
|
||||
broadcaster,
|
||||
lldb.SBProcess.eBroadcastBitStateChanged,
|
||||
event):
|
||||
if listener.WaitForEvent(5, event):
|
||||
desc = lldbutil.get_description(event)
|
||||
#print "Event description:", desc
|
||||
match = pattern.search(desc)
|
||||
|
@ -290,10 +301,6 @@ class EventAPITestCase(TestBase):
|
|||
# Wait until the 'MyListeningThread' terminates.
|
||||
my_thread.join()
|
||||
|
||||
# We are no longer interested in receiving state changed events.
|
||||
# Remove our custom listener before the inferior is killed.
|
||||
broadcaster.RemoveListener(listener, lldb.SBProcess.eBroadcastBitStateChanged)
|
||||
|
||||
# The final judgement. :-)
|
||||
self.assertTrue(self.state == 2,
|
||||
"Both expected state changed events received")
|
||||
|
|
Loading…
Reference in New Issue