[Lldb-commits] [lldb] r220113 - Fixed python API event test cases.

Greg Clayton gclayton at apple.com
Fri Oct 17 16:58:27 PDT 2014


Author: gclayton
Date: Fri Oct 17 18:58:27 2014
New Revision: 220113

URL: http://llvm.org/viewvc/llvm-project?rev=220113&view=rev
Log:
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


Modified:
    lldb/trunk/test/python_api/event/TestEvents.py

Modified: lldb/trunk/test/python_api/event/TestEvents.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/event/TestEvents.py?rev=220113&r1=220112&r2=220113&view=diff
==============================================================================
--- lldb/trunk/test/python_api/event/TestEvents.py (original)
+++ lldb/trunk/test/python_api/event/TestEvents.py Fri Oct 17 18:58:27 2014
@@ -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')
 
+        listener = lldb.SBListener("my listener")
+
         # 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)
+        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
 
-        # Get a handle on the process's broadcaster.
-        broadcaster = process.GetBroadcaster()
+        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)
 
+        listener = lldb.SBListener("my listener")
+
         # 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)
-
-        # Get a handle on the process's broadcaster.
-        broadcaster = process.GetBroadcaster()
-        self.assertTrue(broadcaster, "Process with valid broadcaster")
+        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")





More information about the lldb-commits mailing list