Skip to content
Snippets Groups Projects
Commit a31b0ef1 authored by Dmitry Ivanov's avatar Dmitry Ivanov Committed by Dmitry Ivanov
Browse files

fix(test): make test/inner.rs more robust

* Use bare exec in inner.rs instead of fork + exec.
* Use parent death signal on linux (man 2 PR_SET_PDEATHSIG).
* Fix usage of waitpid() (man 2 waitpid).
parent 60c20d51
No related branches found
No related tags found
1 merge request!1405fix(test): make test/inner.rs more robust
use crate::cli::args;
use crate::ipc;
use crate::{cli::args, ipc};
use ::tarantool::test::TestCase;
use nix::unistd::{self, fork, ForkResult};
use std::io::Write;
use std::io::{self, ErrorKind, Write};
macro_rules! color {
(@priv red) => { "\x1b[0;31m" };
......@@ -48,6 +47,13 @@ pub fn main(args: args::Test) -> ! {
let pid = unsafe { fork() };
match pid.expect("fork failed") {
ForkResult::Child => {
// On linux, kill child if the test runner has died.
// Perhaps it's the easiest way to implement this.
#[cfg(target_os = "linux")]
unsafe {
libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGKILL);
}
drop(rx);
unistd::close(0).ok(); // stdin
if !args.nocapture {
......@@ -75,16 +81,26 @@ pub fn main(args: args::Test) -> ! {
buf
};
let mut rc: i32 = 0;
unsafe {
libc::waitpid(
child.into(), // pid_t
&mut rc as *mut libc::c_int, // int*
0, // int options
)
};
let mut rc: libc::c_int = 0;
loop {
let ret = unsafe { libc::waitpid(child.into(), &mut rc, 0) };
// Only EINTR is allowed, other errors are uncalled for.
if ret == -1 {
match io::Error::last_os_error().kind() {
ErrorKind::Interrupted => continue,
other => panic!("waitpid() returned {other}"),
}
}
// Break only if process exited or was terminated by a signal.
if libc::WIFEXITED(rc) || libc::WIFSIGNALED(rc) {
break;
}
}
if rc == 0 {
// If the test passed, its exit code should be zero.
if libc::WIFEXITED(rc) && libc::WEXITSTATUS(rc) == 0 {
println!("{PASSED}");
cnt_passed += 1;
} else {
......
use std::os::unix::process::CommandExt;
fn main() {
let status = std::process::Command::new(env!("CARGO_BIN_EXE_picodata"))
std::process::Command::new(env!("CARGO_BIN_EXE_picodata"))
.arg("test")
.args(std::env::args().skip(1))
.status()
.unwrap();
if !status.success() {
std::process::exit(1);
}
.exec();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment