Skip to content

Commit a7ebd89

Browse files
committed
groups tests: Add groups mutex and print message when tests skipped
Fix groups mutex name
1 parent e36d4af commit a7ebd89

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
@@ -128,9 +128,16 @@ mod linux_android {
128128
fn test_setgroups() {
129129
// Skip this test when not run as root as `setgroups()` requires root.
130130
if !Uid::current().is_root() {
131+
use std::io;
132+
let stderr = io::stderr();
133+
let mut handle = stderr.lock();
134+
writeln!(handle, "test_setgroups requires root privileges. Skipping test.").unwrap();
131135
return
132136
}
133137

138+
#[allow(unused_variables)]
139+
let m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test");
140+
134141
// Save the existing groups
135142
let old_groups = getgroups().unwrap();
136143

@@ -152,9 +159,16 @@ fn test_initgroups() {
152159
// Skip this test when not run as root as `initgroups()` and `setgroups()`
153160
// require root.
154161
if !Uid::current().is_root() {
162+
use std::io;
163+
let stderr = io::stderr();
164+
let mut handle = stderr.lock();
165+
writeln!(handle, "test_initgroups requires root privileges. Skipping test.").unwrap();
155166
return
156167
}
157168

169+
#[allow(unused_variables)]
170+
let m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test");
171+
158172
// Save the existing groups
159173
let old_groups = getgroups().unwrap();
160174

0 commit comments

Comments
 (0)