[Lldb-commits] [lldb] e211a7d - Re-land "[lldb/Test] Make substrs argument to self.expect ordered."

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 3 20:19:35 PST 2020


Author: Jonas Devlieghere
Date: 2020-02-03T20:19:25-08:00
New Revision: e211a7d2aafeeb9536f3aa9492601099655b833c

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

LOG: Re-land "[lldb/Test] Make substrs argument to self.expect ordered."

Re-landing this now that (hopefully) all the failures this caused on the
bots have been addressed.

This patch changes the behavior of the substrs argument to self.expect.
Currently, the elements of substrs are unordered and as long as the
string appears in the output, the assertion passes.

We can be more precise by requiring that the substrings be ordered in
the way they appear. My hope is that this will make it harder to
accidentally pass a check because a string appears out of order.

Differential revision: https://reviews.llvm.org/D73766

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py
    lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
    lldb/packages/Python/lldbsuite/test/lldbtest.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py b/lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py
index 81d7804b85f2..95df78eef12a 100644
--- a/lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py
+++ b/lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py
@@ -245,6 +245,7 @@ def do_target_variable_command_no_fail(self, exe_name):
         # It will find all the global and static variables in the current
         # compile unit.
         self.expect("target variable",
+                    ordered=False,
                     substrs=['my_global_char',
                              'my_static_int',
                              'my_global_str',

diff  --git a/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
index a471058b3b45..04b874942acb 100644
--- a/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
+++ b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
@@ -79,6 +79,7 @@ def test_c_global_variables(self):
         self.expect(
             "frame variable --show-types --scope --show-globals --no-args",
             VARIABLES_DISPLAYED_CORRECTLY,
+            ordered=False,
             substrs=[
                 'STATIC: (const char *) g_func_static_cstr',
                 '"g_func_static_cstr"',

diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 602749c80fa8..fe4b198e93ce 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2261,6 +2261,7 @@ def expect(
             substrs=None,
             trace=False,
             error=False,
+            ordered=True,
             matching=True,
             exe=True,
             inHistory=False):
@@ -2273,6 +2274,10 @@ def expect(
         'startstr', matches the substrings contained in 'substrs', and regexp
         matches the patterns contained in 'patterns'.
 
+        When matching is true and ordered is true, which are both the default,
+        the strings in the substrs array have to appear in the command output
+        in the order in which they appear in the array.
+
         If the keyword argument error is set to True, it signifies that the API
         client is expecting the command to fail.  In this case, the error stream
         from running the command is retrieved and compared against the golden
@@ -2341,8 +2346,11 @@ def expect(
         # Look for sub strings, if specified.
         keepgoing = matched if matching else not matched
         if substrs and keepgoing:
+            start = 0
             for substr in substrs:
-                matched = output.find(substr) != -1
+                index = output[start:].find(substr)
+                start = start + index if ordered and matching else 0
+                matched = index != -1
                 with recording(self, trace) as sbuf:
                     print("%s sub string: %s" % (heading, substr), file=sbuf)
                     print("Matched" if matched else "Not matched", file=sbuf)


        


More information about the lldb-commits mailing list