xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/getrlimit/getrlimit02.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Wipro Technologies, 2002. All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  * AUTHOR: Suresh Babu V. <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker  */
6*49cdfc7eSAndroid Build Coastguard Worker 
7*49cdfc7eSAndroid Build Coastguard Worker /*\
8*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  * Test for checking error conditions for getrlimit(2):
11*49cdfc7eSAndroid Build Coastguard Worker  *
12*49cdfc7eSAndroid Build Coastguard Worker  * 1. getrlimit(2) returns -1 and sets errno to EFAULT if an invalid
13*49cdfc7eSAndroid Build Coastguard Worker  *	  address is given for address parameter.
14*49cdfc7eSAndroid Build Coastguard Worker  * 2. getrlimit(2) returns -1 and sets errno to EINVAL if an invalid
15*49cdfc7eSAndroid Build Coastguard Worker  *	  resource type (RLIM_NLIMITS is a out of range resource type) is
16*49cdfc7eSAndroid Build Coastguard Worker  *	  passed.
17*49cdfc7eSAndroid Build Coastguard Worker  */
18*49cdfc7eSAndroid Build Coastguard Worker 
19*49cdfc7eSAndroid Build Coastguard Worker #include <sys/resource.h>
20*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
21*49cdfc7eSAndroid Build Coastguard Worker 
22*49cdfc7eSAndroid Build Coastguard Worker #define INVALID_RES_TYPE 1000
23*49cdfc7eSAndroid Build Coastguard Worker 
24*49cdfc7eSAndroid Build Coastguard Worker static struct rlimit rlim;
25*49cdfc7eSAndroid Build Coastguard Worker 
26*49cdfc7eSAndroid Build Coastguard Worker static struct tcase {
27*49cdfc7eSAndroid Build Coastguard Worker 	int exp_errno;
28*49cdfc7eSAndroid Build Coastguard Worker 	char *desc;
29*49cdfc7eSAndroid Build Coastguard Worker 	struct rlimit *rlim;
30*49cdfc7eSAndroid Build Coastguard Worker 	int res_type;
31*49cdfc7eSAndroid Build Coastguard Worker } tcases[] = {
32*49cdfc7eSAndroid Build Coastguard Worker 	{EFAULT, "invalid address", (void *)-1, RLIMIT_CORE},
33*49cdfc7eSAndroid Build Coastguard Worker 	{EINVAL, "invalid resource type", &rlim, INVALID_RES_TYPE}
34*49cdfc7eSAndroid Build Coastguard Worker };
35*49cdfc7eSAndroid Build Coastguard Worker 
verify_getrlimit(unsigned int i)36*49cdfc7eSAndroid Build Coastguard Worker static void verify_getrlimit(unsigned int i)
37*49cdfc7eSAndroid Build Coastguard Worker {
38*49cdfc7eSAndroid Build Coastguard Worker 	struct tcase *tc = &tcases[i];
39*49cdfc7eSAndroid Build Coastguard Worker 
40*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_FAIL(getrlimit(tc->res_type, tc->rlim),
41*49cdfc7eSAndroid Build Coastguard Worker 				tc->exp_errno,
42*49cdfc7eSAndroid Build Coastguard Worker 				"getrlimit() with %s",
43*49cdfc7eSAndroid Build Coastguard Worker 				tc->desc);
44*49cdfc7eSAndroid Build Coastguard Worker }
45*49cdfc7eSAndroid Build Coastguard Worker 
46*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
47*49cdfc7eSAndroid Build Coastguard Worker 	.tcnt = ARRAY_SIZE(tcases),
48*49cdfc7eSAndroid Build Coastguard Worker 	.test = verify_getrlimit,
49*49cdfc7eSAndroid Build Coastguard Worker };
50