diff --git a/Cargo.lock b/Cargo.lock index b242124a9..9e1b27579 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -637,7 +637,6 @@ dependencies = [ "serde_derive", "serde_json", "test_infra", - "vmm-sys-util", "wait-timeout", ] diff --git a/performance-metrics/Cargo.toml b/performance-metrics/Cargo.toml index 913a99874..565449660 100644 --- a/performance-metrics/Cargo.toml +++ b/performance-metrics/Cargo.toml @@ -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" diff --git a/performance-metrics/src/main.rs b/performance-metrics/src/main.rs index 37d5402eb..e7fe86897 100644 --- a/performance-metrics/src/main.rs +++ b/performance-metrics/src/main.rs @@ -336,6 +336,8 @@ fn run_test_with_timetout(test: &'static PerformanceTest) -> Result 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();