diff --git a/Cargo.lock b/Cargo.lock index 05d1c2d1eb..fb9faa51d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -1080,9 +1080,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ui_test" -version = "0.26.5" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ee4c40e5a5f9fa6864ff976473e5d6a6e9884b6ce68b40690d9f87e1994c83" +checksum = "180a1250feba0214b892e22c3a14e9f6688cc084d7b45ec4672106fcb7914641" dependencies = [ "annotate-snippets", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index cb02914fd9..1266dbb4a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,8 +48,8 @@ windows-sys = { version = "0.52", features = [ ] } [dev-dependencies] +ui_test = "0.27.1" colored = "2" -ui_test = "0.26.5" rustc_version = "0.4" regex = "1.5.5" tempfile = "3" diff --git a/tests/fail/function_calls/exported_symbol_bad_unwind1.stderr b/tests/fail/function_calls/exported_symbol_bad_unwind1.stderr index 5f306cc8ab..a87353a23b 100644 --- a/tests/fail/function_calls/exported_symbol_bad_unwind1.stderr +++ b/tests/fail/function_calls/exported_symbol_bad_unwind1.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind1.rs:LL:CC: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect error: Undefined Behavior: unwinding past a stack frame that does not allow unwinding --> tests/fail/function_calls/exported_symbol_bad_unwind1.rs:LL:CC | diff --git a/tests/fail/function_calls/exported_symbol_bad_unwind2.both.stderr b/tests/fail/function_calls/exported_symbol_bad_unwind2.both.stderr index aef45042e8..364840e925 100644 --- a/tests/fail/function_calls/exported_symbol_bad_unwind2.both.stderr +++ b/tests/fail/function_calls/exported_symbol_bad_unwind2.both.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: panic in a function that cannot unwind stack backtrace: diff --git a/tests/fail/function_calls/exported_symbol_bad_unwind2.definition.stderr b/tests/fail/function_calls/exported_symbol_bad_unwind2.definition.stderr index aef45042e8..364840e925 100644 --- a/tests/fail/function_calls/exported_symbol_bad_unwind2.definition.stderr +++ b/tests/fail/function_calls/exported_symbol_bad_unwind2.definition.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: panic in a function that cannot unwind stack backtrace: diff --git a/tests/fail/function_calls/exported_symbol_bad_unwind2.extern_block.stderr b/tests/fail/function_calls/exported_symbol_bad_unwind2.extern_block.stderr index a81e8226e5..a3c60d3899 100644 --- a/tests/fail/function_calls/exported_symbol_bad_unwind2.extern_block.stderr +++ b/tests/fail/function_calls/exported_symbol_bad_unwind2.extern_block.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect error: Undefined Behavior: unwinding past a stack frame that does not allow unwinding --> tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC | diff --git a/tests/fail/function_calls/return_pointer_on_unwind.stderr b/tests/fail/function_calls/return_pointer_on_unwind.stderr index db876cb5ce..f0baf4fdcb 100644 --- a/tests/fail/function_calls/return_pointer_on_unwind.stderr +++ b/tests/fail/function_calls/return_pointer_on_unwind.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/function_calls/return_pointer_on_unwind.rs:LL:CC: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory --> tests/fail/function_calls/return_pointer_on_unwind.rs:LL:CC | diff --git a/tests/fail/intrinsics/uninit_uninhabited_type.stderr b/tests/fail/intrinsics/uninit_uninhabited_type.stderr index ffc3a3eae9..a86b0ff641 100644 --- a/tests/fail/intrinsics/uninit_uninhabited_type.stderr +++ b/tests/fail/intrinsics/uninit_uninhabited_type.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: aborted execution: attempted to instantiate uninhabited type `!` note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread caused non-unwinding panic. aborting. error: abnormal termination: the program aborted execution --> RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC diff --git a/tests/fail/intrinsics/zero_fn_ptr.stderr b/tests/fail/intrinsics/zero_fn_ptr.stderr index 49cfc473bd..45ec676ab5 100644 --- a/tests/fail/intrinsics/zero_fn_ptr.stderr +++ b/tests/fail/intrinsics/zero_fn_ptr.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: aborted execution: attempted to zero-initialize type `fn()`, which is invalid note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread caused non-unwinding panic. aborting. error: abnormal termination: the program aborted execution --> RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC diff --git a/tests/fail/panic/abort_unwind.stderr b/tests/fail/panic/abort_unwind.stderr index e9c5413693..0c1eaa632e 100644 --- a/tests/fail/panic/abort_unwind.stderr +++ b/tests/fail/panic/abort_unwind.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/panic/abort_unwind.rs:LL:CC: PANIC!!! note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: panic in a function that cannot unwind stack backtrace: diff --git a/tests/fail/panic/bad_unwind.stderr b/tests/fail/panic/bad_unwind.stderr index c152d1a960..b9b6546656 100644 --- a/tests/fail/panic/bad_unwind.stderr +++ b/tests/fail/panic/bad_unwind.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/panic/bad_unwind.rs:LL:CC: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect error: Undefined Behavior: unwinding past a stack frame that does not allow unwinding --> tests/fail/panic/bad_unwind.rs:LL:CC | diff --git a/tests/fail/panic/double_panic.stderr b/tests/fail/panic/double_panic.stderr index 3e00821796..93533236b4 100644 --- a/tests/fail/panic/double_panic.stderr +++ b/tests/fail/panic/double_panic.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/panic/double_panic.rs:LL:CC: first note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread 'main' panicked at tests/fail/panic/double_panic.rs:LL:CC: second stack backtrace: diff --git a/tests/fail/panic/panic_abort1.stderr b/tests/fail/panic/panic_abort1.stderr index c5f04d581c..3c870c06cc 100644 --- a/tests/fail/panic/panic_abort1.stderr +++ b/tests/fail/panic/panic_abort1.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/panic/panic_abort1.rs:LL:CC: panicking from libstd note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect error: abnormal termination: the program aborted execution --> RUSTLIB/panic_abort/src/lib.rs:LL:CC | diff --git a/tests/fail/panic/panic_abort2.stderr b/tests/fail/panic/panic_abort2.stderr index 535cddfd4d..16d45189f0 100644 --- a/tests/fail/panic/panic_abort2.stderr +++ b/tests/fail/panic/panic_abort2.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/panic/panic_abort2.rs:LL:CC: 42-panicking from libstd note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect error: abnormal termination: the program aborted execution --> RUSTLIB/panic_abort/src/lib.rs:LL:CC | diff --git a/tests/fail/panic/panic_abort3.stderr b/tests/fail/panic/panic_abort3.stderr index e74cf342e3..7e07ead183 100644 --- a/tests/fail/panic/panic_abort3.stderr +++ b/tests/fail/panic/panic_abort3.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/panic/panic_abort3.rs:LL:CC: panicking from libcore note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect error: abnormal termination: the program aborted execution --> RUSTLIB/panic_abort/src/lib.rs:LL:CC | diff --git a/tests/fail/panic/panic_abort4.stderr b/tests/fail/panic/panic_abort4.stderr index 3983d169bd..226560eb0b 100644 --- a/tests/fail/panic/panic_abort4.stderr +++ b/tests/fail/panic/panic_abort4.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/panic/panic_abort4.rs:LL:CC: 42-panicking from libcore note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect error: abnormal termination: the program aborted execution --> RUSTLIB/panic_abort/src/lib.rs:LL:CC | diff --git a/tests/fail/terminate-terminator.stderr b/tests/fail/terminate-terminator.stderr index e1c0fabd03..00c032d977 100644 --- a/tests/fail/terminate-terminator.stderr +++ b/tests/fail/terminate-terminator.stderr @@ -3,7 +3,6 @@ warning: You have explicitly enabled MIR optimizations, overriding Miri's defaul thread 'main' panicked at tests/fail/terminate-terminator.rs:LL:CC: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: panic in a function that cannot unwind stack backtrace: diff --git a/tests/fail/unwind-action-terminate.stderr b/tests/fail/unwind-action-terminate.stderr index 8183712205..e7a123b03e 100644 --- a/tests/fail/unwind-action-terminate.stderr +++ b/tests/fail/unwind-action-terminate.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/fail/unwind-action-terminate.rs:LL:CC: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: panic in a function that cannot unwind stack backtrace: diff --git a/tests/panic/alloc_error_handler_hook.stderr b/tests/panic/alloc_error_handler_hook.stderr index 363298e49d..c1ef50f088 100644 --- a/tests/panic/alloc_error_handler_hook.stderr +++ b/tests/panic/alloc_error_handler_hook.stderr @@ -1,5 +1,4 @@ thread 'main' panicked at tests/panic/alloc_error_handler_hook.rs:LL:CC: alloc error hook called note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect yes we are unwinding! diff --git a/tests/panic/alloc_error_handler_panic.stderr b/tests/panic/alloc_error_handler_panic.stderr index 2cdff03f10..202325468b 100644 --- a/tests/panic/alloc_error_handler_panic.stderr +++ b/tests/panic/alloc_error_handler_panic.stderr @@ -1,5 +1,4 @@ thread 'main' panicked at RUSTLIB/std/src/alloc.rs:LL:CC: memory allocation of 4 bytes failed note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect yes we are unwinding! diff --git a/tests/panic/div-by-zero-2.stderr b/tests/panic/div-by-zero-2.stderr index e47a754d38..0d67e94823 100644 --- a/tests/panic/div-by-zero-2.stderr +++ b/tests/panic/div-by-zero-2.stderr @@ -1,4 +1,3 @@ thread 'main' panicked at tests/panic/div-by-zero-2.rs:LL:CC: attempt to divide by zero note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect diff --git a/tests/panic/function_calls/exported_symbol_good_unwind.stderr b/tests/panic/function_calls/exported_symbol_good_unwind.stderr index ec75b6201c..ac8d09f8e6 100644 --- a/tests/panic/function_calls/exported_symbol_good_unwind.stderr +++ b/tests/panic/function_calls/exported_symbol_good_unwind.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/panic/function_calls/exported_symbol_good_unwind.rs:LL:CC: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread 'main' panicked at tests/panic/function_calls/exported_symbol_good_unwind.rs:LL:CC: explicit panic thread 'main' panicked at tests/panic/function_calls/exported_symbol_good_unwind.rs:LL:CC: diff --git a/tests/panic/oob_subslice.stderr b/tests/panic/oob_subslice.stderr index d608cec20a..7e265501c8 100644 --- a/tests/panic/oob_subslice.stderr +++ b/tests/panic/oob_subslice.stderr @@ -1,4 +1,3 @@ thread 'main' panicked at tests/panic/oob_subslice.rs:LL:CC: range end index 5 out of range for slice of length 4 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect diff --git a/tests/panic/overflowing-lsh-neg.stderr b/tests/panic/overflowing-lsh-neg.stderr index 29150052b3..b5601ec324 100644 --- a/tests/panic/overflowing-lsh-neg.stderr +++ b/tests/panic/overflowing-lsh-neg.stderr @@ -1,4 +1,3 @@ thread 'main' panicked at tests/panic/overflowing-lsh-neg.rs:LL:CC: attempt to shift left with overflow note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect diff --git a/tests/panic/overflowing-rsh-1.stderr b/tests/panic/overflowing-rsh-1.stderr index 9a71a797da..53feca04ea 100644 --- a/tests/panic/overflowing-rsh-1.stderr +++ b/tests/panic/overflowing-rsh-1.stderr @@ -1,4 +1,3 @@ thread 'main' panicked at tests/panic/overflowing-rsh-1.rs:LL:CC: attempt to shift right with overflow note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect diff --git a/tests/panic/overflowing-rsh-2.stderr b/tests/panic/overflowing-rsh-2.stderr index b671c53c61..44436696fe 100644 --- a/tests/panic/overflowing-rsh-2.stderr +++ b/tests/panic/overflowing-rsh-2.stderr @@ -1,4 +1,3 @@ thread 'main' panicked at tests/panic/overflowing-rsh-2.rs:LL:CC: attempt to shift right with overflow note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect diff --git a/tests/panic/panic2.stderr b/tests/panic/panic2.stderr index 5640bd0b8d..b99422b0b3 100644 --- a/tests/panic/panic2.stderr +++ b/tests/panic/panic2.stderr @@ -1,4 +1,3 @@ thread 'main' panicked at tests/panic/panic2.rs:LL:CC: 42-panicking from libstd note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect diff --git a/tests/panic/panic3.stderr b/tests/panic/panic3.stderr index 0114320503..774b8da88e 100644 --- a/tests/panic/panic3.stderr +++ b/tests/panic/panic3.stderr @@ -1,4 +1,3 @@ thread 'main' panicked at tests/panic/panic3.rs:LL:CC: panicking from libcore note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect diff --git a/tests/panic/panic4.stderr b/tests/panic/panic4.stderr index f13b355ea4..e149f5eff6 100644 --- a/tests/panic/panic4.stderr +++ b/tests/panic/panic4.stderr @@ -1,4 +1,3 @@ thread 'main' panicked at tests/panic/panic4.rs:LL:CC: 42-panicking from libcore note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect diff --git a/tests/panic/transmute_fat2.stderr b/tests/panic/transmute_fat2.stderr index a9bc0eb9d0..66172aca92 100644 --- a/tests/panic/transmute_fat2.stderr +++ b/tests/panic/transmute_fat2.stderr @@ -1,4 +1,3 @@ thread 'main' panicked at tests/panic/transmute_fat2.rs:LL:CC: index out of bounds: the len is 0 but the index is 0 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect diff --git a/tests/panic/unsupported_foreign_function.stderr b/tests/panic/unsupported_foreign_function.stderr index 278af9612d..402f17bdea 100644 --- a/tests/panic/unsupported_foreign_function.stderr +++ b/tests/panic/unsupported_foreign_function.stderr @@ -1,4 +1,3 @@ thread 'main' panicked at tests/panic/unsupported_foreign_function.rs:LL:CC: unsupported Miri functionality: can't call foreign function `foo` on $OS note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect diff --git a/tests/panic/unsupported_syscall.stderr b/tests/panic/unsupported_syscall.stderr index e9b2b5b665..dc14d2cab8 100644 --- a/tests/panic/unsupported_syscall.stderr +++ b/tests/panic/unsupported_syscall.stderr @@ -1,4 +1,3 @@ thread 'main' panicked at tests/panic/unsupported_syscall.rs:LL:CC: unsupported Miri functionality: can't execute syscall with ID 0 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect diff --git a/tests/pass-dep/libc/libc-mem.rs b/tests/pass-dep/libc/libc-mem.rs index c399616b9a..3d555e737a 100644 --- a/tests/pass-dep/libc/libc-mem.rs +++ b/tests/pass-dep/libc/libc-mem.rs @@ -79,13 +79,17 @@ fn test_strcpy() { } fn test_malloc() { - // Test that small allocations sometimes *are* not very aligned. - let saw_unaligned = (0..64).any(|_| unsafe { - let p = libc::malloc(3); - libc::free(p); - (p as usize) % 4 != 0 // find any that this is *not* 4-aligned - }); - assert!(saw_unaligned); + // Real systems may always align to at least a specific power of 2 (like 4 or 8). + #[cfg(miri)] + { + // Test that small allocations sometimes *are* not very aligned. + let saw_unaligned = (0..64).any(|_| unsafe { + let p = libc::malloc(3); + libc::free(p); + (p as usize) % 4 != 0 // find any that this is *not* 4-aligned + }); + assert!(saw_unaligned); + } unsafe { let p1 = libc::malloc(20); diff --git a/tests/pass-dep/num_cpus.rs b/tests/pass-dep/num_cpus.rs index 84339feb11..397f54953f 100644 --- a/tests/pass-dep/num_cpus.rs +++ b/tests/pass-dep/num_cpus.rs @@ -1,4 +1,5 @@ //@compile-flags: -Zmiri-disable-isolation +//@only-miri: fake cpu number fn main() { assert_eq!(num_cpus::get(), 1); diff --git a/tests/pass-dep/page_size_override.rs b/tests/pass-dep/page_size_override.rs index 68858f3875..74ea101b23 100644 --- a/tests/pass-dep/page_size_override.rs +++ b/tests/pass-dep/page_size_override.rs @@ -1,4 +1,5 @@ //@compile-flags: -Zmiri-force-page-size=8 +//@only-miri: fake page size fn main() { let page_size = page_size::get(); diff --git a/tests/pass/panic/catch_panic.stderr b/tests/pass/panic/catch_panic.stderr index cb74312a83..5241b60887 100644 --- a/tests/pass/panic/catch_panic.stderr +++ b/tests/pass/panic/catch_panic.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC: Hello from std::panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect Caught panic message (&str): Hello from std::panic thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC: Hello from std::panic: 1 diff --git a/tests/pass/panic/concurrent-panic.stderr b/tests/pass/panic/concurrent-panic.stderr index 9c87489e8d..0e7940053b 100644 --- a/tests/pass/panic/concurrent-panic.stderr +++ b/tests/pass/panic/concurrent-panic.stderr @@ -3,7 +3,6 @@ Thread 1 reported it has started thread '' panicked at tests/pass/panic/concurrent-panic.rs:LL:CC: panic in thread 2 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect Thread 2 blocking on thread 1 Thread 2 reported it has started Unlocking mutex diff --git a/tests/pass/panic/nested_panic_caught.stderr b/tests/pass/panic/nested_panic_caught.stderr index e066f7dfce..b05d8d070d 100644 --- a/tests/pass/panic/nested_panic_caught.stderr +++ b/tests/pass/panic/nested_panic_caught.stderr @@ -1,7 +1,6 @@ thread 'main' panicked at tests/pass/panic/nested_panic_caught.rs:LL:CC: once note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread 'main' panicked at tests/pass/panic/nested_panic_caught.rs:LL:CC: twice stack backtrace: diff --git a/tests/pass/panic/thread_panic.stderr b/tests/pass/panic/thread_panic.stderr index 9464e76b6c..4baf7e45fd 100644 --- a/tests/pass/panic/thread_panic.stderr +++ b/tests/pass/panic/thread_panic.stderr @@ -1,6 +1,5 @@ thread '' panicked at tests/pass/panic/thread_panic.rs:LL:CC: Hello! note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect thread 'childthread' panicked at tests/pass/panic/thread_panic.rs:LL:CC: Hello, world! diff --git a/tests/ui.rs b/tests/ui.rs index 9553a37c9a..2b6044aa49 100644 --- a/tests/ui.rs +++ b/tests/ui.rs @@ -9,15 +9,22 @@ use colored::*; use regex::bytes::Regex; use ui_test::build_manager::BuildManager; use ui_test::color_eyre::eyre::{Context, Result}; +use ui_test::custom_flags::Flag; use ui_test::custom_flags::edition::Edition; +use ui_test::custom_flags::run::Run; use ui_test::dependencies::DependencyBuilder; -use ui_test::per_test_config::TestConfig; +use ui_test::per_test_config::{Comments, Condition, TestConfig}; use ui_test::spanned::Spanned; -use ui_test::{CommandBuilder, Config, Format, Match, OutputConflictHandling, status_emitter}; +use ui_test::{ + CommandBuilder, Config, Errored, Format, Match, ignore_output_conflict, status_emitter, +}; #[derive(Copy, Clone, Debug)] enum Mode { - Pass, + Pass { + /// Whether to compile and run with rustc instead of miri + rustc: bool, + }, /// Requires annotations Fail, /// Not used for tests, but for `miri run --dep` @@ -81,9 +88,18 @@ fn build_native_lib() -> PathBuf { native_lib_path } +struct WithDependencies { + bless: bool, +} + /// Does *not* set any args or env vars, since it is shared between the test runner and /// run_dep_mode. -fn miri_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> Config { +fn miri_config( + target: &str, + path: &str, + mode: Mode, + with_dependencies: Option, +) -> Config { // Miri is rustc-like, so we create a default builder for rustc and modify it let mut program = CommandBuilder::rustc(); program.program = miri_path(); @@ -98,8 +114,89 @@ fn miri_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> ..Config::rustc(path) }; + if let Mode::Pass { rustc: true } = mode { + config.comment_defaults.base().add_custom("run", Run { + exit_code: 0, + output_conflict_handling: Some(|path, actual, errors, config| { + let path = path.with_file_name( + path.file_name().unwrap().to_str().unwrap().replace(".run.", "."), + ); + // Blessing is only allowed in miri mode, rustc mode must match + ui_test::error_on_output_conflict(&path, actual, errors, config); + }), + }); + config.program.envs.push(("MIRI_BE_RUSTC".into(), Some("host".into()))); + + #[derive(Debug)] + struct Strip; + + impl Flag for Strip { + fn clone_inner(&self) -> Box { + Box::new(Strip) + } + + fn must_be_unique(&self) -> bool { + true + } + + fn apply( + &self, + cmd: &mut Command, + _config: &TestConfig, + _build_manager: &BuildManager, + ) -> Result<(), Errored> { + let mut c = Command::new(cmd.get_program()); + for (k, v) in cmd.get_envs() { + match v { + Some(v) => c.env(k, v), + None => c.env_remove(k), + }; + } + if let Some(dir) = cmd.get_current_dir() { + c.current_dir(dir); + } + c.args( + cmd.get_args().filter(|arg| !arg.as_encoded_bytes().starts_with(b"-Zmiri-")), + ); + *cmd = c; + Ok(()) + } + + fn test_condition( + &self, + _config: &Config, + comments: &Comments, + revision: &str, + ) -> bool { + for rev in comments.for_revision(revision) { + for arg in &rev.compile_flags { + // A real execution will preempt, and thus behave differently + if arg.starts_with("-Zmiri-preemption-rate") { + return true; + } + // FIXME: can probably support these somehow + if arg.starts_with("-Zmiri-env") { + return true; + } + } + } + false + } + } + + config.comment_defaults.base().add_custom("strip_dash_z_miri", Strip); + + // Only run on no target if `only-miri` is passed. + config + .custom_comments + .insert("only-miri", |parser, _, _| parser.only.push(Condition::Target(vec![]))); + } else { + // Nop, we are in miri mode + config.custom_comments.insert("only-miri", |_, _, _| {}); + } + config.comment_defaults.base().exit_status = match mode { - Mode::Pass => Some(0), + Mode::Pass { .. } => Some(0), Mode::Fail => Some(1), Mode::RunDep => None, Mode::Panic => Some(101), @@ -118,21 +215,27 @@ fn miri_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> // keep in sync with `./miri run` config.comment_defaults.base().add_custom("edition", Edition("2021".into())); - if with_dependencies { + if let Some(WithDependencies { bless }) = with_dependencies { + let program = match mode { + Mode::Pass { rustc: true } => CommandBuilder::cargo(), + _ => + CommandBuilder { + // Set the `cargo-miri` binary, which we expect to be in the same folder as the `miri` binary. + // (It's a separate crate, so we don't get an env var from cargo.) + program: miri_path() + .with_file_name(format!("cargo-miri{}", env::consts::EXE_SUFFIX)), + // There is no `cargo miri build` so we just use `cargo miri run`. + args: ["miri", "run"].into_iter().map(Into::into).collect(), + // Reset `RUSTFLAGS` to work around . + envs: vec![("RUSTFLAGS".into(), None)], + ..CommandBuilder::cargo() + }, + }; config.comment_defaults.base().set_custom("dependencies", DependencyBuilder { - program: CommandBuilder { - // Set the `cargo-miri` binary, which we expect to be in the same folder as the `miri` binary. - // (It's a separate crate, so we don't get an env var from cargo.) - program: miri_path() - .with_file_name(format!("cargo-miri{}", env::consts::EXE_SUFFIX)), - // There is no `cargo miri build` so we just use `cargo miri run`. - args: ["miri", "run"].into_iter().map(Into::into).collect(), - // Reset `RUSTFLAGS` to work around . - envs: vec![("RUSTFLAGS".into(), None)], - ..CommandBuilder::cargo() - }, + program, crate_manifest_path: Path::new("test_dependencies").join("Cargo.toml"), build_std: None, + bless_lockfile: bless, }); } config @@ -145,23 +248,56 @@ fn run_tests( with_dependencies: bool, tmpdir: &Path, ) -> Result<()> { + // Handle command-line arguments. + let mut args = ui_test::Args::test()?; + args.bless |= env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0"); + + let with_dependencies = with_dependencies.then_some(WithDependencies { bless: args.bless }); + let mut config = miri_config(target, path, mode, with_dependencies); + config.with_args(&args); + if let Mode::Pass { rustc: true } = mode { + config.fill_host_and_target()?; + // Rustc mode only works on the host + if !config.host_matches_target() { + return Ok(()); + } + config.output_conflict_handling = ui_test::ignore_output_conflict; + + config.bless_command = + Some("add `//@only-miri:` to the test if it cannot be run on the host directly".into()); + } else { + config.bless_command = Some("./miri test --bless".into()); + } + + if env::var_os("MIRI_SKIP_UI_CHECKS").is_some() { + assert!(!args.bless, "cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time"); + config.output_conflict_handling = ignore_output_conflict; + } // Add a test env var to do environment communication tests. config.program.envs.push(("MIRI_ENV_VAR_TEST".into(), Some("0".into()))); // Let the tests know where to store temp files (they might run for a different target, which can make this hard to find). config.program.envs.push(("MIRI_TEMP".into(), Some(tmpdir.to_owned().into()))); - // If a test ICEs, we want to see a backtrace. - config.program.envs.push(("RUST_BACKTRACE".into(), Some("1".into()))); // Add some flags we always want. - config.program.args.push( - format!( - "--sysroot={}", - env::var("MIRI_SYSROOT").expect("MIRI_SYSROOT must be set to run the ui test suite") - ) - .into(), - ); + match mode { + // rustc mode doesn't want miri specific flags + Mode::Pass { rustc: true } => {} + _ => { + // If a test ICEs, we want to see a backtrace. + config.program.envs.push(("RUST_BACKTRACE".into(), Some("1".into()))); + config.program.args.push( + format!( + "--sysroot={}", + env::var("MIRI_SYSROOT") + .expect("MIRI_SYSROOT must be set to run the ui test suite") + ) + .into(), + ); + } + } + config.program.args.push("-Dwarnings".into()); config.program.args.push("-Dunused".into()); config.program.args.push("-Ainternal_features".into()); @@ -181,16 +317,6 @@ fn run_tests( config.program.args.push(flag); } - // Handle command-line arguments. - let mut args = ui_test::Args::test()?; - args.bless |= env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0"); - config.with_args(&args); - config.bless_command = Some("./miri test --bless".into()); - - if env::var_os("MIRI_SKIP_UI_CHECKS").is_some() { - assert!(!args.bless, "cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time"); - config.output_conflict_handling = OutputConflictHandling::Ignore; - } eprintln!(" Compiler: {}", config.program.display()); ui_test::run_tests_generic( // Only run one test suite. In the future we can add all test suites to one `Vec` and run @@ -261,11 +387,13 @@ regexes! { // Windows file paths r"\\" => "/", // erase Rust stdlib path - "[^ \n`]*/(rust[^/]*|checkout)/library/" => "RUSTLIB/", + "[^ \n`]*/(rust[^/]*|checkout|rustc/[0-9a-f]+)/library/" => "RUSTLIB/", // erase platform file paths "sys/pal/[a-z]+/" => "sys/pal/PLATFORM/", // erase paths into the crate registry r"[^ ]*/\.?cargo/registry/.*/(.*\.rs)" => "CARGO_REGISTRY/.../$1", + // erase extra panic message that actual runtime code doesn't have + "note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect\n" => "", } enum Dependencies { @@ -312,13 +440,21 @@ fn main() -> Result<()> { } } - ui(Mode::Pass, "tests/pass", &target, WithoutDependencies, tmpdir.path())?; - ui(Mode::Pass, "tests/pass-dep", &target, WithDependencies, tmpdir.path())?; + ui(Mode::Pass { rustc: false }, "tests/pass", &target, WithoutDependencies, tmpdir.path())?; + for rustc in [false, true] { + ui(Mode::Pass { rustc }, "tests/pass-dep", &target, WithDependencies, tmpdir.path())?; + } ui(Mode::Panic, "tests/panic", &target, WithDependencies, tmpdir.path())?; ui(Mode::Fail, "tests/fail", &target, WithoutDependencies, tmpdir.path())?; ui(Mode::Fail, "tests/fail-dep", &target, WithDependencies, tmpdir.path())?; if cfg!(unix) { - ui(Mode::Pass, "tests/native-lib/pass", &target, WithoutDependencies, tmpdir.path())?; + ui( + Mode::Pass { rustc: false }, + "tests/native-lib/pass", + &target, + WithoutDependencies, + tmpdir.path(), + )?; ui(Mode::Fail, "tests/native-lib/fail", &target, WithoutDependencies, tmpdir.path())?; } @@ -326,7 +462,8 @@ fn main() -> Result<()> { } fn run_dep_mode(target: String, args: impl Iterator) -> Result<()> { - let mut config = miri_config(&target, "", Mode::RunDep, /* with dependencies */ true); + let mut config = + miri_config(&target, "", Mode::RunDep, Some(WithDependencies { bless: false })); config.comment_defaults.base().custom.remove("edition"); // `./miri` adds an `--edition` in `args`, so don't set it twice config.fill_host_and_target()?; config.program.args = args.collect();