blob: 8d05d3771fdd675e3df70b6dbb52ca6e37a55d8f [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
Todd Fiala9b095782014-06-23 20:56:48 +000016 def test_ignore_signal(self):
17 """Test Python SBUnixSignals.Suppress/Stop/Notify() API."""
18 self.buildDefault()
19 exe = os.path.join(os.getcwd(), "a.out")
20 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
21
22 target = self.dbg.CreateTarget(exe)
23 self.assertTrue(target, VALID_TARGET)
24
25 line = line_number("main.cpp", "// Set break point at this line and setup signal ignores.")
26 breakpoint = target.BreakpointCreateByLocation("main.cpp", line)
27 self.assertTrue(breakpoint, VALID_BREAKPOINT)
28
29 # Launch the process, and do not stop at the entry point.
30 process = target.LaunchSimple (None, None, self.get_process_working_directory())
31
32 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
33 self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint")
34
35 unix_signals = process.GetUnixSignals()
36 sigint = unix_signals.GetSignalNumberFromName("SIGINT")
37 unix_signals.SetShouldSuppress(sigint, True)
38 unix_signals.SetShouldStop(sigint, False)
39 unix_signals.SetShouldNotify(sigint, False)
40
41 process.Continue()
42 self.assertTrue(process.state == lldb.eStateExited, "The process should have exited")
43 self.assertTrue(process.GetExitStatus() == 0, "The process should have returned 0")
44
45
46if __name__ == '__main__':
47 import atexit
48 lldb.SBDebugger.Initialize()
49 atexit.register(lambda: lldb.SBDebugger.Terminate())
50 unittest2.main()