diff --git a/Cargo.toml b/Cargo.toml index c6128b2405aa..c46ba7c41429 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,4 +31,4 @@ cargo_miri = ["cargo_metadata"] [dev-dependencies] compiletest_rs = { version = "0.3.4", features = ["tmp"] } -dirs = "1.0.2" +colored = "1.6" diff --git a/tests/compile-fail/deallocate-bad-alignment.rs b/tests/compile-fail-fullmir/deallocate-bad-alignment.rs similarity index 100% rename from tests/compile-fail/deallocate-bad-alignment.rs rename to tests/compile-fail-fullmir/deallocate-bad-alignment.rs diff --git a/tests/compile-fail/deallocate-bad-size.rs b/tests/compile-fail-fullmir/deallocate-bad-size.rs similarity index 100% rename from tests/compile-fail/deallocate-bad-size.rs rename to tests/compile-fail-fullmir/deallocate-bad-size.rs diff --git a/tests/compile-fail/deallocate-twice.rs b/tests/compile-fail-fullmir/deallocate-twice.rs similarity index 100% rename from tests/compile-fail/deallocate-twice.rs rename to tests/compile-fail-fullmir/deallocate-twice.rs diff --git a/tests/compile-fail/out_of_bounds_ptr_1.rs b/tests/compile-fail-fullmir/out_of_bounds_ptr_1.rs similarity index 100% rename from tests/compile-fail/out_of_bounds_ptr_1.rs rename to tests/compile-fail-fullmir/out_of_bounds_ptr_1.rs diff --git a/tests/compile-fail/out_of_bounds_ptr_2.rs b/tests/compile-fail-fullmir/out_of_bounds_ptr_2.rs similarity index 100% rename from tests/compile-fail/out_of_bounds_ptr_2.rs rename to tests/compile-fail-fullmir/out_of_bounds_ptr_2.rs diff --git a/tests/compile-fail/ptr_offset_overflow.rs b/tests/compile-fail-fullmir/ptr_offset_overflow.rs similarity index 100% rename from tests/compile-fail/ptr_offset_overflow.rs rename to tests/compile-fail-fullmir/ptr_offset_overflow.rs diff --git a/tests/compile-fail/reallocate-bad-size.rs b/tests/compile-fail-fullmir/reallocate-bad-size.rs similarity index 100% rename from tests/compile-fail/reallocate-bad-size.rs rename to tests/compile-fail-fullmir/reallocate-bad-size.rs diff --git a/tests/compile-fail/reallocate-change-alloc.rs b/tests/compile-fail-fullmir/reallocate-change-alloc.rs similarity index 100% rename from tests/compile-fail/reallocate-change-alloc.rs rename to tests/compile-fail-fullmir/reallocate-change-alloc.rs diff --git a/tests/compile-fail/reallocate-dangling.rs b/tests/compile-fail-fullmir/reallocate-dangling.rs similarity index 100% rename from tests/compile-fail/reallocate-dangling.rs rename to tests/compile-fail-fullmir/reallocate-dangling.rs diff --git a/tests/compile-fail/stack_free.rs b/tests/compile-fail-fullmir/stack_free.rs similarity index 100% rename from tests/compile-fail/stack_free.rs rename to tests/compile-fail-fullmir/stack_free.rs diff --git a/tests/compiletest.rs b/tests/compiletest.rs index d5ed02504ab6..cfbfa70d42ee 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -1,7 +1,9 @@ #![feature(slice_concat_ext)] extern crate compiletest_rs as compiletest; -extern crate dirs; +extern crate colored; + +use colored::*; use std::slice::SliceConcatExt; use std::path::{PathBuf, Path}; @@ -31,12 +33,26 @@ fn rustc_lib_path() -> PathBuf { option_env!("RUSTC_LIB_PATH").unwrap().into() } -fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, fullmir: bool) { - eprintln!( +fn have_fullmir() -> bool { + // We assume we have full MIR when MIRI_SYSROOT is set or when we are in rustc + std::env::var("MIRI_SYSROOT").is_ok() || rustc_test_suite().is_some() +} + +fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir: bool) { + if need_fullmir && !have_fullmir() { + eprintln!("{}", format!( + "## Skipping compile-fail tests in {} against miri for target {} due to missing mir", + path, + target + ).yellow().bold()); + return; + } + + eprintln!("{}", format!( "## Running compile-fail tests in {} against miri for target {}", path, target - ); + ).green().bold()); let mut config = compiletest::Config::default().tempdir(); config.mode = "compile-fail".parse().expect("Invalid mode"); config.rustc_path = miri_path(); @@ -45,29 +61,17 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, fullmir: b config.run_lib_path = rustc_lib_path(); config.compile_lib_path = rustc_lib_path(); } - // if we are building as part of the rustc test suite, we already have fullmir for everything - if fullmir && rustc_test_suite().is_none() { - if host != target { - // skip fullmir on nonhost - return; - } - let sysroot = dirs::home_dir().unwrap() - .join(".xargo") - .join("HOST"); - flags.push(format!("--sysroot {}", sysroot.to_str().unwrap())); - config.src_base = PathBuf::from(path.to_string()); - } else { - flags.push(format!("--sysroot {}", sysroot.to_str().unwrap())); - config.src_base = PathBuf::from(path.to_string()); - } + flags.push(format!("--sysroot {}", sysroot.display())); + config.src_base = PathBuf::from(path.to_string()); flags.push("-Zmir-emit-validate=1".to_owned()); config.target_rustcflags = Some(flags.join(" ")); config.target = target.to_owned(); + config.host = host.to_owned(); compiletest::run_tests(&config); } -fn run_pass(path: &str) { - eprintln!("## Running run-pass tests in {} against rustc", path); +fn rustc_pass(sysroot: &Path, path: &str) { + eprintln!("{}", format!("## Running run-pass tests in {} against rustc", path).green().bold()); let mut config = compiletest::Config::default().tempdir(); config.mode = "run-pass".parse().expect("Invalid mode"); config.src_base = PathBuf::from(path); @@ -75,7 +79,7 @@ fn run_pass(path: &str) { config.rustc_path = rustc_path; config.run_lib_path = rustc_lib_path(); config.compile_lib_path = rustc_lib_path(); - config.target_rustcflags = Some(format!("-Dwarnings --sysroot {}", get_sysroot().display())); + config.target_rustcflags = Some(format!("-Dwarnings --sysroot {}", sysroot.display())); } else { config.target_rustcflags = Some("-Dwarnings".to_owned()); } @@ -83,14 +87,23 @@ fn run_pass(path: &str) { compiletest::run_tests(&config); } -fn miri_pass(path: &str, target: &str, host: &str, fullmir: bool, opt: bool) { +fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir: bool, opt: bool) { + if need_fullmir && !have_fullmir() { + eprintln!("{}", format!( + "## Skipping run-pass tests in {} against miri for target {} due to missing mir", + path, + target + ).yellow().bold()); + return; + } + let opt_str = if opt { " with optimizations" } else { "" }; - eprintln!( + eprintln!("{}", format!( "## Running run-pass tests in {} against miri for target {}{}", path, target, opt_str - ); + ).green().bold()); let mut config = compiletest::Config::default().tempdir(); config.mode = "ui".parse().expect("Invalid mode"); config.src_base = PathBuf::from(path); @@ -102,21 +115,9 @@ fn miri_pass(path: &str, target: &str, host: &str, fullmir: bool, opt: bool) { config.compile_lib_path = rustc_lib_path(); } let mut flags = Vec::new(); - // Control miri logging. This is okay despite concurrent test execution as all tests - // will set this env var to the same value. - env::set_var("MIRI_LOG", "warn"); - // if we are building as part of the rustc test suite, we already have fullmir for everything - if fullmir && rustc_test_suite().is_none() { - if host != target { - // skip fullmir on nonhost - return; - } - let sysroot = dirs::home_dir().unwrap() - .join(".xargo") - .join("HOST"); - + flags.push(format!("--sysroot {}", sysroot.display())); + if have_fullmir() { flags.push("-Zmiri-start-fn".to_owned()); - flags.push(format!("--sysroot {}", sysroot.to_str().unwrap())); } if opt { flags.push("-Zmir-opt-level=3".to_owned()); @@ -125,6 +126,9 @@ fn miri_pass(path: &str, target: &str, host: &str, fullmir: bool, opt: bool) { // For now, only validate without optimizations. Inlining breaks validation. flags.push("-Zmir-emit-validate=1".to_owned()); } + // Control miri logging. This is okay despite concurrent test execution as all tests + // will set this env var to the same value. + env::set_var("MIRI_LOG", "warn"); config.target_rustcflags = Some(flags.join(" ")); compiletest::run_tests(&config); } @@ -181,9 +185,9 @@ fn run_pass_miri(opt: bool) { let host = get_host(); for_all_targets(&sysroot, |target| { - miri_pass("tests/run-pass", &target, &host, false, opt); + miri_pass(&sysroot, "tests/run-pass", &target, &host, false, opt); }); - miri_pass("tests/run-pass-fullmir", &host, &host, true, opt); + miri_pass(&sysroot, "tests/run-pass-fullmir", &host, &host, true, opt); } #[test] @@ -201,8 +205,9 @@ fn run_pass_miri_opt() { #[test] fn run_pass_rustc() { - run_pass("tests/run-pass"); - run_pass("tests/run-pass-fullmir"); + let sysroot = get_sysroot(); + rustc_pass(&sysroot, "tests/run-pass"); + rustc_pass(&sysroot, "tests/run-pass-fullmir"); } #[test] @@ -211,6 +216,6 @@ fn compile_fail_miri() { let host = get_host(); // FIXME: run tests for other targets, too - compile_fail(&sysroot, "tests/compile-fail", &host, &host, true); - //compile_fail(&sysroot, "tests/compile-fail-fullmir", &host, &host, true); + compile_fail(&sysroot, "tests/compile-fail", &host, &host, false); + compile_fail(&sysroot, "tests/compile-fail-fullmir", &host, &host, true); }