[Lldb-commits] [lldb] r328106 - Last batch of test-tree cleaning changes

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 21 08:29:32 PDT 2018


Author: labath
Date: Wed Mar 21 08:29:32 2018
New Revision: 328106

URL: http://llvm.org/viewvc/llvm-project?rev=328106&view=rev
Log:
Last batch of test-tree cleaning changes

- postmortem tests: make sure the core files are created in the build
  folder
- TestSourceManager: copy the .c file into the build dir before
  modifying it
- TestLogging: create log files in the build folder

After these changes I get a clean test run (on linux) even if I set the
source tree to be read only. It's possible some of the skipped/xfailed
tests are still creating files in the source tree, but at the moment, I
don't have plans to go hunting for those.

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/TestMiniDumpNew.py
    lldb/trunk/packages/Python/lldbsuite/test/logging/TestLogging.py
    lldb/trunk/packages/Python/lldbsuite/test/source-manager/Makefile
    lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py?rev=328106&r1=328105&r2=328106&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py Wed Mar 21 08:29:32 2018
@@ -87,30 +87,28 @@ class LinuxCoreTestCase(TestBase):
     def test_same_pid_running(self):
         """Test that we read the information from the core correctly even if we have a running
         process with the same PID around"""
-        try:
-            shutil.copyfile("linux-x86_64.out", "linux-x86_64-pid.out")
-            shutil.copyfile("linux-x86_64.core", "linux-x86_64-pid.core")
-            with open("linux-x86_64-pid.core", "r+b") as f:
-                # These are offsets into the NT_PRSTATUS and NT_PRPSINFO structures in the note
-                # segment of the core file. If you update the file, these offsets may need updating
-                # as well. (Notes can be viewed with readelf --notes.)
-                for pid_offset in [0x1c4, 0x320]:
-                    f.seek(pid_offset)
-                    self.assertEqual(
-                        struct.unpack(
-                            "<I",
-                            f.read(4))[0],
-                        self._x86_64_pid)
+        exe_file = self.getBuildArtifact("linux-x86_64-pid.out")
+        core_file = self.getBuildArtifact("linux-x86_64-pid.core")
+        shutil.copyfile("linux-x86_64.out", exe_file)
+        shutil.copyfile("linux-x86_64.core", core_file)
+        with open(core_file, "r+b") as f:
+            # These are offsets into the NT_PRSTATUS and NT_PRPSINFO structures in the note
+            # segment of the core file. If you update the file, these offsets may need updating
+            # as well. (Notes can be viewed with readelf --notes.)
+            for pid_offset in [0x1c4, 0x320]:
+                f.seek(pid_offset)
+                self.assertEqual(
+                    struct.unpack(
+                        "<I",
+                        f.read(4))[0],
+                    self._x86_64_pid)
 
-                    # We insert our own pid, and make sure the test still
-                    # works.
-                    f.seek(pid_offset)
-                    f.write(struct.pack("<I", os.getpid()))
-            self.do_test("linux-x86_64-pid", os.getpid(), self._x86_64_regions,
-                    "a.out")
-        finally:
-            self.RemoveTempFile("linux-x86_64-pid.out")
-            self.RemoveTempFile("linux-x86_64-pid.core")
+                # We insert our own pid, and make sure the test still
+                # works.
+                f.seek(pid_offset)
+                f.write(struct.pack("<I", os.getpid()))
+        self.do_test(self.getBuildArtifact("linux-x86_64-pid"), os.getpid(),
+                self._x86_64_regions, "a.out")
 
     @skipIf(oslist=['windows'])
     @skipIf(triple='^mips')

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/TestMiniDumpNew.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/TestMiniDumpNew.py?rev=328106&r1=328105&r2=328106&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/TestMiniDumpNew.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/TestMiniDumpNew.py Wed Mar 21 08:29:32 2018
@@ -162,32 +162,25 @@ class MiniDumpNewTestCase(TestBase):
     def test_deeper_stack_in_minidump_with_same_pid_running(self):
         """Test that we read the information from the core correctly even if we
         have a running process with the same PID"""
