[Lldb-commits] [lldb] r325570 - Avoid dirtying the source tree in breakpoint command tests

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 20 02:24:37 PST 2018


Author: labath
Date: Tue Feb 20 02:24:37 2018
New Revision: 325570

URL: http://llvm.org/viewvc/llvm-project?rev=325570&view=rev
Log:
Avoid dirtying the source tree in breakpoint command tests

Summary:
The paralelization patch exposed a bunch of cases where we were still
touching the source tree (as these tests were now stepping on each
others toes and being flaky).

This patch removes such issues from breakpoint command tests. Since the
only reason they were creating files was to indirectly test whether the
breakpoint commands got executed (and plumbing the full build tree path
to all places that needed it would be messy) I decided to modify the
tests to check for a different side effect instead: modification of a
global variable. This also makes the code simpler as checking the value
of the global variable is easier, and there is nothing to clean up.

As the tests aren't really doing anything debug-info related, I took the
opportunity to also mark them as NO_DEBUG_INFO_TESTCASEs.

Reviewers: jingham, aprantl

Subscribers: lldb-commits

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

Added:
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/side_effect.py
Modified:
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py?rev=325570&r1=325569&r2=325570&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py Tue Feb 20 02:24:37 2018
@@ -11,18 +11,14 @@ import lldb
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
+import side_effect
 
 
 class BreakpointCommandTestCase(TestBase):
 
+    NO_DEBUG_INFO_TESTCASE = True
     mydir = TestBase.compute_mydir(__file__)
 
-    @classmethod
-    def classCleanup(cls):
-        """Cleanup the test byproduct of breakpoint_command_sequence(self)."""
-        cls.RemoveTempFile("output.txt")
-        cls.RemoveTempFile("output2.txt")
-
     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528")
     def test_breakpoint_command_sequence(self):
         """Test a sequence of breakpoint command add, list, and delete."""
@@ -71,7 +67,7 @@ class BreakpointCommandTestCase(TestBase
         self.runCmd(
             "breakpoint command add -s command -o 'frame variable --show-types --scope' 1 4")
         self.runCmd(
-            "breakpoint command add -s python -o 'here = open(\"output.txt\", \"w\"); here.write(\"lldb\\n\"); here.close()' 2")
+            "breakpoint command add -s python -o 'import side_effect; side_effect.one_liner = \"one liner was here\"' 2")
         self.runCmd(
             "breakpoint command add --python-function bktptcmd.function 3")
 
@@ -104,9 +100,8 @@ class BreakpointCommandTestCase(TestBase
                              "frame variable --show-types --scope"])
         self.expect("breakpoint command list 2", "Breakpoint 2 command ok",
                     substrs=["Breakpoint commands (Python):",
-                             "here = open",
-                             "here.write",
-                             "here.close()"])
+                             "import side_effect",
+                             "side_effect.one_liner"])
         self.expect("breakpoint command list 3", "Breakpoint 3 command ok",
                     substrs=["Breakpoint commands (Python):",
                              "bktptcmd.function(frame, bp_loc, internal_dict)"])
@@ -151,40 +146,14 @@ class BreakpointCommandTestCase(TestBase
             extra_options="-f a.c",
             num_expected_locations=1)
 
-        # Run the program.  Remove 'output.txt' if it exists.
-        self.RemoveTempFile("output.txt")
-        self.RemoveTempFile("output2.txt")
+        # Reset our canary variables and run the program.
+        side_effect.one_liner = None
+        side_effect.bktptcmd = None
         self.runCmd("run", RUN_SUCCEEDED)
 
-        # Check that the file 'output.txt' exists and contains the string
-        # "lldb".
-
-        # The 'output.txt' file should now exist.
-        self.assertTrue(
-            os.path.isfile("output.txt"),
-            "'output.txt' exists due to breakpoint command for breakpoint 2.")
-        self.assertTrue(
-            os.path.isfile("output2.txt"),
-            "'output2.txt' exists due to breakpoint command for breakpoint 3.")
-
-        # Read the output file produced by running the program.
-        with open('output.txt', 'r') as f:
-            output = f.read()
-
-        self.expect(
-            output,
-            "File 'output.txt' and the content matches",
-            exe=False,
-            startstr="lldb")
-
-        with open('output2.txt', 'r') as f:
-            output = f.read()
-
-        self.expect(
-            output,
-            "File 'output2.txt' and the content matches",
-            exe=False,
-            startstr="lldb")
+        # Check the value of canary variables.
+        self.assertEquals("one liner was here", side_effect.one_liner)
+        self.assertEquals("function was here", side_effect.bktptcmd)
 
         # Finish the program.
         self.runCmd("process continue")
