Skip to content

Commit 73eb9f8

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 73eb9f8

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
def common_setup(self):
13+
self.build()
14+
lldbutil.run_to_source_breakpoint(
15+
self, "// break here", lldb.SBFileSpec("main.cpp")
16+
)
17+
18+
@skipIf(archs=no_match(["rv64gc"]))
19+
def test_int_arg(self):
20+
self.common_setup()
21+
self.expect_expr("foo(foo(5), foo())", result_type="int", result_value="8")
22+
23+
@skipIf(archs=no_match(["rv64gc"]))
24+
def test_double_arg(self):
25+
self.common_setup()
26+
self.expect(
27+
"expr func_with_double_arg(1, 6.5)",
28+
error=True,
29+
substrs=["Architecture passes failure on function $__lldb_expr"],
30+
)
31+
32+
@skipIf(archs=no_match(["rv64gc"]))
33+
def test_ptr_arg(self):
34+
self.common_setup()
35+
self.expect(
36+
'expr func_with_ptr_arg("bla")',
37+
error=True,
38+
substrs=["Architecture passes failure on function $__lldb_expr"],
39+
)
40+
41+
@skipIf(archs=no_match(["rv64gc"]))
42+
def test_struct_arg(self):
43+
self.common_setup()
44+
self.expect_expr("func_with_struct_arg(s)", result_type="int", result_value="3")
45+
46+
@skipIf(archs=no_match(["rv64gc"]))
47+
def test_unsupported_struct_arg(self):
48+
self.common_setup()
49+
self.expect(
50+
"expr func_with_unsupported_struct_arg(u)",
51+
error=True,
52+
substrs=["Architecture passes failure on function $__lldb_expr"],
53+
)
54+
55+
@skipIf(archs=no_match(["rv64gc"]))
56+
def test_double_ret_val(self):
57+
self.common_setup()
58+
59+
self.expect(
60+
"expr func_with_double_return()",
61+
error=True,
62+
substrs=["Architecture passes failure on function $__lldb_expr"],
63+
)
64+
65+
@skipIf(archs=no_match(["rv64gc"]))
66+
def test_ptr_ret_val(self):
67+
self.common_setup()
68+
self.expect(
69+
"expr func_with_ptr_return()",
70+
error=True,
71+
substrs=["Architecture passes failure on function $__lldb_expr"],
72+
)
73+
74+
@skipIf(archs=no_match(["rv64gc"]))
75+
def test_struct_return(self):
76+
self.common_setup()
77+
self.expect_expr("func_with_struct_return()", result_type="S")
78+
79+
@skipIf(archs=no_match(["rv64gc"]))
80+
def test_ptr_ret_val(self):
81+
self.common_setup()
82+
self.expect(
83+
"expr func_with_unsupported_struct_return()",
84+
error=True,
85+
substrs=["Architecture passes failure on function $__lldb_expr"],
86+
)
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)