Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
7555a2a3a7 | |||
9cd88d923d | |||
6fdc52b320 | |||
f9ca8beaad | |||
132a0ee501 | |||
360ef2f959 | |||
0f887d0c76 | |||
983b1cbeef | |||
d967fc0920 |
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "hardware-tests"
|
||||
description = "Bit Goblin PC hardware test suite."
|
||||
version = "0.2.4"
|
||||
version = "0.3.1"
|
||||
edition = "2021"
|
||||
readme = "README.md"
|
||||
license = "BSD 2-Clause"
|
||||
@ -14,6 +14,7 @@ path = "src/main.rs"
|
||||
[dependencies]
|
||||
chrono = "0.4.20"
|
||||
clap = { version = "3.2.16", features = ["derive"] }
|
||||
sysinfo = "0.25.1"
|
||||
|
||||
[package.metadata.deb]
|
||||
depends = "fio"
|
||||
|
@ -1,13 +1,15 @@
|
||||
use chrono::prelude::*;
|
||||
use std::{fs,process};
|
||||
|
||||
use crate::text;
|
||||
|
||||
// ping a host
|
||||
pub fn ping_host(host: &str, count: &u16) {
|
||||
println!("Pinging host {}, {} times.", host, count);
|
||||
pub fn ping_host(address: &str, count: &u16) {
|
||||
println!("Pinging host {}, {} times.", address, count);
|
||||
|
||||
// run the ping command
|
||||
let output = process::Command::new("ping")
|
||||
.arg(host)
|
||||
.arg(address)
|
||||
.arg(format!("-c {}", count))
|
||||
.output()
|
||||
.expect("Failed to execute command");
|
||||
@ -15,8 +17,12 @@ pub fn ping_host(host: &str, count: &u16) {
|
||||
// check that the command succeeded
|
||||
assert!(output.status.success());
|
||||
|
||||
// print out the ping results from stdout
|
||||
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||
// grab the ping results from 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
|
75
src/main.rs
75
src/main.rs
@ -1,4 +1,6 @@
|
||||
mod tests;
|
||||
mod benchmarks;
|
||||
mod stress;
|
||||
mod text;
|
||||
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
|
||||
@ -9,20 +11,41 @@ struct Cli {
|
||||
#[clap(subcommand)]
|
||||
command: Commands,
|
||||
|
||||
#[clap(short = 'l', default_value_t = 1, help = "Number of times to run test. Default = 1", global = true)]
|
||||
#[clap(short = 'l', long, default_value_t = 1, help = "Number of times to run test. Default = 1", global = true)]
|
||||
loopcount: u8,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
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.")]
|
||||
Disk(Disk),
|
||||
// network tests subcommand
|
||||
// network benchmarks subcommand
|
||||
#[clap(name = "network", about = "Test various aspects of your network.")]
|
||||
Net(Net),
|
||||
}
|
||||
|
||||
#[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 = 'r', long, default_value_t = 5, help = "Length of time (in minutes) to run the stress test. Defaults to 5")]
|
||||
runtime: u16,
|
||||
#[clap(short = 't', long, default_value_t = 0, help = "Number of threads to use; defaults to CPU's max thread count. Defaults to 0 (automatic)")]
|
||||
threads: usize,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct Disk {
|
||||
#[clap(subcommand)]
|
||||
@ -34,36 +57,36 @@ enum DiskCommands {
|
||||
// sequential disk read subcommand
|
||||
#[clap(name = "read_seq", about = "Sequential disk read speed test.")]
|
||||
ReadSeqTest {
|
||||
#[clap(short = 'f', default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||
#[clap(short = 't', long, default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||
tempfile: String,
|
||||
#[clap(short = 's', default_value_t = 15)]
|
||||
#[clap(short = 's', long, default_value_t = 15)]
|
||||
size: u8,
|
||||
},
|
||||
|
||||
// random disk read subcommand
|
||||
#[clap(name = "read_rand", about = "Random 4K disk read speed test.")]
|
||||
ReadRandTest {
|
||||
#[clap(short = 'f', default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||
#[clap(short = 't', long, default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||
tempfile: String,
|
||||
#[clap(short = 's', default_value_t = 15)]
|
||||
#[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', default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||
#[clap(short = 't', long, default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||
tempfile: String,
|
||||
#[clap(short = 's', default_value_t = 15)]
|
||||
#[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', default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||
#[clap(short = 't', long, default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||
tempfile: String,
|
||||
#[clap(short = 's', default_value_t = 15)]
|
||||
#[clap(short = 's', long, default_value_t = 15)]
|
||||
size: u8,
|
||||
},
|
||||
}
|
||||
@ -79,18 +102,18 @@ enum NetCommands {
|
||||
// ping subcommand
|
||||
#[clap(name = "ping", about = "Ping a host to determine network latency.")]
|
||||
Ping {
|
||||
#[clap(short = 't', default_value_t = String::from("8.8.8.8"))]
|
||||
host: String,
|
||||
#[clap(short = 'c', default_value_t = 30)]
|
||||
#[clap(short = 'a', long, default_value_t = String::from("8.8.8.8"))]
|
||||
address: String,
|
||||
#[clap(short = 'c', long, default_value_t = 30)]
|
||||
count: u16,
|
||||
},
|
||||
|
||||
// bandwidth test subcommand
|
||||
#[clap(name = "bandwidth", about = "Downloads a remote file to determine network 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,
|
||||
#[clap(short = 'o', default_value_t = String::from("./tempfile"))]
|
||||
#[clap(short = 't', long, default_value_t = String::from("/tmp/bw-test.tmp"))]
|
||||
output: String,
|
||||
},
|
||||
}
|
||||
@ -100,44 +123,48 @@ fn main() {
|
||||
|
||||
// map subcommands back to the main command
|
||||
match &cli.command {
|
||||
Commands::Cpu(args) => match &args.cpu_commands {
|
||||
CpuCommands::StressTest { runtime, threads } => stress::cpu::cpu_stress_math(*runtime, *threads),
|
||||
},
|
||||
|
||||
Commands::Disk(args) => match &args.disk_commands {
|
||||
DiskCommands::ReadSeqTest { tempfile, size } => {
|
||||
for i in 0..cli.loopcount {
|
||||
println!("Test run number {}.", i + 1);
|
||||
tests::disk::disk_read_seq_test(tempfile, size);
|
||||
benchmarks::disk::disk_read_seq_test(tempfile, size);
|
||||
}
|
||||
},
|
||||
DiskCommands::ReadRandTest { tempfile, size } => {
|
||||
for i in 0..cli.loopcount {
|
||||
println!("Test run number {}.", i + 1);
|
||||
tests::disk::disk_read_rand_test(tempfile, size);
|
||||
benchmarks::disk::disk_read_rand_test(tempfile, size);
|
||||
}
|
||||
},
|
||||
DiskCommands::WriteSeqTest { tempfile, size } => {
|
||||
for i in 0..cli.loopcount {
|
||||
println!("Test run number {}.", i + 1);
|
||||
tests::disk::disk_write_seq_test(tempfile, size);
|
||||
benchmarks::disk::disk_write_seq_test(tempfile, size);
|
||||
}
|
||||
},
|
||||
DiskCommands::WriteRandTest { tempfile, size } => {
|
||||
for i in 0..cli.loopcount {
|
||||
println!("Test run number {}.", i + 1);
|
||||
tests::disk::disk_write_rand_test(tempfile, size);
|
||||
benchmarks::disk::disk_write_rand_test(tempfile, size);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Commands::Net(args) => match &args.net_commands {
|
||||
NetCommands::Ping { host, count } => {
|
||||
NetCommands::Ping { address, count } => {
|
||||
for i in 0..cli.loopcount {
|
||||
println!("Test run number {}.", i + 1);
|
||||
tests::network::ping_host(host, count);
|
||||
benchmarks::network::ping_host(address, count);
|
||||
}
|
||||
},
|
||||
NetCommands::Bandwidth { download, output } => {
|
||||
for i in 0..cli.loopcount {
|
||||
println!("Test run number {}.", i + 1);
|
||||
tests::network::bandwidth_test(download, output);
|
||||
benchmarks::network::bandwidth_test(download, output);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
38
src/stress/cpu.rs
Normal file
38
src/stress/cpu.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use std::{thread, time};
|
||||
use std::process::exit;
|
||||
use sysinfo::{System,SystemExt};
|
||||
|
||||
pub fn cpu_stress_math(runtime: u16, 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 0..num_threads {
|
||||
println!("Spawning thread number {}", i + 1);
|
||||
thread::spawn (|| {
|
||||
worker();
|
||||
});
|
||||
}
|
||||
|
||||
println!("Sleeping main thread for the allotted runtime of {} minute(s).", runtime);
|
||||
let duration = time::Duration::from_secs((runtime * 60).into());
|
||||
thread::sleep(duration);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
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;
|
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