Fix getgroups / setgroups tests across platforms

See #619
This commit is contained in:
Justine Tunney 2022-09-18 03:17:06 -07:00
parent 97bb5a3a80
commit 40991ec992
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
3 changed files with 17 additions and 27 deletions

View file

@ -18,30 +18,14 @@
*/
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/macros.internal.h"
#include "libc/testlib/testlib.h"
TEST(getgroups, test) {
int rc;
uint32_t res[1000];
rc = getgroups(0, NULL);
if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
EXPECT_NE(-1, rc);
EXPECT_NE(-1, getgroups(sizeof(res) / sizeof(res[0]), res));
} else {
EXPECT_EQ(-1, rc);
EXPECT_EQ(ENOSYS, errno);
}
}
TEST(setgroups, test) {
int rc;
uint32_t src[5];
EXPECT_EQ(-1, setgroups(0, NULL));
if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
EXPECT_EQ(EPERM, errno);
EXPECT_EQ(-1, setgroups(sizeof(src) / sizeof(src[0]), src));
} else {
EXPECT_EQ(ENOSYS, errno);
}
int n;
if (IsWindows()) return;
uint32_t G[500];
EXPECT_GT((n = getgroups(ARRAYLEN(G), G)), 0);
if (getuid()) return; // this needs root
EXPECT_SYS(0, 0, setgroups(n, G));
}