blob: f8c3db8e79b74e0618d8660421ef8c09360ddb74 [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
Vince Harron7ac3ea42015-06-26 15:13:21 +000015 @expectedFlakeyLinux # this test fails 1/100 dosep runs
Zachary Turner4a58dd32015-09-16 18:08:33 +000016 @skipIfWindows # Windows doesn't have signals
Todd Fiala9b095782014-06-23 20:56:48 +000017 def test_ignore_signal(self):
18 """Test Python SBUnixSignals.Suppress/Stop/Notify() API."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000019 self.build()
Todd Fiala9b095782014-06-23 20:56:48 +000020 exe = os.path.join(os.getcwd(), "a.out")
21 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
22
23 target = self.dbg.CreateTarget(exe)
24 self.assertTrue(target, VALID_TARGET)
25
26 line = line_number("main.cpp", "// Set break point at this line and setup signal ignores.")
27 breakpoint = target.BreakpointCreateByLocation("main.cpp", line)
28 self.assertTrue(breakpoint, VALID_BREAKPOINT)
29
30 # Launch the process, and do not stop at the entry point.
31 process = target.LaunchSimple (None, None, self.get_process_working_directory())
32
33 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
34 self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint")
35
36 unix_signals = process.GetUnixSignals()
37 sigint = unix_signals.GetSignalNumberFromName("SIGINT")
38 unix_signals.SetShouldSuppress(sigint, True)
39 unix_signals.SetShouldStop(sigint, False)
40 unix_signals.SetShouldNotify(sigint, False)
41
42 process.Continue()
43 self.assertTrue(process.state == lldb.eStateExited, "The process should have exited")
44 self.assertTrue(process.GetExitStatus() == 0, "The process should have returned 0")
45
46
47if __name__ == '__main__':
48 import atexit
49 lldb.SBDebugger.Initialize()
50 atexit.register(lambda: lldb.SBDebugger.Terminate())
51 unittest2.main()