• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *   Copyright (c) Wipro Technologies, 2002. All Rights Reserved.
4  *
5  *   This program is free software;  you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  *   the GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program;  if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /****************************************************************************
21  *
22  *    TEST IDENTIFIER	: getrlimit02
23  *
24  *    EXECUTED BY	: anyone
25  *
26  *    TEST TITLE	: test for checking error conditions for getrlimit(2)
27  *
28  *    TEST CASE TOTAL	: 2
29  *
30  *    AUTHOR		: Suresh Babu V. <suresh.babu@wipro.com>
31  *
32  *    SIGNALS
33  *      Uses SIGUSR1 to pause before test if option set.
34  *      (See the parse_opts(3) man page).
35  *
36  * DESCRIPTION
37  *      Verify that,
38  *   1) getrlimit(2) returns -1 and sets errno to EFAULT if an invalid
39  *	address is given for address parameter.
40  *   2) getrlimit(2) returns -1 and sets errno to EINVAL if an invalid
41  *	resource type (RLIM_NLIMITS is a out of range resource type) is
42  *	passed.
43  *
44  * Setup:
45  *   Setup signal handling.
46  *   Pause for SIGUSR1 if option specified.
47  *
48  *  Test:
49  *   Loop if the proper options are given.
50  *   Execute system call
51  *   Check return code, if system call failed and errno set == expected errno
52  *		Issue sys call fails with expected return value and errno.
53  *      Otherwise,
54  *		Issue sys call failed to produce expected error.
55  *
56  *   Cleanup:
57  *	Print errno log and/or timing stats if options given
58  *
59  * USAGE:  <for command-line>
60  *  getrlimit02 [-c n] [-e] [-i n] [-I x] [-P x] [-p] [-t] [-h]
61  *     where,  -c n  : Run n copies concurrently.
62  *		-e   : Turn on errno logging.
63  *		-i n : Execute test n times.
64  *		-I x : Execute test for x seconds.
65  *		-P x : Pause for x seconds between iterations.
66  *		-p   : Pause for SIGUSR1 before startingt
67  *		-t   : Turn on syscall timing.
68  *		-h   : Display usage information.
69  *
70  ***************************************************************************/
71 #include <stdio.h>
72 #include <errno.h>
73 #include <sys/resource.h>
74 #include "test.h"
75 
76 #define RLIMIT_TOO_HIGH 1000
77 
78 char *TCID = "getrlimit02";
79 
80 static void cleanup(void);
81 static void setup(void);
82 
83 static struct rlimit rlim;
84 static struct test_case_t {
85 	int exp_errno;		/* Expected error no            */
86 	char *exp_errval;	/* Expected error value string  */
87 	struct rlimit *rlim;	/* rlimit structure             */
88 	int res_type;		/* resource type                */
89 
90 } testcases[] = {
91 #ifndef UCLINUX
92 	/* Skip since uClinux does not implement memory protection */
93 	{
94 	EFAULT, "EFAULT", (void *)-1, RLIMIT_NOFILE},
95 #endif
96 	{
97 	EINVAL, "EINVAL", &rlim, RLIMIT_TOO_HIGH}
98 };
99 
100 int TST_TOTAL = ARRAY_SIZE(testcases);
101 
main(int ac,char ** av)102 int main(int ac, char **av)
103 {
104 	int i;
105 	int lc;
106 
107 	tst_parse_opts(ac, av, NULL, NULL);
108 
109 	/* Do initial setup */
110 	setup();
111 
112 	/* check for looping state if -i option is given */
113 	for (lc = 0; TEST_LOOPING(lc); lc++) {
114 		tst_count = 0;
115 
116 		for (i = 0; i < TST_TOTAL; ++i) {
117 
118 			/*
119 			 * Test the system call.
120 			 */
121 			TEST(getrlimit(testcases[i].res_type,
122 				       testcases[i].rlim));
123 
124 			if ((TEST_RETURN == -1) &&
125 			    (TEST_ERRNO == testcases[i].exp_errno)) {
126 				tst_resm(TPASS, "expected failure; got %s",
127 					 testcases[i].exp_errval);
128 			} else {
129 				tst_resm(TFAIL, "call failed to produce "
130 					 "expected error;  errno: %d : %s",
131 					 TEST_ERRNO, strerror(TEST_ERRNO));
132 			}
133 		}
134 	}
135 	/* do cleanup and exit */
136 	cleanup();
137 
138 	tst_exit();
139 }
140 
141 /*
142  * setup() - performs all one time setup for this test.
143  */
setup(void)144 void setup(void)
145 {
146 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
147 
148 	/* Pause if the option was specified */
149 	TEST_PAUSE;
150 }
151 
152 /*
153  * cleanup()  - performs all one time cleanup for this test
154  *		completion or premature exit.
155  */
cleanup(void)156 void cleanup(void)
157 {
158 
159 }
160