5 Commits

Author SHA1 Message Date
7555a2a3a7 Version bump to v0.3.1
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-08-17 18:05:41 -04:00
9cd88d923d Changed the parameter for the network ping test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-08-17 18:03:48 -04:00
6fdc52b320 Updated the network bandwidth arguments to be more consistent with the disk command arguments
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-08-17 18:01:14 -04:00
f9ca8beaad Fixed the tempfile flags for some of the disk commands
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-08-17 17:58:04 -04:00
132a0ee501 Added a runtime parameter to the CPU stress test to automatically limit how long it runs
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-08-17 15:28:11 -04:00
4 changed files with 36 additions and 30 deletions

View File

@ -1,7 +1,7 @@
[package] [package]
name = "hardware-tests" name = "hardware-tests"
description = "Bit Goblin PC hardware test suite." description = "Bit Goblin PC hardware test suite."
version = "0.3.0" version = "0.3.1"
edition = "2021" edition = "2021"
readme = "README.md" readme = "README.md"
license = "BSD 2-Clause" license = "BSD 2-Clause"

View File

@ -4,12 +4,12 @@ use std::{fs,process};
use crate::text; use crate::text;
// ping a host // ping a host
pub fn ping_host(host: &str, count: &u16) { pub fn ping_host(address: &str, count: &u16) {
println!("Pinging host {}, {} times.", host, count); println!("Pinging host {}, {} times.", address, count);
// run the ping command // run the ping command
let output = process::Command::new("ping") let output = process::Command::new("ping")
.arg(host) .arg(address)
.arg(format!("-c {}", count)) .arg(format!("-c {}", count))
.output() .output()
.expect("Failed to execute command"); .expect("Failed to execute command");

View File

@ -39,7 +39,9 @@ enum CpuCommands {
// CPU stress test subcommand // CPU stress test subcommand
#[clap(name = "stress", about = "Stress test the CPU with math!")] #[clap(name = "stress", about = "Stress test the CPU with math!")]
StressTest { StressTest {
#[clap(short = 't', long, default_value_t = 0, help = "Number of threads to use; defaults to CPU's max thread count.")] #[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, threads: usize,
}, },
} }
@ -55,7 +57,7 @@ enum DiskCommands {
// sequential disk read subcommand // sequential disk read subcommand
#[clap(name = "read_seq", about = "Sequential disk read speed test.")] #[clap(name = "read_seq", about = "Sequential disk read speed test.")]
ReadSeqTest { ReadSeqTest {
#[clap(short = 'f', long, default_value_t = String::from("/tmp/disk-test.tmp"))] #[clap(short = 't', long, default_value_t = String::from("/tmp/disk-test.tmp"))]
tempfile: String, tempfile: String,
#[clap(short = 's', long, default_value_t = 15)] #[clap(short = 's', long, default_value_t = 15)]
size: u8, size: u8,
@ -64,7 +66,7 @@ enum DiskCommands {
// random disk read subcommand // random disk read subcommand
#[clap(name = "read_rand", about = "Random 4K disk read speed test.")] #[clap(name = "read_rand", about = "Random 4K disk read speed test.")]
ReadRandTest { ReadRandTest {
#[clap(short = 'f', long, default_value_t = String::from("/tmp/disk-test.tmp"))] #[clap(short = 't', long, default_value_t = String::from("/tmp/disk-test.tmp"))]
tempfile: String, tempfile: String,
#[clap(short = 's', long, default_value_t = 15)] #[clap(short = 's', long, default_value_t = 15)]
size: u8, size: u8,
@ -100,8 +102,8 @@ 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', long, default_value_t = String::from("8.8.8.8"))] #[clap(short = 'a', long, default_value_t = String::from("8.8.8.8"))]
host: String, address: String,
#[clap(short = 'c', long, default_value_t = 30)] #[clap(short = 'c', long, default_value_t = 30)]
count: u16, count: u16,
}, },
@ -111,7 +113,7 @@ enum NetCommands {
Bandwidth { Bandwidth {
#[clap(short = 'd', long, 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', long, default_value_t = String::from("./tempfile"))] #[clap(short = 't', long, default_value_t = String::from("/tmp/bw-test.tmp"))]
output: String, output: String,
}, },
} }
@ -122,7 +124,7 @@ 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 { Commands::Cpu(args) => match &args.cpu_commands {
CpuCommands::StressTest { threads } => stress::cpu::cpu_stress_math(*threads), CpuCommands::StressTest { runtime, threads } => stress::cpu::cpu_stress_math(*runtime, *threads),
}, },
Commands::Disk(args) => match &args.disk_commands { Commands::Disk(args) => match &args.disk_commands {
@ -153,10 +155,10 @@ fn main() {
} }
Commands::Net(args) => match &args.net_commands { Commands::Net(args) => match &args.net_commands {
NetCommands::Ping { host, count } => { NetCommands::Ping { address, count } => {
for i in 0..cli.loopcount { for i in 0..cli.loopcount {
println!("Test run number {}.", i + 1); println!("Test run number {}.", i + 1);
benchmarks::network::ping_host(host, count); benchmarks::network::ping_host(address, count);
} }
}, },
NetCommands::Bandwidth { download, output } => { NetCommands::Bandwidth { download, output } => {

View File

@ -1,28 +1,32 @@
use std::thread; use std::{thread, time};
use std::process::exit;
use sysinfo::{System,SystemExt}; use sysinfo::{System,SystemExt};
pub fn cpu_stress_math(threads: usize) { pub fn cpu_stress_math(runtime: u16, threads: usize) {
// fetch system information // fetch system information
let mut sys = System::new_all(); let mut sys = System::new_all();
sys.refresh_all(); sys.refresh_all();
let num_cpus = sys.cpus().len(); let num_cpus = sys.cpus().len();
let mut num_threads = threads; let mut num_threads = threads;
if num_threads == 0 { if num_threads == 0 {
println!("Number of threads not specified, defaulting to CPU's thread count of {}.", num_cpus); println!("Number of threads not specified, defaulting to CPU's thread count of {}.", num_cpus);
num_threads = num_cpus; num_threads = num_cpus;
} else { } else {
println!("Using specified thread count of {}", num_threads); println!("Using specified thread count of {}", num_threads);
} }
for i in 1..num_threads { for i in 0..num_threads {
println!("Spawning thread number {}", i); println!("Spawning thread number {}", i + 1);
thread::spawn (|| { thread::spawn (|| {
worker(); worker();
}); });
} }
println!("Using main as last thread");
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() { fn worker() {