[Lldb-commits] [lldb] r233670 - Fix TestSendSignal.py for remote.

Chaoren Lin chaorenl at google.com
Mon Mar 30 21:26:34 PDT 2015


Author: chaoren
Date: Mon Mar 30 23:26:34 2015
New Revision: 233670

URL: http://llvm.org/viewvc/llvm-project?rev=233670&view=rev
Log:
Fix TestSendSignal.py for remote.

Summary: There is an extra eStateConnected before eStateRunning with remote.

Reviewers: clayborg, ovyalov

Reviewed By: clayborg, ovyalov

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D8714

Modified:
    lldb/trunk/test/functionalities/signal/TestSendSignal.py

Modified: lldb/trunk/test/functionalities/signal/TestSendSignal.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/signal/TestSendSignal.py?rev=233670&r1=233669&r2=233670&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/signal/TestSendSignal.py (original)
+++ lldb/trunk/test/functionalities/signal/TestSendSignal.py Mon Mar 30 23:26:34 2015
@@ -6,6 +6,7 @@ import lldb
 from lldbtest import *
 import lldbutil
 
+
 class SendSignalTestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
@@ -29,6 +30,19 @@ class SendSignalTestCase(TestBase):
         # Find the line number to break inside main().
         self.line = line_number('main.c', 'Put breakpoint here')
 
+    def match_state(self, process_listener, expected_state):
+        num_seconds = 5
+        broadcaster = self.process().GetBroadcaster()
+        event_type_mask = lldb.SBProcess.eBroadcastBitStateChanged
+        event = lldb.SBEvent()
+        got_event = process_listener.WaitForEventForBroadcasterWithType(
+            num_seconds, broadcaster, event_type_mask, event)
+        self.assertTrue(got_event, "Got an event")
+        state = lldb.SBProcess.GetStateFromEvent(event)
+        self.assertTrue(state == expected_state,
+                        "It was the %s state." %
+                        lldb.SBDebugger_StateAsCString(expected_state))
+
     def send_signal(self):
         """Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process."""
 
@@ -39,7 +53,7 @@ class SendSignalTestCase(TestBase):
         self.assertTrue(target, VALID_TARGET)
 
         # Now create a breakpoint on main.c by name 'c'.
-        breakpoint = target.BreakpointCreateByLocation ('main.c', self.line)
+        breakpoint = target.BreakpointCreateByLocation('main.c', self.line)
         self.assertTrue(breakpoint and
                         breakpoint.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
@@ -54,11 +68,11 @@ class SendSignalTestCase(TestBase):
         # Now launch the process, no arguments & do not stop at entry point.
         launch_info = lldb.SBLaunchInfo([exe])
         launch_info.SetWorkingDirectory(self.get_process_working_directory())
-        
+
         process_listener = lldb.SBListener("signal_test_listener")
         launch_info.SetListener(process_listener)
         error = lldb.SBError()
-        process = target.Launch (launch_info, error)
+        process = target.Launch(launch_info, error)
         self.assertTrue(process, PROCESS_IS_VALID)
 
         self.runCmd("process handle -n False -p True -s True SIGUSR1")
@@ -70,8 +84,6 @@ class SendSignalTestCase(TestBase):
 
         self.setAsync(True)
 
-        broadcaster = process.GetBroadcaster()
-
         self.assertTrue(process_listener.IsValid(), "Got a good process listener")
 
         # Disable our breakpoint, we don't want to hit it anymore...
@@ -80,28 +92,24 @@ class SendSignalTestCase(TestBase):
         # Now continue:
         process.Continue()
 
-        event = lldb.SBEvent()
-        got_event = process_listener.WaitForEventForBroadcasterWithType(5, broadcaster, lldb.SBProcess.eBroadcastBitStateChanged, event)
-        event_type = lldb.SBProcess.GetStateFromEvent(event)
-        self.assertTrue (got_event, "Got an event")
-        self.assertTrue (event_type == lldb.eStateRunning, "It was the running event.")
-        
+        # If running remote test, there should be a connected event
+        if lldb.remote_platform:
+            self.match_state(process_listener, lldb.eStateConnected)
+
+        self.match_state(process_listener, lldb.eStateRunning)
+
         # Now signal the process, and make sure it stops:
         process.Signal(signal.SIGUSR1)
 
-        got_event = process_listener.WaitForEventForBroadcasterWithType(5, broadcaster, lldb.SBProcess.eBroadcastBitStateChanged, event)
+        self.match_state(process_listener, lldb.eStateStopped)
 
-        event_type = lldb.SBProcess.GetStateFromEvent(event)
-        self.assertTrue (got_event, "Got an event")
-        self.assertTrue (event_type == lldb.eStateStopped, "It was the stopped event.")
-        
         # Now make sure the thread was stopped with a SIGUSR1:
-        threads = lldbutil.get_stopped_threads (process, lldb.eStopReasonSignal)
-        self.assertTrue (len(threads) == 1, "One thread stopped for a signal.")
+        threads = lldbutil.get_stopped_threads(process, lldb.eStopReasonSignal)
+        self.assertTrue(len(threads) == 1, "One thread stopped for a signal.")
         thread = threads[0]
 
-        self.assertTrue (thread.GetStopReasonDataCount() >= 1, "There was data in the event.")
-        self.assertTrue (thread.GetStopReasonDataAtIndex(0) == signal.SIGUSR1, "The stop signal was SIGUSR1")
+        self.assertTrue(thread.GetStopReasonDataCount() >= 1, "There was data in the event.")
+        self.assertTrue(thread.GetStopReasonDataAtIndex(0) == signal.SIGUSR1, "The stop signal was SIGUSR1")
 
 if __name__ == '__main__':
     import atexit





More information about the lldb-commits mailing list