#![feature(slice_concat_ext)]
extern crate compiletest_rs as compiletest;
-extern crate dirs;
use std::slice::SliceConcatExt;
use std::path::{PathBuf, Path};
option_env!("RUSTC_LIB_PATH").unwrap().into()
}
-fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, fullmir: bool) {
+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!(
+ "## Skipping compile-fail tests in {} against miri for target {} due to missing mir",
+ path,
+ target
+ );
+ return;
+ }
+
eprintln!(
"## Running compile-fail tests in {} against miri for target {}",
path,
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) {
+fn rustc_pass(sysroot: &Path, path: &str) {
eprintln!("## Running run-pass tests in {} against rustc", path);
let mut config = compiletest::Config::default().tempdir();
config.mode = "run-pass".parse().expect("Invalid mode");
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());
}
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!(
+ "## Skipping run-pass tests in {} against miri for target {} due to missing mir",
+ path,
+ target
+ );
+ return;
+ }
+
let opt_str = if opt { " with optimizations" } else { "" };
eprintln!(
"## Running run-pass tests in {} against miri for target {}{}",
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());
// 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);
}
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]
#[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]