1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) International Business Machines Corp., 2001
4 * Ported by Wayne Boyer
5 */
6
7 /*\
8 * [Description]
9 * Testcase to check the basic functionality of getgid().
10 *
11 * [Algorithm]
12 * For functionality test the return value from getgid() is compared to passwd
13 * entry.
14 */
15
16 #include <pwd.h>
17 #include "tst_test.h"
18 #include "compat_tst_16.h"
19
run(void)20 static void run(void)
21 {
22 uid_t uid;
23 struct passwd *pwent;
24
25 TEST(GETGID());
26 if (TST_RET < 0)
27 tst_brk(TBROK, "This should never happen");
28
29 uid = getuid();
30 pwent = getpwuid(uid);
31 if (pwent == NULL)
32 tst_brk(TBROK | TERRNO, "getuid() returned unexpected value %d", uid);
33
34 GID16_CHECK(pwent->pw_gid, getgid);
35
36 if (pwent->pw_gid != TST_RET) {
37 tst_res(TFAIL, "getgid() return value "
38 "%ld unexpected - expected %d",
39 TST_RET, pwent->pw_gid);
40 return;
41 }
42
43 tst_res(TPASS, "values from getgid() and getpwuid() match");
44 }
45
46 static struct tst_test test = {
47 .test_all = run,
48 };
49