mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-05 13:05:45 +00:00
tests: Port test_snapshot_restore to new methodology
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
6cd31e7a4d
commit
070f47246c
@ -4735,7 +4735,6 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
fn test_snapshot_restore() {
|
fn test_snapshot_restore() {
|
||||||
test_block!(tb, "", {
|
|
||||||
let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
||||||
let guest = Guest::new(&mut focal);
|
let guest = Guest::new(&mut focal);
|
||||||
let mut workload_path = dirs::home_dir().unwrap();
|
let mut workload_path = dirs::home_dir().unwrap();
|
||||||
@ -4789,37 +4788,32 @@ mod tests {
|
|||||||
|
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
|
||||||
|
let console_text = String::from("On a branch floating down river a cricket, singing.");
|
||||||
|
let console_cmd = format!("echo {} | sudo tee /dev/hvc0", console_text);
|
||||||
|
// Create the snapshot directory
|
||||||
|
let snapshot_dir = temp_snapshot_dir_path(&guest.tmp_dir);
|
||||||
|
|
||||||
|
let r = std::panic::catch_unwind(|| {
|
||||||
// Check the number of vCPUs
|
// Check the number of vCPUs
|
||||||
aver_eq!(tb, guest.get_cpu_count().unwrap_or_default(), 4);
|
assert_eq!(guest.get_cpu_count().unwrap_or_default(), 4);
|
||||||
// Check the guest RAM
|
// Check the guest RAM
|
||||||
aver!(tb, guest.get_total_memory().unwrap_or_default() > 3_840_000);
|
assert!(guest.get_total_memory().unwrap_or_default() > 3_840_000);
|
||||||
// Check block devices are readable
|
// Check block devices are readable
|
||||||
aver!(
|
assert!(guest
|
||||||
tb,
|
|
||||||
guest
|
|
||||||
.ssh_command("dd if=/dev/vda of=/dev/null bs=1M iflag=direct count=1024")
|
.ssh_command("dd if=/dev/vda of=/dev/null bs=1M iflag=direct count=1024")
|
||||||
.is_ok()
|
.is_ok());
|
||||||
);
|
assert!(guest
|
||||||
aver!(
|
|
||||||
tb,
|
|
||||||
guest
|
|
||||||
.ssh_command("dd if=/dev/vdb of=/dev/null bs=1M iflag=direct count=8")
|
.ssh_command("dd if=/dev/vdb of=/dev/null bs=1M iflag=direct count=8")
|
||||||
.is_ok()
|
.is_ok());
|
||||||
);
|
|
||||||
// Check if the rng device is readable
|
// Check if the rng device is readable
|
||||||
aver!(
|
assert!(guest
|
||||||
tb,
|
|
||||||
guest
|
|
||||||
.ssh_command("head -c 1000 /dev/hwrng > /dev/null")
|
.ssh_command("head -c 1000 /dev/hwrng > /dev/null")
|
||||||
.is_ok()
|
.is_ok());
|
||||||
);
|
|
||||||
// Check vsock
|
// Check vsock
|
||||||
guest.check_vsock(socket.as_str());
|
guest.check_vsock(socket.as_str());
|
||||||
// Check if the console is usable
|
// Check if the console is usable
|
||||||
let console_text =
|
|
||||||
String::from("On a branch floating down river a cricket, singing.");
|
assert!(guest.ssh_command(&console_cmd).is_ok());
|
||||||
let console_cmd = format!("echo {} | sudo tee /dev/hvc0", console_text);
|
|
||||||
aver!(tb, guest.ssh_command(&console_cmd).is_ok());
|
|
||||||
|
|
||||||
// Only for PCI, we can check that removing and adding back the
|
// Only for PCI, we can check that removing and adding back the
|
||||||
// virtio-net device does not break the snapshot/restore support
|
// virtio-net device does not break the snapshot/restore support
|
||||||
@ -4829,50 +4823,42 @@ mod tests {
|
|||||||
#[cfg(not(feature = "mmio"))]
|
#[cfg(not(feature = "mmio"))]
|
||||||
{
|
{
|
||||||
// Unplug the virtio-net device
|
// Unplug the virtio-net device
|
||||||
aver!(
|
assert!(remote_command(&api_socket, "remove-device", Some(net_id),));
|
||||||
tb,
|
|
||||||
remote_command(&api_socket, "remove-device", Some(net_id),)
|
|
||||||
);
|
|
||||||
thread::sleep(std::time::Duration::new(10, 0));
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
|
|
||||||
// Plug the virtio-net device again
|
// Plug the virtio-net device again
|
||||||
aver!(
|
assert!(remote_command(
|
||||||
tb,
|
&api_socket,
|
||||||
remote_command(&api_socket, "add-net", Some(net_params.as_str()),)
|
"add-net",
|
||||||
);
|
Some(net_params.as_str()),
|
||||||
|
));
|
||||||
thread::sleep(std::time::Duration::new(10, 0));
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause the VM
|
// Pause the VM
|
||||||
aver!(tb, remote_command(&api_socket, "pause", None));
|
assert!(remote_command(&api_socket, "pause", None));
|
||||||
|
|
||||||
// Create the snapshot directory
|
|
||||||
let snapshot_dir = temp_snapshot_dir_path(&guest.tmp_dir);
|
|
||||||
|
|
||||||
// Take a snapshot from the VM
|
// Take a snapshot from the VM
|
||||||
aver!(
|
assert!(remote_command(
|
||||||
tb,
|
|
||||||
remote_command(
|
|
||||||
&api_socket,
|
&api_socket,
|
||||||
"snapshot",
|
"snapshot",
|
||||||
Some(format!("file://{}", snapshot_dir).as_str()),
|
Some(format!("file://{}", snapshot_dir).as_str()),
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
// Wait to make sure the snapshot is completed
|
// Wait to make sure the snapshot is completed
|
||||||
thread::sleep(std::time::Duration::new(10, 0));
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
|
});
|
||||||
|
|
||||||
// Shutdown the source VM and check console output
|
// Shutdown the source VM and check console output
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
match child.wait_with_output() {
|
let output = child.wait_with_output().unwrap();
|
||||||
Ok(out) => {
|
handle_child_output(r, &output);
|
||||||
aver!(
|
|
||||||
tb,
|
let r = std::panic::catch_unwind(|| {
|
||||||
String::from_utf8_lossy(&out.stdout).contains(&console_text)
|
assert!(String::from_utf8_lossy(&output.stdout).contains(&console_text));
|
||||||
);
|
});
|
||||||
}
|
|
||||||
Err(_) => aver!(tb, false),
|
handle_child_output(r, &output);
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the vsock socket file.
|
// Remove the vsock socket file.
|
||||||
Command::new("rm")
|
Command::new("rm")
|
||||||
@ -4895,47 +4881,35 @@ mod tests {
|
|||||||
// Wait for the VM to be restored
|
// Wait for the VM to be restored
|
||||||
thread::sleep(std::time::Duration::new(10, 0));
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
|
|
||||||
|
let r = std::panic::catch_unwind(|| {
|
||||||
// Resume the VM
|
// Resume the VM
|
||||||
aver!(tb, remote_command(&api_socket, "resume", None));
|
assert!(remote_command(&api_socket, "resume", None));
|
||||||
|
|
||||||
// Perform same checks to validate VM has been properly restored
|
// Perform same checks to validate VM has been properly restored
|
||||||
aver_eq!(tb, guest.get_cpu_count().unwrap_or_default(), 4);
|
assert_eq!(guest.get_cpu_count().unwrap_or_default(), 4);
|
||||||
aver!(tb, guest.get_total_memory().unwrap_or_default() > 3_840_000);
|
assert!(guest.get_total_memory().unwrap_or_default() > 3_840_000);
|
||||||
aver!(
|
assert!(guest
|
||||||
tb,
|
|
||||||
guest
|
|
||||||
.ssh_command("dd if=/dev/vda of=/dev/null bs=1M iflag=direct count=1024")
|
.ssh_command("dd if=/dev/vda of=/dev/null bs=1M iflag=direct count=1024")
|
||||||
.is_ok()
|
.is_ok());
|
||||||
);
|
assert!(guest
|
||||||
aver!(
|
|
||||||
tb,
|
|
||||||
guest
|
|
||||||
.ssh_command("dd if=/dev/vdb of=/dev/null bs=1M iflag=direct count=8")
|
.ssh_command("dd if=/dev/vdb of=/dev/null bs=1M iflag=direct count=8")
|
||||||
.is_ok()
|
.is_ok());
|
||||||
);
|
assert!(guest
|
||||||
aver!(
|
|
||||||
tb,
|
|
||||||
guest
|
|
||||||
.ssh_command("head -c 1000 /dev/hwrng > /dev/null")
|
.ssh_command("head -c 1000 /dev/hwrng > /dev/null")
|
||||||
.is_ok()
|
.is_ok());
|
||||||
);
|
|
||||||
guest.check_vsock(socket.as_str());
|
guest.check_vsock(socket.as_str());
|
||||||
aver!(tb, guest.ssh_command(&console_cmd).is_ok());
|
assert!(guest.ssh_command(&console_cmd).is_ok());
|
||||||
|
|
||||||
// Shutdown the target VM and check console output
|
// Shutdown the target VM and check console output
|
||||||
let _ = child.kill();
|
|
||||||
match child.wait_with_output() {
|
|
||||||
Ok(out) => {
|
|
||||||
aver!(
|
|
||||||
tb,
|
|
||||||
String::from_utf8_lossy(&out.stdout).contains(&console_text)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Err(_) => aver!(tb, false),
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
});
|
});
|
||||||
|
let _ = child.kill();
|
||||||
|
let output = child.wait_with_output().unwrap();
|
||||||
|
handle_child_output(r, &output);
|
||||||
|
|
||||||
|
let r = std::panic::catch_unwind(|| {
|
||||||
|
assert!(String::from_utf8_lossy(&output.stdout).contains(&console_text));
|
||||||
|
});
|
||||||
|
|
||||||
|
handle_child_output(r, &output);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(feature = "mmio"), test)]
|
#[cfg_attr(not(feature = "mmio"), test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user