]> git.lizzy.rs Git - rust.git/commitdiff
use compiletest_rs
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 22 Apr 2016 08:34:14 +0000 (10:34 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 22 Apr 2016 08:34:14 +0000 (10:34 +0200)
23 files changed:
Cargo.lock
Cargo.toml
src/bin/miri.rs
tests/compile-fail/errors.rs [new file with mode: 0644]
tests/compile-test.rs [deleted file]
tests/compiletest.rs [new file with mode: 0644]
tests/run-pass/arrays.rs
tests/run-pass/bools.rs
tests/run-pass/c_enums.rs
tests/run-pass/calls.rs
tests/run-pass/closures.rs
tests/run-pass/errors.rs [deleted file]
tests/run-pass/heap.rs
tests/run-pass/ints.rs
tests/run-pass/loops.rs
tests/run-pass/pointers.rs
tests/run-pass/products.rs
tests/run-pass/specialization.rs
tests/run-pass/std.rs
tests/run-pass/strings.rs
tests/run-pass/sums.rs
tests/run-pass/trivial.rs
tests/run-pass/vecs.rs

index 8fc715429970f1bc843dcce39866cdd04dd4245b..4827e7fd8a6a762cf3ec69018d58bc4461f79142 100644 (file)
@@ -3,6 +3,7 @@ name = "miri"
 version = "0.1.0"
 dependencies = [
  "byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "compiletest_rs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -10,3 +11,16 @@ name = "byteorder"
 version = "0.4.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
+[[package]]
+name = "compiletest_rs"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "log"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
index a369f6070c86b4afed6ac8f322479e36bfe59c6f..9fa9f145c72b95411f1f4d340532b80ec5ed6a51 100644 (file)
@@ -12,3 +12,6 @@ name = "miri"
 
 [dependencies]
 byteorder = "0.4.2"
+
+[dev-dependencies]
+compiletest_rs = "0.1.1"
index 8efa1a6864def8eb8872704c5be83b1056011e0b..ebfb379d313488c92657367cef88c172676981b3 100644 (file)
@@ -6,14 +6,13 @@
 
 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;
 
         control.after_analysis.callback = Box::new(|state| {
             state.session.abort_if_errors();
diff --git a/tests/compile-fail/errors.rs b/tests/compile-fail/errors.rs
new file mode 100644 (file)
index 0000000..d971724
--- /dev/null
@@ -0,0 +1,49 @@
+#![feature(custom_attribute)]
+#![allow(dead_code, unused_attributes)]
+
+#[miri_run]
+fn overwriting_part_of_relocation_makes_the_rest_undefined() -> i32 {
+    let mut p = &42;
+    unsafe {
+        let ptr: *mut _ = &mut p;
+        *(ptr as *mut u32) = 123;
+    }
+    *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 //~ 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 } //~ 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 //~ 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) } //~ ERROR: pointer offset outside bounds of allocation
+}
+
+#[miri_run]
+fn dangling_pointer_deref() -> i32 {
+    let p = {
+        let b = Box::new(42);
+        &*b as *const i32
+    };
+    unsafe { *p } //~ ERROR: dangling pointer was dereferenced
+}
+
+fn main() {}
diff --git a/tests/compile-test.rs b/tests/compile-test.rs
deleted file mode 100644 (file)
index c7cdb97..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-use std::{env, fs};
-use std::process::{Command, Output};
-
-fn run_miri(file: &str, sysroot: &str) -> Output {
-    Command::new("cargo")
-        .args(&["run", "--", "--sysroot", sysroot, file])
-        .output()
-        .unwrap_or_else(|e| panic!("failed to execute process: {}", e))
-}
-
-#[test]
-fn run_pass() {
-    let sysroot = env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
-
-    let test_files = fs::read_dir("./tests/run-pass/")
-                         .expect("Can't read `run-pass` directory")
-                         .filter_map(|entry| entry.ok())
-                         .filter(|entry| {
-                             entry.clone()
-                                  .file_type()
-                                  .map(|x| x.is_file())
-                                  .unwrap_or(false)
-                         })
-                         .filter_map(|entry| entry.path().to_str().map(|x| x.to_string()));
-
-    for file in test_files {
-        println!("{}: compile test running", file);  
-
-        let test_run = run_miri(&file, &sysroot);
-
-        if test_run.status.code().unwrap_or(-1) != 0 {
-            println!("{}: error {:?}", file, test_run);
-        } else {
-            println!("{}: ok", file);
-        }
-    }
-}
diff --git a/tests/compiletest.rs b/tests/compiletest.rs
new file mode 100644 (file)
index 0000000..224d7f0
--- /dev/null
@@ -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");
+}
index 05925fa98cfb49ce81a4e8ff874f1bb74d5f5c3b..26a4196b1b975eac33f969a3027d3268321a31ca 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -33,3 +32,5 @@ fn index() -> i32 {
 fn array_repeat() -> [u8; 8] {
     [42; 8]
 }
+
+fn main() {}
index 699409e17a4d6f0035fddce3c221df0bbbfd4240..948c09c0fdaabc835755f6b38f0f3c447c1b8902 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -27,3 +26,5 @@ fn match_bool() -> i16 {
         _ => 0,
     }
 }
+
+fn main() {}
index 1da35d64b8409d7d8f0f9d6e783ad177be93e8cd..442e58a22a98149869934e5d90badc60ec8600d4 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -20,3 +19,5 @@ fn unsafe_match() -> bool {
         _ => false,
     }
 }
+
+fn main() {}
index 0e9199f969df8d62f94f5c118186fbb4f7beba1e..62ea521d956e5d507cdca54b79cb02cec0d7c650 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -39,3 +38,5 @@ fn cross_crate_fn_call() -> i64 {
 fn test_size_of() -> usize {
     ::std::mem::size_of::<Option<i32>>()
 }
+
+fn main() {}
index 9b6e2966648777424b5a39bb80700e7880d29bea..3612cfcb4c4763bf0df2170b385b370e74736ef1 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -37,3 +36,5 @@ fn inner<T: Copy>(t: T) -> (i32, T, T) {
 //     }
 //     y
 // }
+
+fn main() {}
diff --git a/tests/run-pass/errors.rs b/tests/run-pass/errors.rs
deleted file mode 100644 (file)
index e123538..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-#![crate_type = "lib"]
-#![feature(custom_attribute)]
-#![allow(dead_code, unused_attributes)]
-
-#[miri_run]
-fn overwriting_part_of_relocation_makes_the_rest_undefined() -> i32 {
-    let mut p = &42;
-    unsafe {
-        let ptr: *mut _ = &mut p;
-        *(ptr as *mut u32) = 123;
-    }
-    *p
-}
-
-#[miri_run]
-fn pointers_to_different_allocations_are_unorderable() -> bool {
-    let x: *const u8 = &1;
-    let y: *const u8 = &2;
-    x < y
-}
-
-#[miri_run]
-fn invalid_bool() -> u8 {
-    let b = unsafe { std::mem::transmute::<u8, bool>(2) };
-    if b { 1 } else { 2 }
-}
-
-#[miri_run]
-fn undefined_byte_read() -> u8 {
-    let v: Vec<u8> = Vec::with_capacity(10);
-    let undef = unsafe { *v.get_unchecked(5) };
-    undef + 1
-}
-
-#[miri_run]
-fn out_of_bounds_read() -> u8 {
-    let v: Vec<u8> = vec![1, 2];
-    unsafe { *v.get_unchecked(5) }
-}
-
-#[miri_run]
-fn dangling_pointer_deref() -> i32 {
-    let p = {
-        let b = Box::new(42);
-        &*b as *const i32
-    };
-    unsafe { *p }
-}
index 268b4121dcbdb2bea64f7ab219a17cf7a3f6b745..3cc01e5829bb9835b7376a6b236fe0c0eb5c27e2 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute, box_syntax)]
 #![allow(dead_code, unused_attributes)]
 
@@ -11,3 +10,5 @@ fn make_box() -> Box<(i16, i16)> {
 fn make_box_syntax() -> Box<(i16, i16)> {
     box (1, 2)
 }
+
+fn main() {}
index b790afe3b54f1f8b6e1468275dcd6de81b7837e1..cc113eaed59239564976ad02e417aada391d174c 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -53,3 +52,5 @@ fn match_int_range() -> i64 {
         _ => 5,
     }
 }
+
+fn main() {}
index 008c6e6ad82939581bbf78f9f21df43f1f79a1c3..081e7bb228b4ab1cfd8847abe314d1880c01d9e9 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -34,3 +33,5 @@ fn for_loop() -> usize {
     }
     sum
 }
+
+fn main() {}
index ab1226c759b3ae85120c32ce8ccf8b10da8ff0b0..b66aabb2505c42dcf66e33caac197a7e5bc1c320 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -58,3 +57,5 @@ fn dangling_pointer() -> *const i32 {
     let b = Box::new(42);
     &*b as *const i32
 }
+
+fn main() {}
index 2fad1daae068a26eac32813906a4ad14a924a70f..1d65006ae6f67ae92d77fdc309ca8fadf2b85728 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -30,3 +29,5 @@ fn field_access() -> (i8, i8) {
     p.x += 5;
     (p.x, p.y)
 }
+
+fn main() {}
index a7323431f4cc830d98e78e57e161aa2fcb3c551b..b8b101fe8421786f04253ea6d2ac84888dcebc2c 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute, specialization)]
 #![allow(dead_code, unused_attributes)]
 
