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