From c5ac78588890695d83731b654d13f5d087c957e4 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 8 Dec 2024 19:27:29 +0900 Subject: [PATCH] Speed up Miri test --- .github/workflows/ci.yml | 8 ++++- ci/miri.sh | 62 +++++++++++++++++++-------------- crossbeam-skiplist/tests/set.rs | 9 +++-- 3 files changed, 49 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb47dbb6e..1a1360a72 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -174,6 +174,12 @@ jobs: # Run miri. miri: + strategy: + fail-fast: false + matrix: + group: + - channel + - others runs-on: ubuntu-latest timeout-minutes: 120 # TODO steps: @@ -181,7 +187,7 @@ jobs: - name: Install Rust run: rustup toolchain install nightly --component miri && rustup default nightly - name: miri - run: ci/miri.sh + run: ci/miri.sh ${{ matrix.group }} # Run cargo-careful. careful: diff --git a/ci/miri.sh b/ci/miri.sh index c42943e22..80bb1f809 100755 --- a/ci/miri.sh +++ b/ci/miri.sh @@ -3,36 +3,46 @@ set -euxo pipefail IFS=$'\n\t' cd "$(dirname "$0")"/.. +group=$1 + # We need 'ts' for the per-line timing sudo apt-get -y install moreutils echo export RUSTFLAGS="${RUSTFLAGS:-} -Z randomize-layout" export RUSTDOCFLAGS="${RUSTDOCFLAGS:-} -Z randomize-layout" +export MIRIFLAGS="${MIRIFLAGS:-} -Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation" -MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation" \ - MIRI_LEAK_CHECK='1' \ - cargo miri test \ - -p crossbeam-channel \ - -p crossbeam-queue \ - -p crossbeam-utils 2>&1 | ts -i '%.s ' - -# -Zmiri-ignore-leaks is needed because we use detached threads in tests in tests/golang.rs: https://github.com/rust-lang/miri/issues/1371 -MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation -Zmiri-ignore-leaks" \ - cargo miri test \ - -p crossbeam-channel --test golang 2>&1 | ts -i '%.s ' - -# Use Tree Borrows instead of Stacked Borrows because epoch is not compatible with Stacked Borrows: https://github.com/crossbeam-rs/crossbeam/issues/545#issuecomment-1192785003 -MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation -Zmiri-tree-borrows" \ - cargo miri test \ - -p crossbeam-epoch \ - -p crossbeam-skiplist \ - -p crossbeam 2>&1 | ts -i '%.s ' - -# Use Tree Borrows instead of Stacked Borrows because epoch is not compatible with Stacked Borrows: https://github.com/crossbeam-rs/crossbeam/issues/545#issuecomment-1192785003 -# -Zmiri-compare-exchange-weak-failure-rate=0.0 is needed because some sequential tests (e.g., -# doctest of Stealer::steal) incorrectly assume that sequential weak CAS will never fail. -# -Zmiri-preemption-rate=0 is needed because this code technically has UB and Miri catches that. -MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation -Zmiri-tree-borrows -Zmiri-compare-exchange-weak-failure-rate=0.0 -Zmiri-preemption-rate=0" \ - cargo miri test \ - -p crossbeam-deque 2>&1 | ts -i '%.s ' +case "${group}" in + channel) + MIRI_LEAK_CHECK='1' \ + cargo miri test \ + -p crossbeam-channel 2>&1 | ts -i '%.s ' + # -Zmiri-ignore-leaks is needed because we use detached threads in tests in tests/golang.rs: https://github.com/rust-lang/miri/issues/1371 + MIRIFLAGS="${MIRIFLAGS} -Zmiri-ignore-leaks" \ + cargo miri test \ + -p crossbeam-channel --test golang 2>&1 | ts -i '%.s ' + ;; + others) + cargo miri test \ + -p crossbeam-queue \ + -p crossbeam-utils 2>&1 | ts -i '%.s ' + # Use Tree Borrows instead of Stacked Borrows because epoch is not compatible with Stacked Borrows: https://github.com/crossbeam-rs/crossbeam/issues/545#issuecomment-1192785003 + MIRIFLAGS="${MIRIFLAGS} -Zmiri-tree-borrows" \ + cargo miri test \ + -p crossbeam-epoch \ + -p crossbeam-skiplist \ + -p crossbeam 2>&1 | ts -i '%.s ' + # Use Tree Borrows instead of Stacked Borrows because epoch is not compatible with Stacked Borrows: https://github.com/crossbeam-rs/crossbeam/issues/545#issuecomment-1192785003 + # -Zmiri-compare-exchange-weak-failure-rate=0.0 is needed because some sequential tests (e.g., + # doctest of Stealer::steal) incorrectly assume that sequential weak CAS will never fail. + # -Zmiri-preemption-rate=0 is needed because this code technically has UB and Miri catches that. + MIRIFLAGS="${MIRIFLAGS} -Zmiri-tree-borrows -Zmiri-compare-exchange-weak-failure-rate=0.0 -Zmiri-preemption-rate=0" \ + cargo miri test \ + -p crossbeam-deque 2>&1 | ts -i '%.s ' + ;; + *) + echo "unknown crate group '${group}'" + exit 1 + ;; +esac diff --git a/crossbeam-skiplist/tests/set.rs b/crossbeam-skiplist/tests/set.rs index ab769003c..65003798b 100644 --- a/crossbeam-skiplist/tests/set.rs +++ b/crossbeam-skiplist/tests/set.rs @@ -1,6 +1,10 @@ use crossbeam_skiplist::SkipSet; use crossbeam_utils::thread; -use std::{iter, ops::Bound, sync::Barrier}; +use std::{ + iter, + ops::Bound, + sync::{Arc, Barrier}, +}; #[test] fn smoke() { @@ -696,9 +700,8 @@ fn clear() { // https://github.com/crossbeam-rs/crossbeam/issues/1023 #[test] fn concurrent_insert_get_same_key() { - use std::sync::Arc; let set: Arc> = Arc::new(SkipSet::new()); - let len = 10_0000; + let len = if cfg!(miri) { 100 } else { 10_000 }; let key = 0; set.insert(0);