Skip to content

Commit 1bd67e3

Browse files
[lldb] Add test for stepping through conformance methods
1 parent 6b7dae2 commit 1bd67e3

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
7+
@skipIf(oslist=["windows", "linux"])
8+
class TestSwiftSteppingThroughWitness(TestBase):
9+
10+
def setUp(self):
11+
TestBase.setUp(self)
12+
self.runCmd(
13+
"settings set target.process.thread.step-avoid-libraries libswift_Concurrency.dylib"
14+
)
15+
16+
@swiftTest
17+
def test_step_in_and_out(self):
18+
"""Test that stepping in and out of protocol methods work"""
19+
self.build()
20+
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
21+
self, "break here", lldb.SBFileSpec("main.swift")
22+
)
23+
24+
thread.StepInto()
25+
stop_reason = thread.GetStopReason()
26+
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
27+
28+
frame0 = thread.frames[0]
29+
frame1 = thread.frames[1]
30+
self.assertIn("SlowRandomNumberGenerator.random", frame0.GetFunctionName())
31+
self.assertIn(
32+
"protocol witness for a.RandomNumberGenerator.random",
33+
frame1.GetFunctionName(),
34+
)
35+
36+
thread.StepOut()
37+
stop_reason = thread.GetStopReason()
38+
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
39+
frame0 = thread.frames[0]
40+
self.assertIn("doMath", frame0.GetFunctionName())
41+
42+
@swiftTest
43+
def test_step_over(self):
44+
"""Test that stepping over protocol methods work"""
45+
self.build()
46+
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
47+
self, "break here", lldb.SBFileSpec("main.swift")
48+
)
49+
50+
thread.StepOver()
51+
stop_reason = thread.GetStopReason()
52+
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
53+
frame0 = thread.frames[0]
54+
self.assertIn("doMath", frame0.GetFunctionName())
55+
56+
line_entry = frame0.GetLineEntry()
57+
self.assertEqual(14, line_entry.GetLine())
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
protocol RandomNumberGenerator {
2+
func random(in range: ClosedRange<Int>) async -> Int
3+
}
4+
5+
class SlowRandomNumberGenerator: RandomNumberGenerator {
6+
func random(in range: ClosedRange<Int>) async -> Int {
7+
try? await Task.sleep(for: .milliseconds(500))
8+
return Int.random(in: range)
9+
}
10+
}
11+
12+
func doMath<RNG: RandomNumberGenerator>(with rng: RNG) async {
13+
let y = await rng.random(in: 101...200) // break here
14+
print("Y is \(y)")
15+
}
16+
17+
let rng = SlowRandomNumberGenerator()
18+
await doMath(with: rng)

0 commit comments

Comments
 (0)