Skip to content

Commit

Permalink
Merge pull request #781 from RalfJung/miri
Browse files Browse the repository at this point in the history
add Miri to CI
  • Loading branch information
dhardy authored Apr 23, 2019
2 parents 8f186ab + 39a312c commit d998742
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/distributions/bernoulli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/distributions/binomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/distributions/cauchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
14 changes: 8 additions & 6 deletions src/distributions/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,29 @@ 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);
}
}
#[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);
}
}
#[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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/distributions/poisson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/distributions/uniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/distributions/weighted/alias_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/distributions/weighted/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/seq/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ mod test {
}

#[test]
#[cfg(not(miri))] // Miri is too slow
fn test_sample_alg() {
let seed_rng = ::test::rng;

Expand Down
3 changes: 3 additions & 0 deletions src/seq/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R: Rng + ?Sized, Iter: Iterator<Item=usize> + Clone>(r: &mut R, iter: Iter) {
Expand Down Expand Up @@ -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 [];
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions utils/ci/miri.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d998742

Please sign in to comment.