Skip to content

Commit da97b8d

Browse files
committed
[lldb][RISCV] add function calls tests
Function calls support in LLDB expressions for RISCV: 6 of 6 Adds tests on function calls inside lldb expressions
1 parent 00bce99 commit da97b8d

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-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: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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_expr("func_with_ptr_arg(\"message\")", result_type="int", result_value="2")
36+
37+
@skipIf(archs=no_match(["rv64gc"]))
38+
def test_ptr_ret_val(self):
39+
self.common_setup()
40+
self.expect("expr func_with_ptr_return()", substrs=["global"])
41+
42+
@skipIf(archs=no_match(["rv64gc"]))
43+
def test_ptr(self):
44+
self.common_setup()
45+
self.expect(
46+
"expr func_with_ptr(\"message\")",
47+
substrs=["message"],
48+
)
49+
50+
@skipIf(archs=no_match(["rv64gc"]))
51+
def test_global_ptr(self):
52+
self.common_setup()
53+
self.expect(
54+
"expr func_with_ptr(g_str)",
55+
substrs=["global"],
56+
)
57+
58+
@skipIf(archs=no_match(["rv64gc"]))
59+
def test_struct_arg(self):
60+
self.common_setup()
61+
self.expect_expr("func_with_struct_arg(s)", result_type="int", result_value="3")
62+
63+
@skipIf(archs=no_match(["rv64gc"]))
64+
def test_unsupported_struct_arg(self):
65+
self.common_setup()
66+
self.expect(
67+
"expr func_with_unsupported_struct_arg(u)",
68+
error=True,
69+
substrs=["Architecture passes failure on function $__lldb_expr"],
70+
)
71+
72+
@skipIf(archs=no_match(["rv64gc"]))
73+
def test_double_ret_val(self):
74+
self.common_setup()
75+
76+
self.expect(
77+
"expr func_with_double_return()",
78+
error=True,
79+
substrs=["Architecture passes failure on function $__lldb_expr"],
80+
)
81+
82+
@skipIf(archs=no_match(["rv64gc"]))
83+
def test_struct_return(self):
84+
self.common_setup()
85+
self.expect_expr("func_with_struct_return()", result_type="S")
86+
87+
@skipIf(archs=no_match(["rv64gc"]))
88+
def test_ptr_ret_val(self):
89+
self.common_setup()
90+
self.expect(
91+
"expr func_with_unsupported_struct_return()",
92+
error=True,
93+
substrs=["Architecture passes failure on function $__lldb_expr"],
94+
)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
char *g_str = "global";
14+
15+
int func_with_double_arg(int a, double b) { return 1; }
16+
17+
int func_with_ptr_arg(char *msg) { return 2; }
18+
char *func_with_ptr_return() { return g_str; }
19+
char *func_with_ptr(char *msg) { return msg; }
20+
21+
int func_with_struct_arg(struct S s) { return 3; }
22+
23+
int func_with_unsupported_struct_arg(struct U u) { return 4; }
24+
25+
double func_with_double_return() { return 42.0; }
26+
27+
struct S func_with_struct_return() {
28+
struct S s = {3, 4};
29+
return s;
30+
}
31+
32+
struct U func_with_unsupported_struct_return() {
33+
struct U u = {3, 42.0};
34+
return u;
35+
}
36+
37+
int foo() { return 3; }
38+
39+
int foo(int a) { return a; }
40+
41+
int foo(int a, int b) { return a + b; }
42+
43+
int main() {
44+
struct S s = {1, 2};
45+
struct U u = {1, 1.0};
46+
double d = func_with_double_arg(1, 1.0) + func_with_struct_arg(s) +
47+
func_with_ptr_arg("msg") + func_with_double_return() +
48+
func_with_unsupported_struct_arg(u) + foo() + foo(1) + foo(1, 2);
49+
char *msg = func_with_ptr("msg");
50+
char *ptr = func_with_ptr_return();
51+
s = func_with_struct_return();
52+
u = func_with_unsupported_struct_return();
53+
return 0; // break here
54+
}

0 commit comments

Comments
 (0)