Skip to content

Commit 7e1877e

Browse files
authored
Rollup merge of #71737 - RalfJung:miri-test-threads, r=shepmaster
Miri: run liballoc tests with threads Miri now supports threads, so we can run these tests. :)
2 parents 09c817e + 7bea58e commit 7e1877e

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/liballoc/alloc/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn allocate_zeroed() {
2323
}
2424

2525
#[bench]
26-
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
26+
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
2727
fn alloc_owned_small(b: &mut Bencher) {
2828
b.iter(|| {
2929
let _: Box<_> = box 10;

src/liballoc/collections/linked_list/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ fn test_insert_prev() {
182182

183183
#[test]
184184
#[cfg_attr(target_os = "emscripten", ignore)]
185-
#[cfg_attr(miri, ignore)] // Miri does not support threads
186185
fn test_send() {
187186
let n = list_from(&[1, 2, 3]);
188187
thread::spawn(move || {

src/liballoc/collections/vec_deque/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::*;
33
use test;
44

55
#[bench]
6-
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
6+
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
77
fn bench_push_back_100(b: &mut test::Bencher) {
88
let mut deq = VecDeque::with_capacity(101);
99
b.iter(|| {
@@ -16,7 +16,7 @@ fn bench_push_back_100(b: &mut test::Bencher) {
1616
}
1717

1818
#[bench]
19-
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
19+
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
2020
fn bench_push_front_100(b: &mut test::Bencher) {
2121
let mut deq = VecDeque::with_capacity(101);
2222
b.iter(|| {
@@ -29,7 +29,7 @@ fn bench_push_front_100(b: &mut test::Bencher) {
2929
}
3030

3131
#[bench]
32-
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
32+
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
3333
fn bench_pop_back_100(b: &mut test::Bencher) {
3434
let mut deq = VecDeque::<i32>::with_capacity(101);
3535

@@ -43,7 +43,7 @@ fn bench_pop_back_100(b: &mut test::Bencher) {
4343
}
4444

4545
#[bench]
46-
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
46+
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
4747
fn bench_pop_front_100(b: &mut test::Bencher) {
4848
let mut deq = VecDeque::<i32>::with_capacity(101);
4949

src/liballoc/sync/tests.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ impl Drop for Canary {
3232

3333
#[test]
3434
#[cfg_attr(target_os = "emscripten", ignore)]
35-
#[cfg_attr(miri, ignore)] // Miri does not support threads
3635
fn manually_share_arc() {
3736
let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
3837
let arc_v = Arc::new(v);
@@ -337,12 +336,13 @@ fn test_ptr_eq() {
337336

338337
#[test]
339338
#[cfg_attr(target_os = "emscripten", ignore)]
340-
#[cfg_attr(miri, ignore)] // Miri does not support threads
341339
fn test_weak_count_locked() {
342340
let mut a = Arc::new(atomic::AtomicBool::new(false));
343341
let a2 = a.clone();
344342
let t = thread::spawn(move || {
345-
for _i in 0..1000000 {
343+
// Miri is too slow
344+
let count = if cfg!(miri) { 1000 } else { 1000000 };
345+
for _i in 0..count {
346346
Arc::get_mut(&mut a);
347347
}
348348
a.store(true, SeqCst);
@@ -351,6 +351,8 @@ fn test_weak_count_locked() {
351351
while !a2.load(SeqCst) {
352352
let n = Arc::weak_count(&a2);
353353
assert!(n < 2, "bad weak count: {}", n);
354+
#[cfg(miri)] // Miri's scheduler does not guarantee liveness, and thus needs this hint.
355+
atomic::spin_loop_hint();
354356
}
355357
t.join().unwrap();
356358
}

0 commit comments

Comments
 (0)