Files
Dave Lee b9225e8607 [lldb] Allow tests to share a single build (#181720)
This changes Python API tests to use a single build shared across all
test functions, instead of the previous default behavior of a separate
build dir for each test function.

This build behavior opt-out, tests can use the previous behavior of one
individual (unshared) build directory per test function, by setting
`SHARED_BUILD_TESTCASE` to False (in the test class).

The motivation is to make the test suite more efficient, by not
repeatedly building the same test source. When running tests on my macOS
machine, this reduces the time of `ninja check-lldb-api` by almost 60%
(sample numbers: from ~492s down to ~207s = 58%). Almost 5min time
saved.

Each test function still calls `self.build()`, but only the first call
will do a build, in the subsequent tests `make` will be a no-op because
the sources won't have changed.
2026-02-18 10:38:45 -08:00

73 lines
2.3 KiB
Python

"""
Tests large source files are not locked on Windows when source cache is disabled
"""
import lldb
import os
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
from shutil import copy
class SettingsUseSourceCacheTestCase(TestBase):
NO_DEBUG_INFO_TESTCASE = True
SHARED_BUILD_TESTCASE = False
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"]))
def test_set_use_source_cache_true(self):
"""Test that after 'set use-source-cache true', files are locked."""
self.set_use_source_cache_and_test(True)
def set_use_source_cache_and_test(self, is_cache_enabled):
"""Common test for both True/False values of use-source-cache."""
self.build()
# Enable/Disable source cache
self.runCmd(
"settings set use-source-cache " + ("true" if is_cache_enabled else "false")
)
# Get paths for the main source file.
src = self.getBuildArtifact("main-copy.cpp")
self.assertTrue(src)
# Make sure source file is bigger than 16K to trigger memory mapping
self.assertGreater(os.stat(src).st_size, 4 * 4096)
target, process, thread, breakpoint = lldbutil.run_to_name_breakpoint(
self, "calc"
)
# Show the source file contents to make sure LLDB loads src file.
self.runCmd("source list")
# Try overwriting the source file.
is_file_overwritten = self.overwriteFile(src)
if is_cache_enabled:
self.assertFalse(
is_file_overwritten,
"Source cache is enabled, but writing to file succeeded",
)
if not is_cache_enabled:
self.assertTrue(
is_file_overwritten,
"Source cache is disabled, but writing to file failed",
)
def overwriteFile(self, src):
"""Write to file and return true iff file was successfully written."""
try:
f = open(src, "w")
f.writelines(["// hello world\n"])
f.close()
return True
except Exception:
return False