Compare commits
17 Commits
90f679c366
...
v0.2.2
Author | SHA1 | Date | |
---|---|---|---|
94218af170 | |||
9856c59da9 | |||
e41a4dfffb | |||
6f86266dee | |||
e39b78d5d7 | |||
be549808b5 | |||
1c56e43de8 | |||
dbd1068cc5 | |||
2cb744d654 | |||
784f64ca16 | |||
1ff6b671eb | |||
33e540add4 | |||
a315e2662c | |||
9000924590 | |||
a9b1ffa614 | |||
b1255c451e | |||
04ebc2290f |
5
.gitignore
vendored
5
.gitignore
vendored
@ -14,3 +14,8 @@ Cargo.lock
|
|||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
25
.woodpecker.yml
Normal file
25
.woodpecker.yml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
pipeline:
|
||||||
|
test_build:
|
||||||
|
image: rust:1.62
|
||||||
|
commands:
|
||||||
|
- cargo build
|
||||||
|
|
||||||
|
build_release:
|
||||||
|
image: rust:1.62
|
||||||
|
commands:
|
||||||
|
- cargo build --release
|
||||||
|
- "mv target/release/bgbench target/release/bgbench-${CI_COMMIT_TAG}-linux-x86_64"
|
||||||
|
when:
|
||||||
|
event: tag
|
||||||
|
|
||||||
|
gitea_release:
|
||||||
|
image: plugins/gitea-release
|
||||||
|
settings:
|
||||||
|
api_key:
|
||||||
|
from_secret: gitea_api_key
|
||||||
|
base_url: https://git.metaunix.net
|
||||||
|
files:
|
||||||
|
- "target/release/*${CI_COMMIT_TAG}-linux-x86_64"
|
||||||
|
title: "${CI_COMMIT_TAG}"
|
||||||
|
when:
|
||||||
|
event: tag
|
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[package]
|
||||||
|
name = "hardware-tests"
|
||||||
|
version = "0.2.2"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "bgbench"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
chrono = "0.4.20"
|
||||||
|
clap = { version = "3.2.16", features = ["derive"] }
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) <year> <owner>
|
Copyright (c) 2022 Bit Goblin
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
25
README.md
25
README.md
@ -1,3 +1,24 @@
|
|||||||
# test-scripts
|
# 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
|
||||||
|
|
||||||
|
Check out the [Releases page](https://git.metaunix.net/BitGoblin/hardware-tests/releases) to find the latest compiled binaries.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
The Bit Goblin hardware test suite is available via the BSD 2-Clause license, so feel free to hack away at it!
|
||||||
|
3
bin/docker-build.sh
Executable file
3
bin/docker-build.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
docker run --rm --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/hardware-tests -w /usr/src/hardware-tests rust:1.62 cargo build
|
112
src/main.rs
Normal file
112
src/main.rs
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
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 {
|
||||||
|
// 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"))]
|
||||||
|
tempfile: String,
|
||||||
|
#[clap(short = 's', 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"))]
|
||||||
|
tempfile: String,
|
||||||
|
#[clap(short = 's', 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"))]
|
||||||
|
tempfile: String,
|
||||||
|
#[clap(short = 's', 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"))]
|
||||||
|
tempfile: String,
|
||||||
|
#[clap(short = 's', default_value_t = 15)]
|
||||||
|
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::ReadSeqTest { tempfile, size } => tests::disk::disk_read_seq_test(tempfile, size),
|
||||||
|
DiskCommands::ReadRandTest { tempfile, size } => tests::disk::disk_read_rand_test(tempfile, size),
|
||||||
|
DiskCommands::WriteSeqTest { tempfile, size } => tests::disk::disk_write_seq_test(tempfile, size),
|
||||||
|
DiskCommands::WriteRandTest { tempfile, size } => tests::disk::disk_write_rand_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),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
109
src/tests/disk.rs
Normal file
109
src/tests/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));
|
||||||
|
}
|
2
src/tests/mod.rs
Normal file
2
src/tests/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod disk;
|
||||||
|
pub mod network;
|
42
src/tests/network.rs
Normal file
42
src/tests/network.rs
Normal 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),
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user