-        try:
-            self.do_change_pid_in_minidump("linux-x86_64_not_crashed.dmp",
-                                           "linux-x86_64_not_crashed-pid.dmp",
-                                           self._linux_x86_64_not_crashed_pid_offset,
-                                           str(self._linux_x86_64_not_crashed_pid),
-                                           str(os.getpid()))
-            self.do_test_deeper_stack("linux-x86_64_not_crashed",
-                                      "linux-x86_64_not_crashed-pid.dmp",
-                                      os.getpid())
-        finally:
-            self.RemoveTempFile("linux-x86_64_not_crashed-pid.dmp")
+        new_core = self.getBuildArtifact("linux-x86_64_not_crashed-pid.dmp")
+        self.do_change_pid_in_minidump("linux-x86_64_not_crashed.dmp",
+                                       new_core,
+                                       self._linux_x86_64_not_crashed_pid_offset,
+                                       str(self._linux_x86_64_not_crashed_pid),
+                                       str(os.getpid()))
+        self.do_test_deeper_stack("linux-x86_64_not_crashed", new_core, os.getpid())
 
     def test_two_cores_same_pid(self):
         """Test that we handle the situation if we have two core files with the same PID """
-        try:
-            self.do_change_pid_in_minidump("linux-x86_64_not_crashed.dmp",
-                                           "linux-x86_64_not_crashed-pid.dmp",
-                                           self._linux_x86_64_not_crashed_pid_offset,
-                                           str(self._linux_x86_64_not_crashed_pid),
-                                           str(self._linux_x86_64_pid))
-            self.do_test_deeper_stack("linux-x86_64_not_crashed",
-                                      "linux-x86_64_not_crashed-pid.dmp",
-                                      self._linux_x86_64_pid)
-            self.test_stack_info_in_minidump()
-        finally:
-            self.RemoveTempFile("linux-x86_64_not_crashed-pid.dmp")
+        new_core = self.getBuildArtifact("linux-x86_64_not_crashed-pid.dmp")
+        self.do_change_pid_in_minidump("linux-x86_64_not_crashed.dmp",
+                                       new_core,
+                                       self._linux_x86_64_not_crashed_pid_offset,
+                                       str(self._linux_x86_64_not_crashed_pid),
+                                       str(self._linux_x86_64_pid))
+        self.do_test_deeper_stack("linux-x86_64_not_crashed",
+                                  new_core, self._linux_x86_64_pid)
+        self.test_stack_info_in_minidump()
 
     def test_local_variables_in_minidump(self):
         """Test that we can examine local variables in a Minidump."""

Modified: lldb/trunk/packages/Python/lldbsuite/test/logging/TestLogging.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/logging/TestLogging.py?rev=328106&r1=328105&r2=328106&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/logging/TestLogging.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/logging/TestLogging.py Wed Mar 21 08:29:32 2018
@@ -17,15 +17,11 @@ from lldbsuite.test import lldbutil
 class LogTestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
-    append_log_file = "lldb-commands-log-append.txt"
-    truncate_log_file = "lldb-commands-log-truncate.txt"
     NO_DEBUG_INFO_TESTCASE = True
 
-    @classmethod
-    def classCleanup(cls):
-        """Cleanup the test byproducts."""
-        cls.RemoveTempFile(cls.truncate_log_file)
-        cls.RemoveTempFile(cls.append_log_file)
+    def setUp(self):
+        super(LogTestCase, self).setUp()
+        self.log_file = self.getBuildArtifact("log-file.txt")
 
     def test(self):
         self.build()
@@ -65,22 +61,17 @@ class LogTestCase(TestBase):
 
     # Check that lldb truncates its log files
     def test_log_truncate(self):
-        if (os.path.exists(self.truncate_log_file)):
-            os.remove(self.truncate_log_file)
-
         # put something in our log file
-        with open(self.truncate_log_file, "w") as f:
+        with open(self.log_file, "w") as f:
             for i in range(1, 1000):
                 f.write("bacon\n")
 
-        self.runCmd(
-            "log enable -t -f '%s' lldb commands" %
-            (self.truncate_log_file))
+        self.runCmd("log enable -t -f '%s' lldb commands" % self.log_file)
         self.runCmd("help log")
         self.runCmd("log disable lldb")
 
