diff --git a/performance-metrics/src/main.rs b/performance-metrics/src/main.rs index 8c1b669bb..c34815581 100644 --- a/performance-metrics/src/main.rs +++ b/performance-metrics/src/main.rs @@ -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 { + 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)] pub struct PerformanceTestOverrides { test_iterations: Option, test_timeout: Option, + test_image_format: Option, } impl fmt::Display for PerformanceTestOverrides { @@ -121,6 +156,10 @@ impl fmt::Display for PerformanceTestOverrides { 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(()) } } @@ -686,6 +725,15 @@ fn main() { .help("Override test timeout, Ex. --timeout 5") .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(); // It seems that the tool (ethr) used for testing the virtio-net latency @@ -723,9 +771,14 @@ fn main() { .map(|s| s.parse()) .transpose() .unwrap_or_default(), + test_image_format: cmd_arguments + .get_one::("image-format") + .map(|s| s.parse()) + .transpose() + .unwrap_or_default(), }); - init_tests(); + init_tests(&overrides); for test in test_list.iter() { if test_filter.is_empty() || test_filter.iter().any(|&s| test.name.contains(s)) { diff --git a/performance-metrics/src/performance_tests.rs b/performance-metrics/src/performance_tests.rs index a2d700490..46eb090fc 100644 --- a/performance-metrics/src/performance_tests.rs +++ b/performance-metrics/src/performance_tests.rs @@ -12,7 +12,7 @@ use std::{fs, thread}; use test_infra::{Error as InfraError, *}; use thiserror::Error; -use crate::{mean, PerformanceTestControl}; +use crate::{mean, ImageFormat, PerformanceTestControl, PerformanceTestOverrides}; #[cfg(target_arch = "x86_64")] pub const FOCAL_IMAGE_NAME: &str = "focal-server-cloudimg-amd64-custom-20210609-0.raw"; @@ -30,16 +30,30 @@ enum Error { 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"; -pub fn init_tests() { - // The test image cannot 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={BLK_IO_TEST_IMG} bs=1M count=4096" - )) - .status - .success()); +pub fn init_tests(overrides: &PerformanceTestOverrides) { + let mut cmd = format!("dd if=/dev/zero of={BLK_IO_TEST_IMG} bs=1M count=4096"); + + if let Some(o) = overrides.test_image_format { + match o { + ImageFormat::Raw => { /* Nothing to do */ } + ImageFormat::Qcow2 => { + 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() {