• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *   Copyright (c) Wipro Technologies, 2002. All Rights Reserved.
4  *   Author: Suresh Babu V. <suresh.babu@wipro.com>
5  *
6  *   This program is free software;  you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
14  *   the GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program;  if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  * Verify that getrlimit(2) call will be successful for all possible resource
23  * types.
24  */
25 #include <stdio.h>
26 #include <errno.h>
27 #include <sys/time.h>
28 #include <sys/resource.h>
29 #include "test.h"
30 
31 static void cleanup(void);
32 static void setup(void);
33 
34 static struct rlimit rlim;
35 static struct test_t {
36 	int res;
37 	char *res_str;
38 } testcases[] = {
39 	{RLIMIT_CPU, "RLIMIT_CPU"},
40 	{RLIMIT_FSIZE, "RLIMIT_FSIZE"},
41 	{RLIMIT_DATA, "RLIMIT_DATA"},
42 	{RLIMIT_STACK, "RLIMIT_STACK"},
43 	{RLIMIT_CORE, "RLIMIT_CORE"},
44 	{RLIMIT_RSS, "RLIMIT_RSS"},
45 	{RLIMIT_NPROC, "RLIMIT_NPROC"},
46 	{RLIMIT_NOFILE, "RLIMIT_NOFILE"},
47 	{RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK"},
48 	{RLIMIT_AS, "RLIMIT_AS"},
49 	{RLIMIT_LOCKS, "RLIMIT_LOCKS"},
50 	{RLIMIT_MSGQUEUE, "RLIMIT_MSGQUEUE"},
51 #ifdef RLIMIT_NICE
52 	{RLIMIT_NICE, "RLIMIT_NICE"},
53 #endif
54 #ifdef RLIMIT_RTPRIO
55 	{RLIMIT_RTPRIO, "RLIMIT_RTPRIO"},
56 #endif
57 	{RLIMIT_SIGPENDING, "RLIMIT_SIGPENDING"},
58 #ifdef RLIMIT_RTTIME
59 	{RLIMIT_RTTIME, "RLIMIT_RTTIME"},
60 #endif
61 };
62 
63 char *TCID = "getrlimit01";
64 int TST_TOTAL = ARRAY_SIZE(testcases);
65 
main(int ac,char ** av)66 int main(int ac, char **av)
67 {
68 	int i;
69 	int lc;
70 
71 	tst_parse_opts(ac, av, NULL, NULL);
72 
73 	setup();
74 
75 	for (lc = 0; TEST_LOOPING(lc); lc++) {
76 
77 		tst_count = 0;
78 
79 		for (i = 0; i < TST_TOTAL; ++i) {
80 
81 			TEST(getrlimit(testcases[i].res, &rlim));
82 
83 			if (TEST_RETURN == -1) {
84 				tst_resm(TFAIL | TTERRNO,
85 					 "getrlimit() test %s failed",
86 					 testcases[i].res_str);
87 			} else {
88 				tst_resm(TPASS,
89 					 "getrlimit() test %s success",
90 					 testcases[i].res_str);
91 			}
92 		}
93 	}
94 
95 	cleanup();
96 	tst_exit();
97 }
98 
setup(void)99 static void setup(void)
100 {
101 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
102 
103 	TEST_PAUSE;
104 }
105 
cleanup(void)106 static void cleanup(void)
107 {
108 }
109