Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Add configurable RNG seed to `OomTest` (#13373)

Nick Fitzgeraldae36b173d317
diff --git a/crates/fuzzing/src/oom.rs b/crates/fuzzing/src/oom.rs
index a7a9971454..38ff2ec909 100644
--- a/crates/fuzzing/src/oom.rs
+++ b/crates/fuzzing/src/oom.rs
@@ -207,6 +207,7 @@ pub struct OomTest {
max_iters: Option<u32>,
max_duration: Option<time::Duration>,
allow_alloc_after_oom: bool,
+ seed: u64,
}
impl OomTest {
@@ -226,6 +227,7 @@ impl OomTest {
max_iters: None,
max_duration: None,
allow_alloc_after_oom: false,
+ seed: 0,
}
}
@@ -250,6 +252,14 @@ impl OomTest {
self
}
+ /// Configure the seed for the RNG used in `fuzz` mode.
+ ///
+ /// The default is `0`.
+ pub fn seed(&mut self, seed: u64) -> &mut Self {
+ self.seed = seed;
+ self
+ }
+
/// Repeatedly run the given test function, injecting OOMs at different
/// times and checking that it correctly handles them.
///
@@ -308,7 +318,7 @@ impl OomTest {
return Ok(());
}
- let mut rng = SmallRng::seed_from_u64(0);
+ let mut rng = SmallRng::seed_from_u64(self.seed);
for _ in 0..max_iters {
let i = rng.random_range(0..total_allocs);