Skip to content

Commit af865ac

Browse files
authored
Merge pull request #6497 from augusto2112/test-expr-eval-forward-interop
[lldb] Add forward interop expression evaluation tests
2 parents fed6b8c + 0ef6679 commit af865ac

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFT_CXX_INTEROP := 1
3+
SWIFTFLAGS_EXTRAS = -Xcc -I$(SRCDIR)
4+
include Makefile.rules
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
"""
3+
Test that evaluating expressions works on forward interop mode.
4+
"""
5+
from lldbsuite.test.lldbtest import *
6+
from lldbsuite.test.decorators import *
7+
8+
9+
class TestSwiftForwardInteropExpressions(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.swift'))
16+
return thread
17+
18+
@expectedFailureAll(oslist=["linux"], bugnumber="rdar://106871422")
19+
@skipIf(setting=('symbols.use-swift-clangimporter', 'false')) # rdar://106871275
20+
@swiftTest
21+
def test(self):
22+
self.setup('Break here')
23+
24+
# Check that we can call free functions.
25+
self.expect('expr returnsInt()', substrs=['Int32', '42'])
26+
27+
# Check that we can call unused free functions.
28+
self.expect('expr returnsIntUnused()', substrs=['Int32', '37'])
29+
30+
# Check that we can call a C++ constructor.
31+
self.expect('expr CxxClass()', substrs=['CxxClass', 'a = 100', 'b = 101'])
32+
33+
# Check that we can call methods.
34+
self.expect('expr cxxClass.sum()', substrs=['Int32', '201'])
35+
36+
# Check that we can access a C++ type's ivars
37+
self.expect('expr cxxClass.a', substrs=['Int32', '100'])
38+
self.expect('expr cxxSubclass.a', substrs=['Int32', '100'])
39+
self.expect('expr cxxSubclass.c', substrs=['Int32', '102'])
40+
41+
# Check that calling a function that throws an exception fails on expression evaluation
42+
self.expect('expr throwException()', substrs=['internal c++ exception breakpoint'], error=True)
43+
44+
# Check that we can make persistent variables.
45+
self.expect('expr var $cxxClass = CxxClass()')
46+
47+
# Check that we can refer to the persistent variable.
48+
self.expect('expr $cxxClass', substrs=['CxxClass', 'a = 100', 'b = 101'])
49+
50+
# Check that we can call methods on the persistent variable.
51+
self.expect('expr $cxxClass.sum()', substrs=['Int32', '201'])
52+
53+
# Check that po prints the fields of a base class
54+
self.expect('po cxxClass', substrs=['CxxClass', 'a : 100', 'b : 101'])
55+
56+
@expectedFailureAll(bugnumber="rdar://106216567")
57+
@swiftTest
58+
def test_po_subclass(self):
59+
self.setup('Break here')
60+
61+
self.expect('po CxxSubclass()', substrs=['CxxClass', 'a : 100', 'b : 101', 'c : 102'])
62+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ReturnsClass
2+
3+
func main() {
4+
_ = returnsInt();
5+
var cxxClass = CxxClass();
6+
var cxxSubclass = CxxSubclass();
7+
print(1) // Break here
8+
}
9+
10+
main()
11+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module ReturnsClass {
2+
header "returns-class.h"
3+
requires cplusplus
4+
}
5+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
3+
int returnsInt() {
4+
return 42;
5+
}
6+
7+
int returnsIntUnused() {
8+
return 37;
9+
}
10+
11+
void throwException() {
12+
throw "Division by zero condition!";
13+
}
14+
15+
struct CxxClass {
16+
int a = 100;
17+
int b = 101;
18+
19+
int sum() {
20+
return a + b;
21+
}
22+
};
23+
24+
struct CxxSubclass: public CxxClass {
25+
int c = 102;
26+
};
27+
28+
29+

0 commit comments

Comments
 (0)