Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
360ef2f959 | |||
0f887d0c76 | |||
983b1cbeef | |||
d967fc0920 | |||
beffae7cd4 | |||
477ad7482a | |||
833c71bed5 | |||
182d9b3cb4 | |||
94218af170 | |||
9856c59da9 | |||
e41a4dfffb | |||
6f86266dee |
@ -2,12 +2,15 @@ pipeline:
|
|||||||
test_build:
|
test_build:
|
||||||
image: rust:1.62
|
image: rust:1.62
|
||||||
commands:
|
commands:
|
||||||
- cargo build
|
- "cargo build"
|
||||||
|
|
||||||
build_release:
|
build_release:
|
||||||
image: rust:1.62
|
image: rust:1.62
|
||||||
commands:
|
commands:
|
||||||
- cargo build --release
|
- "cargo install cargo-deb cargo-generate-rpm"
|
||||||
|
- "cargo build --release"
|
||||||
|
- "cargo deb"
|
||||||
|
- "cargo generate-rpm"
|
||||||
- "mv target/release/bgbench target/release/bgbench-${CI_COMMIT_TAG}-linux-x86_64"
|
- "mv target/release/bgbench target/release/bgbench-${CI_COMMIT_TAG}-linux-x86_64"
|
||||||
when:
|
when:
|
||||||
event: tag
|
event: tag
|
||||||
@ -20,6 +23,8 @@ pipeline:
|
|||||||
base_url: https://git.metaunix.net
|
base_url: https://git.metaunix.net
|
||||||
files:
|
files:
|
||||||
- "target/release/*${CI_COMMIT_TAG}-linux-x86_64"
|
- "target/release/*${CI_COMMIT_TAG}-linux-x86_64"
|
||||||
|
- "target/debian/hardware-tests*.deb"
|
||||||
|
- "target/generate-rpm/hardware-tests*.rpm"
|
||||||
title: "${CI_COMMIT_TAG}"
|
title: "${CI_COMMIT_TAG}"
|
||||||
when:
|
when:
|
||||||
event: tag
|
event: tag
|
||||||
|
19
Cargo.toml
19
Cargo.toml
@ -1,14 +1,27 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hardware-tests"
|
name = "hardware-tests"
|
||||||
version = "0.2.1"
|
description = "Bit Goblin PC hardware test suite."
|
||||||
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
readme = "README.md"
|
||||||
|
license = "BSD 2-Clause"
|
||||||
|
authors = ["Gregory Ballantine <gballantine@bitgoblin.tech>"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "bgbench"
|
name = "bgbench"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.20"
|
chrono = "0.4.20"
|
||||||
clap = { version = "3.2.16", features = ["derive"] }
|
clap = { version = "3.2.16", features = ["derive"] }
|
||||||
|
sysinfo = "0.25.1"
|
||||||
|
|
||||||
|
[package.metadata.deb]
|
||||||
|
depends = "fio"
|
||||||
|
|
||||||
|
[package.metadata.generate-rpm]
|
||||||
|
assets = [
|
||||||
|
{ source = "target/release/bgbench", dest = "/usr/bin/bgbench", mode = "755" },
|
||||||
|
]
|
||||||
|
[package.metadata.generate-rpm.requires]
|
||||||
|
fio = "*"
|
||||||
|
11
README.md
11
README.md
@ -1,6 +1,6 @@
|
|||||||
# Bit Goblin Hardware Tests
|
# Bit Goblin Hardware Tests
|
||||||
|
|
||||||
Scripts used for testing hardware in Bit Goblin's videos.
|
Benchmarking suite used for testing hardware in Bit Goblin's videos.
|
||||||
|
|
||||||
## Download & Installation
|
## Download & Installation
|
||||||
|
|
||||||
@ -8,9 +8,16 @@ Check out the [Releases page](https://git.metaunix.net/BitGoblin/hardware-tests/
|
|||||||
|
|
||||||
Currently there is no installation method other than downloading the provided release binaries. In the future I want to build Linux package repositories for this, and have a Windows installer.
|
Currently there is no installation method other than downloading the provided release binaries. In the future I want to build Linux package repositories for this, and have a Windows installer.
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
Simply run the tool with `./bgbench` and you'll be presented with the available subcommands.
|
||||||
|
|
||||||
|
### Runtime requirements:
|
||||||
|
* disk - requires `fio`.
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
The easiest way to build the program is using the official Rust image from Docker Hub, for which there's a wrapper script at `bin/docker-build.sh` that can be used to build the test programs. These will be available under `target/debug/`.
|
The easiest way to build the program is using the official Rust image from Docker Hub, for which there's a wrapper script at `bin/docker-build.sh` that can be used to build the test program. These will be available under `target/debug/`. Else you can just run a `cargo build` to compile the program.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
109
src/benchmarks/disk.rs
Normal file
109
src/benchmarks/disk.rs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
|
||||||
|
// check that the command succeeded
|
||||||
|
assert!(output.status.success());
|
||||||
|
|
||||||
|
// 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=1")
|
||||||
|
.arg("--direct=1")
|
||||||
|
.arg("--numjobs=32")
|
||||||
|
.arg("--runtime=60")
|
||||||
|
.arg("--group_reporting")
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
// check that the command succeeded
|
||||||
|
assert!(output.status.success());
|
||||||
|
|
||||||
|
// print the test's output
|
||||||
|
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
|
}
|
||||||
|
|
||||||
|
// test sequential disk write speeds w/ fio
|
||||||
|
pub fn disk_write_seq_test(tempfile: &str, size: &u8) {
|
||||||
|
// run the fio command
|
||||||
|
let output = Command::new("fio")
|
||||||
|
.arg("--name=TEST")
|
||||||
|
.arg(format!("--filename={}", tempfile))
|
||||||
|
.arg("--rw=write")
|
||||||
|
.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");
|
||||||
|
|
||||||
|
// check that the command succeeded
|
||||||
|
assert!(output.status.success());
|
||||||
|
|
||||||
|
// print the test's output
|
||||||
|
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
|
}
|
||||||
|
|
||||||
|
// test random 4K disk write speeds w/ fio
|
||||||
|
pub fn disk_write_rand_test(tempfile: &str, size: &u8) {
|
||||||
|
// run the fio command
|
||||||
|
let output = Command::new("fio")
|
||||||
|
.arg("--name=TEST")
|
||||||
|
.arg(format!("--filename={}", tempfile))
|
||||||
|
.arg("--rw=randrw")
|
||||||
|
.arg("--size=2g")
|
||||||
|
.arg(format!("--io_size={}g", size))
|
||||||
|
.arg("--blocksize=4k")
|
||||||
|
.arg("--ioengine=libaio")
|
||||||
|
.arg("--fsync=1")
|
||||||
|
.arg("--iodepth=1")
|
||||||
|
.arg("--direct=1")
|
||||||
|
.arg("--numjobs=32")
|
||||||
|
.arg("--runtime=60")
|
||||||
|
.arg("--group_reporting")
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
// check that the command succeeded
|
||||||
|
assert!(output.status.success());
|
||||||
|
|
||||||
|
// print the test's output
|
||||||
|
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use std::{fs,process};
|
use std::{fs,process};
|
||||||
|
|
||||||
|
use crate::text;
|
||||||
|
|
||||||
// ping a host
|
// ping a host
|
||||||
pub fn ping_host(host: &str, count: &u16) {
|
pub fn ping_host(host: &str, count: &u16) {
|
||||||
println!("Pinging host {}, {} times.", host, count);
|
println!("Pinging host {}, {} times.", host, count);
|
||||||
@ -15,8 +17,12 @@ pub fn ping_host(host: &str, count: &u16) {
|
|||||||
// check that the command succeeded
|
// check that the command succeeded
|
||||||
assert!(output.status.success());
|
assert!(output.status.success());
|
||||||
|
|
||||||
// print out the ping results from stdout
|
// grab the ping results from stdout
|
||||||
println!("{}", String::from_utf8_lossy(&output.stdout));
|
let results_raw = &String::from_utf8_lossy(&output.stdout);
|
||||||
|
let results = text::format::trim_output(results_raw, 4);
|
||||||
|
for line in results {
|
||||||
|
println!("{}", line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// timed file copy test to guage bandwidth speeds
|
// timed file copy test to guage bandwidth speeds
|
126
src/main.rs
126
src/main.rs
@ -1,6 +1,8 @@
|
|||||||
mod tests;
|
mod benchmarks;
|
||||||
|
mod stress;
|
||||||
|
mod text;
|
||||||
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Args, Parser, Subcommand};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(name = "Bit Goblin Benchmark", author, version, about = "Bit Goblin's hardware benchmarking tool.", long_about = None)]
|
#[clap(name = "Bit Goblin Benchmark", author, version, about = "Bit Goblin's hardware benchmarking tool.", long_about = None)]
|
||||||
@ -8,39 +10,81 @@ use clap::{Parser, Subcommand};
|
|||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
command: Commands,
|
command: Commands,
|
||||||
|
|
||||||
|
#[clap(short = 'l', long, default_value_t = 1, help = "Number of times to run test. Default = 1", global = true)]
|
||||||
|
loopcount: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
// disk tests subcommand
|
// CPU benchmarks subcommand
|
||||||
|
#[clap(name = "cpu", about = "CPU benchmarks and stress tests.")]
|
||||||
|
Cpu(Cpu),
|
||||||
|
// disk benchmarks subcommand
|
||||||
#[clap(name = "disk", about = "Hard drive and SSD benchmarks.")]
|
#[clap(name = "disk", about = "Hard drive and SSD benchmarks.")]
|
||||||
Disk(Disk),
|
Disk(Disk),
|
||||||
// network tests subcommand
|
// network benchmarks subcommand
|
||||||
#[clap(name = "network", about = "Test various aspects of your network.")]
|
#[clap(name = "network", about = "Test various aspects of your network.")]
|
||||||
Net(Net),
|
Net(Net),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Args)]
|
||||||
|
struct Cpu {
|
||||||
|
#[clap(subcommand)]
|
||||||
|
cpu_commands: CpuCommands,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
enum CpuCommands {
|
||||||
|
// CPU stress test subcommand
|
||||||
|
#[clap(name = "stress", about = "Stress test the CPU with math!")]
|
||||||
|
StressTest {
|
||||||
|
#[clap(short = 't', long, default_value_t = 0, help = "Number of threads to use; defaults to CPU's max thread count.")]
|
||||||
|
threads: usize,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
struct Disk {
|
struct Disk {
|
||||||
#[structopt(subcommand)]
|
#[clap(subcommand)]
|
||||||
disk_commands: DiskCommands,
|
disk_commands: DiskCommands,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum DiskCommands {
|
enum DiskCommands {
|
||||||
// disk read subcommand
|
// sequential disk read subcommand
|
||||||
#[clap(name = "read-test", about = "Read from /dev/zero to determine sequential disk read speeds.")]
|
#[clap(name = "read_seq", about = "Sequential disk read speed test.")]
|
||||||
ReadTest {
|
ReadSeqTest {
|
||||||
#[clap(short = 's', default_value_t = 15)]
|
#[clap(short = 'f', long, default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||||
|
tempfile: String,
|
||||||
|
#[clap(short = 's', long, default_value_t = 15)]
|
||||||
size: u8,
|
size: u8,
|
||||||
},
|
},
|
||||||
|
|
||||||
// disk write subcommand
|
// random disk read subcommand
|
||||||
#[clap(name = "write-test", about = "Write a large file to determine sequential disk write speeds.")]
|
#[clap(name = "read_rand", about = "Random 4K disk read speed test.")]
|
||||||
WriteTest {
|
ReadRandTest {
|
||||||
#[clap(short = 't', default_value_t = String::from("/tmp/disk-test.tmp"))]
|
#[clap(short = 'f', long, default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||||
tempfile: String,
|
tempfile: String,
|
||||||
#[clap(short = 's', default_value_t = 5)]
|
#[clap(short = 's', long, default_value_t = 15)]
|
||||||
|
size: u8,
|
||||||
|
},
|
||||||
|
|
||||||
|
// sequential disk write subcommand
|
||||||
|
#[clap(name = "write_seq", about = "Write a large file to determine sequential disk write speeds.")]
|
||||||
|
WriteSeqTest {
|
||||||
|
#[clap(short = 't', long, default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||||
|
tempfile: String,
|
||||||
|
#[clap(short = 's', long, default_value_t = 15)]
|
||||||
|
size: u8,
|
||||||
|
},
|
||||||
|
|
||||||
|
// random 4K disk write subcommand
|
||||||
|
#[clap(name = "write_rand", about = "Write a bunch of smallfiles to determine random disk write speeds.")]
|
||||||
|
WriteRandTest {
|
||||||
|
#[clap(short = 't', long, default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||||
|
tempfile: String,
|
||||||
|
#[clap(short = 's', long, default_value_t = 15)]
|
||||||
size: u8,
|
size: u8,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -56,18 +100,18 @@ enum NetCommands {
|
|||||||
// ping subcommand
|
// ping subcommand
|
||||||
#[clap(name = "ping", about = "Ping a host to determine network latency.")]
|
#[clap(name = "ping", about = "Ping a host to determine network latency.")]
|
||||||
Ping {
|
Ping {
|
||||||
#[clap(short = 't', default_value_t = String::from("8.8.8.8"))]
|
#[clap(short = 't', long, default_value_t = String::from("8.8.8.8"))]
|
||||||
host: String,
|
host: String,
|
||||||
#[clap(short = 'c', default_value_t = 30)]
|
#[clap(short = 'c', long, default_value_t = 30)]
|
||||||
count: u16,
|
count: u16,
|
||||||
},
|
},
|
||||||
|
|
||||||
// bandwidth test subcommand
|
// bandwidth test subcommand
|
||||||
#[clap(name = "bandwidth", about = "Downloads a remote file to determine network bandwidth.")]
|
#[clap(name = "bandwidth", about = "Downloads a remote file to determine network bandwidth.")]
|
||||||
Bandwidth {
|
Bandwidth {
|
||||||
#[clap(short = 'd', default_value_t = String::from("https://www.bitgoblin.tech/hardware-tests/export-01.mp4"))]
|
#[clap(short = 'd', long, default_value_t = String::from("https://www.bitgoblin.tech/hardware-tests/export-01.mp4"))]
|
||||||
download: String,
|
download: String,
|
||||||
#[clap(short = 'o', default_value_t = String::from("./tempfile"))]
|
#[clap(short = 'o', long, default_value_t = String::from("./tempfile"))]
|
||||||
output: String,
|
output: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -77,14 +121,50 @@ fn main() {
|
|||||||
|
|
||||||
// map subcommands back to the main command
|
// map subcommands back to the main command
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
|
Commands::Cpu(args) => match &args.cpu_commands {
|
||||||
|
CpuCommands::StressTest { threads } => stress::cpu::cpu_stress_math(*threads),
|
||||||
|
},
|
||||||
|
|
||||||
Commands::Disk(args) => match &args.disk_commands {
|
Commands::Disk(args) => match &args.disk_commands {
|
||||||
DiskCommands::ReadTest { size } => tests::disk::disk_read_test(size),
|
DiskCommands::ReadSeqTest { tempfile, size } => {
|
||||||
DiskCommands::WriteTest { tempfile, size } => tests::disk::disk_write_test(tempfile, size),
|
for i in 0..cli.loopcount {
|
||||||
|
println!("Test run number {}.", i + 1);
|
||||||
|
benchmarks::disk::disk_read_seq_test(tempfile, size);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
DiskCommands::ReadRandTest { tempfile, size } => {
|
||||||
|
for i in 0..cli.loopcount {
|
||||||
|
println!("Test run number {}.", i + 1);
|
||||||
|
benchmarks::disk::disk_read_rand_test(tempfile, size);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
DiskCommands::WriteSeqTest { tempfile, size } => {
|
||||||
|
for i in 0..cli.loopcount {
|
||||||
|
println!("Test run number {}.", i + 1);
|
||||||
|
benchmarks::disk::disk_write_seq_test(tempfile, size);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
DiskCommands::WriteRandTest { tempfile, size } => {
|
||||||
|
for i in 0..cli.loopcount {
|
||||||
|
println!("Test run number {}.", i + 1);
|
||||||
|
benchmarks::disk::disk_write_rand_test(tempfile, size);
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Net(args) => match &args.net_commands {
|
Commands::Net(args) => match &args.net_commands {
|
||||||
NetCommands::Ping { host, count } => tests::network::ping_host(host, count),
|
NetCommands::Ping { host, count } => {
|
||||||
NetCommands::Bandwidth { download, output } => tests::network::bandwidth_test(download, output),
|
for i in 0..cli.loopcount {
|
||||||
|
println!("Test run number {}.", i + 1);
|
||||||
|
benchmarks::network::ping_host(host, count);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
NetCommands::Bandwidth { download, output } => {
|
||||||
|
for i in 0..cli.loopcount {
|
||||||
|
println!("Test run number {}.", i + 1);
|
||||||
|
benchmarks::network::bandwidth_test(download, output);
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
src/stress/cpu.rs
Normal file
34
src/stress/cpu.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
use std::thread;
|
||||||
|
use sysinfo::{System,SystemExt};
|
||||||
|
|
||||||
|
pub fn cpu_stress_math(threads: usize) {
|
||||||
|
// fetch system information
|
||||||
|
let mut sys = System::new_all();
|
||||||
|
sys.refresh_all();
|
||||||
|
let num_cpus = sys.cpus().len();
|
||||||
|
|
||||||
|
let mut num_threads = threads;
|
||||||
|
if num_threads == 0 {
|
||||||
|
println!("Number of threads not specified, defaulting to CPU's thread count of {}.", num_cpus);
|
||||||
|
num_threads = num_cpus;
|
||||||
|
} else {
|
||||||
|
println!("Using specified thread count of {}", num_threads);
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 1..num_threads {
|
||||||
|
println!("Spawning thread number {}", i);
|
||||||
|
thread::spawn (|| {
|
||||||
|
worker();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
println!("Using main as last thread");
|
||||||
|
worker();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn worker() {
|
||||||
|
let mut _x = 0;
|
||||||
|
loop {
|
||||||
|
_x += 1;
|
||||||
|
_x -= 1;
|
||||||
|
}
|
||||||
|
}
|
1
src/stress/mod.rs
Normal file
1
src/stress/mod.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod cpu;
|
@ -1,56 +0,0 @@
|
|||||||
use std::fs;
|
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
// test disk read speeds by reading for /dev/zero and writing it to /dev/null
|
|
||||||
pub fn disk_read_test(size: &u8) {
|
|
||||||
// convert size in Gigabytes down to Megabytes
|
|
||||||
let size_gigs: u32 = (*size as u32 * 1024 * 8).into();
|
|
||||||
|
|
||||||
// run sync to clear out any disk caches prior to running
|
|
||||||
Command::new("sync");
|
|
||||||
|
|
||||||
// run the dd command
|
|
||||||
let output = Command::new("dd")
|
|
||||||
.arg("bs=128k")
|
|
||||||
.arg(format!("count={}", size_gigs))
|
|
||||||
.arg("if=/dev/zero")
|
|
||||||
.arg("of=/dev/null")
|
|
||||||
.output()
|
|
||||||
.expect("Failed to execute command");
|
|
||||||
|
|
||||||
// check that the command succeeded
|
|
||||||
assert!(output.status.success());
|
|
||||||
|
|
||||||
// dd's output ends up in stderr
|
|
||||||
println!("{}", String::from_utf8_lossy(&output.stderr));
|
|
||||||
|
|
||||||
// run another sync to clear out the disk's cache
|
|
||||||
Command::new("sync");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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),
|
|
||||||
}
|
|
||||||
}
|
|
8
src/text/format.rs
Normal file
8
src/text/format.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
use std::vec::Vec;
|
||||||
|
|
||||||
|
pub fn trim_output(text: &str, linecount: u16) -> Vec<&str> {
|
||||||
|
let text_vec: Vec<&str> = text.split("\n").collect();
|
||||||
|
let text_start = text_vec.len() - (linecount as usize);
|
||||||
|
let text_trim = text_vec.as_slice()[text_start..].to_vec();
|
||||||
|
return text_trim;
|
||||||
|
}
|
1
src/text/mod.rs
Normal file
1
src/text/mod.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod format;
|
Reference in New Issue
Block a user