@@ -18,3 +17,5 @@ fn is_unit() -> bool { true }
 fn specialization() -> (bool, bool) {
     (i32::is_unit(), <()>::is_unit())
 }
+
+fn main() {}
index 55e801b93d03e7260f9ab6822a3a305fc4fa9b6d..d9c0e3ca1fe4881e030b10f6bb2787bdf8c4f055 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute, box_syntax)]
 #![allow(dead_code, unused_attributes)]
 
@@ -44,3 +43,5 @@ fn rc_reference_cycle() -> Loop {
 fn true_assert() {
     assert_eq!(1, 1);
 }
+
+fn main() {}
index 6d27153aaa8978cae6dd579540522fe3cb7d51ef..3d71fa4e09f87a8e7759b7bf0b8a6b59eaa0fa44 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -21,3 +20,5 @@ fn hello() -> &'static str {
 fn hello_bytes_fat() -> &'static [u8] {
     b"Hello, world!"
 }
+
+fn main() {}
index 209629eabbf8274ce0bbcf16e6a997e3ece97cb7..7f92f0d5ffffebb0b8281312dab1063b6a14a005 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -53,3 +52,5 @@ fn match_opt_some() -> i8 {
 fn two_nones() -> (Option<i16>, Option<i16>) {
     (None, None)
 }
+
+fn main() {}
index 9761e94792950bfa748395fa2f977795a731b469..e9d0f694648b2e5f5b953a60b0c6672cd87c6157 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -10,3 +9,5 @@ fn unit_var() {
     let x = ();
     x
 }
+
+fn main() {}
index 63757947b0a1f6e0c8fdde66d861bbb3c300f841..325762289c5bdebfc736495be1c53b8ff2ff5392 100644 (file)
@@ -1,4 +1,3 @@
-#![crate_type = "lib"]
 #![feature(custom_attribute)]
 #![allow(dead_code, unused_attributes)]
 
@@ -36,3 +35,5 @@ fn vec_reallocate() -> Vec<u8> {
     v.push(5);
     v
 }
+
+fn main() {}