diff --git a/integration_tests/tests/block.rs b/integration_tests/tests/block.rs index 9145995676..be7f1d1ba3 100644 --- a/integration_tests/tests/block.rs +++ b/integration_tests/tests/block.rs @@ -13,9 +13,11 @@ use fixture::Config; use fixture::TestVm; use tempfile::NamedTempFile; +const DEFAULT_BLOCK_SIZE: u64 = 1024 * 1024; + fn prepare_disk_img() -> NamedTempFile { let mut disk = NamedTempFile::new().unwrap(); - disk.as_file_mut().set_len(1024 * 1024).unwrap(); + disk.as_file_mut().set_len(DEFAULT_BLOCK_SIZE).unwrap(); // Add /sbin and /usr/sbin to PATH since some distributions put mkfs.ext4 in one of those // directories but don't add them to non-root PATH. @@ -47,3 +49,45 @@ fn mount_block() { "42" ); } + +#[test] +fn resize() { + let disk = prepare_disk_img(); + let disk_path = disk.path().to_str().unwrap().to_string(); + println!("disk={disk_path}"); + + let config = Config::new().extra_args(vec!["--rwdisk".to_string(), disk_path]); + let mut vm = TestVm::new(config).unwrap(); + + // Check the initial block device size. + assert_eq!( + vm.exec_in_guest("blockdev --getsize64 /dev/vdb") + .unwrap() + .trim() + .parse::() + .unwrap(), + DEFAULT_BLOCK_SIZE + ); + + let new_size = DEFAULT_BLOCK_SIZE * 2; + + // The index of the disk to resize. + let disk_index = 1; + + vm.disk(vec![ + "resize".to_string(), + disk_index.to_string(), + new_size.to_string(), + ]) + .expect("Disk resizing command failed"); + + // Check the new block device size. + assert_eq!( + vm.exec_in_guest("blockdev --getsize64 /dev/vdb") + .unwrap() + .trim() + .parse::() + .unwrap(), + new_size + ); +} diff --git a/integration_tests/tests/fixture/mod.rs b/integration_tests/tests/fixture/mod.rs index 38bde5f6a1..12f71afdc0 100644 --- a/integration_tests/tests/fixture/mod.rs +++ b/integration_tests/tests/fixture/mod.rs @@ -391,8 +391,9 @@ impl TestVm { Ok(trimmed.to_string()) } - fn crosvm_command(&self, command: &str) -> Result<()> { - let args = [self.control_socket_path.to_str().unwrap()]; + fn crosvm_command(&self, command: &str, mut args: Vec) -> Result<()> { + args.push(self.control_socket_path.to_str().unwrap().to_string()); + println!("$ crosvm {} {:?}", command, &args.join(" ")); let mut cmd = Command::new(find_crosvm_binary()); @@ -422,15 +423,19 @@ impl TestVm { } pub fn stop(&self) -> Result<()> { - self.crosvm_command("stop") + self.crosvm_command("stop", vec![]) } pub fn suspend(&self) -> Result<()> { - self.crosvm_command("suspend") + self.crosvm_command("suspend", vec![]) } pub fn resume(&self) -> Result<()> { - self.crosvm_command("resume") + self.crosvm_command("resume", vec![]) + } + + pub fn disk(&self, args: Vec) -> Result<()> { + self.crosvm_command("disk", args) } }