Skip to content

Commit 8db0bc0

Browse files
authored
Merge pull request #27 from oli-obk/travis
create a miri-pass test that allows us to run miri for arbitrary targets
2 parents bac37e6 + 60f2bb9 commit 8db0bc0

File tree

5 files changed

+83
-32
lines changed

5 files changed

+83
-32
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
language: rust
22
rust:
33
- nightly
4-
matrix:
5-
allow_failures:
6-
- rust: nightly
74
before_script:
85
- |
96
pip install 'travis-cargo<0.2' --user &&
107
export PATH=$HOME/.local/bin:$PATH
118
script:
129
- |
13-
travis-cargo build &&
10+
env RUST_SYSROOT=$HOME/rust travis-cargo build &&
1411
env RUST_SYSROOT=$HOME/rust travis-cargo test
1512
notifications:
1613
email:

Cargo.lock

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ log = "0.3.6"
2121
log_settings = "0.1.1"
2222

2323
[dev-dependencies]
24-
compiletest_rs = "0.1.1"
24+
compiletest_rs = "0.2"

src/bin/miri.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use miri::{
1717
Frame,
1818
};
1919
use rustc::session::Session;
20-
use rustc_driver::{driver, CompilerCalls};
20+
use rustc_driver::{driver, CompilerCalls, Compilation};
2121
use rustc::ty::{TyCtxt, subst};
2222
use rustc::hir::def_id::DefId;
2323

@@ -31,6 +31,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
3131
) -> driver::CompileController<'a> {
3232
let mut control = driver::CompileController::basic();
3333

34+
control.after_analysis.stop = Compilation::Stop;
3435
control.after_analysis.callback = Box::new(|state| {
3536
state.session.abort_if_errors();
3637

@@ -70,6 +71,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
7071
}
7172
}
7273
}
74+
state.session.abort_if_errors();
7375
});
7476

7577
control

tests/compiletest.rs

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,89 @@
11
extern crate compiletest_rs as compiletest;
22

3-
use std::path::PathBuf;
3+
use std::path::{PathBuf, Path};
4+
use std::io::Write;
45

5-
fn run_mode(mode: &'static str) {
6+
fn run_mode(dir: &'static str, mode: &'static str, sysroot: &str) {
67
// Disable rustc's new error fomatting. It breaks these tests.
78
std::env::remove_var("RUST_NEW_ERROR_FORMAT");
8-
9-
// Taken from https://github.com/Manishearth/rust-clippy/pull/911.
10-
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
11-
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
12-
let sysroot = match (home, toolchain) {
13-
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
14-
_ => option_env!("RUST_SYSROOT")
15-
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
16-
.to_owned(),
17-
};
189
let flags = format!("--sysroot {} -Dwarnings", sysroot);
19-
20-
// FIXME: read directories in sysroot/lib/rustlib and generate the test targets from that
21-
let targets = &["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"];
22-
23-
for &target in targets {
24-
use std::io::Write;
25-
let stderr = std::io::stderr();
26-
write!(stderr.lock(), "running tests for target {}", target).unwrap();
10+
for_all_targets(sysroot, |target| {
2711
let mut config = compiletest::default_config();
2812
config.host_rustcflags = Some(flags.clone());
2913
config.mode = mode.parse().expect("Invalid mode");
30-
config.run_lib_path = format!("{}/lib/rustlib/{}/lib", sysroot, target);
14+
config.run_lib_path = Path::new(sysroot).join("lib").join("rustlib").join(&target).join("lib");
3115
config.rustc_path = "target/debug/miri".into();
32-
config.src_base = PathBuf::from(format!("tests/{}", mode));
16+
config.src_base = PathBuf::from(format!("tests/{}", dir));
3317
config.target = target.to_owned();
3418
config.target_rustcflags = Some(flags.clone());
3519
compiletest::run_tests(&config);
20+
});
21+
}
22+
23+
fn for_all_targets<F: FnMut(String)>(sysroot: &str, mut f: F) {
24+
for target in std::fs::read_dir(format!("{}/lib/rustlib/", sysroot)).unwrap() {
25+
let target = target.unwrap();
26+
if !target.metadata().unwrap().is_dir() {
27+
continue;
28+
}
29+
let target = target.file_name().into_string().unwrap();
30+
if target == "etc" {
31+
continue;
32+
}
33+
let stderr = std::io::stderr();
34+
writeln!(stderr.lock(), "running tests for target {}", target).unwrap();
35+
f(target);
3636
}
3737
}
3838

3939
#[test]
4040
fn compile_test() {
41-
run_mode("compile-fail");
42-
run_mode("run-pass");
41+
let mut failed = false;
42+
// Taken from https://github.com/Manishearth/rust-clippy/pull/911.
43+
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
44+
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
45+
let sysroot = match (home, toolchain) {
46+
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
47+
_ => option_env!("RUST_SYSROOT")
48+
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
49+
.to_owned(),
50+
};
51+
run_mode("compile-fail", "compile-fail", &sysroot);
52+
for_all_targets(&sysroot, |target| {
53+
for file in std::fs::read_dir("tests/run-pass").unwrap() {
54+
let file = file.unwrap();
55+
if !file.metadata().unwrap().is_file() {
56+
continue;
57+
}
58+
let file = file.path();
59+
let stderr = std::io::stderr();
60+
write!(stderr.lock(), "test [miri-pass] {} ", file.to_str().unwrap()).unwrap();
61+
let mut cmd = std::process::Command::new("target/debug/miri");
62+
cmd.arg(file);
63+
cmd.arg("-Dwarnings");
64+
cmd.arg(format!("--target={}", target));
65+
let libs = Path::new(&sysroot).join("lib");
66+
let sysroot = libs.join("rustlib").join(&target).join("lib");
67+
let paths = std::env::join_paths(&[libs, sysroot]).unwrap();
68+
cmd.env(compiletest::procsrv::dylib_env_var(), paths);
69+
match cmd.output() {
70+
Ok(ref output) if output.status.success() => writeln!(stderr.lock(), "ok").unwrap(),
71+
Ok(output) => {
72+
failed = true;
73+
writeln!(stderr.lock(), "FAILED with exit code {}", output.status.code().unwrap_or(0)).unwrap();
74+
writeln!(stderr.lock(), "stdout: \n {}", std::str::from_utf8(&output.stdout).unwrap()).unwrap();
75+
writeln!(stderr.lock(), "stderr: \n {}", std::str::from_utf8(&output.stderr).unwrap()).unwrap();
76+
}
77+
Err(e) => {
78+
failed = true;
79+
writeln!(stderr.lock(), "FAILED: {}", e).unwrap();
80+
},
81+
}
82+
}
83+
let stderr = std::io::stderr();
84+
writeln!(stderr.lock(), "").unwrap();
85+
});
86+
if failed {
87+
panic!("some tests failed");
88+
}
4389
}

0 commit comments

Comments
 (0)