• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Wipro Technologies Ltd, 2002.  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  * You should have received a copy of the GNU General Public License along
13  * with this program; if not, write the Free Software Foundation, Inc.,
14  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  */
17 /**********************************************************
18  *
19  *    TEST IDENTIFIER	: getrusage02
20  *
21  *    EXECUTED BY	: anyone
22  *
23  *    TEST TITLE	: Tests for error conditions
24  *
25  *    TEST CASE TOTAL	: 2
26  *
27  *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
28  *
29  *    SIGNALS
30  * 	Uses SIGUSR1 to pause before test if option set.
31  * 	(See the parse_opts(3) man page).
32  *
33  *    DESCRIPTION
34  *	Verify that
35  *	1) getrusage() fails with errno EINVAL when an invalid value
36  *	   is given for who
37  *	2) getrusage() fails with errno EFAULT when an invalid address
38  *	   is given for usage
39  *
40  * 	Setup:
41  * 	  Setup signal handling.
42  *	  Pause for SIGUSR1 if option specified.
43  *
44  * 	Test:
45  *	 Loop if the proper options are given.
46  * 	  Execute system call
47  *	  if call failed with expected errno,
48  *		Test Passed
49  *	  else
50  *		Test Failed
51  *
52  * 	Cleanup:
53  * 	  Print errno log and/or timing stats if options given
54  *
55  * USAGE:  <for command-line>
56  *  getrusage02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f]
57  * 			     [-p]
58  *			where,  -c n : Run n copies concurrently.
59  *				-e   : Turn on errno logging.
60  *				-h   : Show help screen
61  *				-f   : Turn off functional testing
62  *				-i n : Execute test n times.
63  *				-I x : Execute test for x seconds.
64  *				-p   : Pause for SIGUSR1 before starting
65  *				-P x : Pause for x seconds between iterations.
66  *				-t   : Turn on syscall timing.
67  *
68  ****************************************************************/
69 
70 #include <errno.h>
71 #include <sched.h>
72 #include <sys/resource.h>
73 #include "test.h"
74 
75 #ifndef RUSAGE_BOTH		/* Removed from user space on RHEL4 */
76 #define RUSAGE_BOTH (-2)	/* still works on SuSE      */
77 #endif /* so this is a work around */
78 
79 static void setup();
80 static void cleanup();
81 
82 char *TCID = "getrusage02";
83 
84 static struct rusage usage;
85 
86 struct test_cases_t {
87 	int who;
88 	struct rusage *usage;
89 	int exp_errno;
90 } test_cases[] = {
91 	{
92 	RUSAGE_BOTH, &usage, EINVAL},
93 #ifndef UCLINUX
94 	{
95 	RUSAGE_SELF, (struct rusage *)-1, EFAULT}
96 #endif
97 };
98 
99 int TST_TOTAL = ARRAY_SIZE(test_cases);
100 
main(int ac,char ** av)101 int main(int ac, char **av)
102 {
103 
104 	int lc, i;
105 
106 	tst_parse_opts(ac, av, NULL, NULL);
107 
108 	setup();
109 
110 	for (lc = 0; TEST_LOOPING(lc); lc++) {
111 
112 		tst_count = 0;
113 
114 		for (i = 0; i < TST_TOTAL; i++) {
115 			TEST(getrusage(test_cases[i].who, test_cases[i].usage));
116 
117 			if (TEST_RETURN == -1 &&
118 			    TEST_ERRNO == test_cases[i].exp_errno)
119 				tst_resm(TPASS | TTERRNO,
120 					 "getrusage failed as expected");
121 			else
122 				tst_resm(TFAIL | TTERRNO,
123 					 "getrusage failed unexpectedly");
124 		}
125 	}
126 
127 	cleanup();
128 
129 	tst_exit();
130 
131 }
132 
setup(void)133 void setup(void)
134 {
135 
136 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
137 
138 	TEST_PAUSE;
139 
140 }
141 
cleanup(void)142 void cleanup(void)
143 {
144 
145 }
146