summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-03-21 15:29:32 +0000
committerPavel Labath <labath@google.com>2018-03-21 15:29:32 +0000
commit292178e10463ad40c73bd86c6783180ddf351586 (patch)
tree11335b95d4c7d492d038f4f1ca860a7201ac2220 /lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
parentbab6ce018fde9a0a9d720b5d0660022bf782e526 (diff)
downloadbcm5719-llvm-292178e10463ad40c73bd86c6783180ddf351586.tar.gz
bcm5719-llvm-292178e10463ad40c73bd86c6783180ddf351586.zip
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. llvm-svn: 328106
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py')
-rw-r--r--lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py67
1 files changed, 22 insertions, 45 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py b/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
index a30f8187cdc..0df4f8b2d2a 100644
--- a/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
+++ b/lldb/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
@@ -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'])
OpenPOWER on IntegriCloud