diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-02-26 10:27:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-26 10:27:41 +0100 |
| commit | 0e08be5360f9412c2a6fed52425f23f22db54ca5 (patch) | |
| tree | 743402f74a38cb114f0cfd218e7a2257e28d51c5 /src/tools/compiletest | |
| parent | dc00e8cdb6cfb6c75b4e98cdc181583cb7d11749 (diff) | |
| parent | e56cc8408d67afe5d58cdd4311ecc97ed44f14aa (diff) | |
| download | rust-0e08be5360f9412c2a6fed52425f23f22db54ca5.tar.gz rust-0e08be5360f9412c2a6fed52425f23f22db54ca5.zip | |
Rollup merge of #120656 - Zalathar:filecheck-flags, r=wesleywiser
Allow tests to specify a `//@ filecheck-flags:` header This allows individual codegen/assembly/mir-opt tests to pass extra flags to the LLVM `filecheck` tool as needed. --- The original motivation was noticing that `tests/run-make/instrument-coverage` was very close to being an ordinary codegen test, except that it needs some extra logic to set up platform-specific variables to be passed into filecheck. I then saw the comment in `verify_with_filecheck` indicating that a `filecheck-flags` header might be useful for other purposes as well.
Diffstat (limited to 'src/tools/compiletest')
| -rw-r--r-- | src/tools/compiletest/src/header.rs | 8 | ||||
| -rw-r--r-- | src/tools/compiletest/src/runtest.rs | 39 |
2 files changed, 31 insertions, 16 deletions
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index c76cba824a3..6de445a5783 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -197,6 +197,8 @@ pub struct TestProps { /// Extra flags to pass to `llvm-cov` when producing coverage reports. /// Only used by the "coverage-run" test mode. pub llvm_cov_flags: Vec<String>, + /// Extra flags to pass to LLVM's `filecheck` tool, in tests that use it. + pub filecheck_flags: Vec<String>, } mod directives { @@ -236,6 +238,7 @@ mod directives { pub const REMAP_SRC_BASE: &'static str = "remap-src-base"; pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset"; pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags"; + pub const FILECHECK_FLAGS: &'static str = "filecheck-flags"; // This isn't a real directive, just one that is probably mistyped often pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags"; } @@ -286,6 +289,7 @@ impl TestProps { mir_unit_test: None, remap_src_base: false, llvm_cov_flags: vec![], + filecheck_flags: vec![], } } @@ -542,6 +546,10 @@ impl TestProps { if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) { self.llvm_cov_flags.extend(split_flags(&flags)); } + + if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) { + self.filecheck_flags.extend(split_flags(&flags)); + } }, ); diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 61211a7d675..f1ba9ab4767 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2909,25 +2909,32 @@ impl<'test> TestCx<'test> { fn verify_with_filecheck(&self, output: &Path) -> ProcRes { let mut filecheck = Command::new(self.config.llvm_filecheck.as_ref().unwrap()); filecheck.arg("--input-file").arg(output).arg(&self.testpaths.file); - // It would be more appropriate to make most of the arguments configurable through - // a comment-attribute similar to `compile-flags`. For example, --check-prefixes is a very - // useful flag. - // - // For now, though… - let prefix_for_target = - if self.config.target.contains("msvc") { "MSVC" } else { "NONMSVC" }; - let prefixes = if let Some(rev) = self.revision { - format!("CHECK,{},{}", prefix_for_target, rev) - } else { - format!("CHECK,{}", prefix_for_target) - }; - if self.config.llvm_version.unwrap_or(0) >= 130000 { - filecheck.args(&["--allow-unused-prefixes", "--check-prefixes", &prefixes]); - } else { - filecheck.args(&["--check-prefixes", &prefixes]); + + // FIXME: Consider making some of these prefix flags opt-in per test, + // via `filecheck-flags` or by adding new header directives. + + // Because we use custom prefixes, we also have to register the default prefix. + filecheck.arg("--check-prefix=CHECK"); + + // Some tests use the current revision name as a check prefix. + if let Some(rev) = self.revision { + filecheck.arg("--check-prefix").arg(rev); } + + // Some tests also expect either the MSVC or NONMSVC prefix to be defined. + let msvc_or_not = if self.config.target.contains("msvc") { "MSVC" } else { "NONMSVC" }; + filecheck.arg("--check-prefix").arg(msvc_or_not); + + // The filecheck tool normally fails if a prefix is defined but not used. + // However, we define several prefixes globally for all tests. + filecheck.arg("--allow-unused-prefixes"); + // Provide more context on failures. filecheck.args(&["--dump-input-context", "100"]); + + // Add custom flags supplied by the `filecheck-flags:` test header. + filecheck.args(&self.props.filecheck_flags); + self.compose_and_run(filecheck, "", None, None) } |
