Skip to content

Commit fddb994

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

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
@swiftTest
10+
def test_step_in_and_out(self):
11+
"""Test that stepping in and out of protocol methods work"""
12+
self.build()
13+
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
14+
self, "break here", lldb.SBFileSpec("main.swift")
15+
)
16+
17+
thread.StepInto()
18+
stop_reason = thread.GetStopReason()
19+
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
20+
21+
frame0 = thread.frames[0]
22+
frame1 = thread.frames[1]
23+
self.assertIn("SlowRandomNumberGenerator.random", frame0.GetFunctionName())
24+
self.assertIn(
25+
"protocol witness for a.RandomNumberGenerator.random",
26+
frame1.GetFunctionName(),
27+
)
28+
29+
thread.StepOut()
30+
stop_reason = thread.GetStopReason()
31+
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
32+
frame0 = thread.frames[0]
33+
self.assertIn("doMath", frame0.GetFunctionName())
34+
35+
@swiftTest
36+
def test_step_over(self):
37+
"""Test that stepping over protocol methods work"""
38+
self.build()
39+
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
40+
self, "break here", lldb.SBFileSpec("main.swift")
41+
)
42+
43+
thread.StepOver()
44+
stop_reason = thread.GetStopReason()
45+
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
46+
frame0 = thread.frames[0]
47+
self.assertIn("doMath", frame0.GetFunctionName())
48+
49+
line_entry = frame0.GetLineEntry()
50+
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)