diff options
author | Marcin Mielniczuk <marmistrz.dev@zoho.eu> | 2017-07-31 11:19:51 +0200 |
---|---|---|
committer | Marcin Mielniczuk <marmistrz.dev@zoho.eu> | 2017-07-31 11:19:51 +0200 |
commit | 5510bf2c737eea78e7ea938d62d6b4665cf08492 (patch) | |
tree | 25572a348addd36555939387db02ea36cf8f83db /test/sys | |
parent | 0fbac87ba58eb57b5c7aa360a274a16daa8de3fc (diff) | |
download | nix-5510bf2c737eea78e7ea938d62d6b4665cf08492.zip |
Add tests for ptrace::cont
Diffstat (limited to 'test/sys')
-rw-r--r-- | test/sys/test_ptrace.rs | 33 | ||||
-rw-r--r-- | test/sys/test_wait.rs | 2 |
2 files changed, 34 insertions, 1 deletions
diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index 16a60ba7..02c86d88 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -46,3 +46,36 @@ fn test_ptrace_setsiginfo() { _ => (), } } + + +#[test] +fn test_ptrace_cont() { + use nix::sys::ptrace; + use nix::sys::signal::{raise, Signal}; + use nix::sys::wait::{waitpid, WaitStatus}; + use nix::unistd::fork; + use nix::unistd::ForkResult::*; + + match fork() { + Ok(Child) => { + ptrace::traceme().unwrap(); + // As recommended by ptrace(2), raise SIGTRAP to pause the child + // until the parent is ready to continue + loop { + raise(Signal::SIGTRAP).unwrap(); + } + + }, + Ok(Parent { child }) => { + assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP))); + ptrace::cont(child, None).unwrap(); + assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP))); + ptrace::cont(child, Signal::SIGKILL).unwrap(); + match waitpid(child, None) { + Ok(WaitStatus::Signaled(pid, Signal::SIGKILL, _)) if pid == child => {} + _ => panic!("The process should have been killed"), + } + }, + Err(_) => panic!("Error: Fork Failed") + } +} diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs index 8eff5d58..bf85715f 100644 --- a/test/sys/test_wait.rs +++ b/test/sys/test_wait.rs @@ -53,7 +53,7 @@ mod ptrace { ptrace::traceme().unwrap(); // As recommended by ptrace(2), raise SIGTRAP to pause the child // until the parent is ready to continue - let _ = raise(SIGTRAP); + raise(SIGTRAP).unwrap(); unsafe { _exit(0) } } |