summaryrefslogtreecommitdiffstats
path: root/lldb/test/signal/TestSendSignal.py
blob: 8748de0b2ab253f52254ec1243ea6fb8df0bc65a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""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):
        # Call super's setUp().
        TestBase.setUp(self)
        # 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 backtrace")

        # 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 -f", 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, send it a SIGUSR1 signal.

        # It is necessary at this point to make command interpreter interaction
        # be asynchronous, because we want to resume the process and to send it
        # a signal.
        self.dbg.SetAsync(True)
        self.runCmd("process continue")
        # Insert a delay of 1 second before doing the signaling stuffs.
        time.sleep(1)

        self.runCmd("process handle -n False -p True -s True SIGUSR1")
        #os.kill(int(pid), signal.SIGUSR1)
        self.runCmd("process signal SIGUSR1")

        # Insert a delay of 1 second before checking the process status.
        time.sleep(1)
        # Make the interaction mode be synchronous again.
        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()
OpenPOWER on IntegriCloud