[lldb][NFC] Modernize call-function tests

This commit is contained in:
Raphael Isemann 2020-04-01 10:06:28 +02:00
parent 90b7bbffdd
commit edb0efca1e
4 changed files with 27 additions and 96 deletions

View File

@ -2,26 +2,15 @@
Test calling std::String member functions.
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class ExprCommandCallFunctionTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break for main.c.
self.line = line_number(
'main.cpp',
'// Please test these expressions while stopped at this line:')
@expectedFailureAll(
compiler="icc",
bugnumber="llvm.org/pr14437, fails with ICC 13.1")
@ -29,15 +18,7 @@ class ExprCommandCallFunctionTestCase(TestBase):
def test_with(self):
"""Test calling std::String member function."""
self.build()
self.runCmd("file " + self.getBuildArtifact("a.out"),
CURRENT_EXECUTABLE_SET)
# Some versions of GCC encode two locations for the 'return' statement
# in main.cpp
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
self.runCmd("run", RUN_SUCCEEDED)
lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
self.expect("print str",
substrs=['Hello world'])

View File

@ -2,13 +2,10 @@
Test calling a function, stopping in the call, continue and gather the result on stop.
"""
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class ExprCommandCallStopContinueTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@ -17,27 +14,16 @@ class ExprCommandCallStopContinueTestCase(TestBase):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break for main.c.
self.line = line_number(
'main.cpp',
'// Please test these expressions while stopped at this line:')
self.func_line = line_number('main.cpp', '{5, "five"}')
def test(self):
"""Test gathering result from interrupted function call."""
self.build()
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
# Some versions of GCC encode two locations for the 'return' statement
# in main.cpp
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
self.runCmd("run", RUN_SUCCEEDED)
lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
lldbutil.run_break_set_by_file_and_line(
self,
"main.cpp",
self.func_line,
line_number('main.cpp', '{5, "five"}'),
num_expected_locations=-1,
loc_exact=True)

View File

@ -7,36 +7,19 @@ Note:
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class ExprCommandCallUserDefinedFunction(TestBase):
mydir = TestBase.compute_mydir(__file__)
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break for main.c.
self.line = line_number(
'main.cpp',
'// Please test these expressions while stopped at this line:')
def test(self):
"""Test return values of user defined function calls."""
self.build()
# Set breakpoint in main and run exe
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
self.runCmd("run", RUN_SUCCEEDED)
lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
# Test recursive function call.
self.expect_expr("fib(5)", result_type="unsigned int", result_value="5")

View File

@ -1,53 +1,34 @@
#include <iostream>
#include <string>
#include <cstring>
#include <string>
struct Five
{
int number;
const char *name;
struct Five {
int number;
const char *name;
};
Five
returnsFive()
{
Five my_five = {5, "five"};
return my_five;
Five returnsFive() {
Five my_five = {5, "five"};
return my_five;
}
unsigned int
fib(unsigned int n)
{
if (n < 2)
return n;
else
return fib(n - 1) + fib(n - 2);
unsigned int fib(unsigned int n) {
if (n < 2)
return n;
else
return fib(n - 1) + fib(n - 2);
}
int
add(int a, int b)
{
return a + b;
int add(int a, int b) { return a + b; }
bool stringCompare(const char *str) {
if (strcmp(str, "Hello world") == 0)
return true;
else
return false;
}
bool
stringCompare(const char *str)
{
if (strcmp( str, "Hello world" ) == 0)
return true;
else
return false;
}
int main (int argc, char const *argv[])
{
std::string str = "Hello world";
std::cout << str << std::endl;
std::cout << str.c_str() << std::endl;
Five main_five = returnsFive();
#if 0
print str
print str.c_str()
#endif
return 0; // Please test these expressions while stopped at this line:
int main(int argc, char const *argv[]) {
std::string str = "Hello world";
Five main_five = returnsFive();
return strlen(str.c_str()); // break here
}