make many std tests work in Miri
This commit is contained in:
parent
27b0444333
commit
8c8dc125b1
@ -268,10 +268,13 @@ fn test_lots_of_insertions() {
|
||||
|
||||
// Try this a few times to make sure we never screw up the hashmap's
|
||||
// internal state.
|
||||
for _ in 0..10 {
|
||||
let loops = if cfg!(miri) { 2 } else { 10 };
|
||||
for _ in 0..loops {
|
||||
assert!(m.is_empty());
|
||||
|
||||
for i in 1..1001 {
|
||||
let count = if cfg!(miri) { 101 } else { 1001 };
|
||||
|
||||
for i in 1..count {
|
||||
assert!(m.insert(i, i).is_none());
|
||||
|
||||
for j in 1..=i {
|
||||
@ -279,42 +282,42 @@ fn test_lots_of_insertions() {
|
||||
assert_eq!(r, Some(&j));
|
||||
}
|
||||
|
||||
for j in i + 1..1001 {
|
||||
for j in i + 1..count {
|
||||
let r = m.get(&j);
|
||||
assert_eq!(r, None);
|
||||
}
|
||||
}
|
||||
|
||||
for i in 1001..2001 {
|
||||
for i in count..(2 * count) {
|
||||
assert!(!m.contains_key(&i));
|
||||
}
|
||||
|
||||
// remove forwards
|
||||
for i in 1..1001 {
|
||||
for i in 1..count {
|
||||
assert!(m.remove(&i).is_some());
|
||||
|
||||
for j in 1..=i {
|
||||
assert!(!m.contains_key(&j));
|
||||
}
|
||||
|
||||
for j in i + 1..1001 {
|
||||
for j in i + 1..count {
|
||||
assert!(m.contains_key(&j));
|
||||
}
|
||||
}
|
||||
|
||||
for i in 1..1001 {
|
||||
for i in 1..count {
|
||||
assert!(!m.contains_key(&i));
|
||||
}
|
||||
|
||||
for i in 1..1001 {
|
||||
for i in 1..count {
|
||||
assert!(m.insert(i, i).is_none());
|
||||
}
|
||||
|
||||
// remove backwards
|
||||
for i in (1..1001).rev() {
|
||||
for i in (1..count).rev() {
|
||||
assert!(m.remove(&i).is_some());
|
||||
|
||||
for j in i..1001 {
|
||||
for j in i..count {
|
||||
assert!(!m.contains_key(&j));
|
||||
}
|
||||
|
||||
@ -817,6 +820,7 @@ fn test_retain() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM
|
||||
#[cfg_attr(target_os = "android", ignore)] // Android used in CI has a broken dlmalloc
|
||||
fn test_try_reserve() {
|
||||
let mut empty_bytes: HashMap<u8, u8> = HashMap::new();
|
||||
|
@ -94,7 +94,7 @@ fn read_to_end() {
|
||||
assert_eq!(c.read_to_end(&mut v).unwrap(), 1);
|
||||
assert_eq!(v, b"1");
|
||||
|
||||
let cap = 1024 * 1024;
|
||||
let cap = if cfg!(miri) { 1024 } else { 1024 * 1024 };
|
||||
let data = (0..cap).map(|i| (i / 3) as u8).collect::<Vec<_>>();
|
||||
let mut v = Vec::new();
|
||||
let (a, b) = data.split_at(data.len() / 2);
|
||||
@ -309,6 +309,7 @@ fn chain_zero_length_read_is_not_eof() {
|
||||
|
||||
#[bench]
|
||||
#[cfg_attr(target_os = "emscripten", ignore)]
|
||||
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
||||
fn bench_read_to_end(b: &mut test::Bencher) {
|
||||
b.iter(|| {
|
||||
let mut lr = repeat(1).take(10000000);
|
||||
|
@ -1768,6 +1768,7 @@ macro_rules! unchanged(
|
||||
}
|
||||
|
||||
#[bench]
|
||||
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
||||
fn bench_path_cmp_fast_path_buf_sort(b: &mut test::Bencher) {
|
||||
let prefix = "my/home";
|
||||
let mut paths: Vec<_> =
|
||||
@ -1781,6 +1782,7 @@ fn bench_path_cmp_fast_path_buf_sort(b: &mut test::Bencher) {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
||||
fn bench_path_cmp_fast_path_long(b: &mut test::Bencher) {
|
||||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
||||
let paths: Vec<_> =
|
||||
@ -1799,6 +1801,7 @@ fn bench_path_cmp_fast_path_long(b: &mut test::Bencher) {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
||||
fn bench_path_cmp_fast_path_short(b: &mut test::Bencher) {
|
||||
let prefix = "my/home";
|
||||
let paths: Vec<_> =
|
||||
@ -1817,6 +1820,7 @@ fn bench_path_cmp_fast_path_short(b: &mut test::Bencher) {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
||||
fn bench_path_hashset(b: &mut test::Bencher) {
|
||||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
||||
let paths: Vec<_> =
|
||||
@ -1835,6 +1839,7 @@ fn bench_path_hashset(b: &mut test::Bencher) {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
||||
fn bench_path_hashset_miss(b: &mut test::Bencher) {
|
||||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
||||
let paths: Vec<_> =
|
||||
|
@ -13,7 +13,7 @@ fn test_full() {
|
||||
#[test]
|
||||
fn test() {
|
||||
let nthreads = 8;
|
||||
let nmsgs = 1000;
|
||||
let nmsgs = if cfg!(miri) { 100 } else { 1000 };
|
||||
let q = Queue::new();
|
||||
match q.pop() {
|
||||
Empty => {}
|
||||
|
@ -77,12 +77,13 @@ fn stress() {
|
||||
}
|
||||
|
||||
unsafe fn stress_bound(bound: usize) {
|
||||
let count = if cfg!(miri) { 1000 } else { 100000 };
|
||||
let q = Arc::new(Queue::with_additions(bound, (), ()));
|
||||
|
||||
let (tx, rx) = channel();
|
||||
let q2 = q.clone();
|
||||
let _t = thread::spawn(move || {
|
||||
for _ in 0..100000 {
|
||||
for _ in 0..count {
|
||||
loop {
|
||||
match q2.pop() {
|
||||
Some(1) => break,
|
||||
@ -93,7 +94,7 @@ unsafe fn stress_bound(bound: usize) {
|
||||
}
|
||||
tx.send(()).unwrap();
|
||||
});
|
||||
for _ in 0..100000 {
|
||||
for _ in 0..count {
|
||||
q.push(1);
|
||||
}
|
||||
rx.recv().unwrap();
|
||||
|
@ -113,23 +113,25 @@ fn chan_gone_concurrent() {
|
||||
|
||||
#[test]
|
||||
fn stress() {
|
||||
let count = if cfg!(miri) { 100 } else { 10000 };
|
||||
let (tx, rx) = sync_channel::<i32>(0);
|
||||
thread::spawn(move || {
|
||||
for _ in 0..10000 {
|
||||
for _ in 0..count {
|
||||
tx.send(1).unwrap();
|
||||
}
|
||||
});
|
||||
for _ in 0..10000 {
|
||||
for _ in 0..count {
|
||||
assert_eq!(rx.recv().unwrap(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stress_recv_timeout_two_threads() {
|
||||
let count = if cfg!(miri) { 100 } else { 10000 };
|
||||
let (tx, rx) = sync_channel::<i32>(0);
|
||||
|
||||
thread::spawn(move || {
|
||||
for _ in 0..10000 {
|
||||
for _ in 0..count {
|
||||
tx.send(1).unwrap();
|
||||
}
|
||||
});
|
||||
@ -146,12 +148,12 @@ fn stress_recv_timeout_two_threads() {
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(recv_count, 10000);
|
||||
assert_eq!(recv_count, count);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stress_recv_timeout_shared() {
|
||||
const AMT: u32 = 1000;
|
||||
const AMT: u32 = if cfg!(miri) { 100 } else { 1000 };
|
||||
const NTHREADS: u32 = 8;
|
||||
let (tx, rx) = sync_channel::<i32>(0);
|
||||
let (dtx, drx) = sync_channel::<()>(0);
|
||||
@ -191,7 +193,7 @@ fn stress_recv_timeout_shared() {
|
||||
|
||||
#[test]
|
||||
fn stress_shared() {
|
||||
const AMT: u32 = 1000;
|
||||
const AMT: u32 = if cfg!(miri) { 100 } else { 1000 };
|
||||
const NTHREADS: u32 = 8;
|
||||
let (tx, rx) = sync_channel::<i32>(0);
|
||||
let (dtx, drx) = sync_channel::<()>(0);
|
||||
@ -438,12 +440,13 @@ fn recv(rx: Receiver<Box<i32>>, i: i32) {
|
||||
|
||||
#[test]
|
||||
fn recv_a_lot() {
|
||||
let count = if cfg!(miri) { 1000 } else { 10000 };
|
||||
// Regression test that we don't run out of stack in scheduler context
|
||||
let (tx, rx) = sync_channel(10000);
|
||||
for _ in 0..10000 {
|
||||
let (tx, rx) = sync_channel(count);
|
||||
for _ in 0..count {
|
||||
tx.send(()).unwrap();
|
||||
}
|
||||
for _ in 0..10000 {
|
||||
for _ in 0..count {
|
||||
rx.recv().unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -120,13 +120,14 @@ fn chan_gone_concurrent() {
|
||||
|
||||
#[test]
|
||||
fn stress() {
|
||||
let count = if cfg!(miri) { 100 } else { 10000 };
|
||||
let (tx, rx) = channel::<i32>();
|
||||
let t = thread::spawn(move || {
|
||||
for _ in 0..10000 {
|
||||
for _ in 0..count {
|
||||
tx.send(1).unwrap();
|
||||
}
|
||||
});
|
||||
for _ in 0..10000 {
|
||||
for _ in 0..count {
|
||||
assert_eq!(rx.recv().unwrap(), 1);
|
||||
}
|
||||
t.join().ok().expect("thread panicked");
|
||||
@ -134,7 +135,7 @@ fn stress() {
|
||||
|
||||
#[test]
|
||||
fn stress_shared() {
|
||||
const AMT: u32 = 10000;
|
||||
const AMT: u32 = if cfg!(miri) { 100 } else { 10000 };
|
||||
const NTHREADS: u32 = 8;
|
||||
let (tx, rx) = channel::<i32>();
|
||||
|
||||
@ -504,12 +505,13 @@ fn very_long_recv_timeout_wont_panic() {
|
||||
|
||||
#[test]
|
||||
fn recv_a_lot() {
|
||||
let count = if cfg!(miri) { 1000 } else { 10000 };
|
||||
// Regression test that we don't run out of stack in scheduler context
|
||||
let (tx, rx) = channel();
|
||||
for _ in 0..10000 {
|
||||
for _ in 0..count {
|
||||
tx.send(()).unwrap();
|
||||
}
|
||||
for _ in 0..10000 {
|
||||
for _ in 0..count {
|
||||
rx.recv().unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ fn smoke() {
|
||||
#[test]
|
||||
fn frob() {
|
||||
const N: u32 = 10;
|
||||
const M: usize = 1000;
|
||||
const M: usize = if cfg!(miri) { 100 } else { 1000 };
|
||||
|
||||
let r = Arc::new(RwLock::new(()));
|
||||
|
||||
|
@ -31,7 +31,8 @@ fn instant_monotonic_concurrent() -> crate::thread::Result<()> {
|
||||
.map(|_| {
|
||||
crate::thread::spawn(|| {
|
||||
let mut old = Instant::now();
|
||||
for _ in 0..5_000_000 {
|
||||
let count = if cfg!(miri) { 1_000 } else { 5_000_000 };
|
||||
for _ in 0..count {
|
||||
let new = Instant::now();
|
||||
assert!(new >= old);
|
||||
old = new;
|
||||
|
Loading…
Reference in New Issue
Block a user