From a691b14aeeea6de133c23050e33732b5fe620a7b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 5 Jun 2023 15:15:48 +0000 Subject: [PATCH] Allow skipping tests from the commandline --- build_system/main.rs | 8 ++++++++ build_system/tests.rs | 27 +++++++++++++++++++-------- build_system/usage.txt | 5 ++++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/build_system/main.rs b/build_system/main.rs index d51e5027cf3..41d0d6f2319 100644 --- a/build_system/main.rs +++ b/build_system/main.rs @@ -90,6 +90,7 @@ fn main() { let mut sysroot_kind = SysrootKind::Clif; let mut use_unstable_features = true; let mut frozen = false; + let mut skip_tests = vec![]; let mut use_backend = None; while let Some(arg) = args.next().as_deref() { match arg { @@ -115,6 +116,12 @@ fn main() { } "--no-unstable-features" => use_unstable_features = false, "--frozen" => frozen = true, + "--skip-test" => { + // FIXME check that all passed in tests actually exist + skip_tests.push(args.next().unwrap_or_else(|| { + arg_error!("--skip-test requires argument"); + })); + } "--use-backend" => { use_backend = Some(match args.next() { Some(name) => name, @@ -218,6 +225,7 @@ fn main() { channel, sysroot_kind, use_unstable_features, + &skip_tests.iter().map(|test| &**test).collect::>(), &cg_clif_dylib, &bootstrap_host_compiler, rustup_toolchain_name.as_deref(), diff --git a/build_system/tests.rs b/build_system/tests.rs index 733a572400b..08d8f708c7d 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -19,7 +19,7 @@ struct TestCase { } enum TestCaseCmd { - Custom { func: &'static dyn Fn(&TestRunner) }, + Custom { func: &'static dyn Fn(&TestRunner<'_>) }, BuildLib { source: &'static str, crate_types: &'static str }, BuildBinAndRun { source: &'static str, args: &'static [&'static str] }, JitBin { source: &'static str, args: &'static str }, @@ -27,7 +27,7 @@ enum TestCaseCmd { impl TestCase { // FIXME reduce usage of custom test case commands - const fn custom(config: &'static str, func: &'static dyn Fn(&TestRunner)) -> Self { + const fn custom(config: &'static str, func: &'static dyn Fn(&TestRunner<'_>)) -> Self { Self { config, cmd: TestCaseCmd::Custom { func } } } @@ -247,6 +247,7 @@ pub(crate) fn run_tests( channel: &str, sysroot_kind: SysrootKind, use_unstable_features: bool, + skip_tests: &[&str], cg_clif_dylib: &CodegenBackend, bootstrap_host_compiler: &Compiler, rustup_toolchain_name: Option<&str>, @@ -256,7 +257,7 @@ pub(crate) fn run_tests( get_default_sysroot(&bootstrap_host_compiler.rustc).join("lib/rustlib/src/rust"); assert!(stdlib_source.exists()); - if config::get_bool("testsuite.no_sysroot") { + if config::get_bool("testsuite.no_sysroot") && !skip_tests.contains(&"testsuite.no_sysroot") { let target_compiler = build_sysroot::build_sysroot( dirs, channel, @@ -271,6 +272,7 @@ pub(crate) fn run_tests( dirs.clone(), target_compiler, use_unstable_features, + skip_tests, bootstrap_host_compiler.triple == target_triple, stdlib_source.clone(), ); @@ -281,8 +283,10 @@ pub(crate) fn run_tests( eprintln!("[SKIP] no_sysroot tests"); } - let run_base_sysroot = config::get_bool("testsuite.base_sysroot"); - let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot"); + let run_base_sysroot = config::get_bool("testsuite.base_sysroot") + && !skip_tests.contains(&"testsuite.base_sysroot"); + let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot") + && !skip_tests.contains(&"testsuite.extended_sysroot"); if run_base_sysroot || run_extended_sysroot { let mut target_compiler = build_sysroot::build_sysroot( @@ -302,6 +306,7 @@ pub(crate) fn run_tests( dirs.clone(), target_compiler, use_unstable_features, + skip_tests, bootstrap_host_compiler.triple == target_triple, stdlib_source, ); @@ -320,20 +325,22 @@ pub(crate) fn run_tests( } } -struct TestRunner { +struct TestRunner<'a> { is_native: bool, jit_supported: bool, use_unstable_features: bool, + skip_tests: &'a [&'a str], dirs: Dirs, target_compiler: Compiler, stdlib_source: PathBuf, } -impl TestRunner { +impl<'a> TestRunner<'a> { fn new( dirs: Dirs, mut target_compiler: Compiler, use_unstable_features: bool, + skip_tests: &'a [&'a str], is_native: bool, stdlib_source: PathBuf, ) -> Self { @@ -360,6 +367,7 @@ fn new( is_native, jit_supported, use_unstable_features, + skip_tests, dirs, target_compiler, stdlib_source, @@ -372,7 +380,10 @@ fn run_testsuite(&self, tests: &[TestCase]) { let tag = tag.to_uppercase(); let is_jit_test = tag == "JIT"; - if !config::get_bool(config) || (is_jit_test && !self.jit_supported) { + if !config::get_bool(config) + || (is_jit_test && !self.jit_supported) + || self.skip_tests.contains(&config) + { eprintln!("[{tag}] {testname} (skipped)"); continue; } else { diff --git a/build_system/usage.txt b/build_system/usage.txt index 9d20cdca6a7..6d3b3a13d6e 100644 --- a/build_system/usage.txt +++ b/build_system/usage.txt @@ -3,7 +3,7 @@ The build system of cg_clif. USAGE: ./y.sh prepare [--out-dir DIR] [--download-dir DIR] ./y.sh build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] - ./y.sh test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.sh test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] [--skip-test TESTNAME] ./y.sh abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] ./y.sh bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] @@ -32,6 +32,9 @@ OPTIONS: --frozen Require Cargo.lock and cache are up to date + --skip-test TESTNAME + Skip testing the TESTNAME test. The test name format is the same as config.txt. + --use-backend NAME Use the existing Cranelift (or other) backend of the rustc with which we built. Warning: This is meant for use in rust's CI only!