Consolidated the test programs into one 'bgbench' program
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
29
src/tests/disk.rs
Normal file
29
src/tests/disk.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
|
||||
// test disk write speeds by continually writing zeroes to it
|
||||
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")
|
||||
.arg("bs=1M")
|
||||
.arg(format!("count={}", size_gigs))
|
||||
.arg("if=/dev/zero")
|
||||
.arg(format!("of={}", tempfile))
|
||||
.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(tempfile) {
|
||||
Ok(()) => println!("Cleaning up..."),
|
||||
Err(e) => println!("There was a problem during cleanup - {}", e),
|
||||
}
|
||||
}
|
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