[Lldb-commits] [lldb] b51321c - [lldb] Fix TestCompletion's pid completion failing randomly

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 31 03:23:16 PDT 2020


Author: Raphael Isemann
Date: 2020-08-31T12:22:41+02:00
New Revision: b51321ccc894f6ed512c27cb43b1f04883d5ed0e

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

LOG: [lldb] Fix TestCompletion's pid completion failing randomly

TestCompletion is randomly failing on some bots. The error message however states
that the computed completions actually do contain the expected pid we're
looking for, so there shouldn't be any test failure.

The reason for that turns out to be that complete_from_to is actually used
for testing two different features. It can be used for testing what the
common prefix for the list of completions is and *also* for checking all the
possible completions that are returned for a command. Which one of the two
things should be checked can't be defined by a parameter to the function, but
is instead guessed by the test method instead based on the results that were
returned. If there is a common prefix in all completions, then that prefix
is searched and otherwise all completions are searched.

For TestCompletion's pid test this behaviour leads to the strange test failures.
If all the pid's that our test LLDB can see have a common prefix (e.g., it
can only see pids [123, 122, 10004, 10000] -> common prefix '1'), then
complete_from_to check that the common prefix contains our pid, which is
always fails ('1' doesn't contain '123' or any other valid pid). If there
isn't a common prefix (e.g., pids are [123, 122, 10004, 777]) then
complete_from_to will check the list of completions instead which works correctly.

This patch is fixing this by adding a simple check method that doesn't
have this behaviour and is simply searching the returned list of completions.
This should get the bots green while I'm working on a proper fix that fixes
complete_from_to.

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/lldbtest.py
    lldb/test/API/functionalities/completion/TestCompletion.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 112b19abab39..dacd5ed734b5 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2296,6 +2296,17 @@ def completions_match(self, command, completions):
         self.assertItemsEqual(completions, list(match_strings)[1:],
                               "List of returned completion is wrong")
 
+    def completions_contain(self, command, completions):
+        """Checks that the completions for the given command contain the given
+        list of completions."""
+        interp = self.dbg.GetCommandInterpreter()
+        match_strings = lldb.SBStringList()
+        interp.HandleCompletion(command, len(command), 0, -1, match_strings)
+        for completion in completions:
+            # match_strings is a 1-indexed list, so we have to slice...
+            self.assertIn(completion, list(match_strings)[1:],
+                          "Couldn't find expected completion")
+
     def filecheck(
             self,
             command,

diff  --git a/lldb/test/API/functionalities/completion/TestCompletion.py b/lldb/test/API/functionalities/completion/TestCompletion.py
index b80594b7568b..f4d361593e48 100644
--- a/lldb/test/API/functionalities/completion/TestCompletion.py
+++ b/lldb/test/API/functionalities/completion/TestCompletion.py
@@ -143,9 +143,9 @@ def test_common_completion_process_pid_and_name(self):
         self.assertIsNotNone(server)
         pid = server.pid
 
-        self.complete_from_to('process attach -p ', [str(pid)])
-        self.complete_from_to('platform process attach -p ', [str(pid)])
-        self.complete_from_to('platform process info ', [str(pid)])
+        self.completions_contain('process attach -p ', [str(pid)])
+        self.completions_contain('platform process attach -p ', [str(pid)])
+        self.completions_contain('platform process info ', [str(pid)])
 
         self.completions_contain_str('process attach -n ', "a.out")
         self.completions_contain_str('platform process attach -n ', "a.out")


        


More information about the lldb-commits mailing list