sysfs01.c revision afd4843765a549fedf06fbf402fe4a07bf84a953
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., 59
14 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
15 *
16 */
17/**************************************************************************
18 *
19 *    TEST IDENTIFIER	: sysfs01
20 *
21 *    EXECUTED BY	: anyone
22 *
23 *    TEST TITLE	: Basic test for sysfs(2)
24 *
25 *    TEST CASE TOTAL	: 1
26 *
27 *    AUTHOR		: Aniruddha Marathe <aniruddha.marathe@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 *    This is a Phase I test for the sysfs(2) system call.
35 *    This test is carried out for option 1 for sysfs(2).
36 *    It is intended to provide a limited exposure of the system call.
37 *
38 *
39 * 	Setup:
40 *	  Setup signal handling.
41 *	  Pause for SIGUSR1 if option specified.
42 *
43 * 	Test:
44 *	 Loop if the proper options are given.
45 *	  Execute system call
46 *	  Check return code, if system call failed (return=-1)
47 *		Log the errno and Issue a FAIL message.
48 *	  Otherwise, Issue a PASS message.
49 *
50 * 	Cleanup:
51 * 	  Print errno log and/or timing stats if options given
52 *
53 * USAGE:  <for command-line>
54 * sysfs01 [-c n]  [-e] [-i n] [-I x] [-p x] [-t] [-h] [-f] [-p]
55 *  where:
56 *  	-c n : run n copies simultaneously.
57 *	-e   : Turn on errno logging.
58 *	-i n : Execute test n times.
59 *	-I x : Execute test for x seconds.
60 *	-p   : Pause for SIGUSR1 before starting
61 *	-P x : Pause for x seconds between iterations.
62 *	-t   : Turn on syscall timing.
63 *
64 *RESTRICTIONS:
65 *There is no glibc or libc support
66 *Kernel should be compiled with ext2 filesystem support
67 ******************************************************************************/
68
69#include "test.h"
70#include "usctest.h"
71#include <errno.h>
72#include <unistd.h>
73#include <syscall.h>
74
75#ifndef _syscall2
76#include <linux/unistd.h>
77#endif
78
79static void setup();
80static void cleanup();
81
82char *TCID = "sysfs01";	/* Test program identifier.    */
83int TST_TOTAL = 1;	/* Total number of test cases. */
84extern int Tst_count;	/* Test Case counter for tst_* routines */
85
86#if defined(__ia64__)
87#define sysfs(arg1, arg2) syscall(__NR_sysfs, arg1, arg2)
88#else
89_syscall2(long, sysfs, int, option, const char*, fsname);
90#endif
91
92int
93main(int ac, char **av)
94{
95
96	int lc;		/* loop counter */
97	char *msg;	/* message returned from parse_opts */
98
99	/* parse standard options */
100	if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL))
101		!= (char *)NULL) {
102		tst_brkm(TBROK, tst_exit,"OPTION PARSING ERROR - %s", msg);
103	}
104
105	/* perform global setup for test */
106	setup();
107
108	/* check looping state if -i option given */
109	for (lc = 0; TEST_LOOPING(lc); lc++) {
110
111		/* reset Tst_count in case we are looping. */
112		Tst_count = 0;
113
114		/*option 1, buf holds fs name */
115		TEST(sysfs(1, "ext2"));
116
117		/* check return code */
118		if (TEST_RETURN == -1) {
119			TEST_ERROR_LOG(TEST_ERRNO);
120			tst_resm(TFAIL, "sysfs(2) Failed for "
121					"option 1 and set errno to %d",
122					TEST_ERRNO);
123		} else {
124			tst_resm(TPASS, "sysfs(2) Passed for "
125					"option 1");
126		}
127	}	/*End of TEST_LOOPING*/
128
129	/*Clean up and exit*/
130	cleanup();
131
132	/*NOTREACHED*/
133	return 0;
134}
135
136/* setup() - performs all ONE TIME setup for this test */
137void
138setup()
139{
140	/* capture signals */
141	tst_sig(NOFORK, DEF_HANDLER, cleanup);
142
143	/* Pause if that option was specified */
144	TEST_PAUSE;
145
146}	/* End setup() */
147
148/*
149 * cleanup() - Performs one time cleanup for this test at
150 * completion or premature exit
151 */
152
153void
154cleanup()
155{
156	/*
157	* print timing stats if that option was specified.
158	* print errno log if that option was specified.
159	*/
160	TEST_CLEANUP;
161
162	/* exit with return code appropriate for results */
163	tst_exit();
164}	/* End cleanup() */
165
166