blob: fd2c820622d030f47b40f83d3e2f7158259a6bc9 [file] [log] [blame]
Todd Fiala9b095782014-06-23 20:56:48 +00001"""
2Test SBProcess APIs, including ReadMemory(), WriteMemory(), and others.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbutil import get_stopped_thread, state_type_to_str
9from lldbtest import *
10
11class SignalsAPITestCase(TestBase):
Greg Clayton4184c792014-08-01 22:10:13 +000012 mydir = TestBase.compute_mydir(__file__)
Todd Fiala9b095782014-06-23 20:56:48 +000013
14 @python_api_test
15 def test_ignore_signal(self):
16 """Test Python SBUnixSignals.Suppress/Stop/Notify() API."""
17 self.buildDefault()
18 exe = os.path.join(os.getcwd(), "a.out")
19 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
20
21 target = self.dbg.CreateTarget(exe)
22 self.assertTrue(target, VALID_TARGET)
23
24 line = line_number("main.cpp", "// Set break point at this line and setup signal ignores.")
25 breakpoint = target.BreakpointCreateByLocation("main.cpp", line)
26 self.assertTrue(breakpoint, VALID_BREAKPOINT)
27
28 # Launch the process, and do not stop at the entry point.
29 process = target.LaunchSimple (None, None, self.get_process_working_directory())
30
31 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
32 self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint")
33
34 unix_signals = process.GetUnixSignals()
35 sigint = unix_signals.GetSignalNumberFromName("SIGINT")
36 unix_signals.SetShouldSuppress(sigint, True)
37 unix_signals.SetShouldStop(sigint, False)
38 unix_signals.SetShouldNotify(sigint, False)
39
40 process.Continue()
41 self.assertTrue(process.state == lldb.eStateExited, "The process should have exited")
42 self.assertTrue(process.GetExitStatus() == 0, "The process should have returned 0")
43
44
45if __name__ == '__main__':
46 import atexit
47 lldb.SBDebugger.Initialize()
48 atexit.register(lambda: lldb.SBDebugger.Terminate())
49 unittest2.main()