Narrow the CRC scope in file_test (#5043)

This narrows the scope of the CRC to try to get better behavior around
mutex lock releasing on crash. Closes #5042.

This breaks apart `ProcessTestFileAndRun` because we need to process the
test file for `SET-CAPTURE-CONSOLE-OUTPUT`. The test file processing
should more reliably not crash than the core `Run` logic though, so
should be reasonably safe to put outside the CRC.

Also support --threads=1 for disabling threading. This is the flipside
for me of reducing how much is in the CRC: make it easier to run on a
single thread if the CRC gets in the way of debugging. This also means a
typical copy-paste execution of a single test will be single-threaded.

---------

Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
Jon Ross-Perkins
2025-02-28 21:25:15 +00:00
committed by GitHub
co-authored by Geoff Romer
parent fc5dcfe957
commit 6d6987dce4
7 changed files with 172 additions and 124 deletions
+6 -6
View File
@@ -23,25 +23,25 @@ class FileTestBaseTest : public FileTestBase {
auto Run(const llvm::SmallVector<llvm::StringRef>& test_args,
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>& fs,
FILE* input_stream, llvm::raw_pwrite_stream& output_stream,
llvm::raw_pwrite_stream& error_stream)
llvm::raw_pwrite_stream& error_stream) const
-> ErrorOr<RunResult> override;
auto GetArgReplacements() -> llvm::StringMap<std::string> override {
auto GetArgReplacements() const -> llvm::StringMap<std::string> override {
return {{"replacement", "replaced"}};
}
auto GetDefaultArgs() -> llvm::SmallVector<std::string> override {
auto GetDefaultArgs() const -> llvm::SmallVector<std::string> override {
return {"default_args", "%s"};
}
auto GetDefaultFileRE(llvm::ArrayRef<llvm::StringRef> filenames)
auto GetDefaultFileRE(llvm::ArrayRef<llvm::StringRef> filenames) const
-> std::optional<RE2> override {
return std::make_optional<RE2>(
llvm::formatv(R"(file: ({0}))", llvm::join(filenames, "|")));
}
auto GetLineNumberReplacements(llvm::ArrayRef<llvm::StringRef> filenames)
-> llvm::SmallVector<LineNumberReplacement> override {
const -> llvm::SmallVector<LineNumberReplacement> override {
auto replacements = FileTestBase::GetLineNumberReplacements(filenames);
auto filename = std::filesystem::path(test_name().str()).filename();
if (llvm::StringRef(filename).starts_with("file_only_re_")) {
@@ -260,7 +260,7 @@ auto FileTestBaseTest::Run(
const llvm::SmallVector<llvm::StringRef>& test_args,
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>& fs,
FILE* input_stream, llvm::raw_pwrite_stream& output_stream,
llvm::raw_pwrite_stream& error_stream) -> ErrorOr<RunResult> {
llvm::raw_pwrite_stream& error_stream) const -> ErrorOr<RunResult> {
PrintArgs(test_args, output_stream);
auto filename = std::filesystem::path(test_name().str()).filename();