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: 5 of 5

Adds tests on function calls inside lldb expressions
  • Loading branch information
dlav-sc committed Jul 18, 2024
1 parent c4db74e commit 73eb9f8
Show file tree
Hide file tree
Showing 3 changed files with 140 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
86 changes: 86 additions & 0 deletions lldb/test/API/riscv/expressions/TestExpressions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""
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("bla")',
error=True,
substrs=["Architecture passes failure on function $__lldb_expr"],
)

@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_ptr_ret_val(self):
self.common_setup()
self.expect(
"expr func_with_ptr_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"],
)
51 changes: 51 additions & 0 deletions lldb/test/API/riscv/expressions/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
struct S {
int a;
int b;
};

struct U {
int a;
double d;
};

int g;

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

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

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; }

int *func_with_ptr_return() { return &g; }

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_ptr_arg("msg") +
func_with_struct_arg(s) + func_with_double_return() +
func_with_unsupported_struct_arg(u) + foo() + foo(1) + foo(1, 2);
int *ptr = func_with_ptr_return();
s = func_with_struct_return();
u = func_with_unsupported_struct_return();
return 0; // break here
}

0 comments on commit 73eb9f8

Please sign in to comment.