diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /src/tools/compiletest | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/tools/compiletest/src/common.rs | 6 | ||||
-rw-r--r-- | src/tools/compiletest/src/header.rs | 35 | ||||
-rw-r--r-- | src/tools/compiletest/src/main.rs | 4 | ||||
-rw-r--r-- | src/tools/compiletest/src/read2.rs | 13 | ||||
-rw-r--r-- | src/tools/compiletest/src/runtest.rs | 63 | ||||
-rw-r--r-- | src/tools/compiletest/src/util.rs | 10 |
6 files changed, 104 insertions, 27 deletions
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 07b80b8ba..a5f5eb447 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -240,7 +240,7 @@ pub struct Config { pub mode: Mode, /// The test suite (essentially which directory is running, but without the - /// directory prefix such as src/test) + /// directory prefix such as tests) pub suite: String, /// The debugger to use in debuginfo mode. Unset otherwise. @@ -617,6 +617,6 @@ pub fn output_base_name(config: &Config, testpaths: &TestPaths, revision: Option /// Absolute path to the directory to use for incremental compilation. Example: /// /path/to/build/host-triple/test/ui/relative/testname.mode/testname.inc -pub fn incremental_dir(config: &Config, testpaths: &TestPaths) -> PathBuf { - output_base_name(config, testpaths, None).with_extension("inc") +pub fn incremental_dir(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf { + output_base_name(config, testpaths, revision).with_extension("inc") } diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 64d97e914..423299495 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -162,6 +162,9 @@ pub struct TestProps { pub stderr_per_bitwidth: bool, // The MIR opt to unit test, if any pub mir_unit_test: Option<String>, + // Whether to tell `rustc` to remap the "src base" directory to a fake + // directory. + pub remap_src_base: bool, } mod directives { @@ -196,6 +199,7 @@ mod directives { pub const INCREMENTAL: &'static str = "incremental"; pub const KNOWN_BUG: &'static str = "known-bug"; pub const MIR_UNIT_TEST: &'static str = "unit-test"; + pub const REMAP_SRC_BASE: &'static str = "remap-src-base"; // This isn't a real directive, just one that is probably mistyped often pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags"; } @@ -241,6 +245,7 @@ impl TestProps { should_ice: false, stderr_per_bitwidth: false, mir_unit_test: None, + remap_src_base: false, } } @@ -273,6 +278,9 @@ impl TestProps { /// `//[foo]`), then the property is ignored unless `cfg` is /// `Some("foo")`. fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) { + // Mode-dependent defaults. + self.remap_src_base = config.mode == Mode::Ui && !config.suite.contains("rustdoc"); + let mut has_edition = false; if !testfile.is_dir() { let file = File::open(testfile).unwrap(); @@ -426,13 +434,19 @@ impl TestProps { self.known_bug = true; } else { panic!( - "Invalid known-bug value: {known_bug}\nIt requires comma-separated issue references (`#000` or `chalk#000`) or `unknown`." + "Invalid known-bug value: {known_bug}\nIt requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`." ); } + } else if config.parse_name_directive(ln, KNOWN_BUG) { + panic!( + "Invalid known-bug attribute, requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`." + ); } + config.set_name_value_directive(ln, MIR_UNIT_TEST, &mut self.mir_unit_test, |s| { s.trim().to_string() }); + config.set_name_directive(ln, REMAP_SRC_BASE, &mut self.remap_src_base); }); } @@ -725,6 +739,10 @@ impl Config { && matches!(line.as_bytes().get(directive.len()), None | Some(&b' ') | Some(&b':')) } + fn parse_negative_name_directive(&self, line: &str, directive: &str) -> bool { + line.starts_with("no-") && self.parse_name_directive(&line[3..], directive) + } + pub fn parse_name_value_directive(&self, line: &str, directive: &str) -> Option<String> { let colon = directive.len(); if line.starts_with(directive) && line.as_bytes().get(colon) == Some(&b':') { @@ -754,8 +772,17 @@ impl Config { } fn set_name_directive(&self, line: &str, directive: &str, value: &mut bool) { - if !*value { - *value = self.parse_name_directive(line, directive) + match value { + true => { + if self.parse_negative_name_directive(line, directive) { + *value = false; + } + } + false => { + if self.parse_name_directive(line, directive) { + *value = true; + } + } } } @@ -906,6 +933,7 @@ pub fn make_test_description<R: Read>( let has_asm_support = config.has_asm_support(); let has_asan = util::ASAN_SUPPORTED_TARGETS.contains(&&*config.target); let has_cfi = util::CFI_SUPPORTED_TARGETS.contains(&&*config.target); + let has_kcfi = util::KCFI_SUPPORTED_TARGETS.contains(&&*config.target); let has_lsan = util::LSAN_SUPPORTED_TARGETS.contains(&&*config.target); let has_msan = util::MSAN_SUPPORTED_TARGETS.contains(&&*config.target); let has_tsan = util::TSAN_SUPPORTED_TARGETS.contains(&&*config.target); @@ -957,6 +985,7 @@ pub fn make_test_description<R: Read>( && config.parse_name_directive(ln, "needs-sanitizer-support"); ignore |= !has_asan && config.parse_name_directive(ln, "needs-sanitizer-address"); ignore |= !has_cfi && config.parse_name_directive(ln, "needs-sanitizer-cfi"); + ignore |= !has_kcfi && config.parse_name_directive(ln, "needs-sanitizer-kcfi"); ignore |= !has_lsan && config.parse_name_directive(ln, "needs-sanitizer-leak"); ignore |= !has_msan && config.parse_name_directive(ln, "needs-sanitizer-memory"); ignore |= !has_tsan && config.parse_name_directive(ln, "needs-sanitizer-thread"); diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 91c701a5d..3092c656c 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -774,8 +774,8 @@ fn make_test_name( revision: Option<&String>, ) -> test::TestName { // Print the name of the file, relative to the repository root. - // `src_base` looks like `/path/to/rust/src/test/ui` - let root_directory = config.src_base.parent().unwrap().parent().unwrap().parent().unwrap(); + // `src_base` looks like `/path/to/rust/tests/ui` + let root_directory = config.src_base.parent().unwrap().parent().unwrap(); let path = testpaths.file.strip_prefix(root_directory).unwrap(); let debugger = match config.debugger { Some(d) => format!("-{}", d), diff --git a/src/tools/compiletest/src/read2.rs b/src/tools/compiletest/src/read2.rs index 7640e6517..a5dc68597 100644 --- a/src/tools/compiletest/src/read2.rs +++ b/src/tools/compiletest/src/read2.rs @@ -110,9 +110,18 @@ impl ProcOutput { fn into_bytes(self) -> Vec<u8> { match self { ProcOutput::Full { bytes, .. } => bytes, - ProcOutput::Abbreviated { mut head, skipped, tail } => { + ProcOutput::Abbreviated { mut head, mut skipped, tail } => { + let mut tail = &*tail; + + // Skip over '{' at the start of the tail, so we don't later wrongfully consider this as json. + // See <https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Weird.20CI.20failure/near/321797811> + while tail.get(0) == Some(&b'{') { + tail = &tail[1..]; + skipped += 1; + } + write!(&mut head, "\n\n<<<<<< SKIPPED {} BYTES >>>>>>\n\n", skipped).unwrap(); - head.extend_from_slice(&tail); + head.extend_from_slice(tail); head } } diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 1542b1c17..859c0f1da 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -44,6 +44,8 @@ use debugger::{check_debugger_output, DebuggerCommands}; #[cfg(test)] mod tests; +const FAKE_SRC_BASE: &str = "fake-test-src-base"; + #[cfg(windows)] fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R { use std::sync::Mutex; @@ -117,8 +119,12 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) { } debug!("running {:?}", testpaths.file.display()); let mut props = TestProps::from_file(&testpaths.file, revision, &config); + + // For non-incremental (i.e. regular UI) tests, the incremental directory + // takes into account the revision name, since the revisions are independent + // of each other and can race. if props.incremental { - props.incremental_dir = Some(incremental_dir(&config, testpaths)); + props.incremental_dir = Some(incremental_dir(&config, testpaths, revision)); } let cx = TestCx { config: &config, props: &props, testpaths, revision }; @@ -1324,12 +1330,19 @@ impl<'test> TestCx<'test> { return; } + // On Windows, translate all '\' path separators to '/' + let file_name = format!("{}", self.testpaths.file.display()).replace(r"\", "/"); + // On Windows, keep all '\' path separators to match the paths reported in the JSON output // from the compiler - let os_file_name = self.testpaths.file.display().to_string(); - - // on windows, translate all '\' path separators to '/' - let file_name = format!("{}", self.testpaths.file.display()).replace(r"\", "/"); + let diagnostic_file_name = if self.props.remap_src_base { + let mut p = PathBuf::from(FAKE_SRC_BASE); + p.push(&self.testpaths.relative_dir); + p.push(self.testpaths.file.file_name().unwrap()); + p.display().to_string() + } else { + self.testpaths.file.display().to_string() + }; // If the testcase being checked contains at least one expected "help" // message, then we'll ensure that all "help" messages are expected. @@ -1339,7 +1352,7 @@ impl<'test> TestCx<'test> { let expect_note = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Note)); // Parse the JSON output from the compiler and extract out the messages. - let actual_errors = json::parse_output(&os_file_name, &proc_res.stderr, proc_res); + let actual_errors = json::parse_output(&diagnostic_file_name, &proc_res.stderr, proc_res); let mut unexpected = Vec::new(); let mut found = vec![false; expected_errors.len()]; for actual_error in &actual_errors { @@ -1924,7 +1937,15 @@ impl<'test> TestCx<'test> { rustc.args(&["--json", "future-incompat"]); } rustc.arg("-Ccodegen-units=1"); + // Hide line numbers to reduce churn rustc.arg("-Zui-testing"); + // Hide libstd sources from ui tests to make sure we generate the stderr + // output that users will see. + // Without this, we may be producing good diagnostics in-tree but users + // will not see half the information. + rustc.arg("-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX"); + rustc.arg("-Ztranslate-remapped-path-to-local-path=no"); + rustc.arg("-Zdeduplicate-diagnostics=no"); // FIXME: use this for other modes too, for perf? rustc.arg("-Cstrip=debuginfo"); @@ -1958,6 +1979,14 @@ impl<'test> TestCx<'test> { } } + if self.props.remap_src_base { + rustc.arg(format!( + "--remap-path-prefix={}={}", + self.config.src_base.display(), + FAKE_SRC_BASE, + )); + } + match emit { Emit::None => {} Emit::Metadata if is_rustdoc => {} @@ -1999,7 +2028,7 @@ impl<'test> TestCx<'test> { rustc.args(&["-Zpolonius"]); } Some(CompareMode::Chalk) => { - rustc.args(&["-Zchalk"]); + rustc.args(&["-Ztrait-solver=chalk"]); } Some(CompareMode::SplitDwarf) if self.config.target.contains("windows") => { rustc.args(&["-Csplit-debuginfo=unpacked", "-Zunstable-options"]); @@ -2090,9 +2119,7 @@ impl<'test> TestCx<'test> { .parent() .unwrap() // chop off `ui` .parent() - .unwrap() // chop off `test` - .parent() - .unwrap(); // chop off `src` + .unwrap(); // chop off `tests` args.push(src.join("src/etc/wasm32-shim.js").display().to_string()); } @@ -2291,6 +2318,8 @@ impl<'test> TestCx<'test> { } else { filecheck.args(&["--check-prefixes", &prefixes]); } + // Provide more context on failures. + filecheck.args(&["--dump-input-context", "100"]); self.compose_and_run(filecheck, "", None, None) } @@ -2918,7 +2947,7 @@ impl<'test> TestCx<'test> { fn run_rmake_test(&self) { let cwd = env::current_dir().unwrap(); - let src_root = self.config.src_base.parent().unwrap().parent().unwrap().parent().unwrap(); + let src_root = self.config.src_base.parent().unwrap().parent().unwrap(); let src_root = cwd.join(&src_root); let tmpdir = cwd.join(self.output_base_name()); @@ -3533,9 +3562,17 @@ impl<'test> TestCx<'test> { let parent_dir = self.testpaths.file.parent().unwrap(); normalize_path(parent_dir, "$DIR"); + if self.props.remap_src_base { + let mut remapped_parent_dir = PathBuf::from(FAKE_SRC_BASE); + if self.testpaths.relative_dir != Path::new("") { + remapped_parent_dir.push(&self.testpaths.relative_dir); + } + normalize_path(&remapped_parent_dir, "$DIR"); + } + let source_bases = &[ - // Source base on the current filesystem (calculated as parent of `src/test/$suite`): - Some(self.config.src_base.parent().unwrap().parent().unwrap().parent().unwrap().into()), + // Source base on the current filesystem (calculated as parent of `tests/$suite`): + Some(self.config.src_base.parent().unwrap().parent().unwrap().into()), // Source base on the sysroot (from the src components downloaded by `download-rustc`): Some(self.config.sysroot_base.join("lib").join("rustlib").join("src").join("rust")), // Virtual `/rustc/$sha` remapped paths (if `remap-debuginfo` is enabled): diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs index ec36f1e4f..6c63b760f 100644 --- a/src/tools/compiletest/src/util.rs +++ b/src/tools/compiletest/src/util.rs @@ -11,7 +11,7 @@ mod tests; pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[ "aarch64-apple-darwin", - "aarch64-fuchsia", + "aarch64-unknown-fuchsia", "aarch64-linux-android", "aarch64-unknown-linux-gnu", "arm-linux-androideabi", @@ -19,7 +19,7 @@ pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[ "i686-linux-android", "i686-unknown-linux-gnu", "x86_64-apple-darwin", - "x86_64-fuchsia", + "x86_64-unknown-fuchsia", "x86_64-linux-android", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu", @@ -28,12 +28,12 @@ pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[ // FIXME(rcvalle): More targets are likely supported. pub const CFI_SUPPORTED_TARGETS: &[&str] = &[ "aarch64-apple-darwin", - "aarch64-fuchsia", + "aarch64-unknown-fuchsia", "aarch64-linux-android", "aarch64-unknown-freebsd", "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", - "x86_64-fuchsia", + "x86_64-unknown-fuchsia", "x86_64-pc-solaris", "x86_64-unknown-freebsd", "x86_64-unknown-illumos", @@ -42,6 +42,8 @@ pub const CFI_SUPPORTED_TARGETS: &[&str] = &[ "x86_64-unknown-netbsd", ]; +pub const KCFI_SUPPORTED_TARGETS: &[&str] = &["aarch64-linux-none", "x86_64-linux-none"]; + pub const LSAN_SUPPORTED_TARGETS: &[&str] = &[ // FIXME: currently broken, see #88132 // "aarch64-apple-darwin", |