summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThomas de Zeeuw <thomasdezeeuw@gmail.com>2018-01-05 16:28:14 +0100
committerThomas de Zeeuw <thomasdezeeuw@gmail.com>2018-01-06 17:05:41 +0100
commitefc9ac3138c85698487cd65186cde6dafc2e72d2 (patch)
tree30436c15f1d96db97ae650211eeb8c0424a58601 /test
parentbb69c29b17b76c9745c4299561070dc8b4da6f6a (diff)
downloadnix-efc9ac3138c85698487cd65186cde6dafc2e72d2.zip
Add sigprocmask
Diffstat (limited to 'test')
-rw-r--r--test/sys/test_signal.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/sys/test_signal.rs b/test/sys/test_signal.rs
index ab99ab19..ae959ef4 100644
--- a/test/sys/test_signal.rs
+++ b/test/sys/test_signal.rs
@@ -5,3 +5,45 @@ use nix::sys::signal::*;
fn test_kill_none() {
kill(getpid(), None).expect("Should be able to send signal to myself.");
}
+
+#[test]
+fn test_sigprocmask_noop() {
+ sigprocmask(SigmaskHow::SIG_BLOCK, None, None)
+ .expect("this should be an effective noop");
+}
+
+#[test]
+fn test_sigprocmask() {
+ #[allow(unused_variables)]
+ let m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
+
+ // This needs to be a signal that rust doesn't use in the test harness.
+ const SIGNAL: Signal = Signal::SIGCHLD;
+
+ let mut old_signal_set = SigSet::empty();
+ sigprocmask(SigmaskHow::SIG_BLOCK, None, Some(&mut old_signal_set))
+ .expect("expect to be able to retrieve old signals");
+
+ // Make sure the old set doesn't contain the signal, otherwise the following
+ // test don't make sense.
+ assert_eq!(old_signal_set.contains(SIGNAL), false,
+ "the {:?} signal is already blocked, please change to a \
+ different one", SIGNAL);
+
+ // Now block the signal.
+ let mut signal_set = SigSet::empty();
+ signal_set.add(SIGNAL);
+ sigprocmask(SigmaskHow::SIG_BLOCK, Some(&signal_set), None)
+ .expect("expect to be able to block signals");
+
+ // And test it again, to make sure the change was effective.
+ old_signal_set.clear();
+ sigprocmask(SigmaskHow::SIG_BLOCK, None, Some(&mut old_signal_set))
+ .expect("expect to be able to retrieve old signals");
+ assert_eq!(old_signal_set.contains(SIGNAL), true,
+ "expected the {:?} to be blocked", SIGNAL);
+
+ // Reset the signal.
+ sigprocmask(SigmaskHow::SIG_UNBLOCK, Some(&signal_set), None)
+ .expect("expect to be able to block signals");
+}