Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use compiletest_rs #7

Merged
merged 1 commit into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ name = "miri"

[dependencies]
byteorder = "0.4.2"

[dev-dependencies]
compiletest_rs = "0.1.1"
3 changes: 1 addition & 2 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ extern crate rustc_driver;

use miri::interpreter;
use rustc::session::Session;
use rustc_driver::{driver, CompilerCalls, Compilation};
use rustc_driver::{driver, CompilerCalls};

struct MiriCompilerCalls;

impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
fn build_controller(&mut self, _: &Session) -> driver::CompileController<'a> {
let mut control = driver::CompileController::basic();
control.after_analysis.stop = Compilation::Stop;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this? Does this mean trans (and any other post-analysis steps) will run after Miri finishes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea. We need that to make run-pass tests actually runnable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point. I guess technically it doesn't make sense for any Miri tests to be run-pass because the execution all happens at compile-time, but this is fine for now.

Later we can rewrite those tests in a smarter way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust has lots of run-pass tests that don't do anything but verify that some construct will compile. So there's precedent for that ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Miri needs much better tests, regardless. :P

control.after_analysis.callback = Box::new(|state| {
state.session.abort_if_errors();
Expand Down
15 changes: 8 additions & 7 deletions tests/run-pass/errors.rs → tests/compile-fail/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand All @@ -9,33 +8,33 @@ fn overwriting_part_of_relocation_makes_the_rest_undefined() -> i32 {
let ptr: *mut _ = &mut p;
*(ptr as *mut u32) = 123;
}
*p
*p //~ ERROR: attempted to read undefined bytes
}

#[miri_run]
fn pointers_to_different_allocations_are_unorderable() -> bool {
let x: *const u8 = &1;
let y: *const u8 = &2;
x < y
x < y //~ ERROR: attempted to do math or a comparison on pointers into different allocations
}

#[miri_run]
fn invalid_bool() -> u8 {
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
if b { 1 } else { 2 }
if b { 1 } else { 2 } //~ ERROR: invalid boolean value read
}

#[miri_run]
fn undefined_byte_read() -> u8 {
let v: Vec<u8> = Vec::with_capacity(10);
let undef = unsafe { *v.get_unchecked(5) };
undef + 1
undef + 1 //~ ERROR: attempted to read undefined bytes
}

#[miri_run]
fn out_of_bounds_read() -> u8 {
let v: Vec<u8> = vec![1, 2];
unsafe { *v.get_unchecked(5) }
unsafe { *v.get_unchecked(5) } //~ ERROR: pointer offset outside bounds of allocation
}

#[miri_run]
Expand All @@ -44,5 +43,7 @@ fn dangling_pointer_deref() -> i32 {
let b = Box::new(42);
&*b as *const i32
};
unsafe { *p }
unsafe { *p } //~ ERROR: dangling pointer was dereferenced
}

fn main() {}
37 changes: 0 additions & 37 deletions tests/compile-test.rs

This file was deleted.

23 changes: 23 additions & 0 deletions tests/compiletest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extern crate compiletest_rs as compiletest;

use std::path::PathBuf;

fn run_mode(mode: &'static str) {
let mut config = compiletest::default_config();
config.rustc_path = "target/debug/miri".into();
let path = std::env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
config.target_rustcflags = Some(format!("--sysroot {}", path));
config.host_rustcflags = Some(format!("--sysroot {}", path));
let cfg_mode = mode.parse().ok().expect("Invalid mode");

config.mode = cfg_mode;
config.src_base = PathBuf::from(format!("tests/{}", mode));

compiletest::run_tests(&config);
}

#[test]
fn compile_test() {
run_mode("compile-fail");
run_mode("run-pass");
}
3 changes: 2 additions & 1 deletion tests/run-pass/arrays.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand Down Expand Up @@ -33,3 +32,5 @@ fn index() -> i32 {
fn array_repeat() -> [u8; 8] {
[42; 8]
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/bools.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand Down Expand Up @@ -27,3 +26,5 @@ fn match_bool() -> i16 {
_ => 0,
}
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/c_enums.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand All @@ -20,3 +19,5 @@ fn unsafe_match() -> bool {
_ => false,
}
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/calls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand Down Expand Up @@ -39,3 +38,5 @@ fn cross_crate_fn_call() -> i64 {
fn test_size_of() -> usize {
::std::mem::size_of::<Option<i32>>()
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/closures.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand Down Expand Up @@ -37,3 +36,5 @@ fn crazy_closure() -> (i32, i32, i32) {
// }
// y
// }

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/heap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute, box_syntax)]
#![allow(dead_code, unused_attributes)]

Expand All @@ -11,3 +10,5 @@ fn make_box() -> Box<(i16, i16)> {
fn make_box_syntax() -> Box<(i16, i16)> {
box (1, 2)
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/ints.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand Down Expand Up @@ -53,3 +52,5 @@ fn match_int_range() -> i64 {
_ => 5,
}
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/loops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand Down Expand Up @@ -34,3 +33,5 @@ fn for_loop() -> usize {
}
sum
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/pointers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand Down Expand Up @@ -58,3 +57,5 @@ fn dangling_pointer() -> *const i32 {
let b = Box::new(42);
&*b as *const i32
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/products.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand Down Expand Up @@ -30,3 +29,5 @@ fn field_access() -> (i8, i8) {
p.x += 5;
(p.x, p.y)
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/specialization.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute, specialization)]
#![allow(dead_code, unused_attributes)]

Expand All @@ -18,3 +17,5 @@ impl IsUnit for () {
fn specialization() -> (bool, bool) {
(i32::is_unit(), <()>::is_unit())
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/std.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute, box_syntax)]
#![allow(dead_code, unused_attributes)]

Expand Down Expand Up @@ -44,3 +43,5 @@ fn rc_reference_cycle() -> Loop {
fn true_assert() {
assert_eq!(1, 1);
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/strings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand All @@ -21,3 +20,5 @@ fn hello_bytes() -> &'static [u8; 13] {
fn hello_bytes_fat() -> &'static [u8] {
b"Hello, world!"
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/sums.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand Down Expand Up @@ -53,3 +52,5 @@ fn match_opt_some() -> i8 {
fn two_nones() -> (Option<i16>, Option<i16>) {
(None, None)
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/trivial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand All @@ -10,3 +9,5 @@ fn unit_var() {
let x = ();
x
}

fn main() {}
3 changes: 2 additions & 1 deletion tests/run-pass/vecs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![crate_type = "lib"]
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]

Expand Down Expand Up @@ -36,3 +35,5 @@ fn vec_reallocate() -> Vec<u8> {
v.push(5);
v
}

fn main() {}