forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 337
/
Copy pathTestSwiftTaskSelect.py
79 lines (66 loc) · 2.8 KB
/
TestSwiftTaskSelect.py
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
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import TestBase
import lldbsuite.test.lldbutil as lldbutil
class TestCase(TestBase):
def test_backtrace_selected_task_variable(self):
self.build()
lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
)
self.do_backtrace_selected_task("task")
def test_backtrace_selected_task_address(self):
self.build()
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
)
frame = thread.frames[0]
task = frame.FindVariable("task")
task_addr = task.GetChildMemberWithName("address").unsigned
self.do_backtrace_selected_task(task_addr)
def do_backtrace_selected_task(self, arg):
self.runCmd(f"task select {arg}")
self.expect(
"thread backtrace",
substrs=[
".sleep(",
"`second() at main.swift:6:",
"`first() at main.swift:2:",
"`closure #1 in static Main.main() at main.swift:12:",
],
)
def test_navigate_stack_of_selected_task_variable(self):
self.build()
_, process, thread, _ = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
)
self.do_test_navigate_selected_task_stack(process, "task")
def test_navigate_stack_of_selected_task_address(self):
self.build()
_, process, thread, _ = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
)
frame = thread.frames[0]
task = frame.FindVariable("task")
task_addr = task.GetChildMemberWithName("address").unsigned
self.do_test_navigate_selected_task_stack(process, task_addr)
def do_test_navigate_selected_task_stack(self, process, arg):
self.runCmd(f"task select {arg}")
thread = process.GetSelectedThread()
self.assertIn(
"libswift_Concurrency.", thread.GetSelectedFrame().module.file.basename
)
frame_idx = -1
for frame in thread:
if "`second()" in str(frame):
frame_idx = frame.idx
self.assertNotEqual(frame_idx, -1)
self.expect(f"frame select {frame_idx}", substrs=[f"frame #{frame_idx}:"])
frame = thread.GetSelectedFrame()
self.assertIn(".second()", frame.function.name)
self.expect("up", substrs=[f"frame #{frame_idx + 1}:"])
frame = thread.GetSelectedFrame()
self.assertIn(".first()", frame.function.name)
self.expect("up", substrs=[f"frame #{frame_idx + 2}:"])
frame = thread.GetSelectedFrame()
self.assertIn(".Main.main()", frame.function.name)