Compare commits

..

No commits in common. "master" and "v0.3.0" have entirely different histories.

10 changed files with 68 additions and 282 deletions

View File

@ -1,11 +1,11 @@
pipeline: pipeline:
test_build: test_build:
image: rust:1.75 image: rust:1.62
commands: commands:
- "cargo build" - "cargo build"
build_release: build_release:
image: rust:1.75 image: rust:1.62
commands: commands:
- "cargo install cargo-deb cargo-generate-rpm" - "cargo install cargo-deb cargo-generate-rpm"
- "cargo build --release" - "cargo build --release"

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.4.1" version = "0.3.0"
edition = "2021" edition = "2021"
readme = "README.md" readme = "README.md"
license = "BSD 2-Clause" license = "BSD 2-Clause"
@ -12,9 +12,9 @@ name = "bgbench"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [dependencies]
chrono = "0.4" chrono = "0.4.20"
clap = { version = "3.2", features = ["derive"] } clap = { version = "3.2.16", features = ["derive"] }
sysinfo = "0.25" sysinfo = "0.25.1"
[package.metadata.deb] [package.metadata.deb]
depends = "fio" depends = "fio"

View File

@ -13,8 +13,7 @@ Currently there is no installation method other than downloading the provided re
Simply run the tool with `./bgbench` and you'll be presented with the available subcommands. Simply run the tool with `./bgbench` and you'll be presented with the available subcommands.
### Runtime requirements: ### Runtime requirements:
* `disk` - requires `fio`. * disk - requires `fio`.
* `network bandwidth` - requires `iperf3`
## Building ## Building

View File

@ -1,19 +0,0 @@
use std::process::Command;
// test system memory with sysbench
pub fn sysbench(threads: &u8, maxprime: &u32) {
// run the fio command
let output = Command::new("sysbench")
.arg("cpu")
.arg(format!("--threads={}", threads))
.arg(format!("--cpu-max-prime={}", maxprime))
.arg("run")
.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));
}

View File

@ -1,36 +0,0 @@
use std::process::Command;
pub fn run_civ6_ai_benchmark() {
// make sure CS:GO is installed via Steam
download_game_steam(289070);
}
// run the CS:GO benchmark (using benchmark file from PTS)
pub fn run_csgo_benchmark() {
// make sure CS:GO is installed via Steam
download_game_steam(730);
}
pub fn run_demd_benchmark() {
// make sure CS:GO is installed via Steam
download_game_steam(337000);
}
fn download_game_steam(game_id: u32) {
let mut steam_path = "steam";
if cfg!(windows) {
steam_path = "C:\\Program Files (x86)\\Steam\\steam.exe";
}
// first we need to make sure CS:GO is installed via Steam
let install_output = Command::new(steam_path)
.arg(format!("steam://install/{}", game_id))
.output()
.expect("Failed to execute command");
// check that the command succeeded
assert!(install_output.status.success());
// print the test's output
println!("{}", String::from_utf8_lossy(&install_output.stdout));
}

View File

@ -1,21 +0,0 @@
use std::process::Command;
// test system memory with sysbench
pub fn sysbench(accessmode: &str, operation: &str, blocksize: &str, totalsize: &str) {
// run the fio command
let output = Command::new("sysbench")
.arg("memory")
.arg(format!("--memory-access-mode={}", accessmode))
.arg(format!("--memory-oper={}", operation))
.arg(format!("--memory-block-size={}", blocksize))
.arg(format!("--memory-total-size={}", totalsize))
.arg("run")
.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));
}

View File

@ -1,5 +1,2 @@
pub mod cpu;
pub mod disk; pub mod disk;
pub mod games;
pub mod memory;
pub mod network; pub mod network;

View File

