Skip to content

Commit

Permalink
[lldb][RISCV] add function calls tests
Browse files Browse the repository at this point in the history
Function calls support in LLDB expressions for RISCV: 6 of 6

Adds tests on function calls inside lldb expressions
  • Loading branch information
dlav-sc committed Sep 2, 2024
1 parent 00bce99 commit da97b8d
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lldb/test/API/riscv/expressions/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CXX_SOURCES := main.cpp

include Makefile.rules
94 changes: 94 additions & 0 deletions lldb/test/API/riscv/expressions/TestExpressions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"""
Test RISC-V expressions evaluation.
"""

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestExpressions(TestBase):
def common_setup(self):
self.build()
lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.cpp")
)

@skipIf(archs=no_match(["rv64gc"]))
def test_int_arg(self):
self.common_setup()
self.expect_expr("foo(foo(5), foo())", result_type="int", result_value="8")

@skipIf(archs=no_match(["rv64gc"]))
def test_double_arg(self):
self.common_setup()
self.expect(
"expr func_with_double_arg(1, 6.5)",
error=True,
substrs=["Architecture passes failure on function $__lldb_expr"],
)

@skipIf(archs=no_match(["rv64gc"]))
def test_ptr_arg(self):
self.common_setup()
self.expect_expr("func_with_ptr_arg(\"message\")", result_type="int", result_value="2")

@skipIf(archs=no_match(["rv64gc"]))
def test_ptr_ret_val(self):
self.common_setup()
self.expect("expr func_with_ptr_return()", substrs=["global"])

@skipIf(archs=no_match(["rv64gc"]))
def test_ptr(self):
self.common_setup()
self.expect(
"expr func_with_ptr(\"message\")",
substrs=["message"],
)

@skipIf(archs=no_match(["rv64gc"]))
def test_global_ptr(self):
self.common_setup()
self.expect(
"expr func_with_ptr(g_str)",
substrs=["global"],
)

@skipIf(archs=no_match(["rv64gc"]))
def test_struct_arg(self):
self.common_setup()
self.expect_expr("func_with_struct_arg(s)", result_type="int", result_value="3")

@skipIf(archs=no_match(["rv64gc"]))
def test_unsupported_struct_arg(self):
self.common_setup()
self.expect(
"expr func_with_unsupported_struct_arg(u)",
error=True,
substrs=["Architecture passes failure on function $__lldb_expr"],
)

@skipIf(archs=no_match(["rv64gc"]))
def test_double_ret_val(self):
self.common_setup()

self.expect(
"expr func_with_double_return()",
error=True,
substrs=["Architecture passes failure on function $__lldb_expr"],
)

@skipIf(archs=no_match(["rv64gc"]))
def test_struct_return(self):
self.common_setup()
self.expect_expr("func_with_struct_return()", result_type="S")

@skipIf(archs=no_match(["rv64gc"]))
def test_ptr_ret_val(self):
self.common_setup()
self.expect(
"expr func_with_unsupported_struct_return()",
error=True,
substrs=["Architecture passes failure on function $__lldb_expr"],
)
54 changes: 54 additions & 0 deletions lldb/test/API/riscv/expressions/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
struct S {
int a;
int b;
};

struct U {
int a;
double d;
};

int g;

char *g_str = "global";

int func_with_double_arg(int a, double b) { return 1; }

int func_with_ptr_arg(char *msg) { return 2; }
char *func_with_ptr_return() { return g_str; }
char *func_with_ptr(char *msg) { return msg; }

int func_with_struct_arg(struct S s) { return 3; }

int func_with_unsupported_struct_arg(struct U u) { return 4; }

double func_with_double_return() { return 42.0; }

struct S func_with_struct_return() {
struct S s = {3, 4};
return s;
}

struct U func_with_unsupported_struct_return() {
struct U u = {3, 42.0};
return u;
}

int foo() { return 3; }

int foo(int a) { return a; }

int foo(int a, int b) { return a + b; }

int main() {
struct S s = {1, 2};
struct U u = {1, 1.0};
double d = func_with_double_arg(1, 1.0) + func_with_struct_arg(s) +
func_with_ptr_arg("msg") + func_with_double_return() +
func_with_unsupported_struct_arg(u) + foo() + foo(1) + foo(1, 2);
char *msg = func_with_ptr("msg");
char *ptr = func_with_ptr_return();
s = func_with_struct_return();
u = func_with_unsupported_struct_return();
return 0; // break here
}

0 comments on commit da97b8d

Please sign in to comment.