blob: b0c441a97e642c960d160943f020ed3ec7d7c8e6 [file] [log] [blame]
robbiew3dde45d2003-01-08 16:33:11 +00001/*
2 *
3 * Copyright (c) Wipro Technologies, 2002. All Rights Reserved.
zenglg.jy2bf2a072013-12-12 18:26:52 +08004 * Author: Suresh Babu V. <suresh.babu@wipro.com>
robbiew3dde45d2003-01-08 16:33:11 +00005 *
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiew3dde45d2003-01-08 16:33:11 +000019 */
20
zenglg.jy2bf2a072013-12-12 18:26:52 +080021/*
22 * Verify that getrlimit(2) call will be successful for all possible resource
23 * types.
24 */
robbiew3dde45d2003-01-08 16:33:11 +000025#include <stdio.h>
26#include <errno.h>
27#include <sys/time.h>
28#include <sys/resource.h>
29#include "test.h"
robbiew3dde45d2003-01-08 16:33:11 +000030
robbiew3dde45d2003-01-08 16:33:11 +000031static void cleanup(void);
32static void setup(void);
33
robbiew3dde45d2003-01-08 16:33:11 +000034static struct rlimit rlim;
35static struct test_t {
36 int res;
37 char *res_str;
38} testcases[] = {
zenglg.jy2bf2a072013-12-12 18:26:52 +080039 {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"},
zenglg.jy63b2c7c2013-12-12 18:27:50 +080050 {RLIMIT_MSGQUEUE, "RLIMIT_MSGQUEUE"},
Cyril Hrubis20af4462014-04-14 17:29:52 +020051#ifdef RLIMIT_NICE
zenglg.jy63b2c7c2013-12-12 18:27:50 +080052 {RLIMIT_NICE, "RLIMIT_NICE"},
Cyril Hrubis20af4462014-04-14 17:29:52 +020053#endif
54#ifdef RLIMIT_RTPRIO
zenglg.jy63b2c7c2013-12-12 18:27:50 +080055 {RLIMIT_RTPRIO, "RLIMIT_RTPRIO"},
Cyril Hrubis20af4462014-04-14 17:29:52 +020056#endif
zenglg.jy63b2c7c2013-12-12 18:27:50 +080057 {RLIMIT_SIGPENDING, "RLIMIT_SIGPENDING"},
58#ifdef RLIMIT_RTTIME
59 {RLIMIT_RTTIME, "RLIMIT_RTTIME"},
60#endif
robbiew3dde45d2003-01-08 16:33:11 +000061};
62
zenglg.jy2bf2a072013-12-12 18:26:52 +080063char *TCID = "getrlimit01";
64int TST_TOTAL = ARRAY_SIZE(testcases);
robbiew3dde45d2003-01-08 16:33:11 +000065
subrata_modak56207ce2009-03-23 13:35:39 +000066int main(int ac, char **av)
robbiew3dde45d2003-01-08 16:33:11 +000067{
68 int i;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020069 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020070 const char *msg;
robbiew3dde45d2003-01-08 16:33:11 +000071
zenglg.jy2bf2a072013-12-12 18:26:52 +080072 msg = parse_opts(ac, av, NULL, NULL);
73 if (msg != NULL)
robbiew3dde45d2003-01-08 16:33:11 +000074 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew3dde45d2003-01-08 16:33:11 +000075
robbiew3dde45d2003-01-08 16:33:11 +000076 setup();
77
robbiew3dde45d2003-01-08 16:33:11 +000078 for (lc = 0; TEST_LOOPING(lc); lc++) {
zenglg.jy2bf2a072013-12-12 18:26:52 +080079
Caspar Zhangd59a6592013-03-07 14:59:12 +080080 tst_count = 0;
robbiew3dde45d2003-01-08 16:33:11 +000081
82 for (i = 0; i < TST_TOTAL; ++i) {
83
robbiew3dde45d2003-01-08 16:33:11 +000084 TEST(getrlimit(testcases[i].res, &rlim));
subrata_modak4bb656a2009-02-26 12:02:09 +000085
robbiew3dde45d2003-01-08 16:33:11 +000086 if (TEST_RETURN == -1) {
zenglg.jy2bf2a072013-12-12 18:26:52 +080087 tst_resm(TFAIL | TTERRNO,
88 "getrlimit() test %s failed",
89 testcases[i].res_str);
subrata_modak56207ce2009-03-23 13:35:39 +000090 } else {
zenglg.jy2bf2a072013-12-12 18:26:52 +080091 tst_resm(TPASS,
92 "getrlimit() test %s success",
93 testcases[i].res_str);
robbiew3dde45d2003-01-08 16:33:11 +000094 }
95 }
96 }
robbiew3dde45d2003-01-08 16:33:11 +000097
zenglg.jy2bf2a072013-12-12 18:26:52 +080098 cleanup();
Garrett Cooper2c282152010-12-16 00:55:50 -080099 tst_exit();
robbiew3dde45d2003-01-08 16:33:11 +0000100}
101
zenglg.jy2bf2a072013-12-12 18:26:52 +0800102static void setup(void)
robbiew3dde45d2003-01-08 16:33:11 +0000103{
robbiew3dde45d2003-01-08 16:33:11 +0000104 tst_sig(NOFORK, DEF_HANDLER, cleanup);
105
robbiew3dde45d2003-01-08 16:33:11 +0000106 TEST_PAUSE;
107}
108
zenglg.jy2bf2a072013-12-12 18:26:52 +0800109static void cleanup(void)
robbiew3dde45d2003-01-08 16:33:11 +0000110{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700111}