• 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	: sysfs(2)
20  *
21  *
22  *    EXECUTED BY	: anyone
23  *
24  *    TEST TITLE	: Test checking for basic error conditions
25  *				 for sysfs(2)
26  *
27  *    TEST CASE TOTAL	: 3
28  *
29  *    AUTHOR		: Aniruddha Marathe <aniruddha.marathe@wipro.com>
30  *
31  *    SIGNALS
32  *	Uses SIGUSR1 to pause before test if option set.
33  *	(See the parse_opts(3) man page).
34  *
35  *    DESCRIPTION
36  *	This test case checks whether sysfs(2) system call returns
37  *	appropriate error number for invalid
38  *	option and for invalid filesystem index and when
39  *	buffer is out of address space
40  *
41  *	Setup:
42  *	  Setup signal handling.
43  *	  Pause for SIGUSR1 if option specified.
44  *
45  *	Test:
46  *	  Loop if the proper options are given.
47  *	  Execute system call with invaid option parameter and for
48  *	  invalid filesystem index
49  *	  Check return code, if system call fails with errno == expected errno
50  *		Issue syscall passed with expected errno
51  *	  Otherwise,
52  *	  Issue syscall failed to produce expected errno
53  *
54  *	Cleanup:
55  *	  Do cleanup for the test.
56  *
57  * USAGE:  <for command-line>
58  *  sysfs06 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
59  *  where:
60  *	-c n : Run n copies simultaneously
61  *	-e   : Turn on errno logging.
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  *RESTRICTIONS:
69  *There is no libc or glibc support
70  *****************************************************************************/
71 
72 #include <errno.h>
73 #include <sys/syscall.h>
74 #include <sys/mman.h>
75 #include "test.h"
76 #include "lapi/syscalls.h"
77 
78 static void setup();
79 static void cleanup();
80 
81 char *TCID = "sysfs06";
82 static int option[3] = { 2, 4, 2 };	/* valid and invalid option */
83 static int fsindex[3] = { 10000, 0, 1 };	/*invalid and valid fsindex */
84 
85 static struct test_case_t {
86 	char *err_desc;		/*error description */
87 	int exp_errno;		/* expected error number */
88 	char *exp_errval;	/*Expected errorvalue string */
89 } testcase[] = {
90 	{
91 	"Invalid option", EINVAL, "EINVAL"}, {
92 	"fs_index is out of bounds", EINVAL, "EINVAL"}, {
93 	"buf is outside your accessible address space", EFAULT, "EFAULT"}
94 };
95 
96 int TST_TOTAL = ARRAY_SIZE(testcase);
97 
98 char *bad_addr = 0;
99 
main(int ac,char ** av)100 int main(int ac, char **av)
101 {
102 	int lc, i;
103 
104 	tst_parse_opts(ac, av, NULL, NULL);
105 
106 	setup();
107 
108 	for (lc = 0; TEST_LOOPING(lc); lc++) {
109 
110 		for (i = 0; i < TST_TOTAL; i++) {
111 
112 			tst_count = 0;
113 			TEST(ltp_syscall
114 			     (__NR_sysfs, option[i], fsindex[i], bad_addr));
115 
116 			/* check return code */
117 			if ((TEST_RETURN == -1)
118 			    && (TEST_ERRNO == testcase[i].exp_errno)) {
119 				tst_resm(TPASS,
120 					 "sysfs(2) expected failure;"
121 					 " Got errno - %s : %s",
122 					 testcase[i].exp_errval,
123 					 testcase[i].err_desc);
124 			} else {
125 				tst_resm(TFAIL, "sysfs(2) failed to produce"
126 					 " expected error; %d, errno"
127 					 ": %s and got %d",
128 					 testcase[i].exp_errno,
129 					 testcase[i].exp_errval, TEST_ERRNO);
130 			}
131 		}		/*End of TEST LOOPS */
132 	}
133 
134 	/*Clean up and exit */
135 	cleanup();
136 
137 	tst_exit();
138 }				/*End of main */
139 
140 /* setup() - performs all ONE TIME setup for this test */
setup(void)141 void setup(void)
142 {
143 
144 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
145 
146 	TEST_PAUSE;
147 
148 	bad_addr =
149 	    mmap(0, 1, PROT_NONE, MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0,
150 		 0);
151 	if (bad_addr == MAP_FAILED)
152 		tst_brkm(TBROK, cleanup, "mmap failed");
153 }
154 
155 /*
156 * cleanup() - Performs one time cleanup for this test at
157 * completion or premature exit
158 */
cleanup(void)159 void cleanup(void)
160 {
161 
162 }
163