mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-03 11:25:20 +00:00
tests: Extend test_*_reboot with checks on fd leaking
Fixes: #1209 Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
601d898f8a
commit
7dc4e91303
@ -2891,6 +2891,10 @@ mod tests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_fd_count(pid: u32) -> usize {
|
||||||
|
fs::read_dir(format!("/proc/{}/fd", pid)).unwrap().count()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(feature = "mmio"), test)]
|
#[cfg_attr(not(feature = "mmio"), test)]
|
||||||
fn test_reboot() {
|
fn test_reboot() {
|
||||||
test_block!(tb, "", {
|
test_block!(tb, "", {
|
||||||
@ -2918,7 +2922,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
let fd_count_1 = get_fd_count(child.id());
|
||||||
let reboot_count = guest
|
let reboot_count = guest
|
||||||
.ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"")
|
.ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -2930,6 +2934,7 @@ mod tests {
|
|||||||
guest.ssh_command("sudo reboot").unwrap_or_default();
|
guest.ssh_command("sudo reboot").unwrap_or_default();
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
let fd_count_2 = get_fd_count(child.id());
|
||||||
let reboot_count = guest
|
let reboot_count = guest
|
||||||
.ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"")
|
.ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -2937,6 +2942,7 @@ mod tests {
|
|||||||
.parse::<u32>()
|
.parse::<u32>()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
aver_eq!(tb, reboot_count, 1);
|
aver_eq!(tb, reboot_count, 1);
|
||||||
|
aver_eq!(tb, fd_count_1, fd_count_2);
|
||||||
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("sudo shutdown -h now")
|
.ssh_command("sudo shutdown -h now")
|
||||||
@ -2974,7 +2980,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
let fd_count_1 = get_fd_count(child.id());
|
||||||
let reboot_count = guest
|
let reboot_count = guest
|
||||||
.ssh_command("journalctl | grep -c -- \"-- Reboot --\"")
|
.ssh_command("journalctl | grep -c -- \"-- Reboot --\"")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -2986,6 +2992,7 @@ mod tests {
|
|||||||
guest.ssh_command("sudo reboot")?;
|
guest.ssh_command("sudo reboot")?;
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
let fd_count_2 = get_fd_count(child.id());
|
||||||
let reboot_count = guest
|
let reboot_count = guest
|
||||||
.ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"")
|
.ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -2993,6 +3000,7 @@ mod tests {
|
|||||||
.parse::<u32>()
|
.parse::<u32>()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
aver_eq!(tb, reboot_count, 1);
|
aver_eq!(tb, reboot_count, 1);
|
||||||
|
aver_eq!(tb, fd_count_1, fd_count_2);
|
||||||
|
|
||||||
guest.ssh_command("sudo shutdown -h now")?;
|
guest.ssh_command("sudo shutdown -h now")?;
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
Loading…
Reference in New Issue
Block a user