Skip to content

Commit cf7dfb9

Browse files
authored
Merge pull request #2632 from fredriss/async-locals-test
[Swift async] Add a baseline test for arguments and locals in logical frames
2 parents 532ccbc + 38dce71 commit cf7dfb9

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS := -Xfrontend -enable-experimental-concurrency -parse-as-library
3+
include Makefile.rules
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
7+
8+
class TestSwiftAsyncBacktraceLocals(lldbtest.TestBase):
9+
10+
mydir = lldbtest.TestBase.compute_mydir(__file__)
11+
12+
@swiftTest
13+
@skipIf(oslist=['windows', 'linux'])
14+
def test(self):
15+
"""Test async unwind"""
16+
self.build()
17+
src = lldb.SBFileSpec('main.swift')
18+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
19+
self, 'main breakpoint', src)
20+
21+
start_bkpt = target.BreakpointCreateBySourceRegex('function start', src, None)
22+
end_bkpt = target.BreakpointCreateBySourceRegex('end iteration', src, None)
23+
24+
if self.TraceOn():
25+
self.runCmd("bt all")
26+
27+
for n in range(10):
28+
lldbutil.continue_to_breakpoint(process, start_bkpt)
29+
for f in range(n+1):
30+
frame = thread.GetFrameAtIndex(f)
31+
self.assertIn("fibonacci", frame.GetFunctionName(),
32+
"Redundantly confirm that we're stopped in fibonacci()")
33+
if f == 0:
34+
# Get arguments (arguments, locals, statics, in_scope_only)
35+
args = frame.GetVariables(True, False, False, True)
36+
self.assertEqual(len(args), 1, "Found one argument")
37+
self.assertEqual(args[0].GetName(), "n", "Found n argument")
38+
self.assertEqual(args[0].GetValue(), str(10-n), "n has correct value")
39+
self.assertIn("Main.main", thread.GetFrameAtIndex(n+1).GetFunctionName())
40+
41+
lldbutil.continue_to_breakpoint(process, end_bkpt)
42+
frame = thread.GetFrameAtIndex(0)
43+
args = frame.GetVariables(True, False, False, True)
44+
self.assertEqual(len(args), 1, "Found one argument")
45+
self.assertEqual(args[0].GetName(), "n", "Found n argument")
46+
self.assertEqual(args[0].GetValue(), str(1), "n has correct value")
47+
48+
lldbutil.continue_to_breakpoint(process, end_bkpt)
49+
frame = thread.GetFrameAtIndex(0)
50+
args = frame.GetVariables(True, False, False, True)
51+
self.assertEqual(len(args), 1, "Found one argument")
52+
self.assertEqual(args[0].GetName(), "n", "Found n argument")
53+
self.assertEqual(args[0].GetValue(), str(0), "n has correct value")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
func fibonacci(_ n: Int) async -> Int {
2+
if n == 0 || n == 1 { // function start
3+
return n // end iteration
4+
}
5+
let n_1 = await fibonacci(n - 1)
6+
let n_2 = await fibonacci(n - 2)
7+
return n_1 + n_2
8+
}
9+
10+
@main struct Main {
11+
static func main() async {
12+
let n = await fibonacci(10) // main breakpoint
13+
print(n)
14+
}
15+
}

0 commit comments

Comments
 (0)