[Lldb-commits] [lldb] r116467 - in /lldb/trunk: source/Interpreter/CommandInterpreter.cpp test/lldbtest.py test/signal/TestSendSignal.py

Johnny Chen johnny.chen at apple.com
Wed Oct 13 18:22:04 PDT 2010


Author: johnny
Date: Wed Oct 13 20:22:03 2010
New Revision: 116467

URL: http://llvm.org/viewvc/llvm-project?rev=116467&view=rev
Log:
Add an initial version of test that exercise the lldb commands: 'process signal'
and 'process handle'.  The test suite would like to control the asynch/sync
execution of the interpreter during the middle of the test method, so the
CommandInterpreter::SetSynchronous(bool value) is modified to allow the mode to
be changed more than once.

In practice, it would be advisable to control the process and to set the
async/sync mode from a single thread, too.

Added:
    lldb/trunk/test/signal/TestSendSignal.py
Modified:
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp
    lldb/trunk/test/lldbtest.py

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=116467&r1=116466&r2=116467&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed Oct 13 20:22:03 2010
@@ -1107,12 +1107,7 @@
 void
 CommandInterpreter::SetSynchronous (bool value)
 {
-    static bool value_set_once = false;
-    if (!value_set_once)
-    {
-        value_set_once = true;
-        m_synchronous_execution  = value;
-    }
+    m_synchronous_execution  = value;
 }
 
 void

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=116467&r1=116466&r2=116467&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Wed Oct 13 20:22:03 2010
@@ -150,6 +150,8 @@
 
 STOPPED_DUE_TO_BREAKPOINT = "Process state is stopped due to breakpoint"
 
+STOPPED_DUE_TO_SIGNAL = "Process state is stopped due to signal"
+
 STOPPED_DUE_TO_STEP_IN = "Process state is stopped due to step in"
 
 DATA_TYPES_DISPLAYED_CORRECTLY = "Data type(s) displayed correctly"

Added: lldb/trunk/test/signal/TestSendSignal.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/signal/TestSendSignal.py?rev=116467&view=auto
==============================================================================
--- lldb/trunk/test/signal/TestSendSignal.py (added)
+++ lldb/trunk/test/signal/TestSendSignal.py Wed Oct 13 20:22:03 2010
@@ -0,0 +1,76 @@
+"""Test that lldb command 'process signal SIGUSR1' to send a signal to the inferior works."""
+
+import os, time, signal
+import unittest2
+import lldb
+from lldbtest import *
+
+class SendSignalTestCase(TestBase):
+
+    mydir = "signal"
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_with_dsym_and_run_command(self):
+        """Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process."""
+        self.buildDsym()
+        self.send_signal()
+
+    def test_with_dwarf_and_run_command(self):
+        """Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process."""
+        self.buildDwarf()
+        self.send_signal()
+
+    def setUp(self):
+        super(SendSignalTestCase, self).setUp()
+        # Find the line number to break inside main().
+        self.line = line_number('main.c', 'Put breakpoint here')
+
+    def send_signal(self):
+        """Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process."""
+
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        # Break inside the main() function and immediately send a signal to the inferior after resuming.
+        self.expect("breakpoint set -f main.c -l %d" % self.line,
+                    BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
+                        self.line)
+
+        self.runCmd("run", RUN_SUCCEEDED)
+        self.runCmd("thread backtrac")
+
+        # The stop reason of the thread should be breakpoint.
+        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+            substrs = ['state is Stopped',
+                       'stop reason = breakpoint'])
+
+        # The breakpoint should have a hit count of 1.
+        self.expect("breakpoint list", BREAKPOINT_HIT_ONCE,
+            substrs = [' resolved, hit count = 1'])
+
+        self.runCmd("process status")
+        output = self.res.GetOutput()
+        pid = re.match("Process (.*) Stopped", output).group(1)
+
+        # After resuming the process, immediately send a SIGUSR1 signal.
+        self.dbg.SetAsync(True)
+        self.runCmd("process continue")
+        self.runCmd("process handle -n False -p True -s True SIGUSR1")
+        #os.kill(int(pid), signal.SIGUSR1)
+        self.runCmd("process signal SIGUSR1")
+
+        time.sleep(1)
+        self.dbg.SetAsync(False)
+        self.expect("process status", STOPPED_DUE_TO_SIGNAL,
+            startstr = "Process %s Stopped" % pid,
+            substrs = ['stop reason = signal SIGUSR1'])
+        self.expect("thread backtrace", STOPPED_DUE_TO_SIGNAL,
+            substrs = ['stop reason = signal SIGUSR1'])
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()





More information about the lldb-commits mailing list