blob: f4a24ca6f70baba5d7e860b37de1c811a4ea33e7 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
subrata_modak4bb656a2009-02-26 12:02:09 +00003 *
plars865695b2001-08-27 22:15:12 +00004 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
subrata_modak4bb656a2009-02-26 12:02:09 +00007 *
plars865695b2001-08-27 22:15:12 +00008 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
subrata_modak4bb656a2009-02-26 12:02:09 +000011 *
plars865695b2001-08-27 22:15:12 +000012 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
plars865695b2001-08-27 22:15:12 +000019 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080020 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
plars865695b2001-08-27 22:15:12 +000023 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
subrata_modak4bb656a2009-02-26 12:02:09 +000025 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
plars865695b2001-08-27 22:15:12 +000030 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31 */
subrata_modak923b23f2009-11-02 13:57:16 +000032/* $Id: ulimit01.c,v 1.6 2009/11/02 13:57:19 subrata_modak Exp $ */
plars865695b2001-08-27 22:15:12 +000033/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000034 *
plars865695b2001-08-27 22:15:12 +000035 * OS Test - Silicon Graphics, Inc.
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
plars865695b2001-08-27 22:15:12 +000037 * TEST IDENTIFIER : ulimit01
subrata_modak4bb656a2009-02-26 12:02:09 +000038 *
plars865695b2001-08-27 22:15:12 +000039 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000040 *
plars865695b2001-08-27 22:15:12 +000041 * TEST TITLE : Basic test for ulimit(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000042 *
plars865695b2001-08-27 22:15:12 +000043 * PARENT DOCUMENT : usctpl01
subrata_modak4bb656a2009-02-26 12:02:09 +000044 *
plars865695b2001-08-27 22:15:12 +000045 * TEST CASE TOTAL : 6
subrata_modak4bb656a2009-02-26 12:02:09 +000046 *
plars865695b2001-08-27 22:15:12 +000047 * WALL CLOCK TIME : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000048 *
plars865695b2001-08-27 22:15:12 +000049 * CPU TYPES : ALL
subrata_modak4bb656a2009-02-26 12:02:09 +000050 *
plars865695b2001-08-27 22:15:12 +000051 * AUTHOR : William Roske
subrata_modak4bb656a2009-02-26 12:02:09 +000052 *
plars865695b2001-08-27 22:15:12 +000053 * CO-PILOT : Dave Fenner
subrata_modak4bb656a2009-02-26 12:02:09 +000054 *
plars865695b2001-08-27 22:15:12 +000055 * DATE STARTED : 03/30/92
subrata_modak4bb656a2009-02-26 12:02:09 +000056 *
plars865695b2001-08-27 22:15:12 +000057 * INITIAL RELEASE : UNICOS 7.0
subrata_modak4bb656a2009-02-26 12:02:09 +000058 *
plars865695b2001-08-27 22:15:12 +000059 * TEST CASES
subrata_modak4bb656a2009-02-26 12:02:09 +000060 *
plars865695b2001-08-27 22:15:12 +000061 * 1.) ulimit(2) returns...(See Description)
subrata_modakbdbaec52009-02-26 12:14:51 +000062 *
plars865695b2001-08-27 22:15:12 +000063 * INPUT SPECIFICATIONS
64 * The standard options for system call tests are accepted.
65 * (See the parse_opts(3) man page).
subrata_modak4bb656a2009-02-26 12:02:09 +000066 *
plars865695b2001-08-27 22:15:12 +000067 * OUTPUT SPECIFICATIONS
subrata_modak56207ce2009-03-23 13:35:39 +000068 *$
plars865695b2001-08-27 22:15:12 +000069 * DURATION
70 * Terminates - with frequency and infinite modes.
subrata_modak4bb656a2009-02-26 12:02:09 +000071 *
plars865695b2001-08-27 22:15:12 +000072 * SIGNALS
73 * Uses SIGUSR1 to pause before test if option set.
74 * (See the parse_opts(3) man page).
75 *
76 * RESOURCES
77 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000078 *
plars865695b2001-08-27 22:15:12 +000079 * ENVIRONMENTAL NEEDS
subrata_modak4bb656a2009-02-26 12:02:09 +000080 * The libcuts.a and libsys.a libraries must be included in
plars865695b2001-08-27 22:15:12 +000081 * the compilation of this test.
subrata_modak4bb656a2009-02-26 12:02:09 +000082 *
plars865695b2001-08-27 22:15:12 +000083 * SPECIAL PROCEDURAL REQUIREMENTS
84 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000085 *
plars865695b2001-08-27 22:15:12 +000086 * INTERCASE DEPENDENCIES
87 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000088 *
plars865695b2001-08-27 22:15:12 +000089 * DETAILED DESCRIPTION
90 * This is a Phase I test for the ulimit(2) system call. It is intended
91 * to provide a limited exposure of the system call, for now. It
92 * should/will be extended when full functional tests are written for
93 * ulimit(2).
subrata_modak4bb656a2009-02-26 12:02:09 +000094 *
plars865695b2001-08-27 22:15:12 +000095 * Setup:
96 * Setup signal handling.
97 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000098 *
plars865695b2001-08-27 22:15:12 +000099 * Test:
100 * Loop if the proper options are given.
101 * Execute system call
102 * Check return code, if system call failed (return=-1)
103 * Log the errno and Issue a FAIL message.
104 * Otherwise, Issue a PASS message.
subrata_modak4bb656a2009-02-26 12:02:09 +0000105 *
plars865695b2001-08-27 22:15:12 +0000106 * Cleanup:
107 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +0000108 *
109 *
plars865695b2001-08-27 22:15:12 +0000110 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
111
112#include <ulimit.h>
113#include <errno.h>
114#include <string.h>
115#include <signal.h>
116#include "test.h"
plars865695b2001-08-27 22:15:12 +0000117
118void setup();
119void cleanup();
120
Cyril Hrubisfdce7d52013-04-04 18:35:48 +0200121char *TCID = "ulimit01";
122int TST_TOTAL = 6;
plars865695b2001-08-27 22:15:12 +0000123
124int cmd;
subrata_modak56207ce2009-03-23 13:35:39 +0000125long limit; /* saved limit */
plars865695b2001-08-27 22:15:12 +0000126
127struct limits_t {
subrata_modak56207ce2009-03-23 13:35:39 +0000128 int cmd;
129 long newlimit;
130 int nlim_flag; /* special flag for UL_SETFSIZE records */
131 int exp_fail;
plars865695b2001-08-27 22:15:12 +0000132} Scenarios[] = {
133
subrata_modak56207ce2009-03-23 13:35:39 +0000134 {
135 UL_GETFSIZE, -1, 0, 0}, {
136 UL_SETFSIZE, -2, 1, 0}, /* case case: must be after UL_GETFSIZE */
137 {
138 UL_SETFSIZE, -2, 2, 0}, /* case case: must be after UL_GETFSIZE */
plars865695b2001-08-27 22:15:12 +0000139#if UL_GMEMLIM
subrata_modak56207ce2009-03-23 13:35:39 +0000140 {
141 UL_GMEMLIM, -1, 0, 0},
plars865695b2001-08-27 22:15:12 +0000142#endif
143#if UL_GDESLIM
subrata_modak56207ce2009-03-23 13:35:39 +0000144 {
145 UL_GDESLIM, -1, 0, 0},
plars865695b2001-08-27 22:15:12 +0000146#endif
147#if UL_GSHMEMLIM
subrata_modak56207ce2009-03-23 13:35:39 +0000148 {
149 UL_GSHMEMLIM, -1, 0, 0},
plars865695b2001-08-27 22:15:12 +0000150#endif
plars865695b2001-08-27 22:15:12 +0000151};
152
subrata_modak56207ce2009-03-23 13:35:39 +0000153int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +0000154{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200155 int lc;
156 int i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200157 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +0000158 int tmp;
plars865695b2001-08-27 22:15:12 +0000159
subrata_modak56207ce2009-03-23 13:35:39 +0000160 TST_TOTAL = sizeof(Scenarios) / sizeof(struct limits_t);
161
plars865695b2001-08-27 22:15:12 +0000162 /***************************************************************
163 * parse standard options
164 ***************************************************************/
Garrett Cooper45e285d2010-11-22 12:19:25 -0800165 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000166 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modak56207ce2009-03-23 13:35:39 +0000167 }
plars865695b2001-08-27 22:15:12 +0000168
169 /***************************************************************
170 * perform global setup for test
171 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000172 setup();
plars865695b2001-08-27 22:15:12 +0000173
174 /***************************************************************
175 * check looping state if -c option given
176 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000177 for (lc = 0; TEST_LOOPING(lc); lc++) {
subrata_modakbdbaec52009-02-26 12:14:51 +0000178
Caspar Zhangd59a6592013-03-07 14:59:12 +0800179 tst_count = 0;
subrata_modakbdbaec52009-02-26 12:14:51 +0000180
subrata_modak56207ce2009-03-23 13:35:39 +0000181 for (i = 0; i < TST_TOTAL; i++) {
plars865695b2001-08-27 22:15:12 +0000182
subrata_modak56207ce2009-03-23 13:35:39 +0000183 cmd = Scenarios[i].cmd;
184 limit = Scenarios[i].newlimit;
plars865695b2001-08-27 22:15:12 +0000185
subrata_modak56207ce2009-03-23 13:35:39 +0000186 /*
187 * Call ulimit(2)
188 */
189 TEST(ulimit(cmd, limit));
plars865695b2001-08-27 22:15:12 +0000190
subrata_modak56207ce2009-03-23 13:35:39 +0000191 /* check return code */
192 if (TEST_RETURN == -1) {
193 if (Scenarios[i].exp_fail) {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200194 tst_resm(TPASS | TTERRNO,
195 "ulimit(%d, %ld) Failed expectedly",
196 cmd, limit);
subrata_modak56207ce2009-03-23 13:35:39 +0000197 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800198 tst_resm(TFAIL | TTERRNO,
subrata_modak923b23f2009-11-02 13:57:16 +0000199 "ulimit(%d, %ld) Failed",
200 cmd, limit);
subrata_modak56207ce2009-03-23 13:35:39 +0000201 }
202 } else {
203 if (Scenarios[i].exp_fail) {
204 tst_resm(TFAIL,
subrata_modak923b23f2009-11-02 13:57:16 +0000205 "ulimit(%d, %ld) returned %ld, succeeded unexpectedly",
subrata_modak56207ce2009-03-23 13:35:39 +0000206 cmd, limit, TEST_RETURN);
Cyril Hrubise38b9612014-06-02 17:20:57 +0200207 } else {
subrata_modak56207ce2009-03-23 13:35:39 +0000208 tst_resm(TPASS,
subrata_modak923b23f2009-11-02 13:57:16 +0000209 "ulimit(%d, %ld) returned %ld",
subrata_modak56207ce2009-03-23 13:35:39 +0000210 cmd, limit, TEST_RETURN);
211 }
212
213 /*
214 * Save the UL_GETFSIZE return value in the newlimit field
215 * for UL_SETFSIZE test cases.
216 */
217 if (cmd == UL_GETFSIZE) {
218 for (tmp = i + 1; tmp < TST_TOTAL;
219 tmp++) {
220 if (Scenarios[tmp].nlim_flag ==
221 1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800222 Scenarios[tmp].newlimit
223 = TEST_RETURN;
subrata_modak56207ce2009-03-23 13:35:39 +0000224 }
225 if (Scenarios[tmp].nlim_flag ==
226 2) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800227 Scenarios[tmp].newlimit
228 = TEST_RETURN - 1;
subrata_modak56207ce2009-03-23 13:35:39 +0000229 }
230 }
231 }
plars865695b2001-08-27 22:15:12 +0000232 }
plars865695b2001-08-27 22:15:12 +0000233 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800234 }
plars865695b2001-08-27 22:15:12 +0000235
236 /***************************************************************
237 * cleanup and exit
238 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000239 cleanup();
plars865695b2001-08-27 22:15:12 +0000240
Garrett Cooper2c282152010-12-16 00:55:50 -0800241 tst_exit();
242}
plars865695b2001-08-27 22:15:12 +0000243
244/***************************************************************
245 * setup() - performs all ONE TIME setup for this test.
246 ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400247void setup(void)
plars865695b2001-08-27 22:15:12 +0000248{
249
subrata_modak56207ce2009-03-23 13:35:39 +0000250 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000251
subrata_modak56207ce2009-03-23 13:35:39 +0000252 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000253
Garrett Cooper2c282152010-12-16 00:55:50 -0800254}
plars865695b2001-08-27 22:15:12 +0000255
256/***************************************************************
257 * cleanup() - performs all ONE TIME cleanup for this test at
258 * completion or premature exit.
259 ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400260void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000261{
plars865695b2001-08-27 22:15:12 +0000262
Chris Dearmanec6edca2012-10-17 19:54:01 -0700263}