Skip to content

Commit fa269ce

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 122fafb commit fa269ce

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-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: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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_expr(
27+
"func_with_double_arg(1, 6.5)", result_type="int", result_value="1"
28+
)
29+
30+
@skipIf(archs=no_match(["rv64gc"]))
31+
def test_ptr_arg(self):
32+
self.common_setup()
33+
self.expect_expr(
34+
'func_with_ptr_arg("message")', result_type="int", result_value="2"
35+
)
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(
62+
"func_with_struct_arg(s)", result_type="int", result_value="110"
63+
)
64+
65+
@skipIf(archs=no_match(["rv64gc"]))
66+
def test_unsupported_struct_arg(self):
67+
self.common_setup()
68+
self.expect_expr(
69+
"func_with_double_struct_arg(u)", result_type="int", result_value="400"
70+
)
71+
72+
@skipIf(archs=no_match(["rv64gc"]))
73+
def test_double_ret_val(self):
74+
self.common_setup()
75+
self.expect_expr(
76+
"func_with_double_return()", result_type="double", result_value="42"
77+
)
78+
79+
@skipIf(archs=no_match(["rv64gc"]))
80+
def test_struct_return(self):
81+
self.common_setup()
82+
self.expect_expr("func_with_struct_return()", result_type="S")
83+
84+
@skipIf(archs=no_match(["rv64gc"]))
85+
def test_struct_double_ret_val(self):
86+
self.common_setup()
87+
self.expect_expr("func_with_double_struct_return()", result_type="U")
88+
89+
@skipIf(archs=no_match(["rv64gc"]))
90+
def test_float_arg(self):
91+
self.common_setup()
92+
self.expect_expr(
93+
"func_with_float_arg(9.99, 8.88)", result_type="int", result_value="7"
94+
)
95+
96+
@skipIf(archs=no_match(["rv64gc"]))
97+
def test_float_ret_val(self):
98+
self.common_setup()
99+
self.expect_expr(
100+
"func_with_float_ret_val()", result_type="float", result_value="8"
101+
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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_float_arg(float a, float b) { return 7; }
18+
float func_with_float_ret_val() { return 8.0f; }
19+
20+
int func_with_ptr_arg(char *msg) { return 2; }
21+
char *func_with_ptr_return() { return g_str; }
22+
char *func_with_ptr(char *msg) { return msg; }
23+
24+
int func_with_struct_arg(S s) { return s.a + s.b; }
25+
26+
int func_with_double_struct_arg(U u) { return u.a * 3 + 31; }
27+
28+
double func_with_double_return() { return 42.0; }
29+
30+
S func_with_struct_return() {
31+
S s = {123, 4};
32+
return s;
33+
}
34+
35+
U func_with_double_struct_return() {
36+
U u = {123, 42.0};
37+
return u;
38+
}
39+
40+
int foo() { return 3; }
41+
42+
int foo(int a) { return a; }
43+
44+
int foo(int a, int b) { return a + b; }
45+
46+
int main() {
47+
S s{11, 99};
48+
U u{123, 7.7};
49+
50+
double d = func_with_double_arg(1, 1.0) + func_with_struct_arg(S{1, 2}) +
51+
func_with_ptr_arg("msg") + func_with_double_return() +
52+
func_with_double_struct_arg(U{1, 1.0}) + foo() + foo(1) +
53+
foo(1, 2) + func_with_float_arg(5.42, 7.86) +
54+
func_with_float_ret_val();
55+
56+
char *msg = func_with_ptr("msg");
57+
char *ptr = func_with_ptr_return();
58+
59+
S s_s = func_with_struct_return();
60+
U s_u = func_with_double_struct_return(); // break here
61+
62+
return 0;
63+
}

0 commit comments

Comments
 (0)