diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 54f4dcc4..d6187777 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -66,3 +66,8 @@ jobs: cd benchmark cargo run --release --bin mutex -- 2 1 0 1 2 cargo run --release --bin rwlock -- 1 1 1 0 1 2 + miri: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: bash ci/miri.sh diff --git a/ci/miri.sh b/ci/miri.sh new file mode 100644 index 00000000..68c8f358 --- /dev/null +++ b/ci/miri.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -ex + +export CARGO_NET_RETRY=5 +export CARGO_NET_TIMEOUT=10 + +rustup toolchain install nightly --component miri +rustup override set nightly +cargo miri setup + +# We use different seeds for the different features to get a bit more test coverage. +SEED=0 +for FEATURE in arc_lock serde deadlock_detection nightly hardware-lock-elision; do + export MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-seed=$SEED" + if [ "$FEATURE" = "deadlock_detection" ]; then + # There's a background thread that never goes away, so Miri can't check for leaks. + MIRIFLAGS="$MIRIFLAGS -Zmiri-ignore-leaks" + fi + cargo miri test --features=$FEATURE + SEED=$(( $SEED+1 )) +done diff --git a/src/condvar.rs b/src/condvar.rs index 91da781e..35ec38f4 100644 --- a/src/condvar.rs +++ b/src/condvar.rs @@ -916,6 +916,7 @@ mod tests { /// This module contains an integration test that is heavily inspired from WebKit's own integration /// tests for it's own Condvar. #[cfg(test)] +#[cfg(not(miri))] // Miri is too slow mod webkit_queue_test { use crate::{Condvar, Mutex, MutexGuard}; use std::{collections::VecDeque, sync::Arc, thread, time::Duration}; diff --git a/src/fair_mutex.rs b/src/fair_mutex.rs index 2807af20..3fe6e4bc 100644 --- a/src/fair_mutex.rs +++ b/src/fair_mutex.rs @@ -122,7 +122,7 @@ mod tests { #[test] fn lots_and_lots() { - const J: u32 = 1000; + const J: u32 = if cfg!(miri) { 200 } else { 1000 }; const K: u32 = 3; let m = Arc::new(FairMutex::new(0)); diff --git a/src/mutex.rs b/src/mutex.rs index 8af38247..16503c94 100644 --- a/src/mutex.rs +++ b/src/mutex.rs @@ -138,7 +138,7 @@ mod tests { #[test] fn lots_and_lots() { - const J: u32 = 1000; + const J: u32 = if cfg!(miri) { 200 } else { 1000 }; const K: u32 = 3; let m = Arc::new(Mutex::new(0)); diff --git a/src/rwlock.rs b/src/rwlock.rs index 730493be..f649b3db 100644 --- a/src/rwlock.rs +++ b/src/rwlock.rs @@ -154,7 +154,7 @@ mod tests { #[test] fn frob() { const N: u32 = 10; - const M: u32 = 1000; + const M: u32 = if cfg!(miri) { 100 } else { 1000 }; let r = Arc::new(RwLock::new(()));