Skip to content

Commit eb1de2f

Browse files
committed
liballoc: more compact way to adjust test sizes for Miri
1 parent f1c3051 commit eb1de2f

File tree

6 files changed

+35
-71
lines changed

6 files changed

+35
-71
lines changed

src/liballoc/collections/vec_deque/tests.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,8 @@ fn test_vec_from_vecdeque() {
386386
assert!(vec.into_iter().eq(vd));
387387
}
388388

389-
#[cfg(not(miri))] // Miri is too slow
390-
let max_pwr = 7;
391-
#[cfg(miri)]
392-
let max_pwr = 5;
389+
// Miri is too slow
390+
let max_pwr = if cfg!(miri) { 5 } else { 7 };
393391

394392
for cap_pwr in 0..max_pwr {
395393
// Make capacity as a (2^x)-1, so that the ring size is 2^x

src/liballoc/tests/binary_heap.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,14 @@ fn panic_safe() {
409409
}
410410
let mut rng = thread_rng();
411411
const DATASZ: usize = 32;
412-
#[cfg(not(miri))] // Miri is too slow
413-
const NTEST: usize = 10;
414-
#[cfg(miri)]
415-
const NTEST: usize = 1;
412+
// Miri is too slow
413+
let ntest = if cfg!(miri) { 1 } else { 10 };
416414

417415
// don't use 0 in the data -- we want to catch the zeroed-out case.
418416
let data = (1..=DATASZ).collect::<Vec<_>>();
419417

420418
// since it's a fuzzy test, run several tries.
421-
for _ in 0..NTEST {
419+
for _ in 0..ntest {
422420
for i in 1..=DATASZ {
423421
DROP_COUNTER.store(0, Ordering::SeqCst);
424422

src/liballoc/tests/btree/map.rs

+16-32
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ const MIN_INSERTS_HEIGHT_2: usize = NODE_CAPACITY + (NODE_CAPACITY + 1) * NODE_C
2828
#[test]
2929
fn test_basic_large() {
3030
let mut map = BTreeMap::new();
31-
#[cfg(not(miri))] // Miri is too slow
32-
let size = 10000;
33-
#[cfg(miri)]
34-
let size = MIN_INSERTS_HEIGHT_2;
31+
// Miri is too slow
32+
let size = if cfg!(miri) { MIN_INSERTS_HEIGHT_2 } else { 10000 };
3533
assert_eq!(map.len(), 0);
3634

3735
for i in 0..size {
@@ -155,10 +153,8 @@ fn test_basic_small() {
155153

156154
#[test]
157155
fn test_iter() {
158-
#[cfg(not(miri))] // Miri is too slow
159-
let size = 10000;
160-
#[cfg(miri)]
161-
let size = 200;
156+
// Miri is too slow
157+
let size = if cfg!(miri) { 200 } else { 10000 };
162158

163159
let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
164160

@@ -180,10 +176,8 @@ fn test_iter() {
180176

181177
#[test]
182178
fn test_iter_rev() {
183-
#[cfg(not(miri))] // Miri is too slow
184-
let size = 10000;
185-
#[cfg(miri)]
186-
let size = 200;
179+
// Miri is too slow
180+
let size = if cfg!(miri) { 200 } else { 10000 };
187181

188182
let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
189183

@@ -289,10 +283,8 @@ fn test_values_mut() {
289283

290284
#[test]
291285
fn test_iter_mixed() {
292-
#[cfg(not(miri))] // Miri is too slow
293-
let size = 10000;
294-
#[cfg(miri)]
295-
let size = 200;
286+
// Miri is too slow
287+
let size = if cfg!(miri) { 200 } else { 10000 };
296288

297289
let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
298290

@@ -525,10 +517,8 @@ fn test_range_backwards_4() {
525517

526518
#[test]
527519
fn test_range_1000() {
528-
#[cfg(not(miri))] // Miri is too slow
529-
let size = 1000;
530-
#[cfg(miri)]
531-
let size = MIN_INSERTS_HEIGHT_2 as u32;
520+
// Miri is too slow
521+
let size = if cfg!(miri) { MIN_INSERTS_HEIGHT_2 as u32 } else { 1000 };
532522
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
533523

534524
fn test(map: &BTreeMap<u32, u32>, size: u32, min: Bound<&u32>, max: Bound<&u32>) {
@@ -566,10 +556,8 @@ fn test_range_borrowed_key() {
566556
#[test]
567557
fn test_range() {
568558
let size = 200;
569-
#[cfg(not(miri))] // Miri is too slow
570-
let step = 1;
571-
#[cfg(miri)]
572-
let step = 66;
559+
// Miri is too slow
560+
let step = if cfg!(miri) { 66 } else { 1 };
573561
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
574562

575563
for i in (0..size).step_by(step) {
@@ -589,10 +577,8 @@ fn test_range() {
589577
#[test]
590578
fn test_range_mut() {
591579
let size = 200;
592-
#[cfg(not(miri))] // Miri is too slow
593-
let step = 1;
594-
#[cfg(miri)]
595-
let step = 66;
580+
// Miri is too slow
581+
let step = if cfg!(miri) { 66 } else { 1 };
596582
let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
597583

598584
for i in (0..size).step_by(step) {
@@ -1263,10 +1249,8 @@ fn test_split_off_empty_left() {
12631249

12641250
#[test]
12651251
fn test_split_off_large_random_sorted() {
1266-
#[cfg(not(miri))] // Miri is too slow
1267-
let mut data = rand_data(1529);
1268-
#[cfg(miri)]
1269-
let mut data = rand_data(529);
1252+
// Miri is too slow
1253+
let mut data = if cfg!(miri) { rand_data(529) } else { rand_data(1529) };
12701254
// special case with maximum height.
12711255
data.sort();
12721256

src/liballoc/tests/btree/set.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,8 @@ fn test_split_off_empty_left() {
621621

622622
#[test]
623623
fn test_split_off_large_random_sorted() {
624-
#[cfg(not(miri))] // Miri is too slow
625-
let mut data = rand_data(1529);
626-
#[cfg(miri)]
627-
let mut data = rand_data(529);
624+
// Miri is too slow
625+
let mut data = if cfg!(miri) { rand_data(529) } else { rand_data(1529) };
628626
// special case with maximum height.
629627
data.sort();
630628

src/liballoc/tests/slice.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -463,15 +463,9 @@ fn test_sort() {
463463

464464
#[test]
465465
fn test_sort_stability() {
466-
#[cfg(not(miri))] // Miri is too slow
467-
let large_range = 500..510;
468-
#[cfg(not(miri))] // Miri is too slow
469-
let rounds = 10;
470-
471-
#[cfg(miri)]
472-
let large_range = 0..0; // empty range
473-
#[cfg(miri)]
474-
let rounds = 1;
466+
// Miri is too slow
467+
let large_range = if cfg!(miri) { 0..0 } else { 500..510 };
468+
let rounds = if cfg!(miri) { 1 } else { 10 };
475469

476470
for len in (2..25).chain(large_range) {
477471
for _ in 0..rounds {
@@ -1727,15 +1721,9 @@ fn panic_safe() {
17271721

17281722
let mut rng = thread_rng();
17291723

1730-
#[cfg(not(miri))] // Miri is too slow
1731-
let lens = (1..20).chain(70..MAX_LEN);
1732-
#[cfg(not(miri))] // Miri is too slow
1733-
let moduli = &[5, 20, 50];
1734-
1735-
#[cfg(miri)]
1736-
let lens = 1..10;
1737-
#[cfg(miri)]
1738-
let moduli = &[5];
1724+
// Miri is too slow
1725+
let lens = if cfg!(miri) { (1..10).chain(20..21) } else { (1..20).chain(70..MAX_LEN) };
1726+
let moduli: &[u32] = if cfg!(miri) { &[5] } else { &[5, 20, 50] };
17391727

17401728
for len in lens {
17411729
for &modulus in moduli {

src/liballoc/tests/vec_deque.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -954,16 +954,14 @@ fn test_append_permutations() {
954954
out
955955
}
956956

957-
#[cfg(not(miri))] // Miri is too slow
958-
const MAX: usize = 5;
959-
#[cfg(miri)]
960-
const MAX: usize = 3;
957+
// Miri is too slow
958+
let max = if cfg!(miri) { 3 } else { 5 };
961959

962960
// Many different permutations of both the `VecDeque` getting appended to
963961
// and the one getting appended are generated to check `append`.
964962
// This ensures all 6 code paths of `append` are tested.
965-
for src_push_back in 0..MAX {
966-
for src_push_front in 0..MAX {
963+
for src_push_back in 0..max {
964+
for src_push_front in 0..max {
967965
// doesn't pop more values than are pushed
968966
for src_pop_back in 0..(src_push_back + src_push_front) {
969967
for src_pop_front in 0..(src_push_back + src_push_front - src_pop_back) {
@@ -974,8 +972,8 @@ fn test_append_permutations() {
974972
src_pop_front,
975973
);
976974

977-
for dst_push_back in 0..MAX {
978-
for dst_push_front in 0..MAX {
975+
for dst_push_back in 0..max {
976+
for dst_push_front in 0..max {
979977
for dst_pop_back in 0..(dst_push_back + dst_push_front) {
980978
for dst_pop_front in
981979
0..(dst_push_back + dst_push_front - dst_pop_back)

0 commit comments

Comments
 (0)