[Lldb-commits] [lldb] [lldb] Fix and re-enable TestUseSourceCache.py (PR #111237)
Igor Kudrin via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 8 22:16:48 PDT 2024
https://github.com/igorkudrin updated https://github.com/llvm/llvm-project/pull/111237
>From 6756842b1c78ac6f41fa467f112aa7632f260582 Mon Sep 17 00:00:00 2001
From: Igor Kudrin <ikudrin at accesssoftek.com>
Date: Fri, 4 Oct 2024 23:27:04 -0700
Subject: [PATCH 1/2] [lldb] Fix and re-enable TestUseSourceCache.py
The decorators caused the main test, i.e. `test_set_use_source_cache_true()`,
to be skipped in most scenarios. In fact, it was only run on a Windows host
targeting a non-Windows remote platform, and it failed in this case because
the source file is opened with the `FILE_SHARE_DELETE` share mode, which
allows the file to be removed, see `llvm::sys::fs::openNativeFileInternal()`
in `llvm/lib/Support/Windows/Path.inc`.
This patch changes the test to check that the content can still be displayed
even after deleting the file when caching is enabled. The updated test is
expected to work on any platform, so the decorators are removed.
---
.../settings/use_source_cache/TestUseSourceCache.py | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py b/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py
index 421599080a9e51..421b13f253f05b 100644
--- a/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py
+++ b/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py
@@ -17,8 +17,6 @@ def test_set_use_source_cache_false(self):
"""Test that after 'set use-source-cache false', files are not locked."""
self.set_use_source_cache_and_test(False)
- @skipIf(hostoslist=no_match(["windows"]))
- @skipIf(oslist=["windows"]) # Fails on windows 11
def test_set_use_source_cache_true(self):
"""Test that after 'set use-source-cache false', files are locked."""
self.set_use_source_cache_and_test(True)
@@ -43,16 +41,15 @@ def set_use_source_cache_and_test(self, is_cache_enabled):
self, "calc"
)
- # Show the source file contents to make sure LLDB loads src file.
- self.runCmd("source list")
+ # Ensure that the source file is loaded.
+ self.expect("step", patterns=["-> .+ int x4 ="])
# Try deleting the source file.
is_file_removed = self.removeFile(src)
if is_cache_enabled:
- self.assertFalse(
- is_file_removed, "Source cache is enabled, but delete file succeeded"
- )
+ # Regardless of whether the file is removed, its contents should be displayed.
+ self.expect("step", patterns=["-> .+ int x5 ="])
if not is_cache_enabled:
self.assertTrue(
>From 433f6efa4657494c9b9a5581f3fa2b5b2299ff24 Mon Sep 17 00:00:00 2001
From: Igor Kudrin <ikudrin at accesssoftek.com>
Date: Tue, 8 Oct 2024 22:16:23 -0700
Subject: [PATCH 2/2] `removeFile()` -> `overwriteFile()`
---
.../use_source_cache/TestUseSourceCache.py | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py b/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py
index 421b13f253f05b..3e9cfcf2fba27d 100644
--- a/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py
+++ b/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py
@@ -44,22 +44,24 @@ def set_use_source_cache_and_test(self, is_cache_enabled):
# Ensure that the source file is loaded.
self.expect("step", patterns=["-> .+ int x4 ="])
- # Try deleting the source file.
- is_file_removed = self.removeFile(src)
+ # Try overwriting the source file.
+ is_file_overwritten = self.overwriteFile(src)
if is_cache_enabled:
- # Regardless of whether the file is removed, its contents should be displayed.
+ # Regardless of whether the file is changed, its original contents should be displayed.
self.expect("step", patterns=["-> .+ int x5 ="])
if not is_cache_enabled:
self.assertTrue(
- is_file_removed, "Source cache is disabled, but delete file failed"
+ is_file_overwritten, "Source cache is disabled, but writing to file failed"
)
- def removeFile(self, src):
- """Remove file and return true iff file was successfully removed."""
+ def overwriteFile(self, src):
+ """Write to file and return true iff file was successfully written."""
try:
- os.remove(src)
+ f = open(src, "w")
+ f.writelines(["// hello world\n"])
+ f.close()
return True
except Exception:
return False
More information about the lldb-commits
mailing list