Added a simple program that tests a disk's write speed

This commit is contained in:
Gregory Ballantine 2022-02-24 20:46:54 -05:00
parent 002fb2fc88
commit 04ebc2290f
3 changed files with 42 additions and 0 deletions

5
.gitignore vendored
View File

@ -14,3 +14,8 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information # MSVC Windows builds of rustc generate these, which store debugging information
*.pdb *.pdb
# Added by cargo
/target

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "hardware-tests"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "hdtest"
path = "src/hdtest.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

25
src/hdtest.rs Normal file
View File

@ -0,0 +1,25 @@
use std::fs;
use std::process::Command;
fn main() {
// run the dd command with a block size of 1 MB, 10K times (10GB file)
let output = Command::new("dd")
.arg("bs=1M")
.arg("count=10240")
.arg("if=/dev/zero")
.arg("of=./speed-test")
.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("./speed-test") {
Ok(()) => println!("Cleaning up..."),
Err(e) => println!("There was a problem during cleanup - {}", e),
}
}