diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-29 11:18:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-29 11:18:07 +0200 |
| commit | 0721364f0de6191cddeaaaeb112fb74aa1a9e30a (patch) | |
| tree | 97d7e70fbfd8a91d0f13e1d35241283112684621 /src/tools | |
| parent | 6c0ab739fb77c67d00ba5b5fa357deec404f9bce (diff) | |
| parent | 93077f3f3922817a70013c403831bf1db4a30114 (diff) | |
Rollup merge of #61755 - Centril:compiletest-force-check, r=petrochenkov
Add `--pass $mode` to compiletest through `./x.py`
Adds a flag `--pass $mode` to compiletest, which is exposed through `./x.py`.
When `--pass $mode` is passed, `{check,build,compile,run}-pass` tests will be forced to run under the given `$mode` unless the directive `// ignore-pass` exists in the test file.
The modes are explained in https://github.com/rust-lang/rust/pull/61778:
- `check` has the same effect as `cargo check`
- `build` or `compile` have the same effect as `cargo build`
- `run` has the same effect as `cargo run`
On my machine, `./x.py -i test src/test/run-pass --stage 1 --pass check` takes 38 seconds whereas it takes 2 min 7 seconds without `--pass check`.
cc https://github.com/rust-lang/rust/issues/61712
r? @petrochenkov
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/compiletest/src/common.rs | 33 | ||||
| -rw-r--r-- | src/tools/compiletest/src/header.rs | 31 | ||||
| -rw-r--r-- | src/tools/compiletest/src/main.rs | 16 | ||||
| -rw-r--r-- | src/tools/compiletest/src/runtest.rs | 36 |
4 files changed, 90 insertions, 26 deletions
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 722979c3c14..a75d9f0b0bb 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -99,6 +99,36 @@ impl fmt::Display for Mode { } } +#[derive(Clone, Copy, PartialEq, Debug, Hash)] +pub enum PassMode { + Check, + Build, + Run, +} + +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 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) + } +} + #[derive(Clone, Debug, PartialEq)] pub enum CompareMode { Nll, @@ -184,6 +214,9 @@ pub struct Config { /// Exactly match the filter, rather than a substring pub filter_exact: bool, + /// Force the pass mode of a check/build/run-pass test to this mode. + pub force_pass_mode: Option<PassMode>, + /// Write out a parseable log of tests that were run pub logfile: Option<PathBuf>, diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 6ce7461f759..52f777db2da 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -6,7 +6,7 @@ use std::path::{Path, PathBuf}; use log::*; -use crate::common::{self, CompareMode, Config, Mode}; +use crate::common::{self, CompareMode, Config, Mode, PassMode}; use crate::util; use crate::extract_gdb_version; @@ -290,13 +290,6 @@ impl EarlyProps { } } -#[derive(Clone, Copy, PartialEq, Debug)] -pub enum PassMode { - Check, - Build, - Run, -} - #[derive(Clone, Debug)] pub struct TestProps { // Lines that should be expected, in order, on standard out @@ -357,7 +350,9 @@ pub struct TestProps { // arguments. (In particular, it propagates to the aux-builds.) pub incremental_dir: Option<PathBuf>, // How far should the test proceed while still passing. - pub pass_mode: Option<PassMode>, + pass_mode: Option<PassMode>, + // Ignore `--pass` overrides from the command line for this test. + ignore_pass: bool, // rustdoc will test the output of the `--test` option pub check_test_line_numbers_match: bool, // Do not pass `-Z ui-testing` to UI tests @@ -400,6 +395,7 @@ impl TestProps { forbid_output: vec![], incremental_dir: None, pass_mode: None, + ignore_pass: false, check_test_line_numbers_match: false, disable_ui_testing_normalization: false, normalize_stdout: vec![], @@ -528,6 +524,10 @@ impl TestProps { self.update_pass_mode(ln, cfg, config); + if !self.ignore_pass { + self.ignore_pass = config.parse_ignore_pass(ln); + } + if !self.disable_ui_testing_normalization { self.disable_ui_testing_normalization = config.parse_disable_ui_testing_normalization(ln); @@ -608,6 +608,15 @@ impl TestProps { (_, None) => {} } } + + pub fn pass_mode(&self, config: &Config) -> Option<PassMode> { + if !self.ignore_pass { + if let (mode @ Some(_), Some(_)) = (config.force_pass_mode, self.pass_mode) { + return mode; + } + } + self.pass_mode + } } fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) { @@ -743,6 +752,10 @@ impl Config { self.parse_name_directive(line, "check-test-line-numbers-match") } + fn parse_ignore_pass(&self, line: &str) -> bool { + self.parse_name_directive(line, "ignore-pass") + } + fn parse_assembly_output(&self, line: &str) -> Option<String> { self.parse_name_value_directive(line, "assembly-output") .map(|r| r.trim().to_string()) diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index d0dc9d11d39..597fdf2d95e 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -5,7 +5,7 @@ extern crate test; -use crate::common::CompareMode; +use crate::common::{CompareMode, PassMode}; use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS}; use crate::common::{Config, TestPaths}; use crate::common::{DebugInfoCdb, DebugInfoGdbLldb, DebugInfoGdb, DebugInfoLldb, Mode, Pretty}; @@ -128,6 +128,12 @@ pub fn parse_config(args: Vec<String>) -> Config { "(compile-fail|run-fail|run-pass|\ run-pass-valgrind|pretty|debug-info|incremental|mir-opt)", ) + .optopt( + "", + "pass", + "force {check,build,run}-pass tests to this mode.", + "check | build | run" + ) .optflag("", "ignored", "run tests marked as ignored") .optflag("", "exact", "filters match exactly") .optopt( @@ -320,6 +326,10 @@ pub fn parse_config(args: Vec<String>) -> Config { run_ignored, filter: matches.free.first().cloned(), filter_exact: matches.opt_present("exact"), + force_pass_mode: matches.opt_str("pass").map(|mode| + mode.parse::<PassMode>() + .unwrap_or_else(|_| panic!("unknown `--pass` option `{}` given", mode)) + ), logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)), runtool: matches.opt_str("runtool"), host_rustcflags: matches.opt_str("host-rustcflags"), @@ -382,6 +392,10 @@ pub fn log_config(config: &Config) { ), ); logv(c, format!("filter_exact: {}", config.filter_exact)); + logv(c, format!( + "force_pass_mode: {}", + opt_str(&config.force_pass_mode.map(|m| format!("{}", m))), + )); logv(c, format!("runtool: {}", opt_str(&config.runtool))); logv( c, diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 8b52a529d44..35caf82dd71 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1,6 +1,6 @@ // ignore-tidy-filelength -use crate::common::CompareMode; +use crate::common::{CompareMode, PassMode}; use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT}; use crate::common::{output_base_dir, output_base_name, output_testname_unique}; use crate::common::{Codegen, CodegenUnits, Rustdoc}; @@ -10,7 +10,7 @@ use crate::common::{Config, TestPaths}; use crate::common::{Incremental, MirOpt, RunMake, Ui, JsDocTest, Assembly}; use diff; use crate::errors::{self, Error, ErrorKind}; -use crate::header::{TestProps, PassMode}; +use crate::header::TestProps; use crate::json; use regex::{Captures, Regex}; use rustfix::{apply_suggestions, get_suggestions_from_json, Filter}; @@ -260,6 +260,10 @@ pub fn compute_stamp_hash(config: &Config) -> String { env::var_os("PYTHONPATH").hash(&mut hash); } + if let Ui | RunPass | Incremental | Pretty = config.mode { + config.force_pass_mode.hash(&mut hash); + } + format!("{:x}", hash.finish()) } @@ -309,10 +313,13 @@ impl<'test> TestCx<'test> { } } + fn pass_mode(&self) -> Option<PassMode> { + self.props.pass_mode(self.config) + } + fn should_run_successfully(&self) -> bool { match self.config.mode { - RunPass => true, - Ui => self.props.pass_mode == Some(PassMode::Run), + RunPass | Ui => self.pass_mode() == Some(PassMode::Run), mode => panic!("unimplemented for mode {:?}", mode), } } @@ -322,7 +329,7 @@ impl<'test> TestCx<'test> { CompileFail => false, RunPass => true, JsDocTest => true, - Ui => self.props.pass_mode.is_some(), + Ui => self.pass_mode().is_some(), Incremental => { let revision = self.revision .expect("incremental tests require a list of revisions"); @@ -330,7 +337,7 @@ impl<'test> TestCx<'test> { true } else if revision.starts_with("cfail") { // FIXME: would be nice if incremental revs could start with "cpass" - self.props.pass_mode.is_some() + self.pass_mode().is_some() } else { panic!("revision name must begin with rpass, rfail, or cfail"); } @@ -1341,7 +1348,7 @@ impl<'test> TestCx<'test> { fn check_error_patterns(&self, output_to_check: &str, proc_res: &ProcRes) { debug!("check_error_patterns"); if self.props.error_patterns.is_empty() { - if self.props.pass_mode.is_some() { + if self.pass_mode().is_some() { return; } else { self.fatal(&format!( @@ -1871,7 +1878,11 @@ impl<'test> TestCx<'test> { result } - fn make_compile_args(&self, input_file: &Path, output_file: TargetLocation) -> Command { + fn make_compile_args( + &self, + input_file: &Path, + output_file: TargetLocation, + ) -> Command { let is_rustdoc = self.config.src_base.ends_with("rustdoc-ui") || self.config.src_base.ends_with("rustdoc-js"); let mut rustc = if !is_rustdoc { @@ -1968,14 +1979,7 @@ impl<'test> TestCx<'test> { } } - if self.props.pass_mode == Some(PassMode::Check) { - assert!( - !self - .props - .compile_flags - .iter() - .any(|s| s.starts_with("--emit")) - ); + if let Some(PassMode::Check) = self.pass_mode() { rustc.args(&["--emit", "metadata"]); } |
