Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Miri to CI #781

Merged
merged 3 commits into from Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
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
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
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
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
Expand Up @@ -304,27 +304,29 @@ mod test {
use distributions::Distribution;
use super::{Beta, ChiSquared, StudentT, FisherF};

const N: u32 = 100;
dhardy marked this conversation as resolved.
Show resolved Hide resolved

#[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
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
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
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
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
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
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
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
@@ -0,0 +1,19 @@
set -ex

if rustup component add miri ; then
dhardy marked this conversation as resolved.
Show resolved Hide resolved
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