@ -1,61 +1,16 @@
use std::process; use chrono::prelude::*;
use std::{fs,process};
use crate::text; use crate::text;
// ping a host // ping a host
pub fn latency_test(address: &str, count: &u16, interval: &u16) { pub fn ping_host(host: &str, count: &u16) {
println!("Pinging host {}, {} times.", address, count); println!("Pinging host {}, {} times.", host, count);
// if we're on Windows we need to use the -n flag for ping counts
let mut count_arg = "-c";
if cfg!(windows) {
count_arg = "-n";
}
// convert the ping interval to seconds
let interval_secs = *interval as f64 / 1000 as f64;
// run the ping command // run the ping command
let output = process::Command::new("ping") let output = process::Command::new("ping")
.arg(address) .arg(host)
.arg(count_arg) .arg(format!("-c {}", count))
.arg(format!("{}", count))
.arg("-i")
.arg(format!("{}", interval_secs))
.output()
.expect("Failed to execute command");
// check that the command succeeded
assert!(output.status.success());
// 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);
}
}
// network jitter test
pub fn jitter_test(address: &str, count: &u16, interval: &u16) {
println!("Pinging host {}, {} times to determine network jitter.", address, count);
// if we're on Windows we need to use the -n flag for ping counts
let mut count_arg = "-c";
if cfg!(windows) {
count_arg = "-n";
}
// convert the ping interval to seconds
let interval_secs = *interval as f64 / 1000 as f64;
// run the ping command
let output = process::Command::new("ping")
.arg(address)
.arg(count_arg)
.arg(format!("{}", count))
.arg("-i")
.arg(format!("{}", interval_secs))
.output() .output()
.expect("Failed to execute command"); .expect("Failed to execute command");
@ -71,20 +26,23 @@ pub fn jitter_test(address: &str, count: &u16, interval: &u16) {
} }
// timed file copy test to guage bandwidth speeds // timed file copy test to guage bandwidth speeds
pub fn bandwidth_test(host: &str) { pub fn bandwidth_test(download: &str, output: &str) {
println!("Testing network bandwidth using iperf; connecting to {}.", host); println!("Testing network bandwidth by downloading {}.", download);
println!("{}", host);
let output = process::Command::new("iperf3") // get start time so we can track how long it takes to complete
.arg("-c") let start_time = Utc::now();
.arg(host)
.output()
.expect("Failed to execute command");
// check that the command succeeded // do the download
assert!(output.status.success());
// grab and print the command's results // get finish time
let results_raw = &String::from_utf8_lossy(&output.stdout); let finish_time = Utc::now();
println!("{}", results_raw); // compute time to complete
let comp_time = finish_time - start_time;
println!("{}", comp_time.num_milliseconds());
// clean up the test file
match fs::remove_file(output) {
Ok(()) => println!("Cleaning up..."),
Err(e) => println!("There was a problem during cleanup - {}", e),
}
} }

View File

