2022-02-24 20:46:54 -05:00
|
|
|
use std::fs;
|
|
|
|
use std::process::Command;
|
|
|
|
|
2022-08-06 01:10:13 -04:00
|
|
|
// test disk sequential read speeds w/ fio
|
|
|
|
pub fn disk_read_seq_test(tempfile: &str, size: &u8) {
|
|
|
|
// run the fio command
|
|
|
|
let output = Command::new("fio")
|
|
|
|
.arg("--name=TEST")
|
|
|
|
.arg(format!("--filename={}", tempfile))
|
|
|
|
.arg("--rw=read")
|
|
|
|
.arg("--size=2g")
|
|
|
|
.arg(format!("--io_size={}g", size))
|
|
|
|
.arg("--blocksize=1024k")
|
|
|
|
.arg("--ioengine=libaio")
|
|
|
|
.arg("--fsync=10000")
|
|
|
|
.arg("--iodepth=32")
|
|
|
|
.arg("--direct=1")
|
|
|
|
.arg("--numjobs=1")
|
|
|
|
.arg("--runtime=60")
|
|
|
|
.arg("--group_reporting")
|
|
|
|
.output()
|
|
|
|
.expect("Failed to execute command");
|
2022-08-05 21:37:15 -04:00
|
|
|
|
2022-08-06 01:10:13 -04:00
|
|
|
// check that the command succeeded
|
|
|
|
assert!(output.status.success());
|
2022-08-05 21:37:15 -04:00
|
|
|
|
2022-08-06 01:10:13 -04:00
|
|
|
// print the test's output
|
|
|
|
println!("{}", String::from_utf8_lossy(&output.stdout));
|
|
|
|
}
|
|
|
|
|
|
|
|
// test disk 4K random read speeds w/ fio
|
|
|
|
pub fn disk_read_rand_test(tempfile: &str, size: &u8) {
|
|
|
|
// run the fio command
|
|
|
|
let output = Command::new("fio")
|
|
|
|
.arg("--name=TEST")
|
|
|
|
.arg(format!("--filename={}", tempfile))
|
|
|
|
.arg("--rw=randread")
|
|
|
|
.arg("--size=2g")
|
|
|
|
.arg(format!("--io_size={}g", size))
|
|
|
|
.arg("--blocksize=4k")
|
|
|
|
.arg("--ioengine=libaio")
|
|
|
|
.arg("--fsync=1")
|
|
|
|
.arg("--iodepth=32")
|
|
|
|
.arg("--direct=1")
|
|
|
|
.arg("--numjobs=1")
|
|
|
|
.arg("--runtime=60")
|
|
|
|
.arg("--group_reporting")
|
2022-08-05 21:37:15 -04:00
|
|
|
.output()
|
|
|
|
.expect("Failed to execute command");
|
|
|
|
|
|
|
|
// check that the command succeeded
|
|
|
|
assert!(output.status.success());
|
|
|
|
|
2022-08-06 01:10:13 -04:00
|
|
|
// print the test's output
|
|
|
|
println!("{}", String::from_utf8_lossy(&output.stdout));
|
2022-08-05 21:37:15 -04:00
|
|
|
}
|
|
|
|
|
2022-08-05 20:58:24 -04:00
|
|
|
// 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
|
2022-02-24 20:46:54 -05:00
|
|
|
let output = Command::new("dd")
|
|
|
|
.arg("bs=1M")
|
2022-08-05 20:58:24 -04:00
|
|
|
.arg(format!("count={}", size_gigs))
|
2022-02-24 20:46:54 -05:00
|
|
|
.arg("if=/dev/zero")
|
2022-08-05 20:58:24 -04:00
|
|
|
.arg(format!("of={}", tempfile))
|
2022-02-24 20:46:54 -05:00
|
|
|
.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
|
2022-08-05 20:58:24 -04:00
|
|
|
match fs::remove_file(tempfile) {
|
2022-02-24 20:46:54 -05:00
|
|
|
Ok(()) => println!("Cleaning up..."),
|
|
|
|
Err(e) => println!("There was a problem during cleanup - {}", e),
|
|
|
|
}
|
|
|
|
}
|