hardware-tests/src/tests/disk.rs
Gregory Ballantine dbd1068cc5
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Consolidated the test programs into one 'bgbench' program
2022-08-05 20:58:24 -04:00

30 lines
945 B
Rust

use std::fs;
use std::process::Command;
// test disk write speeds by continually writing zeroes to it
pub fn disk_write_test(tempfile: &str, size: &u8) {
// convert size in Gigabytes down to Megabytes
let size_gigs: u32 = (*size as u32 * 1024).into();
// run the dd command with a block size of 1 MB
let output = Command::new("dd")
.arg("bs=1M")
.arg(format!("count={}", size_gigs))
.arg("if=/dev/zero")
.arg(format!("of={}", tempfile))
.output()
.expect("Failed to execute command");
// check that the command succeeded
assert!(output.status.success());
// for whatever reason, `dd` output ends up in stderr
println!("{}", String::from_utf8_lossy(&output.stderr));
// remove the test file
match fs::remove_file(tempfile) {
Ok(()) => println!("Cleaning up..."),
Err(e) => println!("There was a problem during cleanup - {}", e),
}
}