diff --git a/src/benchmarks/network.rs b/src/benchmarks/network.rs index 8973008..4a7e17d 100644 --- a/src/benchmarks/network.rs +++ b/src/benchmarks/network.rs @@ -25,6 +25,28 @@ pub fn ping_host(address: &str, count: &u16) { } } +// network jitter test +pub fn jitter_test(address: &str, count: &u16) { + println!("Pinging host {}, {} times to determine network jitter.", address, count); + + // run the ping command + let output = process::Command::new("ping") + .arg(address) + .arg(format!("-c {}", count)) + .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); + } +} + // timed file copy test to guage bandwidth speeds pub fn bandwidth_test(download: &str, output: &str) { println!("Testing network bandwidth by downloading {}.", download); diff --git a/src/main.rs b/src/main.rs index d79c191..cda1935 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,8 +11,8 @@ struct Cli { #[clap(subcommand)] command: Commands, - #[clap(short = 'l', long, default_value_t = 1, help = "Number of times to run test. Default = 1", global = true)] - loopcount: u8, + #[clap(short = 'i', long, default_value_t = 1, help = "Number of times to run test. Default = 1", global = true)] + iterations: u8, } #[derive(Subcommand)] @@ -108,6 +108,15 @@ enum NetCommands { count: u16, }, + // jitter subcommand + #[clap(name = "jitter", about = "Ping a host to determine network jitter.")] + Jitter { + #[clap(short = 'a', long, default_value_t = String::from("8.8.8.8"))] + address: String, + #[clap(short = 'c', long, default_value_t = 30)] + count: u16, + }, + // bandwidth test subcommand #[clap(name = "bandwidth", about = "Downloads a remote file to determine network bandwidth.")] Bandwidth { @@ -129,25 +138,25 @@ fn main() { Commands::Disk(args) => match &args.disk_commands { DiskCommands::ReadSeqTest { tempfile, size } => { - for i in 0..cli.loopcount { + for i in 0..cli.iterations { println!("Test run number {}.", i + 1); benchmarks::disk::disk_read_seq_test(tempfile, size); } }, DiskCommands::ReadRandTest { tempfile, size } => { - for i in 0..cli.loopcount { + for i in 0..cli.iterations { println!("Test run number {}.", i + 1); benchmarks::disk::disk_read_rand_test(tempfile, size); } }, DiskCommands::WriteSeqTest { tempfile, size } => { - for i in 0..cli.loopcount { + for i in 0..cli.iterations { println!("Test run number {}.", i + 1); benchmarks::disk::disk_write_seq_test(tempfile, size); } }, DiskCommands::WriteRandTest { tempfile, size } => { - for i in 0..cli.loopcount { + for i in 0..cli.iterations { println!("Test run number {}.", i + 1); benchmarks::disk::disk_write_rand_test(tempfile, size); } @@ -156,13 +165,19 @@ fn main() { Commands::Net(args) => match &args.net_commands { NetCommands::Ping { address, count } => { - for i in 0..cli.loopcount { + for i in 0..cli.iterations { println!("Test run number {}.", i + 1); benchmarks::network::ping_host(address, count); } }, + NetCommands::Jitter { address, count } => { + for i in 0..cli.iterations { + println!("Test run number {}.", i + 1); + benchmarks::network::jitter_test(address, count); + } + }, NetCommands::Bandwidth { download, output } => { - for i in 0..cli.loopcount { + for i in 0..cli.iterations { println!("Test run number {}.", i + 1); benchmarks::network::bandwidth_test(download, output); }