diff options
author | Markus Jais <markusjais@gmx.de> | 2015-06-04 21:29:04 +0200 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2015-06-08 11:30:23 -0700 |
commit | 1d9bbacdfbdf21e8af25a19a91f746bed1087b5e (patch) | |
tree | 27f7ee5d7913a8bc81acbf7653f34cb696bae8bb | |
parent | d8010d83eae7865d3d7a67ee6d5ca2304a0970ec (diff) | |
download | nix-1d9bbacdfbdf21e8af25a19a91f746bed1087b5e.zip |
added wait system call and unit test
-rw-r--r-- | src/sys/wait.rs | 6 | ||||
-rw-r--r-- | test/test_unistd.rs | 17 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/sys/wait.rs b/src/sys/wait.rs index a6bccd8a..9252609b 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -16,7 +16,7 @@ bitflags!( } ); -#[derive(Clone, Copy)] +#[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum WaitStatus { Exited(pid_t), StillAlive @@ -42,3 +42,7 @@ pub fn waitpid(pid: pid_t, options: Option<WaitPidFlag>) -> Result<WaitStatus> { Ok(Exited(res)) } } + +pub fn wait() -> Result<WaitStatus> { + waitpid(-1, None) +} diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 50af197c..055c0c1a 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -30,6 +30,23 @@ fn test_fork_and_waitpid() { } #[test] +fn test_wait() { + let pid = fork(); + match pid { + Ok(Child) => {} // ignore child here + Ok(Parent(child_pid)) => { + let wait_status = wait(); + + // just assert that (any) one child returns with WaitStatus::Exited + assert_eq!(wait_status, Ok(WaitStatus::Exited(child_pid))); + }, + // panic, fork should never fail unless there is a serious problem with the OS + Err(_) => panic!("Error: Fork Failed") + } +} + + +#[test] fn test_getpid() { let pid = getpid(); let ppid = getppid(); |