Compare commits
2 Commits
go
...
b1255c451e
Author | SHA1 | Date | |
---|---|---|---|
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
|
||||
*.pdb
|
||||
|
||||
|
||||
|
||||
# Added by cargo
|
||||
|
||||
/target
|
||||
|
17
Cargo.toml
Normal file
17
Cargo.toml
Normal file
@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "hardware-tests"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[[bin]]
|
||||
name = "hdtest"
|
||||
path = "src/hdtest.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "nettest"
|
||||
path = "src/nettest.rs"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "3.1.2", features = ["derive"] }
|
25
src/hdtest.rs
Normal file
25
src/hdtest.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
// run the dd command with a block size of 1 MB, 10K times (10GB file)
|
||||
let output = Command::new("dd")
|
||||
.arg("bs=1M")
|
||||
.arg("count=10240")
|
||||
.arg("if=/dev/zero")
|
||||
.arg("of=./speed-test")
|
||||
.output()
|
||||
.expect("Failed to execute command");
|
||||
|
||||
// check that the command succeeded
|
||||
assert!(output.status.success());
|
||||
|
||||
// for whatever reason, `dd` output ends up in stderr
|
||||
println!("{}", String::from_utf8_lossy(&output.stderr));
|
||||
|
||||
// remove the test file
|
||||
match fs::remove_file("./speed-test") {
|
||||
Ok(()) => println!("Cleaning up..."),
|
||||
Err(e) => println!("There was a problem during cleanup - {}", e),
|
||||
}
|
||||
}
|
46
src/nettest.rs
Normal file
46
src/nettest.rs
Normal file
@ -0,0 +1,46 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
use std::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(default_value_t = String::from("8.8.8.8"))]
|
||||
host: String
|
||||
},
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
// map subcommands back to the main command
|
||||
match &cli.command {
|
||||
Commands::Ping { host } => ping_host(host)
|
||||
}
|
||||
}
|
||||
|
||||
// ping a host
|
||||
fn ping_host(host: &str) {
|
||||
println!("Pinging host {}", host);
|
||||
|
||||
// run the ping command with 100 pings
|
||||
let output = process::Command::new("ping")
|
||||
.arg(host)
|
||||
.arg("-c 100")
|
||||
.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));
|
||||
}
|
Reference in New Issue
Block a user