]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/tools/lldb-mi/target/TestMiTarget.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / tools / lldb-mi / target / TestMiTarget.py
1 """
2 Test lldb-mi -target-xxx commands.
3 """
4
5 from __future__ import print_function
6
7 import lldbmi_testcase
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
11
12 class MiTargetTestCase(lldbmi_testcase.MiTestCaseBase):
13
14     mydir = TestBase.compute_mydir(__file__)
15
16     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
17     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
18     @skipIfLinux # cannot attach to process on linux
19     def test_lldbmi_target_attach_wait_for(self):
20         """Test that 'lldb-mi --interpreter' works for -target-attach -n <name> --waitfor."""
21            
22         # Build target executable with unique name
23         exeName = self.testMethodName
24         d = {'EXE': exeName}
25         self.buildProgram("test_attach.cpp", exeName)
26         self.addTearDownCleanup(dictionary=d)
27         
28         self.spawnLldbMi(args = None)
29         
30         # Load executable
31         # FIXME: -file-exec-and-sybmols is not required for target attach, but the test will not pass without this
32         self.runCmd("-file-exec-and-symbols %s" % exeName)
33         self.expect("\^done")
34         
35         # Set up attach
36         self.runCmd("-target-attach -n %s --waitfor" % exeName)
37         time.sleep(4) # Give attach time to setup
38               
39         # Start target process
40         self.spawnSubprocess(os.path.join(os.path.dirname(__file__), exeName));
41         self.addTearDownHook(self.cleanupSubprocesses)
42         self.expect("\^done")
43         
44         # Set breakpoint on printf
45         line = line_number('test_attach.cpp', '// BP_i++')
46         self.runCmd("-break-insert -f test_attach.cpp:%d" % line)
47         self.expect("\^done,bkpt={number=\"1\"")
48         
49         # Continue to breakpoint
50         self.runCmd("-exec-continue")
51         self.expect("\*stopped,reason=\"breakpoint-hit\"")
52         
53         # Detach
54         self.runCmd("-target-detach")
55         self.expect("\^done")
56         
57     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
58     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
59     @skipIfLinux # cannot attach to process on linux
60     def test_lldbmi_target_attach_name(self):
61         """Test that 'lldb-mi --interpreter' works for -target-attach -n <name>."""
62            
63         # Build target executable with unique name
64         exeName = self.testMethodName
65         d = {'EXE': exeName}
66         self.buildProgram("test_attach.cpp", exeName)
67         self.addTearDownCleanup(dictionary=d)
68         
69         # Start target process
70         targetProcess = self.spawnSubprocess(os.path.join(os.path.dirname(__file__), exeName));
71         self.addTearDownHook(self.cleanupSubprocesses)
72         
73         self.spawnLldbMi(args = None)
74         
75         # Set up atatch
76         self.runCmd("-target-attach -n %s" % exeName)
77         self.expect("\^done")
78         
79         # Set breakpoint on printf
80         line = line_number('test_attach.cpp', '// BP_i++')
81         self.runCmd("-break-insert -f test_attach.cpp:%d" % line)
82         self.expect("\^done,bkpt={number=\"1\"")
83         
84         # Continue to breakpoint
85         self.runCmd("-exec-continue")
86         self.expect("\*stopped,reason=\"breakpoint-hit\"")
87         
88         # Detach
89         self.runCmd("-target-detach")
90         self.expect("\^done")
91         
92     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
93     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
94     @skipIfLinux # cannot attach to process on linux
95     def test_lldbmi_target_attach_pid(self):
96         """Test that 'lldb-mi --interpreter' works for -target-attach <pid>."""
97            
98         # Build target executable with unique name
99         exeName = self.testMethodName
100         d = {'EXE': exeName}
101         self.buildProgram("test_attach.cpp", exeName)
102         self.addTearDownCleanup(dictionary=d)
103         
104         # Start target process
105         targetProcess = self.spawnSubprocess(os.path.join(os.path.dirname(__file__), exeName));
106         self.addTearDownHook(self.cleanupSubprocesses)
107         
108         self.spawnLldbMi(args = None)
109         
110         # Set up atatch
111         self.runCmd("-target-attach %d" % targetProcess.pid)
112         self.expect("\^done")
113         
114         # Set breakpoint on printf
115         line = line_number('test_attach.cpp', '// BP_i++')
116         self.runCmd("-break-insert -f test_attach.cpp:%d" % line)
117         self.expect("\^done,bkpt={number=\"1\"")
118         
119         # Continue to breakpoint
120         self.runCmd("-exec-continue")
121         self.expect("\*stopped,reason=\"breakpoint-hit\"")
122         
123         # Detach
124         self.runCmd("-target-detach")
125         self.expect("\^done")