xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/setgroups/setgroups01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-only
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Linux Test Project, 2003-2023
5*49cdfc7eSAndroid Build Coastguard Worker  *
6*49cdfc7eSAndroid Build Coastguard Worker  * Author: William Roske
7*49cdfc7eSAndroid Build Coastguard Worker  * CO-PILOT: Dave Fenner
8*49cdfc7eSAndroid Build Coastguard Worker  */
9*49cdfc7eSAndroid Build Coastguard Worker 
10*49cdfc7eSAndroid Build Coastguard Worker /*\
11*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
12*49cdfc7eSAndroid Build Coastguard Worker  *
13*49cdfc7eSAndroid Build Coastguard Worker  * Check the basic functionality of the setgroups() system call.
14*49cdfc7eSAndroid Build Coastguard Worker  */
15*49cdfc7eSAndroid Build Coastguard Worker 
16*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
17*49cdfc7eSAndroid Build Coastguard Worker #include "compat_tst_16.h"
18*49cdfc7eSAndroid Build Coastguard Worker 
19*49cdfc7eSAndroid Build Coastguard Worker static int len = NGROUPS;
20*49cdfc7eSAndroid Build Coastguard Worker 
21*49cdfc7eSAndroid Build Coastguard Worker static GID_T list[NGROUPS];
22*49cdfc7eSAndroid Build Coastguard Worker 
verify_setgroups(void)23*49cdfc7eSAndroid Build Coastguard Worker static void verify_setgroups(void)
24*49cdfc7eSAndroid Build Coastguard Worker {
25*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_POSITIVE(SETGROUPS(1, list), "setgroups()");
26*49cdfc7eSAndroid Build Coastguard Worker }
27*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)28*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
29*49cdfc7eSAndroid Build Coastguard Worker {
30*49cdfc7eSAndroid Build Coastguard Worker 	len = GETGROUPS(NGROUPS, list);
31*49cdfc7eSAndroid Build Coastguard Worker 	if (len < 0)
32*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK | TERRNO, "getgroups() Failed");
33*49cdfc7eSAndroid Build Coastguard Worker }
34*49cdfc7eSAndroid Build Coastguard Worker 
35*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
36*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = verify_setgroups,
37*49cdfc7eSAndroid Build Coastguard Worker 	.setup = setup,
38*49cdfc7eSAndroid Build Coastguard Worker 	.needs_root = 1,
39*49cdfc7eSAndroid Build Coastguard Worker };
40