Skip to content

Commit fd3ce5d

Browse files
authored
Adds Miri to CI/CD (#1446)
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.
1 parent 492b274 commit fd3ce5d

File tree

9 files changed

+42
-1
lines changed

9 files changed

+42
-1
lines changed

Diff for: .github/workflows/ci.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ jobs:
8888
run: sudo apt-get install libopenblas-dev gfortran
8989
- run: ./scripts/all-tests.sh "$FEATURES" ${{ matrix.rust }}
9090

91+
miri:
92+
runs-on: ubuntu-latest
93+
name: miri
94+
steps:
95+
- uses: actions/checkout@v4
96+
- uses: dtolnay/rust-toolchain@nightly
97+
with:
98+
components: miri
99+
- uses: Swatinem/rust-cache@v2
100+
- run: ./scripts/miri-tests.sh
101+
91102
cross_test:
92103
#if: ${{ github.event_name == 'merge_group' }}
93104
runs-on: ubuntu-latest
@@ -149,6 +160,7 @@ jobs:
149160
- format # should format be required?
150161
- nostd
151162
- tests
163+
- miri
152164
- cross_test
153165
- cargo-careful
154166
- docs

Diff for: ndarray-rand/tests/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ fn oversampling_without_replacement_should_panic()
5757
}
5858

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

8788
#[cfg(feature = "quickcheck")]
8889
quickcheck! {
90+
#[cfg_attr(miri, ignore)] // This takes *forever* with Miri
8991
fn sampling_behaves_as_expected(m: u8, n: u8, strategy: SamplingStrategy) -> TestResult {
9092
let (m, n) = (m as usize, n as usize);
9193
let a = Array::random((m, n), Uniform::new(0., 2.));

Diff for: scripts/miri-tests.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
set -x
4+
set -e
5+
6+
# We rely on layout-dependent casts, which should be covered with #[repr(transparent)]
7+
# This should catch if we missed that
8+
RUSTFLAGS="-Zrandomize-layout"
9+
10+
# Miri reports a stacked borrow violation deep within rayon, in a crate called crossbeam-epoch
11+
# The crate has a PR to fix this: https://github.com/crossbeam-rs/crossbeam/pull/871
12+
# but using Miri's tree borrow mode may resolve it for now.
13+
# Disabled until we can figure out a different rayon issue: https://github.com/rust-lang/miri/issues/1371
14+
# MIRIFLAGS="-Zmiri-tree-borrows"
15+
16+
# General tests
17+
# Note that we exclude blas feature because Miri can't do cblas_gemm
18+
cargo miri test -v -p ndarray -p ndarray-rand --features approx,serde

Diff for: src/dimension/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,7 @@ mod test
10201020
}
10211021

10221022
quickcheck! {
1023+
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
10231024
// FIXME: This test is extremely slow, even with i16 values, investigate
10241025
fn arith_seq_intersect_correct(
10251026
first1: i8, len1: i8, step1: i8,

Diff for: tests/array.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2629,6 +2629,7 @@ mod array_cow_tests
26292629
});
26302630
}
26312631

2632+
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
26322633
#[test]
26332634
fn test_clone_from()
26342635
{

Diff for: tests/azip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn test_azip2_sum()
216216
}
217217

218218
#[test]
219-
#[cfg(feature = "approx")]
219+
#[cfg(all(feature = "approx", feature = "std"))]
220220
fn test_azip3_slices()
221221
{
222222
use approx::assert_abs_diff_eq;

Diff for: tests/dimension.rs

+1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ fn test_array_view()
323323
}
324324

325325
#[test]
326+
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
326327
#[cfg(feature = "std")]
327328
#[allow(clippy::cognitive_complexity)]
328329
fn test_all_ndindex()

Diff for: tests/iterators.rs

+1
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ fn test_into_iter_2d()
971971
assert_eq!(v, [1, 3, 2, 4]);
972972
}
973973

974+
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
974975
#[test]
975976
fn test_into_iter_sliced()
976977
{

Diff for: tests/oper.rs

+5
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ fn scaled_add()
502502
}
503503

504504
#[cfg(feature = "approx")]
505+
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
505506
#[test]
506507
fn scaled_add_2()
507508
{
@@ -540,6 +541,7 @@ fn scaled_add_2()
540541
}
541542

542543
#[cfg(feature = "approx")]
544+
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
543545
#[test]
544546
fn scaled_add_3()
545547
{
@@ -592,6 +594,7 @@ fn scaled_add_3()
592594
}
593595

594596
#[cfg(feature = "approx")]
597+
#[cfg_attr(miri, ignore)]
595598
#[test]
596599
fn gen_mat_mul()
597600
{
@@ -681,6 +684,7 @@ fn gen_mat_mul_i32()
681684

682685
#[cfg(feature = "approx")]
683686
#[test]
687+
#[cfg_attr(miri, ignore)] // Takes too long
684688
fn gen_mat_vec_mul()
685689
{
686690
use approx::assert_relative_eq;
@@ -746,6 +750,7 @@ fn gen_mat_vec_mul()
746750
}
747751

748752
#[cfg(feature = "approx")]
753+
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
749754
#[test]
750755
fn vec_mat_mul()
751756
{

0 commit comments

Comments
 (0)