aboutsummaryrefslogtreecommitdiff
path: root/tests/utils/src/bin/saturate_serial.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utils/src/bin/saturate_serial.rs')
-rw-r--r--tests/utils/src/bin/saturate_serial.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/utils/src/bin/saturate_serial.rs b/tests/utils/src/bin/saturate_serial.rs
index 18ca12fb7..85676b106 100644
--- a/tests/utils/src/bin/saturate_serial.rs
+++ b/tests/utils/src/bin/saturate_serial.rs
@@ -2,7 +2,7 @@ use std::path::Path;
2use std::time::Duration; 2use std::time::Duration;
3use std::{env, io, process, thread}; 3use std::{env, io, process, thread};
4 4
5use rand::random; 5use rand::{rng, Rng};
6use serial::SerialPort; 6use serial::SerialPort;
7 7
8pub fn main() { 8pub fn main() {
@@ -34,14 +34,15 @@ fn saturate<T: SerialPort>(port: &mut T, idles: bool) -> io::Result<()> {
34 })?; 34 })?;
35 35
36 let mut written = 0; 36 let mut written = 0;
37 let mut rng = rng();
37 loop { 38 loop {
38 let len = random::<usize>() % 0x1000; 39 let len = rng.random_range(1..=0x1000);
39 let buf: Vec<u8> = (written..written + len).map(|x| x as u8).collect(); 40 let buf: Vec<u8> = (written..written + len).map(|x| x as u8).collect();
40 41
41 port.write_all(&buf)?; 42 port.write_all(&buf)?;
42 43
43 if idles { 44 if idles {
44 let micros = (random::<usize>() % 1000) as u64; 45 let micros = rng.random_range(1..=1000) as u64;
45 println!("Sleeping {}us", micros); 46 println!("Sleeping {}us", micros);
46 port.flush().unwrap(); 47 port.flush().unwrap();
47 thread::sleep(Duration::from_micros(micros)); 48 thread::sleep(Duration::from_micros(micros));