summaryrefslogtreecommitdiff
path: root/test/test.rs
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2017-06-30 10:49:18 -0600
committerAlan Somers <asomers@gmail.com>2017-07-16 13:29:27 -0600
commit64f798492c5d7abfef8be9837ae0703cda43b48e (patch)
tree07bbaa6486c77b35c80609e3538966d510c4f58e /test/test.rs
parent386c50cf0a9c3d5c1e481fb76ee2f17a12b3fc44 (diff)
downloadnix-64f798492c5d7abfef8be9837ae0703cda43b48e.zip
Fix thread safety issues in aio, chdir, and wait tests
They have four problems: * The chdir tests change the process's cwd, which is global. Protect them all with a mutex. * The wait tests will reap any subprocess, and several tests create subprocesses. Protect them all with a mutex so only one subprocess-creating test will run at a time. * When a multithreaded test forks, the child process can sometimes block in the stack unwinding code. It blocks on a mutex that was held by a different thread in the parent, but that thread doesn't exist in the child, so a deadlock results. Fix this by immediately calling std::process:exit in the child processes. * My previous attempt at thread safety in the aio tests didn't work, because anonymous MutexGuards drop immediately. Fix this by naming the SIGUSR2_MTX MutexGuards. Fixes #251
Diffstat (limited to 'test/test.rs')
-rw-r--r--test/test.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/test.rs b/test/test.rs
index 2cf30360..4c81aa2b 100644
--- a/test/test.rs
+++ b/test/test.rs
@@ -25,6 +25,7 @@ mod test_unistd;
use nixtest::assert_size_of;
use std::os::unix::io::RawFd;
+use std::sync::Mutex;
use nix::unistd::read;
/// Helper function analogous to std::io::Read::read_exact, but for `RawFD`s
@@ -37,6 +38,17 @@ fn read_exact(f: RawFd, buf: &mut [u8]) {
}
}
+lazy_static! {
+ /// Any test that changes the process's current working directory must grab
+ /// this mutex
+ pub static ref CWD_MTX: Mutex<()> = Mutex::new(());
+ /// Any test that creates child processes must grab this mutex, regardless
+ /// of what it does with those children.
+ pub static ref FORK_MTX: Mutex<()> = Mutex::new(());
+ /// Any test that registers a SIGUSR2 handler must grab this mutex
+ pub static ref SIGUSR2_MTX: Mutex<()> = Mutex::new(());
+}
+
#[test]
pub fn test_size_of_long() {
// This test is mostly here to ensure that 32bit CI is correctly