Skip to content

Commit 6c10e02

Browse files
committed
unistd: Add a simple test for setgroups/getgroups
1 parent c3b7291 commit 6c10e02

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/test_unistd.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,27 @@ mod linux_android {
104104
}
105105
}
106106

107+
#[test]
108+
fn test_setgroups() {
109+
if !Uid::current().is_root() {
110+
// setgroups() requires root
111+
return
112+
}
113+
114+
// Save the existing groups
115+
let old_groups = getgroups().unwrap();
116+
117+
// Set some new made up groups
118+
let groups = [Gid::from_raw(123), Gid::from_raw(456)];
119+
setgroups(&groups).unwrap();
120+
121+
let new_groups = getgroups().unwrap();
122+
assert_eq!(new_groups, groups);
123+
124+
// Revert back to the old groups
125+
setgroups(&old_groups).unwrap();
126+
}
127+
107128
macro_rules! execve_test_factory(
108129
($test_name:ident, $syscall:ident, $unix_sh:expr, $android_sh:expr) => (
109130
#[test]

0 commit comments

Comments
 (0)