Consolidated the test programs into one 'bgbench' program
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-08-05 20:58:24 -04:00
parent 2cb744d654
commit dbd1068cc5
7 changed files with 139 additions and 95 deletions

View File

@ -8,8 +8,7 @@ pipeline:
image: rust:1.62 image: rust:1.62
commands: commands:
- cargo build --release - cargo build --release
- "mv target/release/nettest target/release/nettest-${CI_COMMIT_TAG}-linux-x86_64" - "mv target/release/bgbench target/release/bgbench-${CI_COMMIT_TAG}-linux-x86_64"
- "mv target/release/hdtest target/release/hdtest-${CI_COMMIT_TAG}-linux-x86_64"
when: when:
event: tag event: tag

View File

@ -4,15 +4,11 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[[bin]] [[bin]]
name = "hdtest" name = "bgbench"
path = "src/hdtest.rs" path = "src/main.rs"
[[bin]]
name = "nettest"
path = "src/nettest.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
chrono = "0.4.19" chrono = "0.4.20"
clap = { version = "3.1.2", features = ["derive"] } clap = { version = "3.2.16", features = ["derive"] }

81
src/main.rs Normal file
View File

@ -0,0 +1,81 @@
mod tests;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[clap(name = "Bit Goblin Benchmark", author, version, about = "Bit Goblin's hardware benchmarking tool.", long_about = None)]
#[clap(propagate_version = true)]
struct Cli {
#[clap(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
// disk tests subcommand
#[clap(name = "disk", about = "Hard drive and SSD benchmarks.")]
Disk(Disk),
// network tests subcommand
#[clap(name = "network", about = "Test various aspects of your network.")]
Net(Net),
}
#[derive(Parser)]
struct Disk {
#[structopt(subcommand)]
disk_commands: DiskCommands,
}
#[derive(Subcommand)]
enum DiskCommands {
#[clap(name = "write-test", about = "Write a large file to determine sequential disk speeds.")]
WriteTest {
#[clap(short = 't', default_value_t = String::from("/tmp/disk-test.tmp"))]
tempfile: String,
#[clap(short = 's', default_value_t = 5)]
size: u8,
},
}
#[derive(Parser)]
struct Net {
#[structopt(subcommand)]
net_commands: NetCommands,
}
#[derive(Subcommand)]
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)]
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"))]
download: String,
#[clap(short = 'o', default_value_t = String::from("./tempfile"))]
output: String,
},
}
fn main() {
let cli = Cli::parse();
// map subcommands back to the main command
match &cli.command {
Commands::Disk(args) => match &args.disk_commands {
DiskCommands::WriteTest { tempfile, size } => tests::disk::disk_write_test(tempfile, size),
}
Commands::Net(args) => match &args.net_commands {
NetCommands::Ping { host, count } => tests::network::ping_host(host, count),
NetCommands::Bandwidth { download, output } => tests::network::bandwidth_test(download, output),
},
}
}

View File

@ -1,80 +0,0 @@
use chrono::prelude::*;
use clap::{Parser, Subcommand};
use std::{fs,process};
#[derive(Parser)]
#[clap(name = "Bit Goblin Network Tester", author, version, about = "Network testing app.", long_about = None)]
#[clap(propagate_version = true)]
struct Cli {
#[clap(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
// ping subcommand
Ping {
#[clap(short = 't', default_value_t = String::from("8.8.8.8"))]
host: String,
#[clap(short = 'c', default_value_t = 30)]
count: u16,
},
// bandwidth test subcommand
Bandwidth {
#[clap(short = 'd', 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"))]
output: String,
},
}
fn main() {
let cli = Cli::parse();
// map subcommands back to the main command
match &cli.command {
Commands::Ping { host, count } => ping_host(host, count),
Commands::Bandwidth { download, output } => bandwidth_test(download, output)
}
}
// ping a host
fn ping_host(host: &str, count: &u16) {
println!("Pinging host {}, {} times.", host, count);
// run the ping command
let output = process::Command::new("ping")
.arg(host)
.arg(format!("-c {}", count))
.output()
.expect("Failed to execute command");
// check that the command succeeded
assert!(output.status.success());
// print out the ping results from stdout
println!("{}", String::from_utf8_lossy(&output.stdout));
}
// timed file copy test to guage bandwidth speeds
fn bandwidth_test(download: &str, output: &str) {
println!("Testing network bandwidth by downloading {}.", download);
// get start time so we can track how long it takes to complete
let start_time = Utc::now();
// do the download
// get finish time
let finish_time = Utc::now();
// 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

@ -1,13 +1,17 @@
use std::fs; use std::fs;
use std::process::Command; use std::process::Command;
fn main() { // test disk write speeds by continually writing zeroes to it
// run the dd command with a block size of 1 MB, 10K times (10GB file) 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") let output = Command::new("dd")
.arg("bs=1M") .arg("bs=1M")
.arg("count=10240") .arg(format!("count={}", size_gigs))
.arg("if=/dev/zero") .arg("if=/dev/zero")
.arg("of=./speed-test") .arg(format!("of={}", tempfile))
.output() .output()
.expect("Failed to execute command"); .expect("Failed to execute command");
@ -18,7 +22,7 @@ fn main() {
println!("{}", String::from_utf8_lossy(&output.stderr)); println!("{}", String::from_utf8_lossy(&output.stderr));
// remove the test file // remove the test file
match fs::remove_file("./speed-test") { match fs::remove_file(tempfile) {
Ok(()) => println!("Cleaning up..."), Ok(()) => println!("Cleaning up..."),
Err(e) => println!("There was a problem during cleanup - {}", e), Err(e) => println!("There was a problem during cleanup - {}", e),
} }

2
src/tests/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod disk;
pub mod network;

42
src/tests/network.rs Normal file
View File

@ -0,0 +1,42 @@
use chrono::prelude::*;
use std::{fs,process};
// ping a host
pub fn ping_host(host: &str, count: &u16) {
println!("Pinging host {}, {} times.", host, count);
// run the ping command
let output = process::Command::new("ping")
.arg(host)
.arg(format!("-c {}", count))
.output()
.expect("Failed to execute command");
// check that the command succeeded
assert!(output.status.success());
// print out the ping results from stdout
println!("{}", String::from_utf8_lossy(&output.stdout));
}
// timed file copy test to guage bandwidth speeds
pub fn bandwidth_test(download: &str, output: &str) {
println!("Testing network bandwidth by downloading {}.", download);
// get start time so we can track how long it takes to complete
let start_time = Utc::now();
// do the download
// get finish time
let finish_time = Utc::now();
// 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),
}
}