-        self.assertTrue(os.path.isfile(self.truncate_log_file))
-        with open(self.truncate_log_file, "r") as f:
+        self.assertTrue(os.path.isfile(self.log_file))
+        with open(self.log_file, "r") as f:
             contents = f.read()
 
         # check that it got removed
@@ -88,21 +79,16 @@ class LogTestCase(TestBase):
 
     # Check that lldb can append to a log file
     def test_log_append(self):
-        if (os.path.exists(self.append_log_file)):
-            os.remove(self.append_log_file)
-
         # put something in our log file
-        with open(self.append_log_file, "w") as f:
+        with open(self.log_file, "w") as f:
             f.write("bacon\n")
 
-        self.runCmd(
-            "log enable -t -a -f '%s' lldb commands" %
-            (self.append_log_file))
+        self.runCmd( "log enable -t -a -f '%s' lldb commands" % self.log_file)
         self.runCmd("help log")
         self.runCmd("log disable lldb")
 
-        self.assertTrue(os.path.isfile(self.append_log_file))
-        with open(self.append_log_file, "r") as f:
+        self.assertTrue(os.path.isfile(self.log_file))
+        with open(self.log_file, "r") as f:
             contents = f.read()
 
         # check that it is still there

Modified: lldb/trunk/packages/Python/lldbsuite/test/source-manager/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/source-manager/Makefile?rev=328106&r1=328105&r2=328106&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/source-manager/Makefile (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/source-manager/Makefile Wed Mar 21 08:29:32 2018
@@ -1,5 +1,13 @@
 LEVEL = ../make
 
-C_SOURCES := main.c
+C_SOURCES := main-copy.c
 
 include $(LEVEL)/Makefile.rules
+
+# Copy file into the build folder to enable the test to modify it.
+main-copy.c: main.c
+	cp -f $< $@
+
+
+clean::
+	$(RM) main-copy.c

Modified: lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py?rev=328106&r1=328105&r2=328106&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py Wed Mar 21 08:29:32 2018
@@ -27,20 +27,19 @@ class SourceManagerTestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
 
-    SOURCE_FILE = 'main.c'
-
     NO_DEBUG_INFO_TESTCASE = True
 
     def setUp(self):
         # Call super's setUp().
         TestBase.setUp(self)
         # Find the line number to break inside main().
-        self.line = line_number(self.SOURCE_FILE, '// Set break point at this line.')
+        self.file = self.getBuildArtifact("main-copy.c")
+        self.line = line_number("main.c", '// Set break point at this line.')
 
     def get_expected_stop_column_number(self):
         """Return the 1-based column number of the first non-whitespace
         character in the breakpoint source line."""
-        stop_line = get_line(self.SOURCE_FILE, self.line)
+        stop_line = get_line(self.file, self.line)
         # The number of spaces that must be skipped to get to the first non-
         # whitespace character --- where we expect the debugger breakpoint
         # column to be --- is equal to the number of characters that get
@@ -71,8 +70,7 @@ class SourceManagerTestCase(TestBase):
         # and styles such as underline.
         self.dbg.SetUseColor(use_color)
 
-        # Create the filespec for 'main.c'.
-        filespec = lldb.SBFileSpec('main.c', False)
+        filespec = lldb.SBFileSpec(self.file, False)
         source_mgr = self.dbg.GetSourceManager()
         # Use a string stream as the destination.
         stream = lldb.SBStream()
@@ -120,12 +118,10 @@ class SourceManagerTestCase(TestBase):
         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 
         # Move main.c to hidden/main.c.
-        main_c = "main.c"
-        main_c_hidden = os.path.join("hidden", main_c)
-        os.rename(main_c, main_c_hidden)
-
-        # Restore main.c after the test.
-        self.addTearDownHook(lambda: os.rename(main_c_hidden, main_c))
+        hidden = self.getBuildArtifact("hidden")
+        lldbutil.mkdir_p(hidden)
+        main_c_hidden = os.path.join(hidden, "main-copy.c")
+        os.rename(self.file, main_c_hidden)
 
         if self.TraceOn():
             system([["ls"]])
@@ -140,12 +136,10 @@ class SourceManagerTestCase(TestBase):
 
         # Set target.source-map settings.
         self.runCmd("settings set target.source-map %s %s" %
-                    (self.getSourceDir(),
-                     os.path.join(self.getSourceDir(), "hidden")))
+                    (self.getBuildDir(), hidden))
         # And verify that the settings work.
         self.expect("settings show target.source-map",
-                    substrs=[self.getSourceDir(),
-                             os.path.join(self.getSourceDir(), "hidden")])
+                    substrs=[self.getBuildDir(), hidden])
 
         # Display main() and verify that the source mapping has been kicked in.
         self.expect("source list -n main", SOURCE_DISPLAYED_CORRECTLY,
@@ -158,19 +152,19 @@ class SourceManagerTestCase(TestBase):
         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 
         lldbutil.run_break_set_by_file_and_line(
-            self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
+            self, "main-copy.c", self.line, num_expected_locations=1, loc_exact=True)
 
         self.runCmd("run", RUN_SUCCEEDED)
 
         # The stop reason of the thread should be breakpoint.
         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
                     substrs=['stopped',
-                             'main.c:%d' % self.line,
+                             'main-copy.c:%d' % self.line,
                              'stop reason = breakpoint'])
 
         # Display some source code.
         self.expect(
-            "source list -f main.c -l %d" %
+            "source list -f main-copy.c -l %d" %
             self.line,
             SOURCE_DISPLAYED_CORRECTLY,
             substrs=['Hello world'])
