From 61c0df793060e60e5bd106dec82fd0951decd63b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 18 Dec 2018 21:49:21 +0100 Subject: [PATCH 1/8] remove outdated README comment --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index b6e1c20076..02e13ad56a 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,6 @@ Now you can run your project in miri: dependencies to be compiled the right way, that would not happen if they have previously already been compiled. 2. To run all tests in your project through Miri, use `cargo +nightly miri test`. - **NOTE**: This is currently broken, see the discussion in - [#479](https://github.com/solson/miri/issues/479). 3. If you have a binary project, you can run it through Miri using `cargo +nightly miri run`. From bf846a637c6755bd4fe215b6103d7aba28a282a5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 18 Dec 2018 21:49:38 +0100 Subject: [PATCH 2/8] test-cargo-miri: be more clear that and why the test failed --- test-cargo-miri/run-test.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test-cargo-miri/run-test.py b/test-cargo-miri/run-test.py index 19e0a14740..7f7f2660c0 100755 --- a/test-cargo-miri/run-test.py +++ b/test-cargo-miri/run-test.py @@ -7,6 +7,10 @@ import sys, subprocess +def fail(msg): + print("TEST FAIL: {}".format(msg)) + sys.exit(1) + def test(name, cmd, stdout_ref, stderr_ref): print("==> Testing `{}` <==".format(name)) ## Call `cargo miri`, capture all output @@ -25,13 +29,11 @@ def test(name, cmd, stdout_ref, stderr_ref): print(stderr, end="") # Test for failures if p.returncode != 0: - sys.exit(1) + fail("Non-zero exit status") if stdout != open(stdout_ref).read(): - print("stdout does not match reference") - sys.exit(1) + fail("stdout does not match reference") if stderr != open(stderr_ref).read(): - print("stderr does not match reference") - sys.exit(1) + fail("stderr does not match reference") def test_cargo_miri_run(): test("cargo miri run", ["cargo", "miri", "run", "-q"], "stdout.ref", "stderr.ref") From 133e012cec90e220f5c7f50d454e8d93b0f79332 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Dec 2018 11:06:35 +0100 Subject: [PATCH 3/8] sync env vars between appveyor and travis --- .travis.yml | 1 + appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dfc4238a6c..51b14a1b34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,3 +38,4 @@ branches: env: global: - RUST_TEST_NOCAPTURE=1 + - RUST_BACKTRACE=1 diff --git a/appveyor.yml b/appveyor.yml index 4f4aebd807..09040ed42a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,7 +25,7 @@ install: build: false test_script: - - set RUSTFLAGS=-g + - set RUST_TEST_NOCAPTURE=1 - set RUST_BACKTRACE=1 # Build miri - cargo build --release --all-features --all-targets From ecf659905145ba9430b54f72c2328edd74462117 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Dec 2018 08:41:31 +0100 Subject: [PATCH 4/8] xargo version check: also check application name, just to be sure --- src/bin/cargo-miri.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index 0a8ddd95a7..4ac1d1a3b4 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -123,8 +123,14 @@ fn xargo_version() -> Option<(u32, u32, u32)> { let line = out.stderr.lines().nth(0) .expect("malformed `xargo --version` output: not at least one line") .expect("malformed `xargo --version` output: error reading first line"); - let version = line.split(' ').nth(1) - .expect("malformed `xargo --version` output: not at least two words"); + let (name, version) = { + let mut split = line.split(' '); + (split.next().expect("malformed `xargo --version` output: empty"), + split.next().expect("malformed `xargo --version` output: not at least two words")) + }; + if name != "xargo" { + panic!("malformed `xargo --version` output: application name is not `xargo`"); + } let mut version_pieces = version.split('.'); let major = version_pieces.next() .expect("malformed `xargo --version` output: not a major version piece") From 11433bf38e586ae517d5caa3ddb82c283cb8a1b3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Dec 2018 09:03:10 +0100 Subject: [PATCH 5/8] actually show warnings about suppressed output --- src/fn_call.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fn_call.rs b/src/fn_call.rs index ab82223f23..ab38270724 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -398,7 +398,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a, Err(_) => -1, } } else { - warn!("Ignored output to FD {}", fd); + eprintln!("Miri: Ignored output to FD {}", fd); n as i64 // pretend it all went well }; // now result is the value we return back to the program this.write_scalar( From e10a26fd3cdcb9a8442fb21b1e13e8425d3e29d7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Dec 2018 11:11:01 +0100 Subject: [PATCH 6/8] add a test for excluding tests on miri --- test-cargo-miri/tests/foo.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test-cargo-miri/tests/foo.rs b/test-cargo-miri/tests/foo.rs index 9827ae82d6..bd7b2c569a 100644 --- a/test-cargo-miri/tests/foo.rs +++ b/test-cargo-miri/tests/foo.rs @@ -9,3 +9,11 @@ fn bar() { fn baz() { assert_eq!(5, 5); } + +// A test that won't work on miri +#[cfg(not(feature = "cargo-miri"))] +#[test] +fn does_not_work_on_miri() { + let x = 0u8; + assert!(&x as *const _ as usize % 4 < 4); +} From d67da9f04bf2acf7ecec1438c28015cd75d01c83 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Dec 2018 11:12:56 +0100 Subject: [PATCH 7/8] no need to set the cargo-miri feature twice --- src/bin/cargo-miri.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index 4ac1d1a3b4..21cc7ee0e3 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -420,8 +420,6 @@ where args.push("--".to_owned()); } args.push("--emit=dep-info,metadata".to_owned()); - args.push("--cfg".to_owned()); - args.push(r#"feature="cargo-miri""#.to_owned()); let path = std::env::current_exe().expect("current executable path invalid"); let exit_status = Command::new("cargo") From adba97e4b24aa5ec920330a549690f664a3e1ab6 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Dec 2018 11:16:19 +0100 Subject: [PATCH 8/8] document the cargo-miri feature --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 02e13ad56a..5a615e656d 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ example above), overriding it in your project directory as well, or use `rustup default nightly` (or `rustup default nightly-YYYY-MM-DD`) to globally make `nightly` the default toolchain. -Now you can run your project in miri: +Now you can run your project in Miri: 1. Run `cargo clean` to eliminate any cached dependencies. Miri needs your dependencies to be compiled the right way, that would not happen if they have @@ -48,6 +48,19 @@ Now you can run your project in miri: 3. If you have a binary project, you can run it through Miri using `cargo +nightly miri run`. +When running code via `cargo miri`, the `cargo-miri` feature is set. You can +use this to exclude test cases that will fail under Miri because they do things +Miri does not support: + +```rust +#[cfg(not(feature = "cargo-miri"))] +#[test] +fn does_not_work_on_miri() { + let x = 0u8; + assert!(&x as *const _ as usize % 4 < 4); +} +``` + ### Common Problems When using the above instructions, you may encounter a number of confusing compiler