robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) Wipro Technologies, 2002. All Rights Reserved. |
zenglg.jy | 2bf2a07 | 2013-12-12 18:26:52 +0800 | [diff] [blame] | 4 | * Author: Suresh Babu V. <suresh.babu@wipro.com> |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
zenglg.jy | 2bf2a07 | 2013-12-12 18:26:52 +0800 | [diff] [blame] | 21 | /* |
| 22 | * Verify that getrlimit(2) call will be successful for all possible resource |
| 23 | * types. |
| 24 | */ |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <errno.h> |
| 27 | #include <sys/time.h> |
| 28 | #include <sys/resource.h> |
| 29 | #include "test.h" |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 30 | |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 31 | static void cleanup(void); |
| 32 | static void setup(void); |
| 33 | |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 34 | static struct rlimit rlim; |
| 35 | static struct test_t { |
| 36 | int res; |
| 37 | char *res_str; |
| 38 | } testcases[] = { |
zenglg.jy | 2bf2a07 | 2013-12-12 18:26:52 +0800 | [diff] [blame] | 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"}, |
zenglg.jy | 63b2c7c | 2013-12-12 18:27:50 +0800 | [diff] [blame] | 50 | {RLIMIT_MSGQUEUE, "RLIMIT_MSGQUEUE"}, |
Cyril Hrubis | 20af446 | 2014-04-14 17:29:52 +0200 | [diff] [blame] | 51 | #ifdef RLIMIT_NICE |
zenglg.jy | 63b2c7c | 2013-12-12 18:27:50 +0800 | [diff] [blame] | 52 | {RLIMIT_NICE, "RLIMIT_NICE"}, |
Cyril Hrubis | 20af446 | 2014-04-14 17:29:52 +0200 | [diff] [blame] | 53 | #endif |
| 54 | #ifdef RLIMIT_RTPRIO |
zenglg.jy | 63b2c7c | 2013-12-12 18:27:50 +0800 | [diff] [blame] | 55 | {RLIMIT_RTPRIO, "RLIMIT_RTPRIO"}, |
Cyril Hrubis | 20af446 | 2014-04-14 17:29:52 +0200 | [diff] [blame] | 56 | #endif |
zenglg.jy | 63b2c7c | 2013-12-12 18:27:50 +0800 | [diff] [blame] | 57 | {RLIMIT_SIGPENDING, "RLIMIT_SIGPENDING"}, |
| 58 | #ifdef RLIMIT_RTTIME |
| 59 | {RLIMIT_RTTIME, "RLIMIT_RTTIME"}, |
| 60 | #endif |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
zenglg.jy | 2bf2a07 | 2013-12-12 18:26:52 +0800 | [diff] [blame] | 63 | char *TCID = "getrlimit01"; |
| 64 | int TST_TOTAL = ARRAY_SIZE(testcases); |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 65 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 66 | int main(int ac, char **av) |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 67 | { |
| 68 | int i; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 69 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 70 | const char *msg; |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 71 | |
zenglg.jy | 2bf2a07 | 2013-12-12 18:26:52 +0800 | [diff] [blame] | 72 | msg = parse_opts(ac, av, NULL, NULL); |
| 73 | if (msg != NULL) |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 74 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 75 | |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 76 | setup(); |
| 77 | |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 78 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
zenglg.jy | 2bf2a07 | 2013-12-12 18:26:52 +0800 | [diff] [blame] | 79 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 80 | tst_count = 0; |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 81 | |
| 82 | for (i = 0; i < TST_TOTAL; ++i) { |
| 83 | |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 84 | TEST(getrlimit(testcases[i].res, &rlim)); |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 85 | |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 86 | if (TEST_RETURN == -1) { |
zenglg.jy | 2bf2a07 | 2013-12-12 18:26:52 +0800 | [diff] [blame] | 87 | tst_resm(TFAIL | TTERRNO, |
| 88 | "getrlimit() test %s failed", |
| 89 | testcases[i].res_str); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 90 | } else { |
zenglg.jy | 2bf2a07 | 2013-12-12 18:26:52 +0800 | [diff] [blame] | 91 | tst_resm(TPASS, |
| 92 | "getrlimit() test %s success", |
| 93 | testcases[i].res_str); |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | } |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 97 | |
zenglg.jy | 2bf2a07 | 2013-12-12 18:26:52 +0800 | [diff] [blame] | 98 | cleanup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 99 | tst_exit(); |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 100 | } |
| 101 | |
zenglg.jy | 2bf2a07 | 2013-12-12 18:26:52 +0800 | [diff] [blame] | 102 | static void setup(void) |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 103 | { |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 104 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 105 | |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 106 | TEST_PAUSE; |
| 107 | } |
| 108 | |
zenglg.jy | 2bf2a07 | 2013-12-12 18:26:52 +0800 | [diff] [blame] | 109 | static void cleanup(void) |
robbiew | 3dde45d | 2003-01-08 16:33:11 +0000 | [diff] [blame] | 110 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 111 | } |