tests: send SIGTERM to kill GuestCommand

Killing CLH by SIGKILL will cause inaccurate code coverage
information. This patch changes the signal to SIGTERM.

Fixes: #6507

Signed-off-by: Songqian Li <sionli@tencent.com>
This commit is contained in:
Songqian Li
2024-06-04 15:28:12 +08:00
committed by Rob Bradford
parent 796db588ea
commit 544de7d000
2 changed files with 101 additions and 85 deletions

View File

@@ -798,6 +798,22 @@ pub fn check_matched_lines_count(input: &str, keywords: Vec<&str>, line_count: u
}
}
pub fn kill_child(child: &mut Child) {
let r = unsafe { libc::kill(child.id() as i32, libc::SIGTERM) };
if r != 0 {
let e = io::Error::last_os_error();
if e.raw_os_error().unwrap() == libc::ESRCH {
return;
}
eprintln!("Failed to kill child with SIGTERM: {e:?}");
}
// The timeout period elapsed without the child exiting
if child.wait_timeout(Duration::new(5, 0)).unwrap().is_none() {
let _ = child.kill();
}
}
pub const PIPE_SIZE: i32 = 32 << 20;
static NEXT_VM_ID: Lazy<Mutex<u8>> = Lazy::new(|| Mutex::new(1));