diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 | 
| commit | f73363f1dd94996356cefbf24388f561891acf0b (patch) | |
| tree | e3c31248bdb36eaec5fd833490d4278162dba2a0 /packages/Python/lldbsuite/test/source-manager | |
| parent | 160ee69dd7ae18978f4068116777639ea98dc951 (diff) | |
Notes
Diffstat (limited to 'packages/Python/lldbsuite/test/source-manager')
| -rw-r--r-- | packages/Python/lldbsuite/test/source-manager/Makefile | 10 | ||||
| -rw-r--r-- | packages/Python/lldbsuite/test/source-manager/TestSourceManager.py | 72 | 
2 files changed, 35 insertions, 47 deletions
| diff --git a/packages/Python/lldbsuite/test/source-manager/Makefile b/packages/Python/lldbsuite/test/source-manager/Makefile index d6cd0db0506f7..5d19a27a2df2e 100644 --- a/packages/Python/lldbsuite/test/source-manager/Makefile +++ b/packages/Python/lldbsuite/test/source-manager/Makefile @@ -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 diff --git a/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py b/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py index 31fe5437d1d2e..0df4f8b2d2a81 100644 --- a/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py +++ b/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py @@ -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 @@ -50,7 +49,7 @@ class SourceManagerTestCase(TestBase):      def do_display_source_python_api(self, use_color, column_marker_regex):          self.build() -        exe = os.path.join(os.getcwd(), "a.out") +        exe = self.getBuildArtifact("a.out")          self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)          target = self.dbg.CreateTarget(exe) @@ -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() @@ -116,16 +114,14 @@ class SourceManagerTestCase(TestBase):      def test_move_and_then_display_source(self):          """Test that target.source-map settings work by moving main.c to hidden/main.c."""          self.build() -        exe = os.path.join(os.getcwd(), "a.out") +        exe = self.getBuildArtifact("a.out")          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,10 +136,10 @@ class SourceManagerTestCase(TestBase):          # Set target.source-map settings.          self.runCmd("settings set target.source-map %s %s" % -                    (os.getcwd(), os.path.join(os.getcwd(), "hidden"))) +                    (self.getBuildDir(), hidden))          # And verify that the settings work.          self.expect("settings show target.source-map", -                    substrs=[os.getcwd(), os.path.join(os.getcwd(), "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, @@ -152,23 +148,23 @@ class SourceManagerTestCase(TestBase):      def test_modify_source_file_while_debugging(self):          """Modify a source file while debugging the executable."""          self.build() -        exe = os.path.join(os.getcwd(), "a.out") +        exe = self.getBuildArtifact("a.out")          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']) @@ -189,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) @@ -197,48 +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" % -                    (os.getcwd(), os.path.join(os.getcwd(), "hidden"))) +                    (self.getBuildDir(), hidden)) -        exe = os.path.join(os.getcwd(), "a.out") -        main = os.path.join(os.getcwd(), "hidden", "main.c") +        exe = self.getBuildArtifact("a.out") +        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( @@ -249,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']) | 
