From 6e907fa6ec15bd51ff4de34e4e36edd655abfc26 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 13 Nov 2023 08:40:40 +0100 Subject: [PATCH] organize pass-dep tests more by the crate they test --- src/tools/miri/test_dependencies/Cargo.toml | 4 ++-- src/tools/miri/tests/pass-dep/getrandom.rs | 9 +++++++++ src/tools/miri/tests/pass-dep/getrandom_1.rs | 8 -------- src/tools/miri/tests/pass-dep/{random.rs => rand.rs} | 11 +++++++---- 4 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 src/tools/miri/tests/pass-dep/getrandom.rs delete mode 100644 src/tools/miri/tests/pass-dep/getrandom_1.rs rename src/tools/miri/tests/pass-dep/{random.rs => rand.rs} (61%) diff --git a/src/tools/miri/test_dependencies/Cargo.toml b/src/tools/miri/test_dependencies/Cargo.toml index 670f5c895cb..d54560608dc 100644 --- a/src/tools/miri/test_dependencies/Cargo.toml +++ b/src/tools/miri/test_dependencies/Cargo.toml @@ -12,8 +12,8 @@ edition = "2021" libc = "0.2" num_cpus = "1.10.1" -getrandom_1 = { package = "getrandom", version = "0.1" } -getrandom = { version = "0.2", features = ["js"] } +getrandom_01 = { package = "getrandom", version = "0.1" } +getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] } rand = { version = "0.8", features = ["small_rng"] } [target.'cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))'.dependencies] diff --git a/src/tools/miri/tests/pass-dep/getrandom.rs b/src/tools/miri/tests/pass-dep/getrandom.rs new file mode 100644 index 00000000000..60d6dd31e79 --- /dev/null +++ b/src/tools/miri/tests/pass-dep/getrandom.rs @@ -0,0 +1,9 @@ +// mac-os `getrandom_01` does some pointer shenanigans +//@compile-flags: -Zmiri-permissive-provenance + +/// Test direct calls of getrandom 0.1 and 0.2 +fn main() { + let mut data = vec![0; 16]; + getrandom_01::getrandom(&mut data).unwrap(); + getrandom_02::getrandom(&mut data).unwrap(); +} diff --git a/src/tools/miri/tests/pass-dep/getrandom_1.rs b/src/tools/miri/tests/pass-dep/getrandom_1.rs deleted file mode 100644 index 2c7bd93fbdb..00000000000 --- a/src/tools/miri/tests/pass-dep/getrandom_1.rs +++ /dev/null @@ -1,8 +0,0 @@ -// mac-os `getrandom_1` does some pointer shenanigans -//@compile-flags: -Zmiri-permissive-provenance - -/// Test old version of `getrandom`. -fn main() { - let mut data = vec![0; 16]; - getrandom_1::getrandom(&mut data).unwrap(); -} diff --git a/src/tools/miri/tests/pass-dep/random.rs b/src/tools/miri/tests/pass-dep/rand.rs similarity index 61% rename from src/tools/miri/tests/pass-dep/random.rs rename to src/tools/miri/tests/pass-dep/rand.rs index 0cd8b06d63d..0dce6d86cf4 100644 --- a/src/tools/miri/tests/pass-dep/random.rs +++ b/src/tools/miri/tests/pass-dep/rand.rs @@ -1,10 +1,13 @@ //@compile-flags: -Zmiri-strict-provenance -use rand::{rngs::SmallRng, Rng, SeedableRng}; +use rand::prelude::*; +// Test using the `rand` crate to generate randomness. fn main() { - // Test `getrandom` directly. - let mut data = vec![0; 16]; - getrandom::getrandom(&mut data).unwrap(); + // Fully deterministic seeding. + let mut rng = SmallRng::seed_from_u64(42); + let _val = rng.gen::(); + let _val = rng.gen::(); + let _val = rng.gen::(); // Try seeding with "real" entropy. let mut rng = SmallRng::from_entropy();