Open
Description
Ptrace lacks proper tests, partially due to tests hanging due to calls to fork. Below I have some example test functionality I wrote to ensure that ptrace works, due to the fork this could cause a test to hang. (It also ignores the ptrace results which is less than optimal).
#[test]
fn ptrace_get_data_test() {
match fork() {
Ok(ForkResult::Parent{ child }) => {
match waitpid(child, Some(__WALL)) {
Ok(WaitStatus::Stopped(child, _) )=> {
let r = ptrace_get_data::<user_regs_struct>(PTRACE_GETREGS, child);
println!("regs: {:#?}", r);
assert!(r.is_ok())
let _ = ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut());
},
_ => assert!(false),
}
}
Ok(ForkResult::Child) => {
let _ = ptrace(PTRACE_TRACEME, Pid::from_raw(0), ptr::null_mut(), ptr::null_mut());
let _ = raise(Signal::SIGSTOP);
}
Err(err) => {
println!("Error {}", err);
}
}
}