summaryrefslogtreecommitdiffstats
path: root/src/tools/compiletest
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/compiletest')
-rw-r--r--src/tools/compiletest/Cargo.toml8
-rw-r--r--src/tools/compiletest/src/common.rs455
-rw-r--r--src/tools/compiletest/src/header.rs178
-rw-r--r--src/tools/compiletest/src/header/cfg.rs324
-rw-r--r--src/tools/compiletest/src/header/tests.rs6
-rw-r--r--src/tools/compiletest/src/main.rs145
-rw-r--r--src/tools/compiletest/src/read2.rs4
-rw-r--r--src/tools/compiletest/src/runtest.rs119
-rw-r--r--src/tools/compiletest/src/util.rs2
9 files changed, 859 insertions, 382 deletions
diff --git a/src/tools/compiletest/Cargo.toml b/src/tools/compiletest/Cargo.toml
index 0db043a4f..85fd6523c 100644
--- a/src/tools/compiletest/Cargo.toml
+++ b/src/tools/compiletest/Cargo.toml
@@ -26,4 +26,10 @@ libc = "0.2"
[target.'cfg(windows)'.dependencies]
miow = "0.5"
-winapi = { version = "0.3", features = ["winerror"] }
+
+[target.'cfg(windows)'.dependencies.windows]
+version = "0.46.0"
+features = [
+ "Win32_Foundation",
+ "Win32_System_Diagnostics_Debug",
+]
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs
index 7fe2e6257..d2f494942 100644
--- a/src/tools/compiletest/src/common.rs
+++ b/src/tools/compiletest/src/common.rs
@@ -8,107 +8,84 @@ use std::process::Command;
use std::str::FromStr;
use crate::util::{add_dylib_path, PathBufExt};
-use lazycell::LazyCell;
-use test::ColorConfig;
-
-#[derive(Clone, Copy, PartialEq, Debug)]
-pub enum Mode {
- RunPassValgrind,
- Pretty,
- DebugInfo,
- Codegen,
- Rustdoc,
- RustdocJson,
- CodegenUnits,
- Incremental,
- RunMake,
- Ui,
- JsDocTest,
- MirOpt,
- Assembly,
-}
+use lazycell::AtomicLazyCell;
+use serde::de::{Deserialize, Deserializer, Error as _};
+use std::collections::{HashMap, HashSet};
+use test::{ColorConfig, OutputFormat};
+
+macro_rules! string_enum {
+ ($(#[$meta:meta])* $vis:vis enum $name:ident { $($variant:ident => $repr:expr,)* }) => {
+ $(#[$meta])*
+ $vis enum $name {
+ $($variant,)*
+ }
-impl Mode {
- pub fn disambiguator(self) -> &'static str {
- // Pretty-printing tests could run concurrently, and if they do,
- // they need to keep their output segregated.
- match self {
- Pretty => ".pretty",
- _ => "",
+ impl $name {
+ $vis const VARIANTS: &'static [Self] = &[$(Self::$variant,)*];
+ $vis const STR_VARIANTS: &'static [&'static str] = &[$(Self::$variant.to_str(),)*];
+
+ $vis const fn to_str(&self) -> &'static str {
+ match self {
+ $(Self::$variant => $repr,)*
+ }
+ }
}
- }
-}
-impl FromStr for Mode {
- type Err = ();
- fn from_str(s: &str) -> Result<Mode, ()> {
- match s {
- "run-pass-valgrind" => Ok(RunPassValgrind),
- "pretty" => Ok(Pretty),
- "debuginfo" => Ok(DebugInfo),
- "codegen" => Ok(Codegen),
- "rustdoc" => Ok(Rustdoc),
- "rustdoc-json" => Ok(RustdocJson),
- "codegen-units" => Ok(CodegenUnits),
- "incremental" => Ok(Incremental),
- "run-make" => Ok(RunMake),
- "ui" => Ok(Ui),
- "js-doc-test" => Ok(JsDocTest),
- "mir-opt" => Ok(MirOpt),
- "assembly" => Ok(Assembly),
- _ => Err(()),
+ impl fmt::Display for $name {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt::Display::fmt(self.to_str(), f)
+ }
}
- }
-}
-impl fmt::Display for Mode {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- let s = match *self {
- RunPassValgrind => "run-pass-valgrind",
- Pretty => "pretty",
- DebugInfo => "debuginfo",
- Codegen => "codegen",
- Rustdoc => "rustdoc",
- RustdocJson => "rustdoc-json",
- CodegenUnits => "codegen-units",
- Incremental => "incremental",
- RunMake => "run-make",
- Ui => "ui",
- JsDocTest => "js-doc-test",
- MirOpt => "mir-opt",
- Assembly => "assembly",
- };
- fmt::Display::fmt(s, f)
+ impl FromStr for $name {
+ type Err = ();
+
+ fn from_str(s: &str) -> Result<Self, ()> {
+ match s {
+ $($repr => Ok(Self::$variant),)*
+ _ => Err(()),
+ }
+ }
+ }
}
}
-#[derive(Clone, Copy, PartialEq, Debug, Hash)]
-pub enum PassMode {
- Check,
- Build,
- Run,
+string_enum! {
+ #[derive(Clone, Copy, PartialEq, Debug)]
+ pub enum Mode {
+ RunPassValgrind => "run-pass-valgrind",
+ Pretty => "pretty",
+ DebugInfo => "debuginfo",
+ Codegen => "codegen",
+ Rustdoc => "rustdoc",
+ RustdocJson => "rustdoc-json",
+ CodegenUnits => "codegen-units",
+ Incremental => "incremental",
+ RunMake => "run-make",
+ Ui => "ui",
+ JsDocTest => "js-doc-test",
+ MirOpt => "mir-opt",
+ Assembly => "assembly",
+ }
}
-impl FromStr for PassMode {
- type Err = ();
- fn from_str(s: &str) -> Result<Self, ()> {
- match s {
- "check" => Ok(PassMode::Check),
- "build" => Ok(PassMode::Build),
- "run" => Ok(PassMode::Run),
- _ => Err(()),
+impl Mode {
+ pub fn disambiguator(self) -> &'static str {
+ // Pretty-printing tests could run concurrently, and if they do,
+ // they need to keep their output segregated.
+ match self {
+ Pretty => ".pretty",
+ _ => "",
}
}
}
-impl fmt::Display for PassMode {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- let s = match *self {
- PassMode::Check => "check",
- PassMode::Build => "build",
- PassMode::Run => "run",
- };
- fmt::Display::fmt(s, f)
+string_enum! {
+ #[derive(Clone, Copy, PartialEq, Debug, Hash)]
+ pub enum PassMode {
+ Check => "check",
+ Build => "build",
+ Run => "run",
}
}
@@ -119,63 +96,30 @@ pub enum FailMode {
Run,
}
-#[derive(Clone, Debug, PartialEq)]
-pub enum CompareMode {
- Polonius,
- Chalk,
- NextSolver,
- SplitDwarf,
- SplitDwarfSingle,
-}
-
-impl CompareMode {
- pub(crate) fn to_str(&self) -> &'static str {
- match *self {
- CompareMode::Polonius => "polonius",
- CompareMode::Chalk => "chalk",
- CompareMode::NextSolver => "next-solver",
- CompareMode::SplitDwarf => "split-dwarf",
- CompareMode::SplitDwarfSingle => "split-dwarf-single",
- }
- }
-
- pub fn parse(s: String) -> CompareMode {
- match s.as_str() {
- "polonius" => CompareMode::Polonius,
- "chalk" => CompareMode::Chalk,
- "next-solver" => CompareMode::NextSolver,
- "split-dwarf" => CompareMode::SplitDwarf,
- "split-dwarf-single" => CompareMode::SplitDwarfSingle,
- x => panic!("unknown --compare-mode option: {}", x),
- }
- }
-}
-
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub enum Debugger {
- Cdb,
- Gdb,
- Lldb,
-}
-
-impl Debugger {
- fn to_str(&self) -> &'static str {
- match self {
- Debugger::Cdb => "cdb",
- Debugger::Gdb => "gdb",
- Debugger::Lldb => "lldb",
- }
+string_enum! {
+ #[derive(Clone, Debug, PartialEq)]
+ pub enum CompareMode {
+ Polonius => "polonius",
+ Chalk => "chalk",
+ NextSolver => "next-solver",
+ SplitDwarf => "split-dwarf",
+ SplitDwarfSingle => "split-dwarf-single",
}
}
-impl fmt::Display for Debugger {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- fmt::Display::fmt(self.to_str(), f)
+string_enum! {
+ #[derive(Clone, Copy, Debug, PartialEq)]
+ pub enum Debugger {
+ Cdb => "cdb",
+ Gdb => "gdb",
+ Lldb => "lldb",
}
}
-#[derive(Clone, Copy, Debug, PartialEq)]
+#[derive(Clone, Copy, Debug, PartialEq, Default, serde::Deserialize)]
+#[serde(rename_all = "kebab-case")]
pub enum PanicStrategy {
+ #[default]
Unwind,
Abort,
}
@@ -337,7 +281,7 @@ pub struct Config {
pub verbose: bool,
/// Print one character per test instead of one line
- pub quiet: bool,
+ pub format: OutputFormat,
/// Whether to use colors in test.
pub color: ColorConfig,
@@ -369,7 +313,8 @@ pub struct Config {
pub cflags: String,
pub cxxflags: String,
pub ar: String,
- pub linker: Option<String>,
+ pub target_linker: Option<String>,
+ pub host_linker: Option<String>,
pub llvm_components: String,
/// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests
@@ -383,7 +328,9 @@ pub struct Config {
/// Only rerun the tests that result has been modified accoring to Git status
pub only_modified: bool,
- pub target_cfg: LazyCell<TargetCfg>,
+ pub target_cfgs: AtomicLazyCell<TargetCfgs>,
+
+ pub nocapture: bool,
}
impl Config {
@@ -394,8 +341,18 @@ impl Config {
})
}
- fn target_cfg(&self) -> &TargetCfg {
- self.target_cfg.borrow_with(|| TargetCfg::new(self))
+ pub fn target_cfgs(&self) -> &TargetCfgs {
+ match self.target_cfgs.borrow() {
+ Some(cfgs) => cfgs,
+ None => {
+ let _ = self.target_cfgs.fill(TargetCfgs::new(self));
+ self.target_cfgs.borrow().unwrap()
+ }
+ }
+ }
+
+ pub fn target_cfg(&self) -> &TargetCfg {
+ &self.target_cfgs().current
}
pub fn matches_arch(&self, arch: &str) -> bool {
@@ -447,94 +404,154 @@ impl Config {
}
}
-#[derive(Clone, Debug)]
+#[derive(Debug, Clone)]
+pub struct TargetCfgs {
+ pub current: TargetCfg,
+ pub all_targets: HashSet<String>,
+ pub all_archs: HashSet<String>,
+ pub all_oses: HashSet<String>,
+ pub all_oses_and_envs: HashSet<String>,
+ pub all_envs: HashSet<String>,
+ pub all_abis: HashSet<String>,
+ pub all_families: HashSet<String>,
+ pub all_pointer_widths: HashSet<String>,
+}
+
+impl TargetCfgs {
+ fn new(config: &Config) -> TargetCfgs {
+ let targets: HashMap<String, TargetCfg> = if config.stage_id.starts_with("stage0-") {
+ // #[cfg(bootstrap)]
+ // Needed only for one cycle, remove during the bootstrap bump.
+ Self::collect_all_slow(config)
+ } else {
+ serde_json::from_str(&rustc_output(
+ config,
+ &["--print=all-target-specs-json", "-Zunstable-options"],
+ ))
+ .unwrap()
+ };
+
+ let mut current = None;
+ let mut all_targets = HashSet::new();
+ let mut all_archs = HashSet::new();
+ let mut all_oses = HashSet::new();
+ let mut all_oses_and_envs = HashSet::new();
+ let mut all_envs = HashSet::new();
+ let mut all_abis = HashSet::new();
+ let mut all_families = HashSet::new();
+ let mut all_pointer_widths = HashSet::new();
+
+ for (target, cfg) in targets.into_iter() {
+ all_archs.insert(cfg.arch.clone());
+ all_oses.insert(cfg.os.clone());
+ all_oses_and_envs.insert(cfg.os_and_env());
+ all_envs.insert(cfg.env.clone());
+ all_abis.insert(cfg.abi.clone());
+ for family in &cfg.families {
+ all_families.insert(family.clone());
+ }
+ all_pointer_widths.insert(format!("{}bit", cfg.pointer_width));
+
+ if target == config.target {
+ current = Some(cfg);
+ }
+ all_targets.insert(target.into());
+ }
+
+ Self {
+ current: current.expect("current target not found"),
+ all_targets,
+ all_archs,
+ all_oses,
+ all_oses_and_envs,
+ all_envs,
+ all_abis,
+ all_families,
+ all_pointer_widths,
+ }
+ }
+
+ // #[cfg(bootstrap)]
+ // Needed only for one cycle, remove during the bootstrap bump.
+ fn collect_all_slow(config: &Config) -> HashMap<String, TargetCfg> {
+ let mut result = HashMap::new();
+ for target in rustc_output(config, &["--print=target-list"]).trim().lines() {
+ let json = rustc_output(
+ config,
+ &["--print=target-spec-json", "-Zunstable-options", "--target", target],
+ );
+ match serde_json::from_str(&json) {
+ Ok(res) => {
+ result.insert(target.into(), res);
+ }
+ Err(err) => panic!("failed to parse target spec for {target}: {err}"),
+ }
+ }
+ result
+ }
+}
+
+#[derive(Clone, Debug, serde::Deserialize)]
+#[serde(rename_all = "kebab-case")]
pub struct TargetCfg {
- arch: String,
- os: String,
- env: String,
- abi: String,
- families: Vec<String>,
- pointer_width: u32,
+ pub(crate) arch: String,
+ #[serde(default = "default_os")]
+ pub(crate) os: String,
+ #[serde(default)]
+ pub(crate) env: String,
+ #[serde(default)]
+ pub(crate) abi: String,
+ #[serde(rename = "target-family", default)]
+ pub(crate) families: Vec<String>,
+ #[serde(rename = "target-pointer-width", deserialize_with = "serde_parse_u32")]
+ pub(crate) pointer_width: u32,
+ #[serde(rename = "target-endian", default)]
endian: Endian,
+ #[serde(rename = "panic-strategy", default)]
panic: PanicStrategy,
}
-#[derive(Eq, PartialEq, Clone, Debug)]
+impl TargetCfg {
+ pub(crate) fn os_and_env(&self) -> String {
+ format!("{}-{}", self.os, self.env)
+ }
+}
+
+fn default_os() -> String {
+ "none".into()
+}
+
+#[derive(Eq, PartialEq, Clone, Debug, Default, serde::Deserialize)]
+#[serde(rename_all = "kebab-case")]
pub enum Endian {
+ #[default]
Little,
Big,
}
-impl TargetCfg {
- fn new(config: &Config) -> TargetCfg {
- let mut command = Command::new(&config.rustc_path);
- add_dylib_path(&mut command, iter::once(&config.compile_lib_path));
- let output = match command
- .arg("--print=cfg")
- .arg("--target")
- .arg(&config.target)
- .args(&config.target_rustcflags)
- .output()
- {
- Ok(output) => output,
- Err(e) => panic!("error: failed to get cfg info from {:?}: {e}", config.rustc_path),
- };
- if !output.status.success() {
- panic!(
- "error: failed to get cfg info from {:?}\n--- stdout\n{}\n--- stderr\n{}",
- config.rustc_path,
- String::from_utf8(output.stdout).unwrap(),
- String::from_utf8(output.stderr).unwrap(),
- );
- }
- let print_cfg = String::from_utf8(output.stdout).unwrap();
- let mut arch = None;
- let mut os = None;
- let mut env = None;
- let mut abi = None;
- let mut families = Vec::new();
- let mut pointer_width = None;
- let mut endian = None;
- let mut panic = None;
- for line in print_cfg.lines() {
- if let Some((name, value)) = line.split_once('=') {
- let value = value.trim_matches('"');
- match name {
- "target_arch" => arch = Some(value),
- "target_os" => os = Some(value),
- "target_env" => env = Some(value),
- "target_abi" => abi = Some(value),
- "target_family" => families.push(value.to_string()),
- "target_pointer_width" => pointer_width = Some(value.parse().unwrap()),
- "target_endian" => {
- endian = Some(match value {
- "little" => Endian::Little,
- "big" => Endian::Big,
- s => panic!("unexpected {s}"),
- })
- }
- "panic" => {
- panic = match value {
- "abort" => Some(PanicStrategy::Abort),
- "unwind" => Some(PanicStrategy::Unwind),
- s => panic!("unexpected {s}"),
- }
- }
- _ => {}
- }
- }
- }
- TargetCfg {
- arch: arch.unwrap().to_string(),
- os: os.unwrap().to_string(),
- env: env.unwrap().to_string(),
- abi: abi.unwrap().to_string(),
- families,
- pointer_width: pointer_width.unwrap(),
- endian: endian.unwrap(),
- panic: panic.unwrap(),
- }
+fn rustc_output(config: &Config, args: &[&str]) -> String {
+ let mut command = Command::new(&config.rustc_path);
+ add_dylib_path(&mut command, iter::once(&config.compile_lib_path));
+ command.args(&config.target_rustcflags).args(args);
+ command.env("RUSTC_BOOTSTRAP", "1");
+
+ let output = match command.output() {
+ Ok(output) => output,
+ Err(e) => panic!("error: failed to run {command:?}: {e}"),
+ };
+ if !output.status.success() {
+ panic!(
+ "error: failed to run {command:?}\n--- stdout\n{}\n--- stderr\n{}",
+ String::from_utf8(output.stdout).unwrap(),
+ String::from_utf8(output.stderr).unwrap(),
+ );
}
+ String::from_utf8(output.stdout).unwrap()
+}
+
+fn serde_parse_u32<'de, D: Deserializer<'de>>(deserializer: D) -> Result<u32, D::Error> {
+ let string = String::deserialize(deserializer)?;
+ string.parse().map_err(D::Error::custom)
}
#[derive(Debug, Clone)]
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs
index d9b39927c..bc65ec932 100644
--- a/src/tools/compiletest/src/header.rs
+++ b/src/tools/compiletest/src/header.rs
@@ -6,24 +6,19 @@ use std::io::BufReader;
use std::path::{Path, PathBuf};
use std::process::Command;
+use build_helper::ci::CiEnv;
use tracing::*;
-use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PassMode};
+use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
+use crate::header::cfg::parse_cfg_name_directive;
+use crate::header::cfg::MatchOutcome;
use crate::util;
use crate::{extract_cdb_version, extract_gdb_version};
+mod cfg;
#[cfg(test)]
mod tests;
-/// The result of parse_cfg_name_directive.
-#[derive(Clone, Copy, PartialEq, Debug)]
-enum ParsedNameDirective {
- /// No match.
- NoMatch,
- /// Match.
- Match,
-}
-
/// Properties which must be known very early, before actually running
/// the test.
#[derive(Default)]
@@ -84,6 +79,9 @@ pub struct TestProps {
pub unset_rustc_env: Vec<String>,
// Environment settings to use during execution
pub exec_env: Vec<(String, String)>,
+ // Environment variables to unset prior to execution.
+ // Variables are unset before applying 'exec_env'
+ pub unset_exec_env: Vec<String>,
// Build documentation for all specified aux-builds as well
pub build_aux_docs: bool,
// Flag to force a crate to be built with the host architecture
@@ -150,6 +148,8 @@ pub struct TestProps {
pub normalize_stdout: Vec<(String, String)>,
pub normalize_stderr: Vec<(String, String)>,
pub failure_status: i32,
+ // For UI tests, allows compiler to exit with arbitrary failure status
+ pub dont_check_failure_status: bool,
// Whether or not `rustfix` should apply the `CodeSuggestion`s of this test and compile the
// resulting Rust code.
pub run_rustfix: bool,
@@ -187,11 +187,13 @@ mod directives {
pub const AUX_CRATE: &'static str = "aux-crate";
pub const EXEC_ENV: &'static str = "exec-env";
pub const RUSTC_ENV: &'static str = "rustc-env";
+ pub const UNSET_EXEC_ENV: &'static str = "unset-exec-env";
pub const UNSET_RUSTC_ENV: &'static str = "unset-rustc-env";
pub const FORBID_OUTPUT: &'static str = "forbid-output";
pub const CHECK_TEST_LINE_NUMBERS_MATCH: &'static str = "check-test-line-numbers-match";
pub const IGNORE_PASS: &'static str = "ignore-pass";
pub const FAILURE_STATUS: &'static str = "failure-status";
+ pub const DONT_CHECK_FAILURE_STATUS: &'static str = "dont-check-failure-status";
pub const RUN_RUSTFIX: &'static str = "run-rustfix";
pub const RUSTFIX_ONLY_MACHINE_APPLICABLE: &'static str = "rustfix-only-machine-applicable";
pub const ASSEMBLY_OUTPUT: &'static str = "assembly-output";
@@ -218,6 +220,7 @@ impl TestProps {
rustc_env: vec![],
unset_rustc_env: vec![],
exec_env: vec![],
+ unset_exec_env: vec![],
build_aux_docs: false,
force_host: false,
check_stdout: false,
@@ -239,6 +242,7 @@ impl TestProps {
normalize_stdout: vec![],
normalize_stderr: vec![],
failure_status: -1,
+ dont_check_failure_status: false,
run_rustfix: false,
rustfix_only_machine_applicable: false,
assembly_output: None,
@@ -278,8 +282,12 @@ 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");
+ // In CI, we've sometimes encountered non-determinism related to truncating very long paths.
+ // Set a consistent (short) prefix to avoid issues, but only in CI to avoid regressing the
+ // contributor experience.
+ if CiEnv::is_ci() {
+ self.remap_src_base = config.mode == Mode::Ui && !config.suite.contains("rustdoc");
+ }
let mut has_edition = false;
if !testfile.is_dir() {
@@ -365,6 +373,12 @@ impl TestProps {
);
config.push_name_value_directive(
ln,
+ UNSET_EXEC_ENV,
+ &mut self.unset_exec_env,
+ |r| r,
+ );
+ config.push_name_value_directive(
+ ln,
RUSTC_ENV,
&mut self.rustc_env,
Config::parse_env,
@@ -401,6 +415,12 @@ impl TestProps {
self.failure_status = code;
}
+ config.set_name_directive(
+ ln,
+ DONT_CHECK_FAILURE_STATUS,
+ &mut self.dont_check_failure_status,
+ );
+
config.set_name_directive(ln, RUN_RUSTFIX, &mut self.run_rustfix);
config.set_name_directive(
ln,
@@ -647,7 +667,7 @@ impl Config {
}
fn parse_custom_normalization(&self, mut line: &str, prefix: &str) -> Option<(String, String)> {
- if self.parse_cfg_name_directive(line, prefix) == ParsedNameDirective::Match {
+ if parse_cfg_name_directive(self, line, prefix).outcome == MatchOutcome::Match {
let from = parse_normalization_string(&mut line)?;
let to = parse_normalization_string(&mut line)?;
Some((from, to))
@@ -664,68 +684,6 @@ impl Config {
self.parse_name_directive(line, "needs-profiler-support")
}
- /// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
- /// or `normalize-stderr-32bit`.
- fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> ParsedNameDirective {
- if !line.as_bytes().starts_with(prefix.as_bytes()) {
- return ParsedNameDirective::NoMatch;
- }
- if line.as_bytes().get(prefix.len()) != Some(&b'-') {
- return ParsedNameDirective::NoMatch;
- }
-
- let name = line[prefix.len() + 1..].split(&[':', ' '][..]).next().unwrap();
-
- let matches_pointer_width = || {
- name.strip_suffix("bit")
- .and_then(|width| width.parse::<u32>().ok())
- .map(|width| self.get_pointer_width() == width)
- .unwrap_or(false)
- };
-
- // If something is ignored for emscripten, it likely also needs to be
- // ignored for wasm32-unknown-unknown.
- // `wasm32-bare` is an alias to refer to just wasm32-unknown-unknown
- // (in contrast to `wasm32` which also matches non-bare targets like
- // asmjs-unknown-emscripten).
- let matches_wasm32_alias = || {
- self.target == "wasm32-unknown-unknown" && matches!(name, "emscripten" | "wasm32-bare")
- };
-
- let is_match = name == "test" ||
- self.target == name || // triple
- self.matches_os(name) ||
- self.matches_env(name) ||
- self.matches_abi(name) ||
- self.matches_family(name) ||
- self.target.ends_with(name) || // target and env
- self.matches_arch(name) ||
- matches_wasm32_alias() ||
- matches_pointer_width() ||
- name == self.stage_id.split('-').next().unwrap() || // stage
- name == self.channel || // channel
- (self.target != self.host && name == "cross-compile") ||
- (name == "endian-big" && self.is_big_endian()) ||
- (self.remote_test_client.is_some() && name == "remote") ||
- match self.compare_mode {
- Some(CompareMode::Polonius) => name == "compare-mode-polonius",
- Some(CompareMode::Chalk) => name == "compare-mode-chalk",
- Some(CompareMode::NextSolver) => name == "compare-mode-next-solver",
- Some(CompareMode::SplitDwarf) => name == "compare-mode-split-dwarf",
- Some(CompareMode::SplitDwarfSingle) => name == "compare-mode-split-dwarf-single",
- None => false,
- } ||
- (cfg!(debug_assertions) && name == "debug") ||
- match self.debugger {
- Some(Debugger::Cdb) => name == "cdb",
- Some(Debugger::Gdb) => name == "gdb",
- Some(Debugger::Lldb) => name == "lldb",
- None => false,
- };
-
- if is_match { ParsedNameDirective::Match } else { ParsedNameDirective::NoMatch }
- }
-
fn has_cfg_prefix(&self, line: &str, prefix: &str) -> bool {
// returns whether this line contains this prefix or not. For prefix
// "ignore", returns true if line says "ignore-x86_64", "ignore-arch",
@@ -964,6 +922,19 @@ pub fn make_test_description<R: Read>(
.join(if config.host.contains("windows") { "rust-lld.exe" } else { "rust-lld" })
.exists();
+ fn is_on_path(file: &'static str) -> impl Fn() -> bool {
+ move || env::split_paths(&env::var_os("PATH").unwrap()).any(|dir| dir.join(file).is_file())
+ }
+
+ // On Windows, dlltool.exe is used for all architectures.
+ #[cfg(windows)]
+ let (has_i686_dlltool, has_x86_64_dlltool) =
+ (is_on_path("dlltool.exe"), is_on_path("dlltool.exe"));
+ // For non-Windows, there are architecture specific dlltool binaries.
+ #[cfg(not(windows))]
+ let (has_i686_dlltool, has_x86_64_dlltool) =
+ (is_on_path("i686-w64-mingw32-dlltool"), is_on_path("x86_64-w64-mingw32-dlltool"));
+
iter_header(path, src, &mut |revision, ln| {
if revision.is_some() && revision != cfg {
return;
@@ -979,21 +950,44 @@ pub fn make_test_description<R: Read>(
}
};
}
- ignore = match config.parse_cfg_name_directive(ln, "ignore") {
- ParsedNameDirective::Match => {
- ignore_message = Some("cfg -> ignore => Match");
- true
- }
- ParsedNameDirective::NoMatch => ignore,
- };
+
+ {
+ let parsed = parse_cfg_name_directive(config, ln, "ignore");
+ ignore = match parsed.outcome {
+ MatchOutcome::Match => {
+ let reason = parsed.pretty_reason.unwrap();
+ // The ignore reason must be a &'static str, so we have to leak memory to
+ // create it. This is fine, as the header is parsed only at the start of
+ // compiletest so it won't grow indefinitely.
+ ignore_message = Some(Box::leak(Box::<str>::from(match parsed.comment {
+ Some(comment) => format!("ignored {reason} ({comment})"),
+ None => format!("ignored {reason}"),
+ })) as &str);
+ true
+ }
+ MatchOutcome::NoMatch => ignore,
+ MatchOutcome::External => ignore,
+ MatchOutcome::Invalid => panic!("invalid line in {}: {ln}", path.display()),
+ };
+ }
if config.has_cfg_prefix(ln, "only") {
- ignore = match config.parse_cfg_name_directive(ln, "only") {
- ParsedNameDirective::Match => ignore,
- ParsedNameDirective::NoMatch => {
- ignore_message = Some("cfg -> only => NoMatch");
+ let parsed = parse_cfg_name_directive(config, ln, "only");
+ ignore = match parsed.outcome {
+ MatchOutcome::Match => ignore,
+ MatchOutcome::NoMatch => {
+ let reason = parsed.pretty_reason.unwrap();
+ // The ignore reason must be a &'static str, so we have to leak memory to
+ // create it. This is fine, as the header is parsed only at the start of
+ // compiletest so it won't grow indefinitely.
+ ignore_message = Some(Box::leak(Box::<str>::from(match parsed.comment {
+ Some(comment) => format!("only executed {reason} ({comment})"),
+ None => format!("only executed {reason}"),
+ })) as &str);
true
}
+ MatchOutcome::External => ignore,
+ MatchOutcome::Invalid => panic!("invalid line in {}: {ln}", path.display()),
};
}
@@ -1031,6 +1025,8 @@ pub fn make_test_description<R: Read>(
reason!(config.debugger == Some(Debugger::Gdb) && ignore_gdb(config, ln));
reason!(config.debugger == Some(Debugger::Lldb) && ignore_lldb(config, ln));
reason!(!has_rust_lld && config.parse_name_directive(ln, "needs-rust-lld"));
+ reason!(config.parse_name_directive(ln, "needs-i686-dlltool") && !has_i686_dlltool());
+ reason!(config.parse_name_directive(ln, "needs-x86_64-dlltool") && !has_x86_64_dlltool());
should_fail |= config.parse_name_directive(ln, "should-fail");
});
@@ -1047,6 +1043,16 @@ pub fn make_test_description<R: Read>(
name,
ignore,
ignore_message,
+ #[cfg(not(bootstrap))]
+ source_file: "",
+ #[cfg(not(bootstrap))]
+ start_line: 0,
+ #[cfg(not(bootstrap))]
+ start_col: 0,
+ #[cfg(not(bootstrap))]
+ end_line: 0,
+ #[cfg(not(bootstrap))]
+ end_col: 0,
should_panic,
compile_fail: false,
no_run: false,
diff --git a/src/tools/compiletest/src/header/cfg.rs b/src/tools/compiletest/src/header/cfg.rs
new file mode 100644
index 000000000..aa36fd708
--- /dev/null
+++ b/src/tools/compiletest/src/header/cfg.rs
@@ -0,0 +1,324 @@
+use crate::common::{CompareMode, Config, Debugger};
+use std::collections::HashSet;
+
+const EXTRA_ARCHS: &[&str] = &["spirv"];
+
+/// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
+/// or `normalize-stderr-32bit`.
+pub(super) fn parse_cfg_name_directive<'a>(
+ config: &Config,
+ line: &'a str,
+ prefix: &str,
+) -> ParsedNameDirective<'a> {
+ if !line.as_bytes().starts_with(prefix.as_bytes()) {
+ return ParsedNameDirective::invalid();
+ }
+ if line.as_bytes().get(prefix.len()) != Some(&b'-') {
+ return ParsedNameDirective::invalid();
+ }
+ let line = &line[prefix.len() + 1..];
+
+ let (name, comment) =
+ line.split_once(&[':', ' ']).map(|(l, c)| (l, Some(c))).unwrap_or((line, None));
+
+ // Some of the matchers might be "" depending on what the target information is. To avoid
+ // problems we outright reject empty directives.
+ if name == "" {
+ return ParsedNameDirective::invalid();
+ }
+
+ let mut outcome = MatchOutcome::Invalid;
+ let mut message = None;
+
+ macro_rules! condition {
+ (
+ name: $name:expr,
+ $(allowed_names: $allowed_names:expr,)?
+ $(condition: $condition:expr,)?
+ message: $($message:tt)*
+ ) => {{
+ // This is not inlined to avoid problems with macro repetitions.
+ let format_message = || format!($($message)*);
+
+ if outcome != MatchOutcome::Invalid {
+ // Ignore all other matches if we already found one
+ } else if $name.custom_matches(name) {
+ message = Some(format_message());
+ if true $(&& $condition)? {
+ outcome = MatchOutcome::Match;
+ } else {
+ outcome = MatchOutcome::NoMatch;
+ }
+ }
+ $(else if $allowed_names.custom_contains(name) {
+ message = Some(format_message());
+ outcome = MatchOutcome::NoMatch;
+ })?
+ }};
+ }
+
+ let target_cfgs = config.target_cfgs();
+ let target_cfg = config.target_cfg();
+
+ condition! {
+ name: "test",
+ message: "always"
+ }
+ condition! {
+ name: &config.target,
+ allowed_names: &target_cfgs.all_targets,
+ message: "when the target is {name}"
+ }
+ condition! {
+ name: &[
+ Some(&*target_cfg.os),
+ // If something is ignored for emscripten, it likely also needs to be
+ // ignored for wasm32-unknown-unknown.
+ (config.target == "wasm32-unknown-unknown").then_some("emscripten"),
+ ],
+ allowed_names: &target_cfgs.all_oses,
+ message: "when the operative system is {name}"
+ }
+ condition! {
+ name: &target_cfg.env,
+ allowed_names: &target_cfgs.all_envs,
+ message: "when the target environment is {name}"
+ }
+ condition! {
+ name: &target_cfg.os_and_env(),
+ allowed_names: &target_cfgs.all_oses_and_envs,
+ message: "when the operative system and target environment are {name}"
+ }
+ condition! {
+ name: &target_cfg.abi,
+ allowed_names: &target_cfgs.all_abis,
+ message: "when the ABI is {name}"
+ }
+ condition! {
+ name: &target_cfg.arch,
+ allowed_names: ContainsEither { a: &target_cfgs.all_archs, b: &EXTRA_ARCHS },
+ message: "when the architecture is {name}"
+ }
+ condition! {
+ name: format!("{}bit", target_cfg.pointer_width),
+ allowed_names: &target_cfgs.all_pointer_widths,
+ message: "when the pointer width is {name}"
+ }
+ condition! {
+ name: &*target_cfg.families,
+ allowed_names: &target_cfgs.all_families,
+ message: "when the target family is {name}"
+ }
+
+ // `wasm32-bare` is an alias to refer to just wasm32-unknown-unknown
+ // (in contrast to `wasm32` which also matches non-bare targets like
+ // asmjs-unknown-emscripten).
+ condition! {
+ name: "wasm32-bare",
+ condition: config.target == "wasm32-unknown-unknown",
+ message: "when the target is WASM"
+ }
+
+ condition! {
+ name: "asmjs",
+ condition: config.target.starts_with("asmjs"),
+ message: "when the architecture is asm.js",
+ }
+ condition! {
+ name: "thumb",
+ condition: config.target.starts_with("thumb"),
+ message: "when the architecture is part of the Thumb family"
+ }
+
+ // Technically the locally built compiler uses the "dev" channel rather than the "nightly"
+ // channel, even though most people don't know or won't care about it. To avoid confusion, we
+ // treat the "dev" channel as the "nightly" channel when processing the directive.
+ condition! {
+ name: if config.channel == "dev" { "nightly" } else { &config.channel },
+ allowed_names: &["stable", "beta", "nightly"],
+ message: "when the release channel is {name}",
+ }
+
+ condition! {
+ name: "cross-compile",
+ condition: config.target != config.host,
+ message: "when cross-compiling"
+ }
+ condition! {
+ name: "endian-big",
+ condition: config.is_big_endian(),
+ message: "on big-endian targets",
+ }
+ condition! {
+ name: config.stage_id.split('-').next().unwrap(),
+ allowed_names: &["stage0", "stage1", "stage2"],
+ message: "when the bootstrapping stage is {name}",
+ }
+ condition! {
+ name: "remote",
+ condition: config.remote_test_client.is_some(),
+ message: "when running tests remotely",
+ }
+ condition! {
+ name: "debug",
+ condition: cfg!(debug_assertions),
+ message: "when building with debug assertions",
+ }
+ condition! {
+ name: config.debugger.as_ref().map(|d| d.to_str()),
+ allowed_names: &Debugger::STR_VARIANTS,
+ message: "when the debugger is {name}",
+ }
+ condition! {
+ name: config.compare_mode
+ .as_ref()
+ .map(|d| format!("compare-mode-{}", d.to_str())),
+ allowed_names: ContainsPrefixed {
+ prefix: "compare-mode-",
+ inner: CompareMode::STR_VARIANTS,
+ },
+ message: "when comparing with {name}",
+ }
+
+ if prefix == "ignore" && outcome == MatchOutcome::Invalid {
+ // Don't error out for ignore-tidy-* diretives, as those are not handled by compiletest.
+ if name.starts_with("tidy-") {
+ outcome = MatchOutcome::External;
+ }
+
+ // Don't error out for ignore-pass, as that is handled elsewhere.
+ if name == "pass" {
+ outcome = MatchOutcome::External;
+ }
+
+ // Don't error out for ignore-llvm-version, that has a custom syntax and is handled
+ // elsewhere.
+ if name == "llvm-version" {
+ outcome = MatchOutcome::External;
+ }
+
+ // Don't error out for ignore-llvm-version, that has a custom syntax and is handled
+ // elsewhere.
+ if name == "gdb-version" {
+ outcome = MatchOutcome::External;
+ }
+ }
+
+ ParsedNameDirective {
+ name: Some(name),
+ comment: comment.map(|c| c.trim().trim_start_matches('-').trim()),
+ outcome,
+ pretty_reason: message,
+ }
+}
+
+/// The result of parse_cfg_name_directive.
+#[derive(Clone, PartialEq, Debug)]
+pub(super) struct ParsedNameDirective<'a> {
+ pub(super) name: Option<&'a str>,
+ pub(super) pretty_reason: Option<String>,
+ pub(super) comment: Option<&'a str>,
+ pub(super) outcome: MatchOutcome,
+}
+
+impl ParsedNameDirective<'_> {
+ fn invalid() -> Self {
+ Self { name: None, pretty_reason: None, comment: None, outcome: MatchOutcome::NoMatch }
+ }
+}
+
+#[derive(Clone, Copy, PartialEq, Debug)]
+pub(super) enum MatchOutcome {
+ /// No match.
+ NoMatch,
+ /// Match.
+ Match,
+ /// The directive was invalid.
+ Invalid,
+ /// The directive is handled by other parts of our tooling.
+ External,
+}
+
+trait CustomContains {
+ fn custom_contains(&self, item: &str) -> bool;
+}
+
+impl CustomContains for HashSet<String> {
+ fn custom_contains(&self, item: &str) -> bool {
+ self.contains(item)
+ }
+}
+
+impl CustomContains for &[&str] {
+ fn custom_contains(&self, item: &str) -> bool {
+ self.contains(&item)
+ }
+}
+
+impl<const N: usize> CustomContains for [&str; N] {
+ fn custom_contains(&self, item: &str) -> bool {
+ self.contains(&item)
+ }
+}
+
+struct ContainsPrefixed<T: CustomContains> {
+ prefix: &'static str,
+ inner: T,
+}
+
+impl<T: CustomContains> CustomContains for ContainsPrefixed<T> {
+ fn custom_contains(&self, item: &str) -> bool {
+ match item.strip_prefix(self.prefix) {
+ Some(stripped) => self.inner.custom_contains(stripped),
+ None => false,
+ }
+ }
+}
+
+struct ContainsEither<'a, A: CustomContains, B: CustomContains> {
+ a: &'a A,
+ b: &'a B,
+}
+
+impl<A: CustomContains, B: CustomContains> CustomContains for ContainsEither<'_, A, B> {
+ fn custom_contains(&self, item: &str) -> bool {
+ self.a.custom_contains(item) || self.b.custom_contains(item)
+ }
+}
+
+trait CustomMatches {
+ fn custom_matches(&self, name: &str) -> bool;
+}
+
+impl CustomMatches for &str {
+ fn custom_matches(&self, name: &str) -> bool {
+ name == *self
+ }
+}
+
+impl CustomMatches for String {
+ fn custom_matches(&self, name: &str) -> bool {
+ name == self
+ }
+}
+
+impl<T: CustomMatches> CustomMatches for &[T] {
+ fn custom_matches(&self, name: &str) -> bool {
+ self.iter().any(|m| m.custom_matches(name))
+ }
+}
+
+impl<const N: usize, T: CustomMatches> CustomMatches for [T; N] {
+ fn custom_matches(&self, name: &str) -> bool {
+ self.iter().any(|m| m.custom_matches(name))
+ }
+}
+
+impl<T: CustomMatches> CustomMatches for Option<T> {
+ fn custom_matches(&self, name: &str) -> bool {
+ match self {
+ Some(inner) => inner.custom_matches(name),
+ None => false,
+ }
+ }
+}
diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs
index e42b8c524..acd588d7f 100644
--- a/src/tools/compiletest/src/header/tests.rs
+++ b/src/tools/compiletest/src/header/tests.rs
@@ -47,7 +47,7 @@ fn config() -> Config {
"--src-base=",
"--build-base=",
"--sysroot-base=",
- "--stage-id=stage2",
+ "--stage-id=stage2-x86_64-unknown-linux-gnu",
"--cc=c",
"--cxx=c++",
"--cflags=",
@@ -174,7 +174,7 @@ fn ignore_target() {
assert!(check_ignore(&config, "// ignore-gnu"));
assert!(check_ignore(&config, "// ignore-64bit"));
- assert!(!check_ignore(&config, "// ignore-i686"));
+ assert!(!check_ignore(&config, "// ignore-x86"));
assert!(!check_ignore(&config, "// ignore-windows"));
assert!(!check_ignore(&config, "// ignore-msvc"));
assert!(!check_ignore(&config, "// ignore-32bit"));
@@ -200,7 +200,7 @@ fn only_target() {
#[test]
fn stage() {
let mut config = config();
- config.stage_id = "stage1".to_owned();
+ config.stage_id = "stage1-x86_64-unknown-linux-gnu".to_owned();
assert!(check_ignore(&config, "// ignore-stage1"));
assert!(!check_ignore(&config, "// ignore-stage2"));
diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs
index 1760c29ec..6a91d25a8 100644
--- a/src/tools/compiletest/src/main.rs
+++ b/src/tools/compiletest/src/main.rs
@@ -6,12 +6,13 @@
extern crate test;
use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS};
-use crate::common::{CompareMode, Config, Debugger, Mode, PassMode, TestPaths};
+use crate::common::{Config, Debugger, Mode, PassMode, TestPaths};
use crate::util::logv;
use build_helper::git::{get_git_modified_files, get_git_untracked_files};
use core::panic;
use getopts::Options;
-use lazycell::LazyCell;
+use lazycell::AtomicLazyCell;
+use std::collections::BTreeSet;
use std::ffi::OsString;
use std::fs;
use std::io::{self, ErrorKind};
@@ -24,6 +25,7 @@ use tracing::*;
use walkdir::WalkDir;
use self::header::{make_test_description, EarlyProps};
+use std::sync::Arc;
#[cfg(test)]
mod tests;
@@ -41,7 +43,7 @@ pub mod util;
fn main() {
tracing_subscriber::fmt::init();
- let config = parse_config(env::args().collect());
+ let config = Arc::new(parse_config(env::args().collect()));
if config.valgrind_path.is_none() && config.force_valgrind {
panic!("Can't find Valgrind to run Valgrind tests");
@@ -114,6 +116,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
)
.optflag("", "quiet", "print one character per test instead of one line")
.optopt("", "color", "coloring: auto, always, never", "WHEN")
+ .optflag("", "json", "emit json output instead of plaintext output")
.optopt("", "logfile", "file to log test execution to", "FILE")
.optopt("", "target", "the target to build for", "TARGET")
.optopt("", "host", "the host to build for", "HOST")
@@ -131,7 +134,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
.reqopt("", "cflags", "flags for the C compiler", "FLAGS")
.reqopt("", "cxxflags", "flags for the CXX compiler", "FLAGS")
.optopt("", "ar", "path to an archiver", "PATH")
- .optopt("", "linker", "path to a linker", "PATH")
+ .optopt("", "target-linker", "path to a linker for the target", "PATH")
+ .optopt("", "host-linker", "path to a linker for the host", "PATH")
.reqopt("", "llvm-components", "list of LLVM components built in", "LIST")
.optopt("", "llvm-bin-dir", "Path to LLVM's `bin` directory", "PATH")
.optopt("", "nodejs", "the name of nodejs", "PATH")
@@ -151,6 +155,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
)
.optflag("", "force-rerun", "rerun tests even if the inputs are unchanged")
.optflag("", "only-modified", "only run tests that result been modified")
+ .optflag("", "nocapture", "")
.optflag("h", "help", "show this message")
.reqopt("", "channel", "current Rust channel", "CHANNEL")
.optopt("", "edition", "default Rust edition", "EDITION");
@@ -281,11 +286,18 @@ pub fn parse_config(args: Vec<String>) -> Config {
&& !opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
lldb_python_dir: matches.opt_str("lldb-python-dir"),
verbose: matches.opt_present("verbose"),
- quiet: matches.opt_present("quiet"),
+ format: match (matches.opt_present("quiet"), matches.opt_present("json")) {
+ (true, true) => panic!("--quiet and --json are incompatible"),
+ (true, false) => test::OutputFormat::Terse,
+ (false, true) => test::OutputFormat::Json,
+ (false, false) => test::OutputFormat::Pretty,
+ },
only_modified: matches.opt_present("only-modified"),
color,
remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from),
- compare_mode: matches.opt_str("compare-mode").map(CompareMode::parse),
+ compare_mode: matches
+ .opt_str("compare-mode")
+ .map(|s| s.parse().expect("invalid --compare-mode provided")),
rustfix_coverage: matches.opt_present("rustfix-coverage"),
has_tidy,
channel: matches.opt_str("channel").unwrap(),
@@ -296,14 +308,17 @@ pub fn parse_config(args: Vec<String>) -> Config {
cflags: matches.opt_str("cflags").unwrap(),
cxxflags: matches.opt_str("cxxflags").unwrap(),
ar: matches.opt_str("ar").unwrap_or_else(|| String::from("ar")),
- linker: matches.opt_str("linker"),
+ target_linker: matches.opt_str("target-linker"),
+ host_linker: matches.opt_str("host-linker"),
llvm_components: matches.opt_str("llvm-components").unwrap(),
nodejs: matches.opt_str("nodejs"),
npm: matches.opt_str("npm"),
force_rerun: matches.opt_present("force-rerun"),
- target_cfg: LazyCell::new(),
+ target_cfgs: AtomicLazyCell::new(),
+
+ nocapture: matches.opt_present("nocapture"),
}
}
@@ -337,9 +352,10 @@ pub fn log_config(config: &Config) {
logv(c, format!("adb_test_dir: {:?}", config.adb_test_dir));
logv(c, format!("adb_device_status: {}", config.adb_device_status));
logv(c, format!("ar: {}", config.ar));
- logv(c, format!("linker: {:?}", config.linker));
+ logv(c, format!("target-linker: {:?}", config.target_linker));
+ logv(c, format!("host-linker: {:?}", config.host_linker));
logv(c, format!("verbose: {}", config.verbose));
- logv(c, format!("quiet: {}", config.quiet));
+ logv(c, format!("format: {:?}", config.format));
logv(c, "\n".to_string());
}
@@ -357,7 +373,7 @@ pub fn opt_str2(maybestr: Option<String>) -> String {
}
}
-pub fn run_tests(config: Config) {
+pub fn run_tests(config: Arc<Config>) {
// If we want to collect rustfix coverage information,
// we first make sure that the coverage file does not exist.
// It will be created later on.
@@ -399,8 +415,10 @@ pub fn run_tests(config: Config) {
};
let mut tests = Vec::new();
- for c in &configs {
- make_tests(c, &mut tests);
+ for c in configs {
+ let mut found_paths = BTreeSet::new();
+ make_tests(c, &mut tests, &mut found_paths);
+ check_overlapping_tests(&found_paths);
}
tests.sort_by(|a, b| a.desc.name.as_slice().cmp(&b.desc.name.as_slice()));
@@ -416,10 +434,14 @@ pub fn run_tests(config: Config) {
// easy to miss which tests failed, and as such fail to reproduce
// the failure locally.
- eprintln!(
+ println!(
"Some tests failed in compiletest suite={}{} mode={} host={} target={}",
config.suite,
- config.compare_mode.map(|c| format!(" compare_mode={:?}", c)).unwrap_or_default(),
+ config
+ .compare_mode
+ .as_ref()
+ .map(|c| format!(" compare_mode={:?}", c))
+ .unwrap_or_default(),
config.mode,
config.host,
config.target
@@ -439,13 +461,13 @@ pub fn run_tests(config: Config) {
}
}
-fn configure_cdb(config: &Config) -> Option<Config> {
+fn configure_cdb(config: &Config) -> Option<Arc<Config>> {
config.cdb.as_ref()?;
- Some(Config { debugger: Some(Debugger::Cdb), ..config.clone() })
+ Some(Arc::new(Config { debugger: Some(Debugger::Cdb), ..config.clone() }))
}
-fn configure_gdb(config: &Config) -> Option<Config> {
+fn configure_gdb(config: &Config) -> Option<Arc<Config>> {
config.gdb_version?;
if config.matches_env("msvc") {
@@ -476,10 +498,10 @@ fn configure_gdb(config: &Config) -> Option<Config> {
env::set_var("RUST_TEST_THREADS", "1");
}
- Some(Config { debugger: Some(Debugger::Gdb), ..config.clone() })
+ Some(Arc::new(Config { debugger: Some(Debugger::Gdb), ..config.clone() }))
}
-fn configure_lldb(config: &Config) -> Option<Config> {
+fn configure_lldb(config: &Config) -> Option<Arc<Config>> {
config.lldb_python_dir.as_ref()?;
if let Some(350) = config.lldb_version {
@@ -492,23 +514,27 @@ fn configure_lldb(config: &Config) -> Option<Config> {
return None;
}
- Some(Config { debugger: Some(Debugger::Lldb), ..config.clone() })
+ Some(Arc::new(Config { debugger: Some(Debugger::Lldb), ..config.clone() }))
}
pub fn test_opts(config: &Config) -> test::TestOpts {
+ if env::var("RUST_TEST_NOCAPTURE").is_ok() {
+ eprintln!(
+ "WARNING: RUST_TEST_NOCAPTURE is no longer used. \
+ Use the `--nocapture` flag instead."
+ );
+ }
+
test::TestOpts {
exclude_should_panic: false,
filters: config.filters.clone(),
filter_exact: config.filter_exact,
run_ignored: if config.run_ignored { test::RunIgnored::Yes } else { test::RunIgnored::No },
- format: if config.quiet { test::OutputFormat::Terse } else { test::OutputFormat::Pretty },
+ format: config.format,
logfile: config.logfile.clone(),
run_tests: true,
bench_benchmarks: true,
- nocapture: match env::var("RUST_TEST_NOCAPTURE") {
- Ok(val) => &val != "0",
- Err(_) => false,
- },
+ nocapture: config.nocapture,
color: config.color,
shuffle: false,
shuffle_seed: None,
@@ -522,18 +548,23 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
}
}
-pub fn make_tests(config: &Config, tests: &mut Vec<test::TestDescAndFn>) {
+pub fn make_tests(
+ config: Arc<Config>,
+ tests: &mut Vec<test::TestDescAndFn>,
+ found_paths: &mut BTreeSet<PathBuf>,
+) {
debug!("making tests from {:?}", config.src_base.display());
- let inputs = common_inputs_stamp(config);
- let modified_tests = modified_tests(config, &config.src_base).unwrap_or_else(|err| {
+ let inputs = common_inputs_stamp(&config);
+ let modified_tests = modified_tests(&config, &config.src_base).unwrap_or_else(|err| {
panic!("modified_tests got error from dir: {}, error: {}", config.src_base.display(), err)
});
collect_tests_from_dir(
- config,
+ config.clone(),
&config.src_base,
&PathBuf::new(),
&inputs,
tests,
+ found_paths,
&modified_tests,
)
.unwrap_or_else(|_| panic!("Could not read tests from {}", config.src_base.display()));
@@ -599,11 +630,12 @@ fn modified_tests(config: &Config, dir: &Path) -> Result<Vec<PathBuf>, String> {
}
fn collect_tests_from_dir(
- config: &Config,
+ config: Arc<Config>,
dir: &Path,
relative_dir_path: &Path,
inputs: &Stamp,
tests: &mut Vec<test::TestDescAndFn>,
+ found_paths: &mut BTreeSet<PathBuf>,
modified_tests: &Vec<PathBuf>,
) -> io::Result<()> {
// Ignore directories that contain a file named `compiletest-ignore-dir`.
@@ -626,7 +658,7 @@ fn collect_tests_from_dir(
// sequential loop because otherwise, if we do it in the
// tests themselves, they race for the privilege of
// creating the directories and sometimes fail randomly.
- let build_dir = output_relative_path(config, relative_dir_path);
+ let build_dir = output_relative_path(&config, relative_dir_path);
fs::create_dir_all(&build_dir).unwrap();
// Add each `.rs` file as a test, and recurse further on any
@@ -637,20 +669,23 @@ fn collect_tests_from_dir(
let file_name = file.file_name();
if is_test(&file_name) && (!config.only_modified || modified_tests.contains(&file_path)) {
debug!("found test file: {:?}", file_path.display());
+ let rel_test_path = relative_dir_path.join(file_path.file_stem().unwrap());
+ found_paths.insert(rel_test_path);
let paths =
TestPaths { file: file_path, relative_dir: relative_dir_path.to_path_buf() };
- tests.extend(make_test(config, &paths, inputs))
+ tests.extend(make_test(config.clone(), &paths, inputs))
} else if file_path.is_dir() {
let relative_file_path = relative_dir_path.join(file.file_name());
if &file_name != "auxiliary" {
debug!("found directory: {:?}", file_path.display());
collect_tests_from_dir(
- config,
+ config.clone(),
&file_path,
&relative_file_path,
inputs,
tests,
+ found_paths,
modified_tests,
)?;
}
@@ -674,14 +709,18 @@ pub fn is_test(file_name: &OsString) -> bool {
!invalid_prefixes.iter().any(|p| file_name.starts_with(p))
}
-fn make_test(config: &Config, testpaths: &TestPaths, inputs: &Stamp) -> Vec<test::TestDescAndFn> {
+fn make_test(
+ config: Arc<Config>,
+ testpaths: &TestPaths,
+ inputs: &Stamp,
+) -> Vec<test::TestDescAndFn> {
let test_path = if config.mode == Mode::RunMake {
// Parse directives in the Makefile
testpaths.file.join("Makefile")
} else {
PathBuf::from(&testpaths.file)
};
- let early_props = EarlyProps::from_file(config, &test_path);
+ let early_props = EarlyProps::from_file(&config, &test_path);
// Incremental tests are special, they inherently cannot be run in parallel.
// `runtest::run` will be responsible for iterating over revisions.
@@ -696,19 +735,22 @@ fn make_test(config: &Config, testpaths: &TestPaths, inputs: &Stamp) -> Vec<test
let src_file =
std::fs::File::open(&test_path).expect("open test file to parse ignores");
let cfg = revision.map(|v| &**v);
- let test_name = crate::make_test_name(config, testpaths, revision);
- let mut desc = make_test_description(config, test_name, &test_path, src_file, cfg);
+ let test_name = crate::make_test_name(&config, testpaths, revision);
+ let mut desc = make_test_description(&config, test_name, &test_path, src_file, cfg);
// Ignore tests that already run and are up to date with respect to inputs.
if !config.force_rerun {
desc.ignore |= is_up_to_date(
- config,
+ &config,
testpaths,
&early_props,
revision.map(|s| s.as_str()),
inputs,
);
}
- test::TestDescAndFn { desc, testfn: make_test_closure(config, testpaths, revision) }
+ test::TestDescAndFn {
+ desc,
+ testfn: make_test_closure(config.clone(), testpaths, revision),
+ }
})
.collect()
}
@@ -842,7 +884,7 @@ fn make_test_name(
}
fn make_test_closure(
- config: &Config,
+ config: Arc<Config>,
testpaths: &TestPaths,
revision: Option<&String>,
) -> test::TestFn {
@@ -1066,3 +1108,24 @@ fn extract_lldb_version(full_version_line: &str) -> Option<(u32, bool)> {
fn not_a_digit(c: char) -> bool {
!c.is_digit(10)
}
+
+fn check_overlapping_tests(found_paths: &BTreeSet<PathBuf>) {
+ let mut collisions = Vec::new();
+ for path in found_paths {
+ for ancestor in path.ancestors().skip(1) {
+ if found_paths.contains(ancestor) {
+ collisions.push((path, ancestor.clone()));
+ }
+ }
+ }
+ if !collisions.is_empty() {
+ let collisions: String = collisions
+ .into_iter()
+ .map(|(path, check_parent)| format!("test {path:?} clashes with {check_parent:?}\n"))
+ .collect();
+ panic!(
+ "{collisions}\n\
+ Tests cannot have overlapping names. Make sure they use unique prefixes."
+ );
+ }
+}
diff --git a/src/tools/compiletest/src/read2.rs b/src/tools/compiletest/src/read2.rs
index a5dc68597..725f7a151 100644
--- a/src/tools/compiletest/src/read2.rs
+++ b/src/tools/compiletest/src/read2.rs
@@ -232,7 +232,7 @@ mod imp {
use miow::iocp::{CompletionPort, CompletionStatus};
use miow::pipe::NamedPipe;
use miow::Overlapped;
- use winapi::shared::winerror::ERROR_BROKEN_PIPE;
+ use windows::Win32::Foundation::ERROR_BROKEN_PIPE;
struct Pipe<'a> {
dst: &'a mut Vec<u8>,
@@ -295,7 +295,7 @@ mod imp {
match self.pipe.read_overlapped(dst, self.overlapped.raw()) {
Ok(_) => Ok(()),
Err(e) => {
- if e.raw_os_error() == Some(ERROR_BROKEN_PIPE as i32) {
+ if e.raw_os_error() == Some(ERROR_BROKEN_PIPE.0 as i32) {
self.done = true;
Ok(())
} else {
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 41c23ff86..7f0b894f5 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -30,6 +30,7 @@ use std::iter;
use std::path::{Path, PathBuf};
use std::process::{Child, Command, ExitStatus, Output, Stdio};
use std::str;
+use std::sync::Arc;
use glob::glob;
use once_cell::sync::Lazy;
@@ -49,8 +50,10 @@ 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;
- use winapi::um::errhandlingapi::SetErrorMode;
- use winapi::um::winbase::SEM_NOGPFAULTERRORBOX;
+
+ use windows::Win32::System::Diagnostics::Debug::{
+ SetErrorMode, SEM_NOGPFAULTERRORBOX, THREAD_ERROR_MODE,
+ };
static LOCK: Mutex<()> = Mutex::new(());
@@ -62,6 +65,7 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
// termination by design. This mode is inherited by all child processes.
unsafe {
let old_mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags
+ let old_mode = THREAD_ERROR_MODE(old_mode);
SetErrorMode(old_mode | SEM_NOGPFAULTERRORBOX);
let r = f();
SetErrorMode(old_mode);
@@ -93,7 +97,7 @@ pub fn get_lib_name(lib: &str, dylib: bool) -> String {
}
}
-pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) {
+pub fn run(config: Arc<Config>, testpaths: &TestPaths, revision: Option<&str>) {
match &*config.target {
"arm-linux-androideabi"
| "armv7-linux-androideabi"
@@ -278,13 +282,15 @@ impl<'test> TestCx<'test> {
Incremental => {
let revision =
self.revision.expect("incremental tests require a list of revisions");
- if revision.starts_with("rpass") || revision.starts_with("rfail") {
+ if revision.starts_with("cpass")
+ || revision.starts_with("rpass")
+ || revision.starts_with("rfail")
+ {
true
} else if revision.starts_with("cfail") {
- // FIXME: would be nice if incremental revs could start with "cpass"
pm.is_some()
} else {
- panic!("revision name must begin with rpass, rfail, or cfail");
+ panic!("revision name must begin with cpass, rpass, rfail, or cfail");
}
}
mode => panic!("unimplemented for mode {:?}", mode),
@@ -304,7 +310,9 @@ impl<'test> TestCx<'test> {
);
}
- self.check_correct_failure_status(proc_res);
+ if !self.props.dont_check_failure_status {
+ self.check_correct_failure_status(proc_res);
+ }
}
}
@@ -384,6 +392,20 @@ impl<'test> TestCx<'test> {
}
}
+ fn run_cpass_test(&self) {
+ let emit_metadata = self.should_emit_metadata(self.pass_mode());
+ let proc_res = self.compile_test(WillExecute::No, emit_metadata);
+
+ if !proc_res.status.success() {
+ self.fatal_proc_rec("compilation failed!", &proc_res);
+ }
+
+ // FIXME(#41968): Move this check to tidy?
+ if !errors::load_errors(&self.testpaths.file, self.revision).is_empty() {
+ self.fatal("compile-pass tests with expected warnings should be moved to ui/");
+ }
+ }
+
fn run_rpass_test(&self) {
let emit_metadata = self.should_emit_metadata(self.pass_mode());
let should_run = self.run_if_enabled();
@@ -393,17 +415,15 @@ impl<'test> TestCx<'test> {
self.fatal_proc_rec("compilation failed!", &proc_res);
}
+ // FIXME(#41968): Move this check to tidy?
+ if !errors::load_errors(&self.testpaths.file, self.revision).is_empty() {
+ self.fatal("run-pass tests with expected warnings should be moved to ui/");
+ }
+
if let WillExecute::Disabled = should_run {
return;
}
- // FIXME(#41968): Move this check to tidy?
- let expected_errors = errors::load_errors(&self.testpaths.file, self.revision);
- assert!(
- expected_errors.is_empty(),
- "run-pass tests with expected warnings should be moved to ui/"
- );
-
let proc_res = self.exec_compiled_test();
if !proc_res.status.success() {
self.fatal_proc_rec("test run failed!", &proc_res);
@@ -983,7 +1003,12 @@ impl<'test> TestCx<'test> {
&["-quiet".as_ref(), "-batch".as_ref(), "-nx".as_ref(), &debugger_script];
let mut gdb = Command::new(self.config.gdb.as_ref().unwrap());
- gdb.args(debugger_opts).env("PYTHONPATH", rust_pp_module_abs_path);
+ let pythonpath = if let Ok(pp) = std::env::var("PYTHONPATH") {
+ format!("{pp}:{rust_pp_module_abs_path}")
+ } else {
+ rust_pp_module_abs_path
+ };
+ gdb.args(debugger_opts).env("PYTHONPATH", pythonpath);
debugger_run_result =
self.compose_and_run(gdb, self.config.run_lib_path.to_str().unwrap(), None, None);
@@ -1149,13 +1174,18 @@ impl<'test> TestCx<'test> {
) -> ProcRes {
// Prepare the lldb_batchmode which executes the debugger script
let lldb_script_path = rust_src_root.join("src/etc/lldb_batchmode.py");
+ let pythonpath = if let Ok(pp) = std::env::var("PYTHONPATH") {
+ format!("{pp}:{}", self.config.lldb_python_dir.as_ref().unwrap())
+ } else {
+ self.config.lldb_python_dir.as_ref().unwrap().to_string()
+ };
self.cmd2procres(
Command::new(&self.config.python)
.arg(&lldb_script_path)
.arg(test_executable)
.arg(debugger_script)
.env("PYTHONUNBUFFERED", "1") // Help debugging #78665
- .env("PYTHONPATH", self.config.lldb_python_dir.as_ref().unwrap()),
+ .env("PYTHONPATH", pythonpath),
)
}
@@ -1540,7 +1570,7 @@ impl<'test> TestCx<'test> {
rustdoc.arg("--output-format").arg("json").arg("-Zunstable-options");
}
- if let Some(ref linker) = self.config.linker {
+ if let Some(ref linker) = self.config.target_linker {
rustdoc.arg(format!("-Clinker={}", linker));
}
@@ -1583,8 +1613,13 @@ impl<'test> TestCx<'test> {
test_client
.args(&["run", &support_libs.len().to_string(), &prog])
.args(support_libs)
- .args(args)
- .envs(env.clone());
+ .args(args);
+
+ for key in &self.props.unset_exec_env {
+ test_client.env_remove(key);
+ }
+ test_client.envs(env.clone());
+
self.compose_and_run(
test_client,
self.config.run_lib_path.to_str().unwrap(),
@@ -1596,7 +1631,13 @@ impl<'test> TestCx<'test> {
let aux_dir = self.aux_output_dir_name();
let ProcArgs { prog, args } = self.make_run_args();
let mut wr_run = Command::new("wr-run");
- wr_run.args(&[&prog]).args(args).envs(env.clone());
+ wr_run.args(&[&prog]).args(args);
+
+ for key in &self.props.unset_exec_env {
+ wr_run.env_remove(key);
+ }
+ wr_run.envs(env.clone());
+
self.compose_and_run(
wr_run,
self.config.run_lib_path.to_str().unwrap(),
@@ -1608,7 +1649,13 @@ impl<'test> TestCx<'test> {
let aux_dir = self.aux_output_dir_name();
let ProcArgs { prog, args } = self.make_run_args();
let mut program = Command::new(&prog);
- program.args(args).current_dir(&self.output_base_dir()).envs(env.clone());
+ program.args(args).current_dir(&self.output_base_dir());
+
+ for key in &self.props.unset_exec_env {
+ program.env_remove(key);
+ }
+ program.envs(env.clone());
+
self.compose_and_run(
program,
self.config.run_lib_path.to_str().unwrap(),
@@ -2053,10 +2100,15 @@ impl<'test> TestCx<'test> {
if self.props.force_host {
self.maybe_add_external_args(&mut rustc, &self.config.host_rustcflags);
+ if !is_rustdoc {
+ if let Some(ref linker) = self.config.host_linker {
+ rustc.arg(format!("-Clinker={}", linker));
+ }
+ }
} else {
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
if !is_rustdoc {
- if let Some(ref linker) = self.config.linker {
+ if let Some(ref linker) = self.config.target_linker {
rustc.arg(format!("-Clinker={}", linker));
}
}
@@ -2105,7 +2157,7 @@ impl<'test> TestCx<'test> {
if let Some(ref p) = self.config.nodejs {
args.push(p.clone());
} else {
- self.fatal("no NodeJS binary found (--nodejs)");
+ self.fatal("emscripten target requested and no NodeJS binary found (--nodejs)");
}
// If this is otherwise wasm, then run tests under nodejs with our
// shim
@@ -2113,7 +2165,7 @@ impl<'test> TestCx<'test> {
if let Some(ref p) = self.config.nodejs {
args.push(p.clone());
} else {
- self.fatal("no NodeJS binary found (--nodejs)");
+ self.fatal("wasm32 target requested and no NodeJS binary found (--nodejs)");
}
let src = self
@@ -2903,10 +2955,11 @@ impl<'test> TestCx<'test> {
fn run_incremental_test(&self) {
// Basic plan for a test incremental/foo/bar.rs:
// - load list of revisions rpass1, cfail2, rpass3
- // - each should begin with `rpass`, `cfail`, or `rfail`
- // - if `rpass`, expect compile and execution to succeed
+ // - each should begin with `cpass`, `rpass`, `cfail`, or `rfail`
+ // - if `cpass`, expect compilation to succeed, don't execute
+ // - if `rpass`, expect compilation and execution to succeed
// - if `cfail`, expect compilation to fail
- // - if `rfail`, expect execution to fail
+ // - if `rfail`, expect compilation to succeed and execution to fail
// - create a directory build/foo/bar.incremental
// - compile foo/bar.rs with -C incremental=.../foo/bar.incremental and -C rpass1
// - because name of revision starts with "rpass", expect success
@@ -2930,7 +2983,12 @@ impl<'test> TestCx<'test> {
print!("revision={:?} props={:#?}", revision, self.props);
}
- if revision.starts_with("rpass") {
+ if revision.starts_with("cpass") {
+ if self.props.should_ice {
+ self.fatal("can only use should-ice in cfail tests");
+ }
+ self.run_cpass_test();
+ } else if revision.starts_with("rpass") {
if self.props.should_ice {
self.fatal("can only use should-ice in cfail tests");
}
@@ -2943,7 +3001,7 @@ impl<'test> TestCx<'test> {
} else if revision.starts_with("cfail") {
self.run_cfail_test();
} else {
- self.fatal("revision name must begin with rpass, rfail, or cfail");
+ self.fatal("revision name must begin with cpass, rpass, rfail, or cfail");
}
}
@@ -2963,6 +3021,7 @@ impl<'test> TestCx<'test> {
|| host.contains("freebsd")
|| host.contains("netbsd")
|| host.contains("openbsd")
+ || host.contains("aix")
{
"gmake"
} else {
@@ -3002,7 +3061,7 @@ impl<'test> TestCx<'test> {
cmd.env("NODE", node);
}
- if let Some(ref linker) = self.config.linker {
+ if let Some(ref linker) = self.config.target_linker {
cmd.env("RUSTC_LINKER", linker);
}
diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs
index 5f6a27e53..748240cc9 100644
--- a/src/tools/compiletest/src/util.rs
+++ b/src/tools/compiletest/src/util.rs
@@ -156,6 +156,8 @@ pub fn dylib_env_var() -> &'static str {
"DYLD_LIBRARY_PATH"
} else if cfg!(target_os = "haiku") {
"LIBRARY_PATH"
+ } else if cfg!(target_os = "aix") {
+ "LIBPATH"
} else {
"LD_LIBRARY_PATH"
}