performance-metrics: Create test image for block I/O tests from main

In this way, we can avoid create/delete large temporary files during
every iteration of block I/O performance tests. Also, we can reuse the
'init/clean_tests()' interface in the future for other setup/cleanup.

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen 2022-02-07 16:39:15 -08:00 committed by Rob Bradford
parent 1cf73c83e2
commit b806935941
4 changed files with 23 additions and 23 deletions

1
Cargo.lock generated
View File

@ -637,7 +637,6 @@ dependencies = [
"serde_derive",
"serde_json",
"test_infra",
"vmm-sys-util",
"wait-timeout",
]

View File

@ -11,5 +11,4 @@ serde = { version = "1.0.136", features = ["rc"] }
serde_derive = "1.0.136"
serde_json = "1.0.78"
test_infra = { path = "../test_infra" }
vmm-sys-util = "0.9.0"
wait-timeout = "0.2.0"

View File

@ -336,6 +336,8 @@ fn run_test_with_timetout(test: &'static PerformanceTest) -> Result<String, Erro
fn main() {
let test_filter = env::var("TEST_FILTER").map_or("".to_string(), |o| o);
init_tests();
// Run performance tests sequentially and report results (in both readable/json format)
let mut json_output = String::new();
for test in TEST_LIST.iter() {
@ -352,6 +354,8 @@ fn main() {
}
}
cleanup_tests();
// Todo: Report/upload to the metrics database
println!("\n\nTests result in json format: \n {}", json_output);
}

View File

@ -10,7 +10,6 @@ use std::time::Duration;
use std::{fmt, fs};
use test_infra::Error as InfraError;
use test_infra::*;
use vmm_sys_util::tempdir::TempDir;
use wait_timeout::ChildExt;
pub const FOCAL_IMAGE_NAME: &str = "focal-server-cloudimg-amd64-custom-20210609-0.raw";
@ -41,6 +40,24 @@ impl From<InfraError> for Error {
}
}
const BLK_IO_TEST_IMG: &str = "/var/tmp/ch-blk-io-test.img";
pub fn init_tests() {
// The test image can not be created on tmpfs (e.g. /tmp) filesystem,
// as tmpfs does not support O_DIRECT
assert!(exec_host_command_output(&format!(
"dd if=/dev/zero of={} bs=1M count=4096",
BLK_IO_TEST_IMG
))
.status
.success());
}
pub fn cleanup_tests() {
fs::remove_file(BLK_IO_TEST_IMG)
.unwrap_or_else(|_| panic!("Failed to remove file '{}'.", BLK_IO_TEST_IMG));
}
const DIRECT_KERNEL_BOOT_CMDLINE: &str =
"root=/dev/vda1 console=hvc0 rw systemd.journald.forward_to_console=1";
@ -593,15 +610,6 @@ pub fn performance_block_io(control: &PerformanceTestControl) -> f64 {
.to_str()
.unwrap()
.to_string();
// The test image can not be created on tmpfs (e.g. /tmp) filesystem,
// as tmpfs does not support O_DIRECT
let test_dir = TempDir::new_with_prefix("/home/ch").unwrap();
let test_img = test_dir
.as_path()
.join("tmp.img")
.to_str()
.unwrap()
.to_string();
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", &format!("boot={}", queue_num * 2)])
@ -617,14 +625,6 @@ pub fn performance_block_io(control: &PerformanceTestControl) -> f64 {
.unwrap();
let r = std::panic::catch_unwind(|| {
// Generate a image file for testing
assert!(exec_host_command_output(&format!(
"dd if=/dev/zero of={} bs=1M count=4096",
test_img
))
.status
.success());
guest.wait_vm_boot(None).unwrap();
// Hotplug test disk
@ -634,7 +634,7 @@ pub fn performance_block_io(control: &PerformanceTestControl) -> f64 {
"add-disk",
&format!(
"path={},num_queues={},queue_size={},direct=on",
test_img, queue_num, queue_size
BLK_IO_TEST_IMG, queue_num, queue_size
)
])
.stderr(Stdio::piped())
@ -661,8 +661,6 @@ pub fn performance_block_io(control: &PerformanceTestControl) -> f64 {
parse_fio_output(&output, fio_ops, queue_num).unwrap()
});
test_dir.remove().unwrap();
let _ = child.kill();
let output = child.wait_with_output().unwrap();