diff --git a/.gitignore b/.gitignore index 3ca43ae..193d30e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,8 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + + +# Added by cargo + +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5ac0304 --- /dev/null +++ b/Cargo.toml @@ -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] diff --git a/src/hdtest.rs b/src/hdtest.rs new file mode 100644 index 0000000..fb2a349 --- /dev/null +++ b/src/hdtest.rs @@ -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), + } +}