From 5799da42ea7ef8326b2518a14b3700d80fbd6cef Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sat, 25 May 2024 13:01:54 -0700 Subject: [PATCH 1/4] m: Remove miri ignored tests Signed-off-by: John Nunley --- tests/rwlock.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/rwlock.rs b/tests/rwlock.rs index 95e4528..290b5db 100644 --- a/tests/rwlock.rs +++ b/tests/rwlock.rs @@ -121,7 +121,6 @@ fn get_mut() { // Miri bug; this works when async is replaced with blocking #[cfg(not(target_family = "wasm"))] #[test] -#[cfg_attr(miri, ignore)] fn contention() { const N: u32 = 10; const M: usize = if cfg!(miri) { 100 } else { 1000 }; @@ -156,7 +155,6 @@ fn contention() { #[cfg(not(target_family = "wasm"))] #[test] -#[cfg_attr(miri, ignore)] fn contention_arc() { const N: u32 = 10; const M: usize = if cfg!(miri) { 100 } else { 1000 }; From 36385360446b8851da629f91b6a6e6b69b52ae38 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sat, 25 May 2024 13:14:41 -0700 Subject: [PATCH 2/4] m: Add blocking test as well Signed-off-by: John Nunley --- tests/rwlock.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/rwlock.rs b/tests/rwlock.rs index 290b5db..f7923cf 100644 --- a/tests/rwlock.rs +++ b/tests/rwlock.rs @@ -118,7 +118,7 @@ fn get_mut() { assert_eq!(lock.into_inner(), 20); } -// Miri bug; this works when async is replaced with blocking +#[cfg_attr(miri, ignore)] #[cfg(not(target_family = "wasm"))] #[test] fn contention() { @@ -153,6 +153,38 @@ fn contention() { }); } +#[cfg(not(target_family = "wasm"))] +#[test] +fn contention_blocking() { + const N: u32 = 10; + const M: usize = if cfg!(miri) { 100 } else { 1000 }; + + let (tx, rx) = flume::unbounded(); + let tx = Arc::new(tx); + let rw = Arc::new(RwLock::new(())); + + // Spawn N tasks that randomly acquire the lock M times. + for _ in 0..N { + let tx = tx.clone(); + let rw = rw.clone(); + + let _spawned = std::thread::spawn(|| { + for _ in 0..M { + if fastrand::u32(..N) == 0 { + drop(rw.write_blocking()); + } else { + drop(rw.read_blocking()); + } + } + tx.send(()).unwrap(); + }); + } + + for _ in 0..N { + rx.recv().unwrap(); + } +} + #[cfg(not(target_family = "wasm"))] #[test] fn contention_arc() { From 26538bad6fa26c4f6f8d623f7e3828e35a2e764d Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sat, 25 May 2024 13:15:58 -0700 Subject: [PATCH 3/4] m: Fix compiler error Signed-off-by: John Nunley --- tests/rwlock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rwlock.rs b/tests/rwlock.rs index f7923cf..6ceb480 100644 --- a/tests/rwlock.rs +++ b/tests/rwlock.rs @@ -168,7 +168,7 @@ fn contention_blocking() { let tx = tx.clone(); let rw = rw.clone(); - let _spawned = std::thread::spawn(|| { + let _spawned = std::thread::spawn(move || { for _ in 0..M { if fastrand::u32(..N) == 0 { drop(rw.write_blocking()); From d585e956f255ebeaa5097ab7fc959499008a41f8 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sat, 25 May 2024 13:21:50 -0700 Subject: [PATCH 4/4] m: Ignore contention_arc as well Signed-off-by: John Nunley --- tests/rwlock.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/rwlock.rs b/tests/rwlock.rs index 6ceb480..7385e85 100644 --- a/tests/rwlock.rs +++ b/tests/rwlock.rs @@ -185,6 +185,7 @@ fn contention_blocking() { } } +#[cfg_attr(miri, ignore)] #[cfg(not(target_family = "wasm"))] #[test] fn contention_arc() {