@ -20,15 +20,9 @@ enum Commands {
// CPU benchmarks subcommand // CPU benchmarks subcommand
#[clap(name = "cpu", about = "CPU benchmarks and stress tests.")] #[clap(name = "cpu", about = "CPU benchmarks and stress tests.")]
Cpu(Cpu), Cpu(Cpu),
// memory benchmarks subcommand
#[clap(name = "memory", about = "Memory benchmarks and stress tests.")]
Mem(Mem),
// disk benchmarks subcommand // 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),
// games benchmarks subcommand
#[clap(name = "games", about = "Benchmark your system with games.")]
Games(Games),
// network benchmarks 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),
@ -45,42 +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 = 'r', long, default_value_t = 5, help = "Length of time (in minutes) to run the stress test. Defaults to 5")] #[clap(short = 't', long, default_value_t = 0, help = "Number of threads to use; defaults to CPU's max thread count.")]
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,
}, },
// CPU benchmark test subcommand
#[clap(name = "benchmark", about = "Benchmark the CPU")]
Benchmark {
#[clap(short = 'm', long, default_value_t = 4)]
threads: u8,
#[clap(short = 'o', long, default_value_t = 10000)]
maxprime: u32,
},
}
#[derive(Args)]
struct Mem {
#[clap(subcommand)]
mem_commands: MemCommands,
}
#[derive(Subcommand)]
enum MemCommands {
// Memory benchmark test subcommand
#[clap(name = "benchmark", about = "Benchmark the system memory")]
Benchmark {
#[clap(short = 'm', long, default_value_t = String::from("seq"))]
accessmode: String,
#[clap(short = 'o', long, default_value_t = String::from("write"))]
operation: String,
#[clap(short = 'b', long, default_value_t = String::from("1K"))]
blocksize: String,
#[clap(short = 's', long, default_value_t = String::from("100G"))]
totalsize: String,
},
} }
#[derive(Args)] #[derive(Args)]
@ -94,7 +55,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 = 't', long, 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', long, default_value_t = 15)] #[clap(short = 's', long, default_value_t = 15)]
size: u8, size: u8,
@ -103,7 +64,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 = 't', long, 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', long, default_value_t = 15)] #[clap(short = 's', long, default_value_t = 15)]
size: u8, size: u8,
@ -128,27 +89,6 @@ enum DiskCommands {
}, },
} }
#[derive(Parser)]
struct Games {
#[structopt(subcommand)]
games_commands: GamesCommands,
}
#[derive(Subcommand)]
enum GamesCommands {
// Civilization 6 AI benchmark subcommand
#[clap(name = "civ6_ai", about = "Run the Civilization 6 AI benchmark via Steam.")]
Civ6AI {},
// CS:GO benchmark subcommand
#[clap(name = "csgo", about = "Run the CS:GO game benchmark via Steam.")]
CSGO {},
// Deus Ex: Mankind Divided benchmark subcommand
#[clap(name = "demd", about = "Run the Deus Ex: Mankind Divided game benchmark via Steam.")]
DEMD {},
}
#[derive(Parser)] #[derive(Parser)]
struct Net { struct Net {
#[structopt(subcommand)] #[structopt(subcommand)]
@ -157,33 +97,22 @@ struct Net {
#[derive(Subcommand)] #[derive(Subcommand)]
enum NetCommands { enum NetCommands {
// bandwidth test subcommand // ping subcommand
#[clap(name = "bandwidth", about = "Uses iperf to test network bandwidth.")] #[clap(name = "ping", about = "Ping a host to determine network latency.")]
Bandwidth { Ping {
#[clap(short = 'a', long, required = true)] #[clap(short = 't', long, default_value_t = String::from("8.8.8.8"))]
host: String, host: String,
#[clap(short = 'c', long, default_value_t = 30)]
count: u16,
}, },
// jitter subcommand // bandwidth test subcommand
#[clap(name = "jitter", about = "Ping a host to determine network jitter.")] #[clap(name = "bandwidth", about = "Downloads a remote file to determine network bandwidth.")]
Jitter { Bandwidth {
#[clap(short = 'a', long, default_value_t = String::from("8.8.8.8"))] #[clap(short = 'd', long, default_value_t = String::from("https://www.bitgoblin.tech/hardware-tests/export-01.mp4"))]
address: String, download: String,
#[clap(short = 'c', long, default_value_t = 100)] #[clap(short = 'o', long, default_value_t = String::from("./tempfile"))]
count: u16, output: String,
#[clap(short = 'i', long, default_value_t = 1000)]
interval: u16,
},
// latency subcommand
#[clap(name = "latency", about = "Ping a host to determine network latency.")]
Latency {
#[clap(short = 'a', long, default_value_t = String::from("8.8.8.8"))]
address: String,
#[clap(short = 'c', long, default_value_t = 100)]
count: u16,
#[clap(short = 'i', long, default_value_t = 1000)]
interval: u16,
}, },
} }
@ -193,12 +122,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 { runtime, threads } => stress::cpu::cpu_stress_math(*runtime, *threads), CpuCommands::StressTest { threads } => stress::cpu::cpu_stress_math(*threads),
CpuCommands::Benchmark { threads, maxprime } => benchmarks::cpu::sysbench(threads, maxprime),
},
Commands::Mem(args) => match &args.mem_commands {
MemCommands::Benchmark { accessmode, operation, blocksize, totalsize } => benchmarks::memory::sysbench(accessmode, operation, blocksize, totalsize),
}, },
Commands::Disk(args) => match &args.disk_commands { Commands::Disk(args) => match &args.disk_commands {
@ -226,31 +150,19 @@ fn main() {
benchmarks::disk::disk_write_rand_test(tempfile, size); benchmarks::disk::disk_write_rand_test(tempfile, size);
} }
}, },
}, }
Commands::Games(args) => match &args.games_commands {
GamesCommands::Civ6AI {} => benchmarks::games::run_civ6_ai_benchmark(),
GamesCommands::CSGO {} => benchmarks::games::run_csgo_benchmark(),
GamesCommands::DEMD {} => benchmarks::games::run_demd_benchmark(),
},
Commands::Net(args) => match &args.net_commands { Commands::Net(args) => match &args.net_commands {
NetCommands::Bandwidth { host } => { NetCommands::Ping { host, 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::bandwidth_test(host); benchmarks::network::ping_host(host, count);
} }
}, },
NetCommands::Jitter { address, count, interval } => { NetCommands::Bandwidth { download, output } => {
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::jitter_test(address, count, interval); benchmarks::network::bandwidth_test(download, output);
}
},
NetCommands::Latency { address, count, interval } => {
for i in 0..cli.loopcount {
println!("Test run number {}.", i + 1);
benchmarks::network::latency_test(address, count, interval);
} }
}, },
}, },

View File

@ -1,32 +1,28 @@
use std::{thread, time}; use std::thread;
use std::process::exit;
use sysinfo::{System,SystemExt}; use sysinfo::{System,SystemExt};
pub fn cpu_stress_math(runtime: u16, threads: usize) { pub fn cpu_stress_math(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 0..num_threads { for i in 1..num_threads {
println!("Spawning thread number {}", i + 1); println!("Spawning thread number {}", i);
thread::spawn (|| { thread::spawn (|| {
worker(); worker();
}); });
} }
println!("Using main as last thread");
println!("Sleeping main thread for the allotted runtime of {} minute(s).", runtime); worker();
let duration = time::Duration::from_secs((runtime * 60).into());
thread::sleep(duration);
exit(0);
} }
fn worker() { fn worker() {