mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-03 03:15:20 +00:00
tests: Port test_console_file to the new methodology
Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
a4abb7f8e5
commit
ded376c6e1
@ -3324,7 +3324,6 @@ mod tests {
|
||||
#[cfg_attr(not(feature = "mmio"), test)]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
fn test_console_file() {
|
||||
test_block!(tb, "", {
|
||||
let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
||||
let guest = Guest::new(&mut focal);
|
||||
|
||||
@ -3339,26 +3338,31 @@ mod tests {
|
||||
"--console",
|
||||
format!("file={}", console_path.to_str().unwrap()).as_str(),
|
||||
])
|
||||
.capture_output()
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
thread::sleep(std::time::Duration::new(20, 0));
|
||||
|
||||
guest.ssh_command("sudo shutdown -h now")?;
|
||||
guest.ssh_command("sudo shutdown -h now").unwrap();
|
||||
thread::sleep(std::time::Duration::new(20, 0));
|
||||
|
||||
let _ = child.kill();
|
||||
let output = child.wait_with_output().unwrap();
|
||||
|
||||
let r = std::panic::catch_unwind(|| {
|
||||
// Check that the cloud-hypervisor binary actually terminated
|
||||
if let Ok(status) = child.wait() {
|
||||
aver_eq!(tb, status.success(), true);
|
||||
}
|
||||
assert_eq!(output.status.success(), true);
|
||||
|
||||
// Do this check after shutdown of the VM as an easy way to ensure
|
||||
// all writes are flushed to disk
|
||||
let mut f = std::fs::File::open(console_path)?;
|
||||
let mut f = std::fs::File::open(console_path).unwrap();
|
||||
let mut buf = String::new();
|
||||
f.read_to_string(&mut buf)?;
|
||||
aver!(tb, buf.contains("cloud login:"));
|
||||
|
||||
Ok(())
|
||||
f.read_to_string(&mut buf).unwrap();
|
||||
assert!(buf.contains("cloud login:"));
|
||||
});
|
||||
|
||||
handle_child_output(r, &output);
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature = "mmio"), test)]
|
||||
|
Loading…
Reference in New Issue
Block a user