From 7ba1232b5ea8f6ab011efe2ce3fb97d955342fdb Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 7 Dec 2019 12:38:13 +0100 Subject: [PATCH 1/3] libcore: ignore tests in Miri instead of removing them entirely --- src/libcore/tests/num/dec2flt/mod.rs | 4 ++-- src/libcore/tests/num/flt2dec/mod.rs | 2 -- src/libcore/tests/num/flt2dec/strategy/dragon.rs | 2 +- src/libcore/tests/num/flt2dec/strategy/grisu.rs | 2 +- src/libcore/tests/ptr.rs | 6 +++--- src/libcore/tests/slice.rs | 8 ++++---- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/libcore/tests/num/dec2flt/mod.rs b/src/libcore/tests/num/dec2flt/mod.rs index 46eacb4200acc..361758f859e2e 100644 --- a/src/libcore/tests/num/dec2flt/mod.rs +++ b/src/libcore/tests/num/dec2flt/mod.rs @@ -53,7 +53,7 @@ fn large() { } #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn subnormals() { test_literal!(5e-324); test_literal!(91e-324); @@ -65,7 +65,7 @@ fn subnormals() { } #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn infinity() { test_literal!(1e400); test_literal!(1e309); diff --git a/src/libcore/tests/num/flt2dec/mod.rs b/src/libcore/tests/num/flt2dec/mod.rs index f85369ce40b8d..2f94ea2fc4b70 100644 --- a/src/libcore/tests/num/flt2dec/mod.rs +++ b/src/libcore/tests/num/flt2dec/mod.rs @@ -256,7 +256,6 @@ pub fn f32_shortest_sanity_test(mut f: F) where F: FnMut(&Decoded, &mut [u8]) check_shortest!(f(minf32) => b"1", -44); } -#[cfg(not(miri))] // Miri is too slow pub fn f32_exact_sanity_test(mut f: F) where F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16) { let minf32 = ldexp_f32(1.0, -149); @@ -362,7 +361,6 @@ pub fn f64_shortest_sanity_test(mut f: F) where F: FnMut(&Decoded, &mut [u8]) check_shortest!(f(minf64) => b"5", -323); } -#[cfg(not(miri))] // Miri is too slow pub fn f64_exact_sanity_test(mut f: F) where F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16) { let minf64 = ldexp_f64(1.0, -1074); diff --git a/src/libcore/tests/num/flt2dec/strategy/dragon.rs b/src/libcore/tests/num/flt2dec/strategy/dragon.rs index 0c545b4d88714..3d985c6796b16 100644 --- a/src/libcore/tests/num/flt2dec/strategy/dragon.rs +++ b/src/libcore/tests/num/flt2dec/strategy/dragon.rs @@ -22,7 +22,7 @@ fn shortest_sanity_test() { } #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn exact_sanity_test() { // This test ends up running what I can only assume is some corner-ish case // of the `exp2` library function, defined in whatever C runtime we're diff --git a/src/libcore/tests/num/flt2dec/strategy/grisu.rs b/src/libcore/tests/num/flt2dec/strategy/grisu.rs index f8bdddfe2e410..a2c7f1b0e83e0 100644 --- a/src/libcore/tests/num/flt2dec/strategy/grisu.rs +++ b/src/libcore/tests/num/flt2dec/strategy/grisu.rs @@ -36,7 +36,7 @@ fn shortest_sanity_test() { } #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn exact_sanity_test() { // See comments in dragon.rs's exact_sanity_test for why this test is // ignored on MSVC diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index 1a6be3a9bbd03..54dbe3004cde6 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -291,7 +291,7 @@ fn write_unaligned_drop() { } #[test] -#[cfg(not(miri))] // Miri does not compute a maximal `mid` for `align_offset` +#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset` fn align_offset_zst() { // For pointers of stride = 0, the pointer is already aligned or it cannot be aligned at // all, because no amount of elements will align the pointer. @@ -306,7 +306,7 @@ fn align_offset_zst() { } #[test] -#[cfg(not(miri))] // Miri does not compute a maximal `mid` for `align_offset` +#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset` fn align_offset_stride1() { // For pointers of stride = 1, the pointer can always be aligned. The offset is equal to // number of bytes. @@ -323,7 +323,7 @@ fn align_offset_stride1() { } #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn align_offset_weird_strides() { #[repr(packed)] struct A3(u16, u8); diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index 6609bc3135ae0..e65d99bbb833e 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -1172,7 +1172,7 @@ fn test_rotate_right() { } #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn brute_force_rotate_test_0() { // In case of edge cases involving multiple algorithms let n = 300; @@ -1291,7 +1291,7 @@ fn sort_unstable() { #[test] #[cfg(not(target_arch = "wasm32"))] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn partition_at_index() { use core::cmp::Ordering::{Equal, Greater, Less}; use rand::rngs::StdRng; @@ -1494,7 +1494,7 @@ pub mod memchr { } #[test] -#[cfg(not(miri))] // Miri does not compute a maximal `mid` for `align_offset` +#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset` fn test_align_to_simple() { let bytes = [1u8, 2, 3, 4, 5, 6, 7]; let (prefix, aligned, suffix) = unsafe { bytes.align_to::() }; @@ -1518,7 +1518,7 @@ fn test_align_to_zst() { } #[test] -#[cfg(not(miri))] // Miri does not compute a maximal `mid` for `align_offset` +#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset` fn test_align_to_non_trivial() { #[repr(align(8))] struct U64(u64, u64); #[repr(align(8))] struct U64U64U32(u64, u64, u32); From ca2ffe3a8030e0fb6593cb6905a371441a10a4e0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 7 Dec 2019 12:42:19 +0100 Subject: [PATCH 2/3] liballoc: ignore tests in Miri instead of removing them entirely --- src/liballoc/alloc/tests.rs | 2 +- src/liballoc/collections/linked_list/tests.rs | 2 +- src/liballoc/collections/vec_deque/tests.rs | 8 ++++---- src/liballoc/sync/tests.rs | 4 ++-- src/liballoc/tests/slice.rs | 4 ++-- src/liballoc/tests/str.rs | 15 +++++++-------- src/liballoc/tests/string.rs | 4 ++-- src/liballoc/tests/vec.rs | 4 ++-- src/liballoc/tests/vec_deque.rs | 4 ++-- 9 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/liballoc/alloc/tests.rs b/src/liballoc/alloc/tests.rs index 956298d7836b8..c902971638b8e 100644 --- a/src/liballoc/alloc/tests.rs +++ b/src/liballoc/alloc/tests.rs @@ -22,7 +22,7 @@ fn allocate_zeroed() { } #[bench] -#[cfg(not(miri))] // Miri does not support benchmarks +#[cfg_attr(miri, ignore)] // Miri does not support benchmarks fn alloc_owned_small(b: &mut Bencher) { b.iter(|| { let _: Box<_> = box 10; diff --git a/src/liballoc/collections/linked_list/tests.rs b/src/liballoc/collections/linked_list/tests.rs index 94b92df129400..1b1d8eab39bfc 100644 --- a/src/liballoc/collections/linked_list/tests.rs +++ b/src/liballoc/collections/linked_list/tests.rs @@ -182,7 +182,7 @@ fn test_insert_prev() { #[test] #[cfg_attr(target_os = "emscripten", ignore)] -#[cfg(not(miri))] // Miri does not support threads +#[cfg_attr(miri, ignore)] // Miri does not support threads fn test_send() { let n = list_from(&[1, 2, 3]); thread::spawn(move || { diff --git a/src/liballoc/collections/vec_deque/tests.rs b/src/liballoc/collections/vec_deque/tests.rs index 8dc097cc08805..f2ce5b1d15dde 100644 --- a/src/liballoc/collections/vec_deque/tests.rs +++ b/src/liballoc/collections/vec_deque/tests.rs @@ -3,7 +3,7 @@ use super::*; use ::test; #[bench] -#[cfg(not(miri))] // Miri does not support benchmarks +#[cfg_attr(miri, ignore)] // Miri does not support benchmarks fn bench_push_back_100(b: &mut test::Bencher) { let mut deq = VecDeque::with_capacity(101); b.iter(|| { @@ -16,7 +16,7 @@ fn bench_push_back_100(b: &mut test::Bencher) { } #[bench] -#[cfg(not(miri))] // Miri does not support benchmarks +#[cfg_attr(miri, ignore)] // Miri does not support benchmarks fn bench_push_front_100(b: &mut test::Bencher) { let mut deq = VecDeque::with_capacity(101); b.iter(|| { @@ -29,7 +29,7 @@ fn bench_push_front_100(b: &mut test::Bencher) { } #[bench] -#[cfg(not(miri))] // Miri does not support benchmarks +#[cfg_attr(miri, ignore)] // Miri does not support benchmarks fn bench_pop_back_100(b: &mut test::Bencher) { let mut deq = VecDeque::::with_capacity(101); @@ -43,7 +43,7 @@ fn bench_pop_back_100(b: &mut test::Bencher) { } #[bench] -#[cfg(not(miri))] // Miri does not support benchmarks +#[cfg_attr(miri, ignore)] // Miri does not support benchmarks fn bench_pop_front_100(b: &mut test::Bencher) { let mut deq = VecDeque::::with_capacity(101); diff --git a/src/liballoc/sync/tests.rs b/src/liballoc/sync/tests.rs index 9220f5e0333ef..9ddba495b7e78 100644 --- a/src/liballoc/sync/tests.rs +++ b/src/liballoc/sync/tests.rs @@ -29,7 +29,7 @@ impl Drop for Canary { #[test] #[cfg_attr(target_os = "emscripten", ignore)] -#[cfg(not(miri))] // Miri does not support threads +#[cfg_attr(miri, ignore)] // Miri does not support threads fn manually_share_arc() { let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let arc_v = Arc::new(v); @@ -334,7 +334,7 @@ fn test_ptr_eq() { #[test] #[cfg_attr(target_os = "emscripten", ignore)] -#[cfg(not(miri))] // Miri does not support threads +#[cfg_attr(miri, ignore)] // Miri does not support threads fn test_weak_count_locked() { let mut a = Arc::new(atomic::AtomicBool::new(false)); let a2 = a.clone(); diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs index d9707b9574078..ec45de7c79e28 100644 --- a/src/liballoc/tests/slice.rs +++ b/src/liballoc/tests/slice.rs @@ -388,7 +388,7 @@ fn test_reverse() { } #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn test_sort() { let mut rng = thread_rng(); @@ -1610,7 +1610,7 @@ fn panic_safe() { let moduli = &[5, 20, 50]; #[cfg(miri)] - let lens = (1..13); + let lens = 1..13; #[cfg(miri)] let moduli = &[10]; diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index cb73c7c179cbf..1b011242d0137 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -166,7 +166,7 @@ fn test_join_for_different_lengths_with_long_separator() { } #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn test_unsafe_slice() { assert_eq!("ab", unsafe {"abc".get_unchecked(0..2)}); assert_eq!("bc", unsafe {"abc".get_unchecked(1..3)}); @@ -483,8 +483,8 @@ mod slice_index { } #[test] - #[cfg(not(target_os = "emscripten"))] // hits an OOM - #[cfg(not(miri))] // Miri is too slow + #[cfg_attr(target_os = "emscripten", ignore)] // hits an OOM + #[cfg_attr(miri, ignore)] // Miri is too slow fn simple_big() { fn a_million_letter_x() -> String { let mut i = 0; @@ -1069,7 +1069,7 @@ fn test_rev_iterator() { } #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn test_chars_decoding() { let mut bytes = [0; 4]; for c in (0..0x110000).filter_map(std::char::from_u32) { @@ -1081,7 +1081,7 @@ fn test_chars_decoding() { } #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn test_chars_rev_decoding() { let mut bytes = [0; 4]; for c in (0..0x110000).filter_map(std::char::from_u32) { @@ -1380,7 +1380,6 @@ fn test_bool_from_str() { assert_eq!("not even a boolean".parse::().ok(), None); } -#[cfg(not(miri))] // Miri is too slow fn check_contains_all_substrings(s: &str) { assert!(s.contains("")); for i in 0..s.len() { @@ -1391,7 +1390,7 @@ fn check_contains_all_substrings(s: &str) { } #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn strslice_issue_16589() { assert!("bananas".contains("nana")); @@ -1408,7 +1407,7 @@ fn strslice_issue_16878() { #[test] -#[cfg(not(miri))] // Miri is too slow +#[cfg_attr(miri, ignore)] // Miri is too slow fn test_strslice_contains() { let x = "There are moments, Jeeves, when one asks oneself, 'Do trousers matter?'"; check_contains_all_substrings(x); diff --git a/src/liballoc/tests/string.rs b/src/liballoc/tests/string.rs index 55edf56345b59..fe7b4ff24b8c9 100644 --- a/src/liballoc/tests/string.rs +++ b/src/liballoc/tests/string.rs @@ -523,7 +523,7 @@ fn test_reserve_exact() { } #[test] -#[cfg(not(miri))] // Miri does not support signalling OOM +#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM fn test_try_reserve() { // These are the interesting cases: @@ -601,7 +601,7 @@ fn test_try_reserve() { } #[test] -#[cfg(not(miri))] // Miri does not support signalling OOM +#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM fn test_try_reserve_exact() { // This is exactly the same as test_try_reserve with the method changed. diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index 9ee254f99acdf..5e788d61f84fd 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -1080,7 +1080,7 @@ fn test_reserve_exact() { } #[test] -#[cfg(not(miri))] // Miri does not support signalling OOM +#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM fn test_try_reserve() { // These are the interesting cases: @@ -1183,7 +1183,7 @@ fn test_try_reserve() { } #[test] -#[cfg(not(miri))] // Miri does not support signalling OOM +#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM fn test_try_reserve_exact() { // This is exactly the same as test_try_reserve with the method changed. diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index 5a0162a536175..ebcc832017172 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -1100,7 +1100,7 @@ fn test_reserve_exact_2() { } #[test] -#[cfg(not(miri))] // Miri does not support signalling OOM +#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM fn test_try_reserve() { // These are the interesting cases: // * exactly isize::MAX should never trigger a CapacityOverflow (can be OOM) @@ -1214,7 +1214,7 @@ fn test_try_reserve() { } #[test] -#[cfg(not(miri))] // Miri does not support signalling OOM +#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM fn test_try_reserve_exact() { // This is exactly the same as test_try_reserve with the method changed. // See that test for comments. From ab73d10a6ea034892d38fa8203954764c7e9df55 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 7 Dec 2019 12:47:18 +0100 Subject: [PATCH 3/3] fix warnings with cfg(miri) --- src/libcore/tests/hash/mod.rs | 6 ++++-- src/libcore/tests/num/dec2flt/mod.rs | 13 ++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/libcore/tests/hash/mod.rs b/src/libcore/tests/hash/mod.rs index 1000088e6b063..cdd850d3561a2 100644 --- a/src/libcore/tests/hash/mod.rs +++ b/src/libcore/tests/hash/mod.rs @@ -70,14 +70,16 @@ fn test_writer_hasher() { let ptr = 5_usize as *mut i32; assert_eq!(hash(&ptr), 5); + if cfg!(miri) { // Miri cannot hash pointers + return; + } + let cs: &mut [u8] = &mut [1, 2, 3]; let ptr = cs.as_ptr(); let slice_ptr = cs as *const [u8]; - #[cfg(not(miri))] // Miri cannot hash pointers assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64); let slice_ptr = cs as *mut [u8]; - #[cfg(not(miri))] // Miri cannot hash pointers assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64); } diff --git a/src/libcore/tests/num/dec2flt/mod.rs b/src/libcore/tests/num/dec2flt/mod.rs index 361758f859e2e..2a309c538b05a 100644 --- a/src/libcore/tests/num/dec2flt/mod.rs +++ b/src/libcore/tests/num/dec2flt/mod.rs @@ -31,7 +31,11 @@ fn ordinary() { test_literal!(0.1); test_literal!(12345.); test_literal!(0.9999999); - #[cfg(not(miri))] // Miri is too slow + + if cfg!(miri) { // Miri is too slow + return; + } + test_literal!(2.2250738585072014e-308); } @@ -77,9 +81,12 @@ fn infinity() { fn zero() { test_literal!(0.0); test_literal!(1e-325); - #[cfg(not(miri))] // Miri is too slow + + if cfg!(miri) { // Miri is too slow + return; + } + test_literal!(1e-326); - #[cfg(not(miri))] // Miri is too slow test_literal!(1e-500); }