1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Wipro Technologies, 2002. All Rights Reserved.
4 * AUTHOR: Suresh Babu V. <suresh.babu@wipro.com>
5 */
6
7 /*\
8 * [Description]
9 *
10 * Test for checking error conditions for getrlimit(2)
11 * 1) getrlimit(2) returns -1 and sets errno to EFAULT if an invalid
12 * address is given for address parameter.
13 * 2) getrlimit(2) returns -1 and sets errno to EINVAL if an invalid
14 * resource type (RLIM_NLIMITS is a out of range resource type) is
15 * passed.
16 */
17
18 #include <sys/resource.h>
19 #include "tst_test.h"
20
21 #define RLIMIT_TOO_HIGH 1000
22
23 static struct rlimit rlim;
24
25 static struct tcase {
26 int exp_errno; /* Expected error no */
27 char *exp_errval; /* Expected error value string */
28 struct rlimit *rlim; /* rlimit structure */
29 int res_type; /* resource type */
30 } tcases[] = {
31 { EINVAL, "EINVAL", &rlim, RLIMIT_TOO_HIGH}
32 };
33
verify_getrlimit(unsigned int i)34 static void verify_getrlimit(unsigned int i)
35 {
36 struct tcase *tc = &tcases[i];
37
38 TEST(getrlimit(tc->res_type, tc->rlim));
39
40 if ((TST_RET == -1) && (TST_ERR == tc->exp_errno)) {
41 tst_res(TPASS, "expected failure; got %s",
42 tc->exp_errval);
43 } else {
44 tst_res(TFAIL, "call failed to produce "
45 "expected error; errno: %d : %s",
46 TST_ERR, strerror(TST_ERR));
47 }
48 }
49
50 static struct tst_test test = {
51 .tcnt = ARRAY_SIZE(tcases),
52 .test = verify_getrlimit,
53 };
54