From: Jordan Rupprecht Date: Mon, 21 Nov 2022 19:56:02 +0000 (-0800) Subject: [test] Fix TestSourceManager when the source file is readonly. X-Git-Tag: upstream/17.0.6~26953 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=71b2ff79043aea637335b28299e978b678fd83bd;p=platform%2Fupstream%2Fllvm.git [test] Fix TestSourceManager when the source file is readonly. This test copies main.c to main-copy.c and modifies main-copy.c while debugging, but main.c may have come from a readonly location, which means writing to main-copy.c will fail because permissions are preserved. Run the equivalent of "chmod u+w" before attempting to modify it. This effect can be seen by attempting to run this test after running `chmod u-w lldb/test/API/source-manager/main.c` --- diff --git a/lldb/test/API/source-manager/TestSourceManager.py b/lldb/test/API/source-manager/TestSourceManager.py index 439366c..9f087b9 100644 --- a/lldb/test/API/source-manager/TestSourceManager.py +++ b/lldb/test/API/source-manager/TestSourceManager.py @@ -9,6 +9,9 @@ o test_modify_source_file_while_debugging: Test the caching mechanism of the source manager. """ +import os +import stat + import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -220,6 +223,11 @@ class SourceManagerTestCase(TestBase): new_content = original_content.replace('Hello world', 'Hello lldb', 1) # Modify the source code file. + # If the source was read only, the copy will also be read only. + # Run "chmod u+w" on it first so we can modify it. + statinfo = os.stat(self.file) + os.chmod(self.file, statinfo.st_mode | stat.S_IWUSR) + with io.open(self.file, 'w', newline='\n') as f: time.sleep(1) f.write(new_content)