JDevlieghere created this revision.
JDevlieghere added a reviewer: LLDB.
Herald added a project: LLDB.

This patch is more of an RFC to change the default 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. I think 
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.

A possible alternative is to keep the option but have it off by default. 
Currently there's about 50 tests failing because of this. If we like to move 
forward with making this the default I plan to incrementally update tests 
before flipping the switch.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D73766

Files:
  
lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/TestMTCSimple.py
  lldb/packages/Python/lldbsuite/test/lldbtest.py


Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2261,6 +2261,7 @@
             substrs=None,
             trace=False,
             error=False,
+            ordered=True,
             matching=True,
             exe=True,
             inHistory=False):
@@ -2341,8 +2342,12 @@
         # 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)
+                print("Looking for %s in %s" % (substr, output[start:]))
+                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)
Index: 
lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/TestMTCSimple.py
===================================================================
--- 
lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/TestMTCSimple.py
+++ 
lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/TestMTCSimple.py
@@ -46,7 +46,7 @@
 
         self.expect(
             "thread info -s",
-            substrs=["instrumentation_class", "api_name", "class_name", 
"selector", "description"])
+            substrs=["api_name", "class_name", "description", 
"instrumentation_class", "selector"])
         self.assertEqual(thread.GetStopReason(), 
lldb.eStopReasonInstrumentation)
         output_lines = self.res.GetOutput().split('\n')
         json_line = '\n'.join(output_lines[2:])


Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2261,6 +2261,7 @@
             substrs=None,
             trace=False,
             error=False,
+            ordered=True,
             matching=True,
             exe=True,
             inHistory=False):
@@ -2341,8 +2342,12 @@
         # 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)
+                print("Looking for %s in %s" % (substr, output[start:]))
+                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)
Index: lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/TestMTCSimple.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/TestMTCSimple.py
+++ lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/TestMTCSimple.py
@@ -46,7 +46,7 @@
 
         self.expect(
             "thread info -s",
-            substrs=["instrumentation_class", "api_name", "class_name", "selector", "description"])
+            substrs=["api_name", "class_name", "description", "instrumentation_class", "selector"])
         self.assertEqual(thread.GetStopReason(), lldb.eStopReasonInstrumentation)
         output_lines = self.res.GetOutput().split('\n')
         json_line = '\n'.join(output_lines[2:])
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to