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: #6507

Signed-off-by: Songqian Li <sionli@tencent.com>
  • Loading branch information
Songqian Li committed Jun 4, 2024
1 parent d82846c commit 45badf2
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 166 deletions.
27 changes: 23 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test_infra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version = "0.1.0"
dirs = "5.0.1"
epoll = "4.3.3"
libc = "0.2.153"
nix = { version = "0.29.0", features = ["signal"] }
once_cell = "1.19.0"
serde = { version = "1.0.197", features = ["rc", "derive"] }
serde_json = "1.0.115"
Expand Down
18 changes: 18 additions & 0 deletions test_infra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#![allow(clippy::undocumented_unsafe_blocks)]

use nix::sys::signal::{kill, Signal};
use nix::unistd::Pid;
use once_cell::sync::Lazy;
use serde_json::Value;
use ssh2::Session;
Expand Down Expand Up @@ -798,6 +800,22 @@ pub fn check_matched_lines_count(input: &str, keywords: Vec<&str>, line_count: u
}
}

pub fn kill_child(child: &Child) {
let pid = Pid::from_raw(child.id() as i32);
match kill(pid, Signal::SIGTERM) {
Ok(_) => {}
Err(e) => {
eprintln!("Failed to kill child with SIGTERM: {:?}", e);
kill(pid, Signal::SIGKILL)
.map_err(|e| {
eprintln!("Failed to kill child with SIGKILL: {:?}", e);
e
})
.unwrap();
}
}
}

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 45badf2

Please sign in to comment.