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	: sysfs04
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	: 1
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.
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 with invaid  option parameter
47  *
48  *	  Check return code, if system call fails with errno == expected errno
49  *		Issue syscall passed with expected errno
50  *	  Otherwise,
51  *	  Issue syscall failed to produce expected errno
52  *
53  *	Cleanup:
54  *	  Do cleanup for the test.
55  *
56  * USAGE:  <for command-line>
57  * sysfs04  [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
58  * where:
59  *	-c n : run n copies simultaneously
60  *	-e   : Turn on errno logging.
61  *	-i n : Execute test n times.
62  *	-I x : Execute test for x seconds.
63  *	-p   : Pause for SIGUSR1 before starting
64  *	-P x : Pause for x seconds between iterations.
65  *	-t   : Turn on syscall timing.
66  *
67  *RESTRICTIONS:
68  *No libc or glibc support
69  *****************************************************************************/
70 
71 #include <errno.h>
72 #include  <sys/syscall.h>
73 #include "test.h"
74 #include "lapi/syscalls.h"
75 
76 #define INVALID_OPTION 100
77 static void setup();
78 static void cleanup();
79 
80 char *TCID = "sysfs04";
81 int TST_TOTAL = 1;
82 
83 int main(int ac, char **av)
84 {
85 	int lc;
86 
87 	tst_parse_opts(ac, av, NULL, NULL);
88 
89 	setup();
90 
91 	for (lc = 0; TEST_LOOPING(lc); lc++) {
92 
93 		tst_count = 0;
94 		TEST(ltp_syscall(__NR_sysfs, INVALID_OPTION));
95 
96 		/* check return code */
97 		if ((TEST_RETURN == -1) && (TEST_ERRNO == EINVAL)) {
98 			tst_resm(TPASS, "sysfs(2) expected failure;"
99 				 " Got errno - EINVAL :" " Invalid option");
100 		} else {
101 			tst_resm(TFAIL, "sysfs(2) failed to produce"
102 				 " expected error; %d, errno"
103 				 " : EINVAL and got %d", EINVAL, TEST_ERRNO);
104 		}
105 	}
106 
107 	/*Clean up and exit */
108 	cleanup();
109 	tst_exit();
110 
111 }				/*End of main */
112 
113 /* setup() - performs all ONE TIME setup for this test */
114 void setup(void)
115 {
116 
117 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
118 
119 	TEST_PAUSE;
120 }
121 
122 /*
123 * cleanup() - Performs one time cleanup for this test at
124 * completion or premature exit
125 */
126 void cleanup(void)
127 {
128 
129 }
130