1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3f08c3bdfSopenharmony_ci *
4f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify it
5f08c3bdfSopenharmony_ci * under the terms of version 2 of the GNU General Public License as
6f08c3bdfSopenharmony_ci * published by the Free Software Foundation.
7f08c3bdfSopenharmony_ci *
8f08c3bdfSopenharmony_ci * This program is distributed in the hope that it would be useful, but
9f08c3bdfSopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
10f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11f08c3bdfSopenharmony_ci *
12f08c3bdfSopenharmony_ci * Further, this software is distributed without any warranty that it is
13f08c3bdfSopenharmony_ci * free of the rightful claim of any third person regarding infringement
14f08c3bdfSopenharmony_ci * or the like.  Any license provided herein, whether implied or
15f08c3bdfSopenharmony_ci * otherwise, applies only to this software file.  Patent licenses, if
16f08c3bdfSopenharmony_ci * any, provided herein do not apply to combinations of this program with
17f08c3bdfSopenharmony_ci * other software, or any other product whatsoever.
18f08c3bdfSopenharmony_ci *
19f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License along
20f08c3bdfSopenharmony_ci * with this program; if not, write the Free Software Foundation, Inc.,
21f08c3bdfSopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22f08c3bdfSopenharmony_ci *
23f08c3bdfSopenharmony_ci * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24f08c3bdfSopenharmony_ci * Mountain View, CA  94043, or:
25f08c3bdfSopenharmony_ci *
26f08c3bdfSopenharmony_ci * http://www.sgi.com
27f08c3bdfSopenharmony_ci *
28f08c3bdfSopenharmony_ci * For further information regarding this notice, see:
29f08c3bdfSopenharmony_ci *
30f08c3bdfSopenharmony_ci * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31f08c3bdfSopenharmony_ci */
32f08c3bdfSopenharmony_ci/* $Id: ulimit01.c,v 1.6 2009/11/02 13:57:19 subrata_modak Exp $ */
33f08c3bdfSopenharmony_ci/**********************************************************
34f08c3bdfSopenharmony_ci *
35f08c3bdfSopenharmony_ci *    OS Test - Silicon Graphics, Inc.
36f08c3bdfSopenharmony_ci *
37f08c3bdfSopenharmony_ci *    TEST IDENTIFIER	: ulimit01
38f08c3bdfSopenharmony_ci *
39f08c3bdfSopenharmony_ci *    EXECUTED BY	: anyone
40f08c3bdfSopenharmony_ci *
41f08c3bdfSopenharmony_ci *    TEST TITLE	: Basic test for ulimit(2)
42f08c3bdfSopenharmony_ci *
43f08c3bdfSopenharmony_ci *    PARENT DOCUMENT	: usctpl01
44f08c3bdfSopenharmony_ci *
45f08c3bdfSopenharmony_ci *    TEST CASE TOTAL	: 6
46f08c3bdfSopenharmony_ci *
47f08c3bdfSopenharmony_ci *    WALL CLOCK TIME	: 1
48f08c3bdfSopenharmony_ci *
49f08c3bdfSopenharmony_ci *    CPU TYPES		: ALL
50f08c3bdfSopenharmony_ci *
51f08c3bdfSopenharmony_ci *    AUTHOR		: William Roske
52f08c3bdfSopenharmony_ci *
53f08c3bdfSopenharmony_ci *    CO-PILOT		: Dave Fenner
54f08c3bdfSopenharmony_ci *
55f08c3bdfSopenharmony_ci *    DATE STARTED	: 03/30/92
56f08c3bdfSopenharmony_ci *
57f08c3bdfSopenharmony_ci *    INITIAL RELEASE	: UNICOS 7.0
58f08c3bdfSopenharmony_ci *
59f08c3bdfSopenharmony_ci *    TEST CASES
60f08c3bdfSopenharmony_ci *
61f08c3bdfSopenharmony_ci * 	1.) ulimit(2) returns...(See Description)
62f08c3bdfSopenharmony_ci *
63f08c3bdfSopenharmony_ci *    INPUT SPECIFICATIONS
64f08c3bdfSopenharmony_ci * 	The standard options for system call tests are accepted.
65f08c3bdfSopenharmony_ci *	(See the parse_opts(3) man page).
66f08c3bdfSopenharmony_ci *
67f08c3bdfSopenharmony_ci *    OUTPUT SPECIFICATIONS
68f08c3bdfSopenharmony_ci *$
69f08c3bdfSopenharmony_ci *    DURATION
70f08c3bdfSopenharmony_ci * 	Terminates - with frequency and infinite modes.
71f08c3bdfSopenharmony_ci *
72f08c3bdfSopenharmony_ci *    SIGNALS
73f08c3bdfSopenharmony_ci * 	Uses SIGUSR1 to pause before test if option set.
74f08c3bdfSopenharmony_ci * 	(See the parse_opts(3) man page).
75f08c3bdfSopenharmony_ci *
76f08c3bdfSopenharmony_ci *    RESOURCES
77f08c3bdfSopenharmony_ci * 	None
78f08c3bdfSopenharmony_ci *
79f08c3bdfSopenharmony_ci *    ENVIRONMENTAL NEEDS
80f08c3bdfSopenharmony_ci * 	The libcuts.a and libsys.a libraries must be included in
81f08c3bdfSopenharmony_ci *	the compilation of this test.
82f08c3bdfSopenharmony_ci *
83f08c3bdfSopenharmony_ci *    SPECIAL PROCEDURAL REQUIREMENTS
84f08c3bdfSopenharmony_ci * 	None
85f08c3bdfSopenharmony_ci *
86f08c3bdfSopenharmony_ci *    INTERCASE DEPENDENCIES
87f08c3bdfSopenharmony_ci * 	None
88f08c3bdfSopenharmony_ci *
89f08c3bdfSopenharmony_ci *    DETAILED DESCRIPTION
90f08c3bdfSopenharmony_ci *	This is a Phase I test for the ulimit(2) system call.  It is intended
91f08c3bdfSopenharmony_ci *	to provide a limited exposure of the system call, for now.  It
92f08c3bdfSopenharmony_ci *	should/will be extended when full functional tests are written for
93f08c3bdfSopenharmony_ci *	ulimit(2).
94f08c3bdfSopenharmony_ci *
95f08c3bdfSopenharmony_ci * 	Setup:
96f08c3bdfSopenharmony_ci * 	  Setup signal handling.
97f08c3bdfSopenharmony_ci *	  Pause for SIGUSR1 if option specified.
98f08c3bdfSopenharmony_ci *
99f08c3bdfSopenharmony_ci * 	Test:
100f08c3bdfSopenharmony_ci *	 Loop if the proper options are given.
101f08c3bdfSopenharmony_ci * 	  Execute system call
102f08c3bdfSopenharmony_ci *	  Check return code, if system call failed (return=-1)
103f08c3bdfSopenharmony_ci *		Log the errno and Issue a FAIL message.
104f08c3bdfSopenharmony_ci *	  Otherwise, Issue a PASS message.
105f08c3bdfSopenharmony_ci *
106f08c3bdfSopenharmony_ci * 	Cleanup:
107f08c3bdfSopenharmony_ci * 	  Print errno log and/or timing stats if options given
108f08c3bdfSopenharmony_ci *
109f08c3bdfSopenharmony_ci *
110f08c3bdfSopenharmony_ci *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
111f08c3bdfSopenharmony_ci
112f08c3bdfSopenharmony_ci#include <ulimit.h>
113f08c3bdfSopenharmony_ci#include <errno.h>
114f08c3bdfSopenharmony_ci#include <string.h>
115f08c3bdfSopenharmony_ci#include <signal.h>
116f08c3bdfSopenharmony_ci#include "test.h"
117f08c3bdfSopenharmony_ci
118f08c3bdfSopenharmony_civoid setup();
119f08c3bdfSopenharmony_civoid cleanup();
120f08c3bdfSopenharmony_ci
121f08c3bdfSopenharmony_cichar *TCID = "ulimit01";
122f08c3bdfSopenharmony_ciint TST_TOTAL = 6;
123f08c3bdfSopenharmony_ci
124f08c3bdfSopenharmony_ciint cmd;
125f08c3bdfSopenharmony_cilong limit;			/* saved limit */
126f08c3bdfSopenharmony_ci
127f08c3bdfSopenharmony_cistruct limits_t {
128f08c3bdfSopenharmony_ci	int cmd;
129f08c3bdfSopenharmony_ci	long newlimit;
130f08c3bdfSopenharmony_ci	int nlim_flag;		/* special flag for UL_SETFSIZE records  */
131f08c3bdfSopenharmony_ci	int exp_fail;
132f08c3bdfSopenharmony_ci} Scenarios[] = {
133f08c3bdfSopenharmony_ci
134f08c3bdfSopenharmony_ci	{
135f08c3bdfSopenharmony_ci	UL_GETFSIZE, -1, 0, 0}, {
136f08c3bdfSopenharmony_ci	UL_SETFSIZE, -2, 1, 0},	/* case case: must be after UL_GETFSIZE */
137f08c3bdfSopenharmony_ci	{
138f08c3bdfSopenharmony_ci	UL_SETFSIZE, -2, 2, 0},	/* case case: must be after UL_GETFSIZE */
139f08c3bdfSopenharmony_ci#if UL_GMEMLIM
140f08c3bdfSopenharmony_ci	{
141f08c3bdfSopenharmony_ci	UL_GMEMLIM, -1, 0, 0},
142f08c3bdfSopenharmony_ci#endif
143f08c3bdfSopenharmony_ci#if UL_GDESLIM
144f08c3bdfSopenharmony_ci	{
145f08c3bdfSopenharmony_ci	UL_GDESLIM, -1, 0, 0},
146f08c3bdfSopenharmony_ci#endif
147f08c3bdfSopenharmony_ci#if UL_GSHMEMLIM
148f08c3bdfSopenharmony_ci	{
149f08c3bdfSopenharmony_ci	UL_GSHMEMLIM, -1, 0, 0},
150f08c3bdfSopenharmony_ci#endif
151f08c3bdfSopenharmony_ci};
152f08c3bdfSopenharmony_ci
153f08c3bdfSopenharmony_ciint main(int ac, char **av)
154f08c3bdfSopenharmony_ci{
155f08c3bdfSopenharmony_ci	int lc;
156f08c3bdfSopenharmony_ci	int i;
157f08c3bdfSopenharmony_ci	int tmp;
158f08c3bdfSopenharmony_ci
159f08c3bdfSopenharmony_ci	TST_TOTAL = sizeof(Scenarios) / sizeof(struct limits_t);
160f08c3bdfSopenharmony_ci
161f08c3bdfSopenharmony_ci    /***************************************************************
162f08c3bdfSopenharmony_ci     * parse standard options
163f08c3bdfSopenharmony_ci     ***************************************************************/
164f08c3bdfSopenharmony_ci	tst_parse_opts(ac, av, NULL, NULL);
165f08c3bdfSopenharmony_ci
166f08c3bdfSopenharmony_ci    /***************************************************************
167f08c3bdfSopenharmony_ci     * perform global setup for test
168f08c3bdfSopenharmony_ci     ***************************************************************/
169f08c3bdfSopenharmony_ci	setup();
170f08c3bdfSopenharmony_ci
171f08c3bdfSopenharmony_ci    /***************************************************************
172f08c3bdfSopenharmony_ci     * check looping state if -c option given
173f08c3bdfSopenharmony_ci     ***************************************************************/
174f08c3bdfSopenharmony_ci	for (lc = 0; TEST_LOOPING(lc); lc++) {
175f08c3bdfSopenharmony_ci
176f08c3bdfSopenharmony_ci		tst_count = 0;
177f08c3bdfSopenharmony_ci
178f08c3bdfSopenharmony_ci		for (i = 0; i < TST_TOTAL; i++) {
179f08c3bdfSopenharmony_ci
180f08c3bdfSopenharmony_ci			cmd = Scenarios[i].cmd;
181f08c3bdfSopenharmony_ci			limit = Scenarios[i].newlimit;
182f08c3bdfSopenharmony_ci
183f08c3bdfSopenharmony_ci			/*
184f08c3bdfSopenharmony_ci			 * Call ulimit(2)
185f08c3bdfSopenharmony_ci			 */
186f08c3bdfSopenharmony_ci			TEST(ulimit(cmd, limit));
187f08c3bdfSopenharmony_ci
188f08c3bdfSopenharmony_ci			/* check return code */
189f08c3bdfSopenharmony_ci			if (TEST_RETURN == -1) {
190f08c3bdfSopenharmony_ci				if (Scenarios[i].exp_fail) {
191f08c3bdfSopenharmony_ci					tst_resm(TPASS | TTERRNO,
192f08c3bdfSopenharmony_ci						 "ulimit(%d, %ld) Failed expectedly",
193f08c3bdfSopenharmony_ci						 cmd, limit);
194f08c3bdfSopenharmony_ci				} else {
195f08c3bdfSopenharmony_ci					tst_resm(TFAIL | TTERRNO,
196f08c3bdfSopenharmony_ci						 "ulimit(%d, %ld) Failed",
197f08c3bdfSopenharmony_ci						 cmd, limit);
198f08c3bdfSopenharmony_ci				}
199f08c3bdfSopenharmony_ci			} else {
200f08c3bdfSopenharmony_ci				if (Scenarios[i].exp_fail) {
201f08c3bdfSopenharmony_ci					tst_resm(TFAIL,
202f08c3bdfSopenharmony_ci						 "ulimit(%d, %ld) returned %ld, succeeded unexpectedly",
203f08c3bdfSopenharmony_ci						 cmd, limit, TEST_RETURN);
204f08c3bdfSopenharmony_ci				} else {
205f08c3bdfSopenharmony_ci					tst_resm(TPASS,
206f08c3bdfSopenharmony_ci						 "ulimit(%d, %ld) returned %ld",
207f08c3bdfSopenharmony_ci						 cmd, limit, TEST_RETURN);
208f08c3bdfSopenharmony_ci				}
209f08c3bdfSopenharmony_ci
210f08c3bdfSopenharmony_ci				/*
211f08c3bdfSopenharmony_ci				 * Save the UL_GETFSIZE return value in the newlimit field
212f08c3bdfSopenharmony_ci				 * for UL_SETFSIZE test cases.
213f08c3bdfSopenharmony_ci				 */
214f08c3bdfSopenharmony_ci				if (cmd == UL_GETFSIZE) {
215f08c3bdfSopenharmony_ci					for (tmp = i + 1; tmp < TST_TOTAL;
216f08c3bdfSopenharmony_ci					     tmp++) {
217f08c3bdfSopenharmony_ci						if (Scenarios[tmp].nlim_flag ==
218f08c3bdfSopenharmony_ci						    1) {
219f08c3bdfSopenharmony_ci							Scenarios[tmp].newlimit
220f08c3bdfSopenharmony_ci							    = TEST_RETURN;
221f08c3bdfSopenharmony_ci						}
222f08c3bdfSopenharmony_ci						if (Scenarios[tmp].nlim_flag ==
223f08c3bdfSopenharmony_ci						    2) {
224f08c3bdfSopenharmony_ci							Scenarios[tmp].newlimit
225f08c3bdfSopenharmony_ci							    = TEST_RETURN - 1;
226f08c3bdfSopenharmony_ci						}
227f08c3bdfSopenharmony_ci					}
228f08c3bdfSopenharmony_ci				}
229f08c3bdfSopenharmony_ci			}
230f08c3bdfSopenharmony_ci		}
231f08c3bdfSopenharmony_ci	}
232f08c3bdfSopenharmony_ci
233f08c3bdfSopenharmony_ci    /***************************************************************
234f08c3bdfSopenharmony_ci     * cleanup and exit
235f08c3bdfSopenharmony_ci     ***************************************************************/
236f08c3bdfSopenharmony_ci	cleanup();
237f08c3bdfSopenharmony_ci
238f08c3bdfSopenharmony_ci	tst_exit();
239f08c3bdfSopenharmony_ci}
240f08c3bdfSopenharmony_ci
241f08c3bdfSopenharmony_ci/***************************************************************
242f08c3bdfSopenharmony_ci * setup() - performs all ONE TIME setup for this test.
243f08c3bdfSopenharmony_ci ***************************************************************/
244f08c3bdfSopenharmony_civoid setup(void)
245f08c3bdfSopenharmony_ci{
246f08c3bdfSopenharmony_ci
247f08c3bdfSopenharmony_ci	tst_sig(NOFORK, DEF_HANDLER, cleanup);
248f08c3bdfSopenharmony_ci
249f08c3bdfSopenharmony_ci	TEST_PAUSE;
250f08c3bdfSopenharmony_ci
251f08c3bdfSopenharmony_ci}
252f08c3bdfSopenharmony_ci
253f08c3bdfSopenharmony_ci/***************************************************************
254f08c3bdfSopenharmony_ci * cleanup() - performs all ONE TIME cleanup for this test at
255f08c3bdfSopenharmony_ci *		completion or premature exit.
256f08c3bdfSopenharmony_ci ***************************************************************/
257f08c3bdfSopenharmony_civoid cleanup(void)
258f08c3bdfSopenharmony_ci{
259f08c3bdfSopenharmony_ci
260f08c3bdfSopenharmony_ci}
261