mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
test_infra: Test ProcessRegistry spawn and cleanup
Spawn a sleep process through the registry, verify it is alive, call cleanup and verify the process was killed. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
a597c74385
commit
6453a9a91a
@@ -2604,3 +2604,26 @@ pub mod aarch64 {
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
pub use aarch64::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod unit_tests {
|
||||
use super::*;
|
||||
|
||||
fn is_alive(pid: u32) -> bool {
|
||||
unsafe { libc::kill(pid as i32, 0) == 0 }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn process_registry_spawn_and_cleanup() {
|
||||
let name = "test_spawn_and_cleanup";
|
||||
let mut cmd = Command::new("sleep");
|
||||
cmd.arg("60");
|
||||
let mut child = ProcessRegistry::spawn(name, &mut cmd).unwrap();
|
||||
let pid = child.id();
|
||||
|
||||
assert!(is_alive(pid));
|
||||
assert!(ProcessRegistry::cleanup(name));
|
||||
let _ = child.wait();
|
||||
assert!(!is_alive(pid));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user