Skip to content

Commit b5cc435

Browse files
committed
groups tests: Add groups mutex and print message when tests skipped
Fix groups mutex name
1 parent 01fa5c7 commit b5cc435

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

test/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ lazy_static! {
4343
/// Any test that changes the process's current working directory must grab
4444
/// this mutex
4545
pub static ref CWD_MTX: Mutex<()> = Mutex::new(());
46+
/// Any test that changes the process's supplementary groups must grab this
47+
/// mutex
48+
pub static ref GROUPS_MTX: Mutex<()> = Mutex::new(());
4649
/// Any test that creates child processes must grab this mutex, regardless
4750
/// of what it does with those children.
4851
pub static ref FORK_MTX: Mutex<()> = Mutex::new(());

test/test_unistd.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,16 @@ mod linux_android {
110110
fn test_setgroups() {
111111
// Skip this test when not run as root as `setgroups()` requires root.
112112
if !Uid::current().is_root() {
113+
use std::io;
114+
let stderr = io::stderr();
115+
let mut handle = stderr.lock();
116+
writeln!(handle, "test_setgroups requires root privileges. Skipping test.").unwrap();
113117
return
114118
}
115119

120+
#[allow(unused_variables)]
121+
let m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test");
122+
116123
// Save the existing groups
117124
let old_groups = getgroups().unwrap();
118125

@@ -134,9 +141,16 @@ fn test_initgroups() {
134141
// Skip this test when not run as root as `initgroups()` and `setgroups()`
135142
// require root.
136143
if !Uid::current().is_root() {
144+
use std::io;
145+
let stderr = io::stderr();
146+
let mut handle = stderr.lock();
147+
writeln!(handle, "test_initgroups requires root privileges. Skipping test.").unwrap();
137148
return
138149
}
139150

151+
#[allow(unused_variables)]
152+
let m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test");
153+
140154
// Save the existing groups
141155
let old_groups = getgroups().unwrap();
142156

0 commit comments

Comments
 (0)