mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-24 17:01:16 +00:00
tests: Add integration testing for VM reboot
Both with direct kernel boot, Ubuntu and Clear firmware boots. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
3af5619256
commit
7205700c5f
131
src/main.rs
131
src/main.rs
@ -2015,4 +2015,135 @@ mod tests {
|
|||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_reboot() {
|
||||||
|
test_block!(tb, "", {
|
||||||
|
let mut clear = ClearDiskConfig::new();
|
||||||
|
let mut bionic = BionicDiskConfig::new();
|
||||||
|
|
||||||
|
vec![
|
||||||
|
&mut clear as &mut dyn DiskConfig,
|
||||||
|
&mut bionic as &mut dyn DiskConfig,
|
||||||
|
]
|
||||||
|
.iter_mut()
|
||||||
|
.for_each(|disk_config| {
|
||||||
|
let guest = Guest::new(*disk_config);
|
||||||
|
|
||||||
|
let mut child = Command::new("target/debug/cloud-hypervisor")
|
||||||
|
.args(&["--cpus", "1"])
|
||||||
|
.args(&["--memory", "size=512M"])
|
||||||
|
.args(&["--kernel", guest.fw_path.as_str()])
|
||||||
|
.args(&[
|
||||||
|
"--disk",
|
||||||
|
guest
|
||||||
|
.disk_config
|
||||||
|
.disk(DiskType::OperatingSystem)
|
||||||
|
.unwrap()
|
||||||
|
.as_str(),
|
||||||
|
guest
|
||||||
|
.disk_config
|
||||||
|
.disk(DiskType::CloudInit)
|
||||||
|
.unwrap()
|
||||||
|
.as_str(),
|
||||||
|
])
|
||||||
|
.args(&["--net", guest.default_net_string().as_str()])
|
||||||
|
.args(&["--serial", "tty", "--console", "off"])
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
|
||||||
|
let reboot_count = guest
|
||||||
|
.ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"")
|
||||||
|
.unwrap_or_default()
|
||||||
|
.trim()
|
||||||
|
.parse::<u32>()
|
||||||
|
.unwrap_or(1);
|
||||||
|
|
||||||
|
aver_eq!(tb, reboot_count, 0);
|
||||||
|
guest.ssh_command("sudo reboot").unwrap_or_default();
|
||||||
|
|
||||||
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
let reboot_count = guest
|
||||||
|
.ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"")
|
||||||
|
.unwrap_or_default()
|
||||||
|
.trim()
|
||||||
|
.parse::<u32>()
|
||||||
|
.unwrap_or_default();
|
||||||
|
aver_eq!(tb, reboot_count, 1);
|
||||||
|
|
||||||
|
guest
|
||||||
|
.ssh_command("sudo shutdown -h now")
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let _ = child.kill();
|
||||||
|
let _ = child.wait();
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bzimage_reboot() {
|
||||||
|
test_block!(tb, "", {
|
||||||
|
let mut clear = ClearDiskConfig::new();
|
||||||
|
let guest = Guest::new(&mut clear);
|
||||||
|
let mut workload_path = dirs::home_dir().unwrap();
|
||||||
|
workload_path.push("workloads");
|
||||||
|
|
||||||
|
let mut kernel_path = workload_path.clone();
|
||||||
|
kernel_path.push("bzImage");
|
||||||
|
|
||||||
|
let mut child = Command::new("target/debug/cloud-hypervisor")
|
||||||
|
.args(&["--cpus", "1"])
|
||||||
|
.args(&["--memory", "size=512M"])
|
||||||
|
.args(&["--kernel", kernel_path.to_str().unwrap()])
|
||||||
|
.args(&[
|
||||||
|
"--disk",
|
||||||
|
guest
|
||||||
|
.disk_config
|
||||||
|
.disk(DiskType::OperatingSystem)
|
||||||
|
.unwrap()
|
||||||
|
.as_str(),
|
||||||
|
guest
|
||||||
|
.disk_config
|
||||||
|
.disk(DiskType::CloudInit)
|
||||||
|
.unwrap()
|
||||||
|
.as_str(),
|
||||||
|
])
|
||||||
|
.args(&["--net", guest.default_net_string().as_str()])
|
||||||
|
.args(&["--cmdline", "root=PARTUUID=3cb0e0a5-925d-405e-bc55-edf0cec8f10a console=tty0 console=ttyS0,115200n8 console=hvc0 quiet init=/usr/lib/systemd/systemd-bootchart initcall_debug tsc=reliable no_timer_check noreplace-smp cryptomgr.notests rootfstype=ext4,btrfs,xfs kvm-intel.nested=1 rw"])
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
|
||||||
|
let reboot_count = guest
|
||||||
|
.ssh_command("journalctl | grep -c -- \"-- Reboot --\"")
|
||||||
|
.unwrap_or_default()
|
||||||
|
.trim()
|
||||||
|
.parse::<u32>()
|
||||||
|
.unwrap_or(1);
|
||||||
|
|
||||||
|
aver_eq!(tb, reboot_count, 0);
|
||||||
|
guest.ssh_command("sudo reboot")?;
|
||||||
|
|
||||||
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
let reboot_count = guest
|
||||||
|
.ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"")
|
||||||
|
.unwrap_or_default()
|
||||||
|
.trim()
|
||||||
|
.parse::<u32>()
|
||||||
|
.unwrap_or_default();
|
||||||
|
aver_eq!(tb, reboot_count, 1);
|
||||||
|
|
||||||
|
guest.ssh_command("sudo shutdown -h now")?;
|
||||||
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
|
let _ = child.kill();
|
||||||
|
let _ = child.wait();
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user