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 * Verify that getrlimit(2) call will be successful for all possible resource
11 * types.
12 */
13
14 #include <sys/resource.h>
15 #include "tst_test.h"
16
17 static struct tcase {
18 int res;
19 char *res_str;
20 } tcases[] = {
21 {RLIMIT_CPU, "RLIMIT_CPU"},
22 {RLIMIT_FSIZE, "RLIMIT_FSIZE"},
23 {RLIMIT_DATA, "RLIMIT_DATA"},
24 {RLIMIT_STACK, "RLIMIT_STACK"},
25 {RLIMIT_CORE, "RLIMIT_CORE"},
26 {RLIMIT_RSS, "RLIMIT_RSS"},
27 {RLIMIT_NPROC, "RLIMIT_NPROC"},
28 {RLIMIT_NOFILE, "RLIMIT_NOFILE"},
29 {RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK"},
30 {RLIMIT_AS, "RLIMIT_AS"},
31 {RLIMIT_LOCKS, "RLIMIT_LOCKS"},
32 {RLIMIT_MSGQUEUE, "RLIMIT_MSGQUEUE"},
33 #ifdef RLIMIT_NICE
34 {RLIMIT_NICE, "RLIMIT_NICE"},
35 #endif
36 #ifdef RLIMIT_RTPRIO
37 {RLIMIT_RTPRIO, "RLIMIT_RTPRIO"},
38 #endif
39 {RLIMIT_SIGPENDING, "RLIMIT_SIGPENDING"},
40 #ifdef RLIMIT_RTTIME
41 {RLIMIT_RTTIME, "RLIMIT_RTTIME"},
42 #endif
43 };
44
verify_getrlimit(unsigned int i)45 static void verify_getrlimit(unsigned int i)
46 {
47 struct rlimit rlim;
48 struct tcase *tc = &tcases[i];
49
50 TEST(getrlimit(tc->res, &rlim));
51
52 if (TST_RET == -1) {
53 tst_res(TFAIL | TTERRNO,
54 "getrlimit() test %s failed",
55 tc->res_str);
56 } else {
57 tst_res(TPASS,
58 "getrlimit() test %s success",
59 tc->res_str);
60 }
61 }
62
63 static struct tst_test test = {
64 .tcnt = ARRAY_SIZE(tcases),
65 .test = verify_getrlimit,
66 };
67