Skip to content

Commit

Permalink
groups tests: Add groups mutex and print message when tests skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
JayH5 committed Sep 9, 2017
1 parent 01fa5c7 commit 9a92ad5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand Down
14 changes: 14 additions & 0 deletions test/test_unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,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();

Expand All @@ -134,9 +141,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_MUTEX.lock().expect("Mutex got poisoned by another test");

// Save the existing groups
let old_groups = getgroups().unwrap();

Expand Down

0 comments on commit 9a92ad5

Please sign in to comment.