diff --git a/.travis.yml b/.travis.yml index 565550d8e39..4e754799448 100644 --- a/.travis.yml +++ b/.travis.yml @@ -256,6 +256,12 @@ matrix: script: - bash utils/ci/script.sh + - rust: nightly + os: linux + env: DESCRIPTION="Miri, nightly" + script: + - sh utils/ci/miri.sh + before_install: - set -e - rustup self update diff --git a/src/distributions/bernoulli.rs b/src/distributions/bernoulli.rs index f49618c67d5..23ef9044931 100644 --- a/src/distributions/bernoulli.rs +++ b/src/distributions/bernoulli.rs @@ -137,6 +137,7 @@ mod test { } #[test] + #[cfg(not(miri))] // Miri is too slow fn test_average() { const P: f64 = 0.3; const NUM: u32 = 3; diff --git a/src/distributions/binomial.rs b/src/distributions/binomial.rs index c4edd217843..434b9d6425b 100644 --- a/src/distributions/binomial.rs +++ b/src/distributions/binomial.rs @@ -287,6 +287,7 @@ mod test { } #[test] + #[cfg(not(miri))] // Miri is too slow fn test_binomial() { let mut rng = ::test::rng(351); test_binomial_mean_and_variance(150, 0.1, &mut rng); diff --git a/src/distributions/cauchy.rs b/src/distributions/cauchy.rs index f02fd33785d..9ffd5601ae6 100644 --- a/src/distributions/cauchy.rs +++ b/src/distributions/cauchy.rs @@ -67,6 +67,7 @@ mod test { } #[test] + #[cfg(not(miri))] // Miri doesn't support transcendental functions fn test_cauchy_median() { let cauchy = Cauchy::new(10.0, 5.0); let mut rng = ::test::rng(123); @@ -80,6 +81,7 @@ mod test { } #[test] + #[cfg(not(miri))] // Miri doesn't support transcendental functions fn test_cauchy_mean() { let cauchy = Cauchy::new(10.0, 5.0); let mut rng = ::test::rng(123); diff --git a/src/distributions/gamma.rs b/src/distributions/gamma.rs index 7cefac42bd1..90f07cedfae 100644 --- a/src/distributions/gamma.rs +++ b/src/distributions/gamma.rs @@ -304,11 +304,13 @@ mod test { use distributions::Distribution; use super::{Beta, ChiSquared, StudentT, FisherF}; + const N: u32 = 100; + #[test] fn test_chi_squared_one() { let chi = ChiSquared::new(1.0); let mut rng = ::test::rng(201); - for _ in 0..1000 { + for _ in 0..N { chi.sample(&mut rng); } } @@ -316,7 +318,7 @@ mod test { fn test_chi_squared_small() { let chi = ChiSquared::new(0.5); let mut rng = ::test::rng(202); - for _ in 0..1000 { + for _ in 0..N { chi.sample(&mut rng); } } @@ -324,7 +326,7 @@ mod test { fn test_chi_squared_large() { let chi = ChiSquared::new(30.0); let mut rng = ::test::rng(203); - for _ in 0..1000 { + for _ in 0..N { chi.sample(&mut rng); } } @@ -338,7 +340,7 @@ mod test { fn test_f() { let f = FisherF::new(2.0, 32.0); let mut rng = ::test::rng(204); - for _ in 0..1000 { + for _ in 0..N { f.sample(&mut rng); } } @@ -347,7 +349,7 @@ mod test { fn test_t() { let t = StudentT::new(11.0); let mut rng = ::test::rng(205); - for _ in 0..1000 { + for _ in 0..N { t.sample(&mut rng); } } @@ -356,7 +358,7 @@ mod test { fn test_beta() { let beta = Beta::new(1.0, 2.0); let mut rng = ::test::rng(201); - for _ in 0..1000 { + for _ in 0..N { beta.sample(&mut rng); } } diff --git a/src/distributions/poisson.rs b/src/distributions/poisson.rs index 1931f80e979..22b7e76baa8 100644 --- a/src/distributions/poisson.rs +++ b/src/distributions/poisson.rs @@ -109,6 +109,7 @@ mod test { use super::Poisson; #[test] + #[cfg(not(miri))] // Miri is too slow fn test_poisson_10() { let poisson = Poisson::new(10.0); let mut rng = ::test::rng(123); @@ -122,6 +123,7 @@ mod test { } #[test] + #[cfg(not(miri))] // Miri doesn't support transcendental functions fn test_poisson_15() { // Take the 'high expected values' path let poisson = Poisson::new(15.0); diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs index 19b49345b37..b8559d36280 100644 --- a/src/distributions/uniform.rs +++ b/src/distributions/uniform.rs @@ -972,6 +972,7 @@ mod tests { } #[test] + #[cfg(not(miri))] // Miri is too slow fn test_integers() { use core::{i8, i16, i32, i64, isize}; use core::{u8, u16, u32, u64, usize}; @@ -1056,6 +1057,7 @@ mod tests { } #[test] + #[cfg(not(miri))] // Miri is too slow fn test_floats() { let mut rng = ::test::rng(252); let mut zero_rng = StepRng::new(0, 0); @@ -1140,6 +1142,7 @@ mod tests { #[cfg(all(feature="std", not(target_arch = "wasm32"), not(target_arch = "asmjs")))] + #[cfg(not(miri))] // Miri does not support catching panics fn test_float_assertions() { use std::panic::catch_unwind; use super::SampleUniform; @@ -1195,6 +1198,7 @@ mod tests { #[test] #[cfg(any(feature = "std", rustc_1_25))] + #[cfg(not(miri))] // Miri is too slow fn test_durations() { #[cfg(feature = "std")] use std::time::Duration; diff --git a/src/distributions/weighted/alias_method.rs b/src/distributions/weighted/alias_method.rs index cc2eb7b27c2..fef4b619b0d 100644 --- a/src/distributions/weighted/alias_method.rs +++ b/src/distributions/weighted/alias_method.rs @@ -362,6 +362,7 @@ mod test { use super::*; #[test] + #[cfg(not(miri))] // Miri is too slow fn test_weighted_index_f32() { test_weighted_index(f32::into); @@ -390,12 +391,14 @@ mod test { #[cfg(all(rustc_1_26, not(target_os = "emscripten")))] #[test] + #[cfg(not(miri))] // Miri is too slow fn test_weighted_index_u128() { test_weighted_index(|x: u128| x as f64); } #[cfg(all(rustc_1_26, not(target_os = "emscripten")))] #[test] + #[cfg(not(miri))] // Miri is too slow fn test_weighted_index_i128() { test_weighted_index(|x: i128| x as f64); @@ -411,11 +414,13 @@ mod test { } #[test] + #[cfg(not(miri))] // Miri is too slow fn test_weighted_index_u8() { test_weighted_index(u8::into); } #[test] + #[cfg(not(miri))] // Miri is too slow fn test_weighted_index_i8() { test_weighted_index(i8::into); diff --git a/src/distributions/weighted/mod.rs b/src/distributions/weighted/mod.rs index 92397ea668b..df388e70aab 100644 --- a/src/distributions/weighted/mod.rs +++ b/src/distributions/weighted/mod.rs @@ -140,6 +140,7 @@ mod test { use super::*; #[test] + #[cfg(not(miri))] // Miri is too slow fn test_weightedindex() { let mut r = ::test::rng(700); const N_REPS: u32 = 5000; diff --git a/src/lib.rs b/src/lib.rs index c7d0577da21..35ac0b94d48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -694,6 +694,7 @@ mod test { } #[test] + #[cfg(not(miri))] // Miri is too slow fn test_gen_ratio_average() { const NUM: u32 = 3; const DENOM: u32 = 10; diff --git a/src/seq/index.rs b/src/seq/index.rs index c64357acc3b..79ed6c0ec7e 100644 --- a/src/seq/index.rs +++ b/src/seq/index.rs @@ -339,6 +339,7 @@ mod test { } #[test] + #[cfg(not(miri))] // Miri is too slow fn test_sample_alg() { let seed_rng = ::test::rng; diff --git a/src/seq/mod.rs b/src/seq/mod.rs index 7731708e220..e4cca760f47 100644 --- a/src/seq/mod.rs +++ b/src/seq/mod.rs @@ -539,6 +539,7 @@ mod test { } #[test] + #[cfg(not(miri))] // Miri is too slow fn test_iterator_choose() { let r = &mut ::test::rng(109); fn test_iter + Clone>(r: &mut R, iter: Iter) { @@ -570,6 +571,7 @@ mod test { } #[test] + #[cfg(not(miri))] // Miri is too slow fn test_shuffle() { let mut r = ::test::rng(108); let empty: &mut [isize] = &mut []; @@ -655,6 +657,7 @@ mod test { #[test] #[cfg(feature = "alloc")] + #[cfg(not(miri))] // Miri is too slow fn test_weighted() { let mut r = ::test::rng(406); const N_REPS: u32 = 3000; diff --git a/utils/ci/miri.sh b/utils/ci/miri.sh new file mode 100644 index 00000000000..0d8cf2a5ade --- /dev/null +++ b/utils/ci/miri.sh @@ -0,0 +1,19 @@ +set -ex + +if rustup component add miri ; then + cargo miri setup + + cargo miri test --no-default-features -- -Zmiri-seed=42 -- -Zunstable-options --exclude-should-panic + cargo miri test --features=serde1,log -- -Zmiri-seed=42 -- -Zunstable-options --exclude-should-panic + cargo miri test --manifest-path rand_core/Cargo.toml + cargo miri test --manifest-path rand_core/Cargo.toml --no-default-features + #cargo miri test --manifest-path rand_distr/Cargo.toml # no unsafe and lots of slow tests + cargo miri test --manifest-path rand_isaac/Cargo.toml --features=serde1 + cargo miri test --manifest-path rand_pcg/Cargo.toml --features=serde1 + cargo miri test --manifest-path rand_xorshift/Cargo.toml --features=serde1 + cargo miri test --manifest-path rand_xoshiro/Cargo.toml + cargo miri test --manifest-path rand_chacha/Cargo.toml + cargo miri test --manifest-path rand_hc/Cargo.toml + cargo miri test --manifest-path rand_jitter/Cargo.toml + cargo miri test --manifest-path rand_os/Cargo.toml -- -Zmiri-seed=42 +fi