@@ -191,7 +185,7 @@ class SourceManagerTestCase(TestBase):
         self.assertTrue(int(m.group(1)) > 0)
 
         # Read the main.c file content.
-        with io.open('main.c', 'r', newline='\n') as f:
+        with io.open(self.file, 'r', newline='\n') as f:
             original_content = f.read()
             if self.TraceOn():
                 print("original content:", original_content)
@@ -199,49 +193,32 @@ class SourceManagerTestCase(TestBase):
         # Modify the in-memory copy of the original source code.
         new_content = original_content.replace('Hello world', 'Hello lldb', 1)
 
-        # This is the function to restore the original content.
-        def restore_file():
-            #print("os.path.getmtime() before restore:", os.path.getmtime('main.c'))
-            time.sleep(1)
-            with io.open('main.c', 'w', newline='\n') as f:
-                f.write(original_content)
-            if self.TraceOn():
-                with open('main.c', 'r') as f:
-                    print("content restored to:", f.read())
-            # Touch the file just to be sure.
-            os.utime('main.c', None)
-            if self.TraceOn():
-                print(
-                    "os.path.getmtime() after restore:",
-                    os.path.getmtime('main.c'))
-
         # Modify the source code file.
-        with io.open('main.c', 'w', newline='\n') as f:
+        with io.open(self.file, 'w', newline='\n') as f:
             time.sleep(1)
             f.write(new_content)
             if self.TraceOn():
                 print("new content:", new_content)
                 print(
                     "os.path.getmtime() after writing new content:",
-                    os.path.getmtime('main.c'))
-            # Add teardown hook to restore the file to the original content.
-            self.addTearDownHook(restore_file)
+                    os.path.getmtime(self.file))
 
         # Display the source code again.  We should see the updated line.
         self.expect(
-            "source list -f main.c -l %d" %
+            "source list -f main-copy.c -l %d" %
             self.line,
             SOURCE_DISPLAYED_CORRECTLY,
             substrs=['Hello lldb'])
 
     def test_set_breakpoint_with_absolute_path(self):
         self.build()
+        hidden = self.getBuildArtifact("hidden")
+        lldbutil.mkdir_p(hidden)
         self.runCmd("settings set target.source-map %s %s" %
-                    (self.getSourceDir(),
-                     os.path.join(self.getSourceDir(), "hidden")))
+                    (self.getBuildDir(), hidden))
 
         exe = self.getBuildArtifact("a.out")
-        main = os.path.join(self.getSourceDir(), "hidden", "main.c")
+        main = os.path.join(self.getBuildDir(), "hidden", "main-copy.c")
         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 
         lldbutil.run_break_set_by_file_and_line(
@@ -252,5 +229,5 @@ class SourceManagerTestCase(TestBase):
         # The stop reason of the thread should be breakpoint.
         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
                     substrs=['stopped',
-                             'main.c:%d' % self.line,
+                             'main-copy.c:%d' % self.line,
                              'stop reason = breakpoint'])




More information about the lldb-commits mailing list