mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
performance-metrics: Add all supported formats to block tests
Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
@@ -106,10 +106,45 @@ impl Default for MetricsReport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Default)]
|
||||||
|
pub enum ImageFormat {
|
||||||
|
#[default]
|
||||||
|
Raw,
|
||||||
|
Qcow2,
|
||||||
|
Vhd,
|
||||||
|
Vhdx,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::str::FromStr for ImageFormat {
|
||||||
|
type Err = ();
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
"raw" => Ok(ImageFormat::Raw),
|
||||||
|
"qcow2" => Ok(ImageFormat::Qcow2),
|
||||||
|
"vhd" => Ok(ImageFormat::Vhd),
|
||||||
|
"vhdx" => Ok(ImageFormat::Vhdx),
|
||||||
|
_ => Err(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ImageFormat {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
ImageFormat::Raw => write!(f, "raw"),
|
||||||
|
ImageFormat::Qcow2 => write!(f, "qcow2"),
|
||||||
|
ImageFormat::Vhd => write!(f, "vhd"),
|
||||||
|
ImageFormat::Vhdx => write!(f, "vhdx"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct PerformanceTestOverrides {
|
pub struct PerformanceTestOverrides {
|
||||||
test_iterations: Option<u32>,
|
test_iterations: Option<u32>,
|
||||||
test_timeout: Option<u32>,
|
test_timeout: Option<u32>,
|
||||||
|
test_image_format: Option<ImageFormat>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for PerformanceTestOverrides {
|
impl fmt::Display for PerformanceTestOverrides {
|
||||||
@@ -121,6 +156,10 @@ impl fmt::Display for PerformanceTestOverrides {
|
|||||||
write!(f, "test_timeout = {test_timeout}")?;
|
write!(f, "test_timeout = {test_timeout}")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(test_image_format) = self.test_image_format {
|
||||||
|
write!(f, "test_image_format = {test_image_format}")?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -686,6 +725,15 @@ fn main() {
|
|||||||
.help("Override test timeout, Ex. --timeout 5")
|
.help("Override test timeout, Ex. --timeout 5")
|
||||||
.num_args(1),
|
.num_args(1),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("image-format")
|
||||||
|
.long("image-format")
|
||||||
|
.help(
|
||||||
|
"Override the image format used for block tests, supported values: qcow2, raw, vhd, vhdx. \
|
||||||
|
Default is 'raw'.",
|
||||||
|
)
|
||||||
|
.num_args(1),
|
||||||
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
// It seems that the tool (ethr) used for testing the virtio-net latency
|
// It seems that the tool (ethr) used for testing the virtio-net latency
|
||||||
@@ -723,9 +771,14 @@ fn main() {
|
|||||||
.map(|s| s.parse())
|
.map(|s| s.parse())
|
||||||
.transpose()
|
.transpose()
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
|
test_image_format: cmd_arguments
|
||||||
|
.get_one::<String>("image-format")
|
||||||
|
.map(|s| s.parse())
|
||||||
|
.transpose()
|
||||||
|
.unwrap_or_default(),
|
||||||
});
|
});
|
||||||
|
|
||||||
init_tests();
|
init_tests(&overrides);
|
||||||
|
|
||||||
for test in test_list.iter() {
|
for test in test_list.iter() {
|
||||||
if test_filter.is_empty() || test_filter.iter().any(|&s| test.name.contains(s)) {
|
if test_filter.is_empty() || test_filter.iter().any(|&s| test.name.contains(s)) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use std::{fs, thread};
|
|||||||
use test_infra::{Error as InfraError, *};
|
use test_infra::{Error as InfraError, *};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::{mean, PerformanceTestControl};
|
use crate::{mean, ImageFormat, PerformanceTestControl, PerformanceTestOverrides};
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub const FOCAL_IMAGE_NAME: &str = "focal-server-cloudimg-amd64-custom-20210609-0.raw";
|
pub const FOCAL_IMAGE_NAME: &str = "focal-server-cloudimg-amd64-custom-20210609-0.raw";
|
||||||
@@ -30,16 +30,30 @@ enum Error {
|
|||||||
RestoreTimeParse,
|
RestoreTimeParse,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The test image cannot be created on tmpfs (e.g. /tmp) filesystem,
|
||||||
|
// as tmpfs does not support O_DIRECT
|
||||||
const BLK_IO_TEST_IMG: &str = "/var/tmp/ch-blk-io-test.img";
|
const BLK_IO_TEST_IMG: &str = "/var/tmp/ch-blk-io-test.img";
|
||||||
|
|
||||||
pub fn init_tests() {
|
pub fn init_tests(overrides: &PerformanceTestOverrides) {
|
||||||
// The test image cannot be created on tmpfs (e.g. /tmp) filesystem,
|
let mut cmd = format!("dd if=/dev/zero of={BLK_IO_TEST_IMG} bs=1M count=4096");
|
||||||
// as tmpfs does not support O_DIRECT
|
|
||||||
assert!(exec_host_command_output(&format!(
|
if let Some(o) = overrides.test_image_format {
|
||||||
"dd if=/dev/zero of={BLK_IO_TEST_IMG} bs=1M count=4096"
|
match o {
|
||||||
))
|
ImageFormat::Raw => { /* Nothing to do */ }
|
||||||
.status
|
ImageFormat::Qcow2 => {
|
||||||
.success());
|
cmd =
|
||||||
|
format!("qemu-img create -f qcow2 -o preallocation=full {BLK_IO_TEST_IMG} 4G");
|
||||||
|
}
|
||||||
|
ImageFormat::Vhd => {
|
||||||
|
cmd = format!("qemu-img create -f vpc -o subformat=fixed {BLK_IO_TEST_IMG} 4G");
|
||||||
|
}
|
||||||
|
ImageFormat::Vhdx => {
|
||||||
|
cmd = format!("qemu-img create -f vhdx -o subformat=fixed {BLK_IO_TEST_IMG} 4G");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert!(exec_host_command_output(&cmd).status.success());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cleanup_tests() {
|
pub fn cleanup_tests() {
|
||||||
|
|||||||
Reference in New Issue
Block a user