[test] Fix TestSourceManager when the source file is readonly.
authorJordan Rupprecht <rupprecht@google.com>
Mon, 21 Nov 2022 19:56:02 +0000 (11:56 -0800)
committerJordan Rupprecht <rupprecht@google.com>
Mon, 21 Nov 2022 19:56:02 +0000 (11:56 -0800)
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`

lldb/test/API/source-manager/TestSourceManager.py

index 439366c..9f087b9 100644 (file)
@@ -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)