Skip to content

Commit

Permalink
tests: send SIGTERM to kill GuestCommand
Browse files Browse the repository at this point in the history
Killing CLH by SIGKILL will cause inaccurate code coverage
information. This patch changes the signal to SIGTERM.

Fixes: cloud-hypervisor#6507

Signed-off-by: Songqian Li <[email protected]>
  • Loading branch information
lisongqian authored and rbradford committed Jun 18, 2024
1 parent 796db58 commit 544de7d
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 85 deletions.
16 changes: 16 additions & 0 deletions test_infra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading

0 comments on commit 544de7d

Please sign in to comment.