OSDN Git Service

Importing Egor's testsuite.
[pf3gnuchains/pf3gnuchains3x.git] / winsup / testsuite / winsup.api / ltp / ulimit01.c
1 /*
2  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3  * 
4  * 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.
7  * 
8  * 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.
11  * 
12  * 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.
18  * 
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  * 
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  * 
26  * http://www.sgi.com 
27  * 
28  * For further information regarding this notice, see: 
29  * 
30  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31  */
32 /* $Id$ */
33 /**********************************************************
34  * 
35  *    OS Test - Silicon Graphics, Inc.
36  * 
37  *    TEST IDENTIFIER   : ulimit01
38  * 
39  *    EXECUTED BY       : anyone
40  * 
41  *    TEST TITLE        : Basic test for ulimit(2)
42  * 
43  *    PARENT DOCUMENT   : usctpl01
44  * 
45  *    TEST CASE TOTAL   : 6
46  * 
47  *    WALL CLOCK TIME   : 1
48  * 
49  *    CPU TYPES         : ALL
50  * 
51  *    AUTHOR            : William Roske
52  * 
53  *    CO-PILOT          : Dave Fenner
54  * 
55  *    DATE STARTED      : 03/30/92
56  * 
57  *    INITIAL RELEASE   : UNICOS 7.0
58  * 
59  *    TEST CASES
60  * 
61  *      1.) ulimit(2) returns...(See Description)
62  *      
63  *    INPUT SPECIFICATIONS
64  *      The standard options for system call tests are accepted.
65  *      (See the parse_opts(3) man page).
66  * 
67  *    OUTPUT SPECIFICATIONS
68  *      
69  *    DURATION
70  *      Terminates - with frequency and infinite modes.
71  * 
72  *    SIGNALS
73  *      Uses SIGUSR1 to pause before test if option set.
74  *      (See the parse_opts(3) man page).
75  *
76  *    RESOURCES
77  *      None
78  * 
79  *    ENVIRONMENTAL NEEDS
80  *      The libcuts.a and libsys.a libraries must be included in 
81  *      the compilation of this test.
82  * 
83  *    SPECIAL PROCEDURAL REQUIREMENTS
84  *      None
85  * 
86  *    INTERCASE DEPENDENCIES
87  *      None
88  * 
89  *    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).
94  * 
95  *      Setup:
96  *        Setup signal handling.
97  *        Pause for SIGUSR1 if option specified.
98  * 
99  *      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.
105  * 
106  *      Cleanup:
107  *        Print errno log and/or timing stats if options given
108  * 
109  * 
110  *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
111
112 #include <ulimit.h>
113 #include <errno.h>
114 #include <string.h>
115 #include <signal.h>
116 #include "test.h"
117 #include "usctest.h"
118
119 void setup();
120 void cleanup();
121
122
123
124 char *TCID="ulimit01";  /* Test program identifier.    */
125 int TST_TOTAL=6;                /* Total number of test cases. */
126 extern int Tst_count;           /* Test Case counter for tst_* routines */
127
128 int cmd;
129 long limit;     /* saved limit */
130
131 struct limits_t {
132    int cmd;
133    long newlimit;
134    int nlim_flag;       /* special flag for UL_SETFSIZE records  */
135    int exp_fail;
136 } Scenarios[] = {
137
138   { UL_GETFSIZE, -1, 0, 0 },
139   { UL_SETFSIZE, -1, 0, 1 },    /* negative test */
140   { UL_SETFSIZE, -2, 1, 0 },    /* case case: must be after UL_GETFSIZE */
141   { UL_SETFSIZE, -2, 2, 0 },    /* case case: must be after UL_GETFSIZE */
142
143 #if UL_GMEMLIM
144   { UL_GMEMLIM, -1, 0, 0 },
145 #endif
146 #if UL_GDESLIM
147   { UL_GDESLIM, -1, 0, 0 },
148 #endif
149 #if UL_GSHMEMLIM
150   { UL_GSHMEMLIM, -1, 0, 0 },
151 #endif
152   
153 };
154
155 int
156 main(int ac, char **av)
157 {
158     int lc;             /* loop counter */
159     int i;              /* inner loop (test case) counter */
160     char *msg;          /* message returned from parse_opts */
161     int tmp;
162
163     TST_TOTAL = sizeof(Scenarios)/sizeof(struct limits_t);
164     
165     /***************************************************************
166      * parse standard options
167      ***************************************************************/
168     if ( (msg=parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *) NULL ) {
169         tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
170         tst_exit();
171     }
172
173     /***************************************************************
174      * perform global setup for test
175      ***************************************************************/
176     setup();
177
178
179     /***************************************************************
180      * check looping state if -c option given
181      ***************************************************************/
182     for (lc=0; TEST_LOOPING(lc); lc++) {
183         
184         /* reset Tst_count in case we are looping. */
185         Tst_count=0;
186         
187         for ( i=0; i<TST_TOTAL; i++) {
188
189             cmd=Scenarios[i].cmd;
190             limit=Scenarios[i].newlimit;
191
192             /* 
193              * Call ulimit(2)
194              */
195             TEST(ulimit(cmd, limit));
196             
197             /* check return code */
198             if ( TEST_RETURN == -1 ) {
199                 if ( Scenarios[i].exp_fail ) {
200                     if ( STD_FUNCTIONAL_TEST ) {
201                         tst_resm(TPASS, "ulimit(%d, %d) Failed, errno=%d : %s", cmd, limit,
202                                         TEST_ERRNO, strerror(TEST_ERRNO));
203                     }
204                 } else {
205                     tst_resm(TFAIL, "ulimit(%d, %d) Failed, errno=%d : %s", cmd, limit,
206                                     TEST_ERRNO, strerror(TEST_ERRNO));
207                 }
208             } else {
209                 if ( Scenarios[i].exp_fail ) {
210                     tst_resm(TFAIL, "ulimit(%d, %d) returned %d",
211                                     cmd, limit, TEST_RETURN);
212                 } else if ( STD_FUNCTIONAL_TEST ) {
213                     tst_resm(TPASS, "ulimit(%d, %d) returned %d",
214                                     cmd, limit, TEST_RETURN);
215                 }
216
217                 /*
218                  * Save the UL_GETFSIZE return value in the newlimit field
219                  * for UL_SETFSIZE test cases.
220                  */
221                 if ( cmd == UL_GETFSIZE ) {
222                     for (tmp=i+1; tmp<TST_TOTAL; tmp++) {
223                         if ( Scenarios[tmp].nlim_flag == 1 ) {
224                             Scenarios[tmp].newlimit = TEST_RETURN;
225                         }
226                         if ( Scenarios[tmp].nlim_flag == 2 ) {
227                             Scenarios[tmp].newlimit = TEST_RETURN-1;
228                         }
229                     }
230                 }
231             }
232         }
233     }   /* End for TEST_LOOPING */
234
235     /***************************************************************
236      * cleanup and exit
237      ***************************************************************/
238     cleanup();
239
240     return 0;
241 }       /* End main */
242
243 /***************************************************************
244  * setup() - performs all ONE TIME setup for this test.
245  ***************************************************************/
246 void 
247 setup()
248 {
249
250     /* capture signals */
251     tst_sig(NOFORK, DEF_HANDLER, cleanup);
252
253     /* Pause if that option was specified */
254     TEST_PAUSE;
255
256 }       /* End setup() */
257
258
259 /***************************************************************
260  * cleanup() - performs all ONE TIME cleanup for this test at
261  *              completion or premature exit.
262  ***************************************************************/
263 void 
264 cleanup()
265 {
266     /*
267      * print timing stats if that option was specified.
268      */
269     TEST_CLEANUP;
270
271     /* exit with return code appropriate for results */
272     tst_exit();
273 }       /* End cleanup() */