199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest calling user defined functions using expression evaluation.
399451b44SJordan Rupprecht
499451b44SJordan RupprechtNote:
599451b44SJordan Rupprecht  LLDBs current first choice of evaluating functions is using the IR interpreter,
699451b44SJordan Rupprecht  which is only supported on Hexagon. Otherwise JIT is used for the evaluation.
799451b44SJordan Rupprecht
899451b44SJordan Rupprecht"""
999451b44SJordan Rupprecht
1099451b44SJordan Rupprechtimport lldb
1199451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
1299451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
1399451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
1499451b44SJordan Rupprecht
1599451b44SJordan Rupprechtclass ExprCommandCallUserDefinedFunction(TestBase):
1699451b44SJordan Rupprecht
1799451b44SJordan Rupprecht    def test(self):
1899451b44SJordan Rupprecht        """Test return values of user defined function calls."""
1999451b44SJordan Rupprecht        self.build()
20edb0efcaSRaphael Isemann        lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
2199451b44SJordan Rupprecht
2299451b44SJordan Rupprecht        # Test recursive function call.
2399451b44SJordan Rupprecht        self.expect_expr("fib(5)", result_type="unsigned int", result_value="5")
2499451b44SJordan Rupprecht
25*36597e47SBruce Mitchener        # Test function with more than one parameter
2699451b44SJordan Rupprecht        self.expect_expr("add(4, 8)", result_type="int", result_value="12")
2799451b44SJordan Rupprecht
28*36597e47SBruce Mitchener        # Test nesting function calls in function parameters
2999451b44SJordan Rupprecht        self.expect_expr("add(add(5,2),add(3,4))", result_type="int", result_value="14")
3099451b44SJordan Rupprecht        self.expect_expr("add(add(5,2),fib(5))", result_type="int", result_value="12")
3199451b44SJordan Rupprecht
32*36597e47SBruce Mitchener        # Test function with pointer parameter
3399451b44SJordan Rupprecht        self.expect_expr('stringCompare((const char*) \"Hello world\")', result_type="bool", result_value="true")
3499451b44SJordan Rupprecht        self.expect_expr('stringCompare((const char*) \"Hellworld\")', result_type="bool", result_value="false")
35