[Lldb-commits] [lldb] d85cc03 - [lldb] Add expect_var_path to test variable path results

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 12 07:15:13 PST 2020


Author: Raphael Isemann
Date: 2020-11-12T16:14:48+01:00
New Revision: d85cc03c9c4cc44c0281320558abc440575ae1d4

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

LOG: [lldb] Add expect_var_path to test variable path results

This adds `expect_var_path` to test variable paths so we no longer have to
use `frame var` and find substrs in the command output. The behaviour
is identical with `expect_expr` (and it also uses the same checking backend),
but it instead calls `GetValueForVariablePath` to evaluate the string as a variable
path.

Also rewrites a few of the tests that previously used `frame variable` to use
`expect_var_path`.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D90450

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/lldbtest.py
    lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py
    lldb/test/API/functionalities/archives/TestBSDArchives.py
    lldb/test/API/lang/cpp/wchar_t/TestCxxWCharT.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 89c25eb55516..a02c445a937a 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2592,6 +2592,35 @@ def expect_expr(
         value_check.check_value(self, eval_result, str(eval_result))
         return eval_result
 
+    def expect_var_path(
+            self,
+            var_path,
+            summary=None,
+            value=None,
+            type=None,
+            children=None
+            ):
+        """
+        Evaluates the given variable path and verifies the result.
+        See also 'frame variable' and SBFrame.GetValueForVariablePath.
+        :param var_path: The variable path as a string.
+        :param summary: The summary that the variable should have. None if the summary should not be checked.
+        :param value: The value that the variable should have. None if the value should not be checked.
+        :param type: The type that the variable result should have. None if the type should not be checked.
+        :param children: The expected children of the variable  as a list of ValueChecks.
+                         None if the children shouldn't be checked.
+        """
+        self.assertTrue(var_path.strip() == var_path,
+                        "Expression contains trailing/leading whitespace: '" + var_path + "'")
+
+        frame = self.frame()
+        eval_result = frame.GetValueForVariablePath(var_path)
+
+        value_check = ValueCheck(type=type, value=value,
+                                 summary=summary, children=children)
+        value_check.check_value(self, eval_result, str(eval_result))
+        return eval_result
+
     def invoke(self, obj, name, trace=False):
         """Use reflection to call a method dynamically with no argument."""
         trace = (True if traceAlways else trace)

diff  --git a/lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py b/lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py
index 8602f7f56b15..9ade3dba12c5 100644
--- a/lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py
+++ b/lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py
@@ -60,21 +60,14 @@ def test(self):
             stop_reason == lldb.eStopReasonBreakpoint,
             "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint")
 
-        self.expect("frame variable argv[1]", substrs=['file1.txt'])
-        self.expect("frame variable argv[2]", substrs=['file2.txt'])
-        self.expect("frame variable argv[3]", substrs=['file3.txt'])
-        self.expect("frame variable argv[4]", substrs=['file4.txy'])
-        self.expect("frame variable argv[5]", substrs=['()'])
-        self.expect("frame variable argv[6]", substrs=['>'])
-        self.expect("frame variable argv[7]", substrs=['<'])
-        self.expect(
-            "frame variable argv[5]",
-            substrs=['file5.tyx'],
-            matching=False)
-        self.expect(
-            "frame variable argv[8]",
-            substrs=['file5.tyx'],
-            matching=False)
+        self.expect_var_path("argv[1]", summary='"file1.txt"')
+        self.expect_var_path("argv[2]", summary='"file2.txt"')
+        self.expect_var_path("argv[3]", summary='"file3.txt"')
+        self.expect_var_path("argv[4]", summary='"file4.txy"')
+        self.expect_var_path("argv[5]", summary='"()"')
+        self.expect_var_path("argv[6]", summary='">"')
+        self.expect_var_path("argv[7]", summary='"<"')
+        self.expect_var_path("argc", value='8')
 
         self.runCmd("process kill")
 

diff  --git a/lldb/test/API/functionalities/archives/TestBSDArchives.py b/lldb/test/API/functionalities/archives/TestBSDArchives.py
index b412ac4c1350..4464edd96bea 100644
--- a/lldb/test/API/functionalities/archives/TestBSDArchives.py
+++ b/lldb/test/API/functionalities/archives/TestBSDArchives.py
@@ -43,8 +43,7 @@ def test(self):
         # Break at a(int) first.
         self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY,
                     substrs=['(int) arg = 1'])
-        self.expect("frame variable __a_global", VARIABLES_DISPLAYED_CORRECTLY,
-                    substrs=['(int) __a_global = 1'])
+        self.expect_var_path("__a_global", type="int", value="1")
 
         # Set breakpoint for b() next.
         lldbutil.run_break_set_by_symbol(
@@ -57,5 +56,4 @@ def test(self):
                              'stop reason = breakpoint'])
         self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY,
                     substrs=['(int) arg = 2'])
-        self.expect("frame variable __b_global", VARIABLES_DISPLAYED_CORRECTLY,
-                    substrs=['(int) __b_global = 2'])
+        self.expect_var_path("__b_global", type="int", value="2")

diff  --git a/lldb/test/API/lang/cpp/wchar_t/TestCxxWCharT.py b/lldb/test/API/lang/cpp/wchar_t/TestCxxWCharT.py
index bb041ef44b91..79f65527ec09 100644
--- a/lldb/test/API/lang/cpp/wchar_t/TestCxxWCharT.py
+++ b/lldb/test/API/lang/cpp/wchar_t/TestCxxWCharT.py
@@ -20,20 +20,16 @@ def test(self):
         lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
 
         # Check that we correctly report templates on wchar_t
-        self.expect("frame variable foo_y",
-                    substrs=['(Foo<wchar_t>) foo_y = '])
+        self.expect_var_path("foo_y", type="Foo<wchar_t>")
 
         # Check that we correctly report templates on int
-        self.expect("frame variable foo_x",
-                    substrs=['(Foo<int>) foo_x = '])
+        self.expect_var_path("foo_x", type="Foo<int>")
 
         # Check that we correctly report wchar_t
-        self.expect("frame variable foo_y.object",
-                    substrs=['(wchar_t) foo_y.object = '])
+        self.expect_var_path("foo_y.object", type="wchar_t")
 
         # Check that we correctly report int
-        self.expect("frame variable foo_x.object",
-                    substrs=['(int) foo_x.object = '])
+        self.expect_var_path("foo_x.object", type="int")
 
         # Check that we can run expressions that return wchar_t
         self.expect("expression L'a'", substrs=['(wchar_t) $', "L'a'"])


        


More information about the lldb-commits mailing list