Skip to content

Commit ce9b4d3

Browse files
authored
Merge pull request #6469 from augusto2112/test-stepping-backward-interop
[lldb] Add Swift/C++ backward interop stepping tests
2 parents f625fac + 12b4e92 commit ce9b4d3

File tree

4 files changed

+335
-0
lines changed

4 files changed

+335
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SWIFT_CXX_HEADER := swift-types.h
2+
SWIFT_SOURCES := swift-types.swift
3+
CXX_SOURCES := main.cpp
4+
SWIFT_CXX_INTEROP := 1
5+
SWIFTFLAGS_EXTRAS = -Xcc -I$(SRCDIR) -parse-as-library
6+
CFLAGS = -I. -g
7+
include Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
2+
"""
3+
Test that Swift types are displayed correctly in C++
4+
"""
5+
from lldbsuite.test.lldbtest import *
6+
from lldbsuite.test.decorators import *
7+
8+
9+
class TestSwiftSteppingBackwardInterop(TestBase):
10+
11+
def setup(self, bkpt_str):
12+
self.build()
13+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
14+
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
15+
self, bkpt_str, lldb.SBFileSpec('main.cpp'))
16+
return thread
17+
18+
19+
def check_step_in(self, thread, caller, callee):
20+
name = thread.frames[0].GetFunctionName()
21+
self.assertIn(caller, name)
22+
thread.StepInto()
23+
name = thread.frames[0].GetFunctionName()
24+
self.assertIn(callee, name)
25+
thread.StepOut()
26+
name = thread.frames[0].GetFunctionName()
27+
self.assertIn(caller, name)
28+
29+
def check_step_over(self, thread, func):
30+
name = thread.frames[0].GetFunctionName()
31+
self.assertIn(func, name)
32+
thread.StepOver()
33+
name = thread.frames[0].GetFunctionName()
34+
self.assertIn(func, name)
35+
36+
@swiftTest
37+
def test_func_step_in(self):
38+
thread = self.setup('Break here for func')
39+
self.check_step_in(thread, 'testFunc', 'swiftFunc')
40+
41+
@swiftTest
42+
def test_func_step_over(self):
43+
thread = self.setup('Break here for func')
44+
self.check_step_over(thread, 'testFunc')
45+
46+
@swiftTest
47+
def test_method_step_in_class(self):
48+
thread = self.setup('Break here for method - class')
49+
self.check_step_in(thread, 'testMethod', 'SwiftClass.swiftMethod')
50+
51+
@swiftTest
52+
def test_method_step_over_class(self):
53+
thread = self.setup('Break here for method - class')
54+
self.check_step_over(thread, 'testMethod')
55+
56+
@expectedFailureAll(bugnumber="rdar://106670255")
57+
@swiftTest
58+
def test_init_step_in_class(self):
59+
thread = self.setup('Break here for constructor - class')
60+
self.check_step_in(thread, 'testConstructor', 'SwiftClass.init')
61+
62+
@swiftTest
63+
def test_init_step_over_class(self):
64+
thread = self.setup('Break here for constructor - class')
65+
self.check_step_over(thread, 'testConstructor')
66+
67+
@swiftTest
68+
def test_static_method_step_in_class(self):
69+
thread = self.setup('Break here for static method - class')
70+
self.check_step_in(thread, 'testStaticMethod', 'SwiftClass.swiftStaticMethod')
71+
72+
@swiftTest
73+
def test_static_method_step_over_class(self):
74+
thread = self.setup('Break here for static method - class')
75+
self.check_step_over(thread, 'testStaticMethod')
76+
77+
@swiftTest
78+
def test_getter_step_in_class(self):
79+
thread = self.setup('Break here for getter - class')
80+
self.check_step_in(thread, 'testGetter', 'SwiftClass.swiftProperty.getter')
81+
82+
@swiftTest
83+
def test_getter_step_over_class(self):
84+
thread = self.setup('Break here for getter - class')
85+
self.check_step_over(thread, 'testGetter')
86+
87+
@swiftTest
88+
def test_setter_step_in_class(self):
89+
thread = self.setup('Break here for setter - class')
90+
self.check_step_in(thread, 'testSetter', 'SwiftClass.swiftProperty.setter')
91+
92+
@swiftTest
93+
def test_setter_step_over_class(self):
94+
thread = self.setup('Break here for setter - class')
95+
self.check_step_over(thread, 'testSetter')
96+
97+
98+
@swiftTest
99+
def test_overriden_step_in_class(self):
100+
thread = self.setup('Break here for overridden - class')
101+
self.check_step_in(thread, 'testOverridenMethod', 'SwiftSubclass.overrideableMethod')
102+
103+
@swiftTest
104+
def test_overriden_step_over_class(self):
105+
thread = self.setup('Break here for overridden')
106+
self.check_step_over(thread, 'testOverridenMethod')
107+
108+
@swiftTest
109+
def test_method_step_in_struct_class(self):
110+
thread = self.setup('Break here for method - struct')
111+
self.check_step_in(thread, 'testMethod', 'SwiftStruct.swiftMethod')
112+
113+
@swiftTest
114+
def test_method_step_over_struct_class(self):
115+
thread = self.setup('Break here for method - struct')
116+
self.check_step_over(thread, 'testMethod')
117+
118+
@expectedFailureAll(bugnumber="rdar://106670255")
119+
@swiftTest
120+
def test_init_step_in_struct_class(self):
121+
thread = self.setup('Break here for constructor - struct')
122+
self.check_step_in(thread, 'testConstructor', 'SwiftStruct.init')
123+
124+
@swiftTest
125+
def test_init_step_over_struct_class(self):
126+
thread = self.setup('Break here for constructor - struct')
127+
self.check_step_over(thread, 'testConstructor')
128+
129+
@swiftTest
130+
def test_static_method_step_in_struct(self):
131+
thread = self.setup('Break here for static method - struct')
132+
self.check_step_in(thread, 'testStaticMethod', 'SwiftStruct.swiftStaticMethod')
133+
134+
@swiftTest
135+
def test_static_method_step_over_struct(self):
136+
thread = self.setup('Break here for static method - struct')
137+
self.check_step_over(thread, 'testStaticMethod')
138+
139+
@swiftTest
140+
def test_getter_step_in_struct(self):
141+
thread = self.setup('Break here for getter - struct')
142+
self.check_step_in(thread, 'testGetter', 'SwiftStruct.swiftProperty.getter')
143+
144+
@swiftTest
145+
def test_getter_step_over_struct(self):
146+
thread = self.setup('Break here for getter - struct')
147+
self.check_step_over(thread, 'testGetter')
148+
149+
@swiftTest
150+
def test_setter_step_in_struct(self):
151+
thread = self.setup('Break here for setter - struct')
152+
self.check_step_in(thread, 'testSetter', 'SwiftStruct.swiftProperty.setter')
153+
154+
@swiftTest
155+
def test_setter_step_over_struct(self):
156+
thread = self.setup('Break here for setter - struct')
157+
self.check_step_over(thread, 'testSetter')
158+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include "swift-types.h"
2+
3+
using namespace a;
4+
5+
int testFunc() {
6+
swiftFunc(); // Break here for func
7+
return 0;
8+
}
9+
10+
int testMethodClass() {
11+
auto swiftClass = SwiftClass::init();
12+
swiftClass.swiftMethod(); // Break here for method - class
13+
return 0;
14+
}
15+
16+
int testConstructorClass() {
17+
auto swiftClass = SwiftClass::init(); // Break here for constructor - class
18+
return 0;
19+
}
20+
21+
int testStaticMethodClass() {
22+
SwiftClass::swiftStaticMethod(); // Break here for static method - class
23+
return 0;
24+
}
25+
26+
int testGetterClass() {
27+
auto swiftClass = SwiftClass::init();
28+
swiftClass.getSwiftProperty(); // Break here for getter - class
29+
return 0;
30+
}
31+
32+
int testSetterClass() {
33+
auto swiftClass = SwiftClass::init();
34+
auto str = getString();
35+
swiftClass.setSwiftProperty(str); // Break here for setter - class
36+
return 0;
37+
}
38+
39+
int testOverridenMethodClass() {
40+
auto swiftClass = SwiftSubclass::init();
41+
swiftClass.overrideableMethod(); // Break here for overridden - class
42+
return 0;
43+
}
44+
45+
void testClass() {
46+
testMethodClass();
47+
testConstructorClass();
48+
testStaticMethodClass();
49+
testGetterClass();
50+
testSetterClass();
51+
testOverridenMethodClass();
52+
}
53+
54+
55+
int testMethodStruct() {
56+
auto swiftStruct = SwiftStruct::init();
57+
swiftStruct.swiftMethod(); // Break here for method - struct
58+
return 0;
59+
}
60+
61+
int testConstructorStruct() {
62+
auto swiftStruct = SwiftStruct::init(); // Break here for constructor - struct
63+
return 0;
64+
}
65+
66+
int testStaticMethodStruct() {
67+
SwiftStruct::swiftStaticMethod(); // Break here for static method - struct
68+
return 0;
69+
}
70+
71+
int testGetterStruct() {
72+
auto swiftStruct = SwiftStruct::init();
73+
swiftStruct.getSwiftProperty(); // Break here for getter - struct
74+
return 0;
75+
}
76+
77+
int testSetterStruct() {
78+
auto swiftStruct = SwiftStruct::init();
79+
auto str = getString();
80+
swiftStruct.setSwiftProperty(str); // Break here for setter - struct
81+
return 0;
82+
}
83+
84+
void testStruct() {
85+
testMethodStruct();
86+
testConstructorStruct();
87+
testStaticMethodStruct();
88+
testGetterStruct();
89+
testSetterStruct();
90+
}
91+
92+
int main() {
93+
testFunc();
94+
testClass();
95+
testStruct();
96+
return 0;
97+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
public func swiftFunc() {
3+
print("Inside a Swift function!")
4+
}
5+
6+
public class SwiftClass {
7+
var field: Int
8+
var arr: [String]
9+
public init() {
10+
field = 42
11+
arr = ["An", "array", "of", "strings"]
12+
}
13+
14+
public func swiftMethod() {
15+
print("Inside a Swift method!")
16+
}
17+
18+
private var _desc = "This is a class with properties!"
19+
public var swiftProperty: String {
20+
get {
21+
return _desc
22+
}
23+
set {
24+
_desc = newValue
25+
}
26+
}
27+
28+
public static func swiftStaticMethod() {
29+
print("In a Swift static method!")
30+
}
31+
32+
public func overrideableMethod() {
33+
print("In the base class!")
34+
}
35+
}
36+
37+
public class SwiftSubclass: SwiftClass {
38+
public override func overrideableMethod() {
39+
print("In subclass!")
40+
}
41+
}
42+
43+
public class SwiftStruct {
44+
var field: Int
45+
var arr: [String]
46+
public init() {
47+
field = 42
48+
arr = ["An", "array", "of", "strings"]
49+
}
50+
51+
public func swiftMethod() {
52+
print("Inside a Swift method!")
53+
}
54+
55+
private var _desc = "This is a class with properties!"
56+
public var swiftProperty: String {
57+
get {
58+
return _desc
59+
}
60+
set {
61+
_desc = newValue
62+
}
63+
}
64+
65+
public static func swiftStaticMethod() {
66+
print("In a Swift static method!")
67+
}
68+
}
69+
70+
public func getString() -> String {
71+
return "A brand new string!";
72+
}
73+

0 commit comments

Comments
 (0)