-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Fix and re-enable TestUseSourceCache.py #111237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Fix and re-enable TestUseSourceCache.py #111237
Conversation
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.
@llvm/pr-subscribers-lldb Author: Igor Kudrin (igorkudrin) ChangesThe decorators caused the main test, i.e. This patch changes the test to check that the content can still be displayed, even after deleting the file, when the source cache is enabled. The updated test is expected to pass on any platform, so the decorators are removed. Full diff: https://github.com/llvm/llvm-project/pull/111237.diff 1 Files Affected:
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(
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Tagging @emrekultursay, as this might be interesting for him. As I understand it, Android Studio was setting use-source-cache:=false
so that users can continue to edit files on windows while lldb has them open.
Judging by this patch, that may no longer be necessary. Or does that only apply for certain situations (certain windows versions, files which are not large enough to be mmapped, etc.)?
Based on the change history of |
Was there an LLDB change about how it opens a source file? When this test was written, LLDB called:
...and that
LLDB used memory mapping for very large files. Maybe the test |
The only change in the sequence I can see was replacing |
At least back when I was looking at this problem (5+ years ago), memory mapping was the key -- I was not able to delete the process if the file was mapped -- regardless of the open flags. That said, this comment seems to indicate this might be possible (though it may refer to FILE_FLAG_DELETE_ON_CLOSE rather then an separate delete operation), so 🤷 Either way, I think this change is fine, as we don't really want to enforce that the file can't be deleted if the source cache setting is "true". |
OK, I figured the problem. In the test, we call Empirically, on Windows 11, I can verify that when LLDB mmaps these large files, then:
I am guessing that there are different mechanisms for deleting/editing/saving, and different editors/tools use different approaches. To make the test more representative, I suggeest replacing the
...and then the test should start passing. |
433f6ef
to
1715b2d
Compare
Well, that's... interesting. Thanks for gathering these. I suspect that this is due to different strategies for saving a file. I know of basically two: you either delete the file and create a new one in its place (if you want a backup you can rename instead of deleting), or you overwrite the file in place (and make a copy if you want a backup). In vim, this is controlled by the With this in mind, deleting the file is representative of an editor wanting to save the file using the deletion strategy, but I still think it's not our goal here to ensure the editor cannot save the file if the setting is |
I agree that having a test that sets |
✅ With the latest revision this PR passed the Python code formatter. |
59d1ba9
to
a469050
Compare
So the test basically shows that it makes sense to set |
LGTM. Thanks. |
Makes sense (and now that I think about it, I think I used some line of reasoning like this on the original patch that introduced this). |
The decorators caused the
test_set_use_source_cache_true()
test to be skipped in most scenarios. It was only run on a Windows host targeting a non-Windows remote platform. The source file is opened with theFILE_SHARE_DELETE
sharing mode, which allows the file to be removed even though it is also memory-mapped; at least, this behavior is observed on Windows 11.The patch replaces the operation with an attempt to overwrite the file, which still fails for such files on Windows 11.