@@ -245,38 +214,16 @@ class BreakpointCommandTestCase(TestBase
             self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
 
         # Now add callbacks for the breakpoints just created.
-        self.runCmd("breakpoint command add -s python -o 'here = open(\"output-2.txt\", \"w\"); here.write(str(frame) + \"\\n\"); here.write(str(bp_loc) + \"\\n\"); here.close()' 1")
+        self.runCmd("breakpoint command add -s python -o 'import side_effect; side_effect.frame = str(frame); side_effect.bp_loc = str(bp_loc)' 1")
 
-        # Remove 'output-2.txt' if it already exists.
-
-        if (os.path.exists('output-2.txt')):
-            os.remove('output-2.txt')
-
-        # Run program, hit breakpoint, and hopefully write out new version of
-        # 'output-2.txt'
+        # Reset canary variables and run.
+        side_effect.frame = None
+        side_effect.bp_loc = None
         self.runCmd("run", RUN_SUCCEEDED)
 
-        # Check that the file 'output.txt' exists and contains the string
-        # "lldb".
-
-        # The 'output-2.txt' file should now exist.
-        self.assertTrue(
-            os.path.isfile("output-2.txt"),
-            "'output-2.txt' exists due to breakpoint command for breakpoint 1.")
-
-        # Read the output file produced by running the program.
-        with open('output-2.txt', 'r') as f:
-            output = f.read()
-
-        self.expect(
-            output,
-            "File 'output-2.txt' and the content matches",
-            exe=False,
-            startstr="frame #0:",
-            patterns=["1.* where = .*main .* resolved, hit count = 1"])
-
-        # Now remove 'output-2.txt'
-        os.remove('output-2.txt')
+        self.expect(side_effect.frame, exe=False, startstr="frame #0:")
+        self.expect(side_effect.bp_loc, exe=False,
+                patterns=["1.* where = .*main .* resolved, hit count = 1"])
 
     def breakpoint_commands_on_creation(self):
         """Test that setting breakpoint commands when creating the breakpoint works"""

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py?rev=325570&r1=325569&r2=325570&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py Tue Feb 20 02:24:37 2018
@@ -12,12 +12,13 @@ import lldb
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
+import side_effect
 
 
 class PythonBreakpointCommandSettingTestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
-    my_var = 10
+    NO_DEBUG_INFO_TESTCASE = True
 
     @add_test_categories(['pyapi'])
     def test_step_out_python(self):
@@ -69,12 +70,9 @@ class PythonBreakpointCommandSettingTest
         self.assertTrue(got_one_in_B, "Failed to match the pattern in B")
         self.target.BreakpointDelete(no_files_bkpt.GetID())
 
-        PythonBreakpointCommandSettingTestCase.my_var = 10
         error = lldb.SBError()
-        error = body_bkpt.SetScriptCallbackBody("\
-import TestBreakpointCommandsFromPython\n\
-TestBreakpointCommandsFromPython.PythonBreakpointCommandSettingTestCase.my_var = 20\n\
-print('Hit breakpoint')")
+        error = body_bkpt.SetScriptCallbackBody(
+                "import side_effect; side_effect.callback = 'callback was here'")
         self.assertTrue(
             error.Success(),
             "Failed to set the script callback body: %s." %
@@ -84,9 +82,9 @@ print('Hit breakpoint')")
             "command script import --allow-reload ./bktptcmd.py")
         func_bkpt.SetScriptCallbackFunction("bktptcmd.function")
 
-        # We will use the function that touches a text file, so remove it
-        # first:
-        self.RemoveTempFile("output2.txt")
+        # Clear out canary variables
+        side_effect.bktptcmd = None
+        side_effect.callback = None
 
         # Now launch the process, and do not stop at entry point.
         self.process = self.target.LaunchSimple(
@@ -100,11 +98,5 @@ print('Hit breakpoint')")
         self.assertTrue(len(threads) == 1, "Stopped at inner breakpoint.")
         self.thread = threads[0]
 
-        self.assertTrue(PythonBreakpointCommandSettingTestCase.my_var == 20)
-
-        # Check for the function version as well, which produced this file:
-        # Remember to clean up after ourselves...
-        self.assertTrue(
-            os.path.isfile("output2.txt"),
-            "'output2.txt' exists due to breakpoint command for breakpoint function.")
-        self.RemoveTempFile("output2.txt")
+        self.assertEquals("callback was here", side_effect.callback)
+        self.assertEquals("function was here", side_effect.bktptcmd)

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py?rev=325570&r1=325569&r2=325570&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py Tue Feb 20 02:24:37 2018
@@ -1,7 +1,5 @@
 from __future__ import print_function
-
+import side_effect
 
 def function(frame, bp_loc, dict):
-    there = open("output2.txt", "w")
-    print("lldb", file=there)
-    there.close()
+    side_effect.bktptcmd = "function was here"

Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/side_effect.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/side_effect.py?rev=325570&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/side_effect.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/side_effect.py Tue Feb 20 02:24:37 2018
@@ -0,0 +1,5 @@
+"""
+A dummy module for testing the execution of various breakpoint commands. A
+command will modify a global variable in this module and test will check its
+value.
+"""




More information about the lldb-commits mailing list