Skip to content

Commit 3ad75f0

Browse files
committed
[lldb][RISCV] add function calls tests
Function calls support in LLDB expressions for RISCV: 5 of 5 Adds tests on function calls inside lldb expressions
1 parent c4db74e commit 3ad75f0

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""
2+
Test RISC-V expressions evaluation.
3+
"""
4+
5+
import lldb
6+
from lldbsuite.test.decorators import *
7+
from lldbsuite.test.lldbtest import *
8+
from lldbsuite.test import lldbutil
9+
10+
11+
class TestExpressions(TestBase):
12+
13+
def common_setup(self):
14+
self.build()
15+
lldbutil.run_to_source_breakpoint(
16+
self, "// break here", lldb.SBFileSpec("main.cpp")
17+
)
18+
19+
@skipIf(archs=no_match(["rv64gc"]))
20+
def test_int_arg(self):
21+
self.common_setup()
22+
self.expect_expr("foo(foo(5), foo())", result_type="int", result_value="8")
23+
24+
@skipIf(archs=no_match(["rv64gc"]))
25+
def test_double_arg(self):
26+
self.common_setup()
27+
self.expect(
28+
"expr func_with_double_arg(1, 6.5)",
29+
error=True,
30+
substrs=["Architecture passes failure on function $__lldb_expr"],
31+
)
32+
33+
@skipIf(archs=no_match(["rv64gc"]))
34+
def test_ptr_arg(self):
35+
self.common_setup()
36+
self.expect(
37+
"expr func_with_ptr_arg(\"bla\")",
38+
error=True,
39+
substrs=["Architecture passes failure on function $__lldb_expr"],
40+
)
41+
42+
@skipIf(archs=no_match(["rv64gc"]))
43+
def test_struct_arg(self):
44+
self.common_setup()
45+
self.expect_expr("func_with_struct_arg(s)", result_type="int", result_value="3")
46+
47+
@skipIf(archs=no_match(["rv64gc"]))
48+
def test_unsupported_struct_arg(self):
49+
self.common_setup()
50+
self.expect(
51+
"expr func_with_unsupported_struct_arg(u)",
52+
error=True,
53+
substrs=["Architecture passes failure on function $__lldb_expr"],
54+
)
55+
56+
@skipIf(archs=no_match(["rv64gc"]))
57+
def test_double_ret_val(self):
58+
self.common_setup()
59+
60+
self.expect(
61+
"expr func_with_double_return()",
62+
error=True,
63+
substrs=["Architecture passes failure on function $__lldb_expr"],
64+
)
65+
66+
@skipIf(archs=no_match(["rv64gc"]))
67+
def test_ptr_ret_val(self):
68+
self.common_setup()
69+
self.expect(
70+
"expr func_with_ptr_return()",
71+
error=True,
72+
substrs=["Architecture passes failure on function $__lldb_expr"],
73+
)
74+
75+
@skipIf(archs=no_match(["rv64gc"]))
76+
def test_struct_return(self):
77+
self.common_setup()
78+
self.expect_expr("func_with_struct_return()", result_type="S")
79+
80+
@skipIf(archs=no_match(["rv64gc"]))
81+
def test_ptr_ret_val(self):
82+
self.common_setup()
83+
self.expect(
84+
"expr func_with_unsupported_struct_return()",
85+
error=True,
86+
substrs=["Architecture passes failure on function $__lldb_expr"],
87+
)
88+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
struct S {
2+
int a;
3+
int b;
4+
};
5+
6+
struct U {
7+
int a;
8+
double d;
9+
};
10+
11+
int g;
12+
13+
int func_with_double_arg(int a, double b) { return 1; }
14+
15+
int func_with_ptr_arg(char *msg) { return 2; }
16+
17+
int func_with_struct_arg(struct S s) { return 3; }
18+
19+
int func_with_unsupported_struct_arg(struct U u) { return 4; }
20+
21+
double func_with_double_return() { return 42.0; }
22+
23+
int *func_with_ptr_return() { return &g; }
24+
25+
struct S func_with_struct_return() {
26+
struct S s = {3, 4};
27+
return s;
28+
}
29+
30+
struct U func_with_unsupported_struct_return() {
31+
struct U u = {3, 42.0};
32+
return u;
33+
}
34+
35+
int foo() { return 3; }
36+
37+
int foo(int a) { return a; }
38+
39+
int foo(int a, int b) { return a + b; }
40+
41+
int main() {
42+
struct S s = {1, 2};
43+
struct U u = {1, 1.0};
44+
double d = func_with_double_arg(1, 1.0) + func_with_ptr_arg("msg") +
45+
func_with_struct_arg(s) + func_with_double_return() +
46+
func_with_unsupported_struct_arg(u) + foo() + foo(1) + foo(1, 2);
47+
int *ptr = func_with_ptr_return();
48+
s = func_with_struct_return();
49+
u = func_with_unsupported_struct_return();
50+
return 0; // break here
51+
}

0 commit comments

Comments
 (0)