Skip to content

Commit

Permalink
Adds Miri to CI/CD (#1446)
Browse files Browse the repository at this point in the history
This is carefully constructed to allow Miri to test most of `ndarray` without slowing down CI/CD very badly; as a result, it skips a number of slow tests. See #1446 for a list.

It also excludes `blas` because Miri cannot call `cblas_gemm`, and it excludes `rayon` because it considers the still-running thread pool to be a leak. `rayon` can be re-added when rust-lang/miri#1371 is resolved.
  • Loading branch information
akern40 authored Oct 30, 2024
1 parent 492b274 commit fd3ce5d
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ jobs:
run: sudo apt-get install libopenblas-dev gfortran
- run: ./scripts/all-tests.sh "$FEATURES" ${{ matrix.rust }}

miri:
runs-on: ubuntu-latest
name: miri
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: miri
- uses: Swatinem/rust-cache@v2
- run: ./scripts/miri-tests.sh

cross_test:
#if: ${{ github.event_name == 'merge_group' }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -149,6 +160,7 @@ jobs:
- format # should format be required?
- nostd
- tests
- miri
- cross_test
- cargo-careful
- docs
Expand Down
2 changes: 2 additions & 0 deletions ndarray-rand/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fn oversampling_without_replacement_should_panic()
}

quickcheck! {
#[cfg_attr(miri, ignore)] // Takes an insufferably long time
fn oversampling_with_replacement_is_fine(m: u8, n: u8) -> TestResult {
let (m, n) = (m as usize, n as usize);
let a = Array::random((m, n), Uniform::new(0., 2.));
Expand Down Expand Up @@ -86,6 +87,7 @@ quickcheck! {

#[cfg(feature = "quickcheck")]
quickcheck! {
#[cfg_attr(miri, ignore)] // This takes *forever* with Miri
fn sampling_behaves_as_expected(m: u8, n: u8, strategy: SamplingStrategy) -> TestResult {
let (m, n) = (m as usize, n as usize);
let a = Array::random((m, n), Uniform::new(0., 2.));
Expand Down
18 changes: 18 additions & 0 deletions scripts/miri-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

set -x
set -e

# We rely on layout-dependent casts, which should be covered with #[repr(transparent)]
# This should catch if we missed that
RUSTFLAGS="-Zrandomize-layout"

# Miri reports a stacked borrow violation deep within rayon, in a crate called crossbeam-epoch
# The crate has a PR to fix this: https://github.com/crossbeam-rs/crossbeam/pull/871
# but using Miri's tree borrow mode may resolve it for now.
# Disabled until we can figure out a different rayon issue: https://github.com/rust-lang/miri/issues/1371
# MIRIFLAGS="-Zmiri-tree-borrows"

# General tests
# Note that we exclude blas feature because Miri can't do cblas_gemm
cargo miri test -v -p ndarray -p ndarray-rand --features approx,serde
1 change: 1 addition & 0 deletions src/dimension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ mod test
}

quickcheck! {
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
// FIXME: This test is extremely slow, even with i16 values, investigate
fn arith_seq_intersect_correct(
first1: i8, len1: i8, step1: i8,
Expand Down
1 change: 1 addition & 0 deletions tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,7 @@ mod array_cow_tests
});
}

#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[test]
fn test_clone_from()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/azip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn test_azip2_sum()
}

#[test]
#[cfg(feature = "approx")]
#[cfg(all(feature = "approx", feature = "std"))]
fn test_azip3_slices()
{
use approx::assert_abs_diff_eq;
Expand Down
1 change: 1 addition & 0 deletions tests/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ fn test_array_view()
}

#[test]
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[cfg(feature = "std")]
#[allow(clippy::cognitive_complexity)]
fn test_all_ndindex()
Expand Down
1 change: 1 addition & 0 deletions tests/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ fn test_into_iter_2d()
assert_eq!(v, [1, 3, 2, 4]);
}

#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[test]
fn test_into_iter_sliced()
{
Expand Down
5 changes: 5 additions & 0 deletions tests/oper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ fn scaled_add()
}

#[cfg(feature = "approx")]
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[test]
fn scaled_add_2()
{
Expand Down Expand Up @@ -540,6 +541,7 @@ fn scaled_add_2()
}

#[cfg(feature = "approx")]
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[test]
fn scaled_add_3()
{
Expand Down Expand Up @@ -592,6 +594,7 @@ fn scaled_add_3()
}

#[cfg(feature = "approx")]
#[cfg_attr(miri, ignore)]
#[test]
fn gen_mat_mul()
{
Expand Down Expand Up @@ -681,6 +684,7 @@ fn gen_mat_mul_i32()

#[cfg(feature = "approx")]
#[test]
#[cfg_attr(miri, ignore)] // Takes too long
fn gen_mat_vec_mul()
{
use approx::assert_relative_eq;
Expand Down Expand Up @@ -746,6 +750,7 @@ fn gen_mat_vec_mul()
}

#[cfg(feature = "approx")]
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[test]
fn vec_mat_mul()
{
Expand Down

0 comments on commit fd3ce5d

Please sign in to comment.