diff options
author | Jamie Hewland <jhewland@gmail.com> | 2017-09-09 21:18:44 +0200 |
---|---|---|
committer | Jamie Hewland <jhewland@gmail.com> | 2017-11-12 10:56:58 +0200 |
commit | a7ebd89b428930c492d7cd2905cc0741c108a4ed (patch) | |
tree | 6519332414e9fb31f5d44337e48b739f50d7e2e4 | |
parent | e36d4afc34e0c97b99ac7f1cbb4a3aeaf14e0ab4 (diff) | |
download | nix-a7ebd89b428930c492d7cd2905cc0741c108a4ed.zip |
groups tests: Add groups mutex and print message when tests skipped
Fix groups mutex name
-rw-r--r-- | test/test.rs | 3 | ||||
-rw-r--r-- | test/test_unistd.rs | 14 |
2 files changed, 17 insertions, 0 deletions
diff --git a/test/test.rs b/test/test.rs index 1b73c4ff..f4942d3d 100644 --- a/test/test.rs +++ b/test/test.rs @@ -43,6 +43,9 @@ 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 changes the process's supplementary groups must grab this + /// mutex + pub static ref GROUPS_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(()); diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 73e8b8ab..2bb432d0 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -128,9 +128,16 @@ mod linux_android { fn test_setgroups() { // Skip this test when not run as root as `setgroups()` requires root. if !Uid::current().is_root() { + use std::io; + let stderr = io::stderr(); + let mut handle = stderr.lock(); + writeln!(handle, "test_setgroups requires root privileges. Skipping test.").unwrap(); return } + #[allow(unused_variables)] + let m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test"); + // Save the existing groups let old_groups = getgroups().unwrap(); @@ -152,9 +159,16 @@ fn test_initgroups() { // Skip this test when not run as root as `initgroups()` and `setgroups()` // require root. if !Uid::current().is_root() { + use std::io; + let stderr = io::stderr(); + let mut handle = stderr.lock(); + writeln!(handle, "test_initgroups requires root privileges. Skipping test.").unwrap(); return } + #[allow(unused_variables)] + let m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test"); + // Save the existing groups let old_groups = getgroups().unwrap(); |