[Lldb-commits] [lldb] edb0efc - [lldb][NFC] Modernize call-function tests

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 1 01:18:05 PDT 2020


Author: Raphael Isemann
Date: 2020-04-01T10:17:42+02:00
New Revision: edb0efca1e73ec5f791d9fe8c28f7c4c85a61c43

URL: https://github.com/llvm/llvm-project/commit/edb0efca1e73ec5f791d9fe8c28f7c4c85a61c43
DIFF: https://github.com/llvm/llvm-project/commit/edb0efca1e73ec5f791d9fe8c28f7c4c85a61c43.diff

LOG: [lldb][NFC] Modernize call-function tests

Added: 
    

Modified: 
    lldb/test/API/commands/expression/call-function/TestCallStdStringFunction.py
    lldb/test/API/commands/expression/call-function/TestCallStopAndContinue.py
    lldb/test/API/commands/expression/call-function/TestCallUserDefinedFunction.py
    lldb/test/API/commands/expression/call-function/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/commands/expression/call-function/TestCallStdStringFunction.py b/lldb/test/API/commands/expression/call-function/TestCallStdStringFunction.py
index 261e702fa59a..f94bcae34cf9 100644
--- a/lldb/test/API/commands/expression/call-function/TestCallStdStringFunction.py
+++ b/lldb/test/API/commands/expression/call-function/TestCallStdStringFunction.py
@@ -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 @@ def setUp(self):
     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'])

diff  --git a/lldb/test/API/commands/expression/call-function/TestCallStopAndContinue.py b/lldb/test/API/commands/expression/call-function/TestCallStopAndContinue.py
index 0f0f1a54e31c..1191176aa706 100644
--- a/lldb/test/API/commands/expression/call-function/TestCallStopAndContinue.py
+++ b/lldb/test/API/commands/expression/call-function/TestCallStopAndContinue.py
@@ -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 @@ 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:')
-        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)
 

diff  --git a/lldb/test/API/commands/expression/call-function/TestCallUserDefinedFunction.py b/lldb/test/API/commands/expression/call-function/TestCallUserDefinedFunction.py
index 98cd0f24f36c..edaa76174b47 100644
--- a/lldb/test/API/commands/expression/call-function/TestCallUserDefinedFunction.py
+++ b/lldb/test/API/commands/expression/call-function/TestCallUserDefinedFunction.py
@@ -7,36 +7,19 @@
 
 """
 
-
-
 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")

diff  --git a/lldb/test/API/commands/expression/call-function/main.cpp b/lldb/test/API/commands/expression/call-function/main.cpp
index cc5f52dbf567..a383ce5c22a0 100644
--- a/lldb/test/API/commands/expression/call-function/main.cpp
+++ b/lldb/test/API/commands/expression/call-function/main.cpp
@@ -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
 }


        


More information about the lldb-commits mailing list