blob: be3b2395708551185e82231a7a64549fb16eb0cd [file] [log] [blame]
robbiew9a55a782002-12-26 20:45:16 +00001/*
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/**************************************************************************
vapier238755b2007-03-22 06:50:54 +000018 *
robbiew9a55a782002-12-26 20:45:16 +000019 * TEST IDENTIFIER : sysfs(2)
20 *
vapier238755b2007-03-22 06:50:54 +000021 *
robbiew9a55a782002-12-26 20:45:16 +000022 * EXECUTED BY : anyone
vapier238755b2007-03-22 06:50:54 +000023 *
robbiew9a55a782002-12-26 20:45:16 +000024 * TEST TITLE : Test checking for basic error conditions
subrata_modak56207ce2009-03-23 13:35:39 +000025 * for sysfs(2)
vapier238755b2007-03-22 06:50:54 +000026 *
27 * TEST CASE TOTAL : 3
28 *
robbiew9a55a782002-12-26 20:45:16 +000029 * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com>
vapier238755b2007-03-22 06:50:54 +000030 *
robbiew9a55a782002-12-26 20:45:16 +000031 * SIGNALS
subrata_modak56207ce2009-03-23 13:35:39 +000032 * Uses SIGUSR1 to pause before test if option set.
33 * (See the parse_opts(3) man page).
robbiew9a55a782002-12-26 20:45:16 +000034 *
35 * DESCRIPTION
vapier238755b2007-03-22 06:50:54 +000036 * This test case checks whether sysfs(2) system call returns
robbiew9a55a782002-12-26 20:45:16 +000037 * appropriate error number for invalid
38 * option and for invalid filesystem name.
vapier238755b2007-03-22 06:50:54 +000039 *
subrata_modak56207ce2009-03-23 13:35:39 +000040 * Setup:
robbiew9a55a782002-12-26 20:45:16 +000041 * Setup signal handling.
42 * Pause for SIGUSR1 if option specified.
vapier238755b2007-03-22 06:50:54 +000043 *
subrata_modak56207ce2009-03-23 13:35:39 +000044 * Test:
robbiew9a55a782002-12-26 20:45:16 +000045 * Loop if the proper options are given.
vapier238755b2007-03-22 06:50:54 +000046 * Execute system call with invaid option parameter and for
robbiew9a55a782002-12-26 20:45:16 +000047 * invalid filesystem name
48 * Check return code, if system call fails with errno == expected errno
49 * Issue syscall passed with expected errno
vapier238755b2007-03-22 06:50:54 +000050 * Otherwise,
robbiew9a55a782002-12-26 20:45:16 +000051 * Issue syscall failed to produce expected errno
vapier238755b2007-03-22 06:50:54 +000052 *
subrata_modak56207ce2009-03-23 13:35:39 +000053 * Cleanup:
54 * Do cleanup for the test.
vapier238755b2007-03-22 06:50:54 +000055 *
robbiew9a55a782002-12-26 20:45:16 +000056 * USAGE: <for command-line>
57 * sysfs05 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-f] [-h] [-p]
58 * where:
subrata_modak56207ce2009-03-23 13:35:39 +000059 * -c n : Run n copies simultaneously
robbiew9a55a782002-12-26 20:45:16 +000060 * -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.
vapier238755b2007-03-22 06:50:54 +000066 *
robbiew9a55a782002-12-26 20:45:16 +000067 *RESTRICTIONS:
68 *There is no libc or glibc support
69 *Kernel must be compiled with ext2 support
70 *****************************************************************************/
71
72#include <errno.h>
73#include <syscall.h>
74#include "test.h"
75#include "usctest.h"
76
77static void setup();
78static void cleanup();
79
robbiew9a55a782002-12-26 20:45:16 +000080char *TCID = "sysfs05"; /* Test program identifier. */
robbiew9a55a782002-12-26 20:45:16 +000081extern int Tst_count; /* Test Case counter for tst_* routines */
vapier238755b2007-03-22 06:50:54 +000082static int option[3] = { 1, 4, 1 }; /* valid and invalid option */
83static char *fsname[] = { "ext0", " ext2", (char *)-1 };
84static int exp_enos[] = { EINVAL, EFAULT, 0 };
robbiew9a55a782002-12-26 20:45:16 +000085
86static struct test_case_t {
87 char *err_desc; /*error description */
vapier238755b2007-03-22 06:50:54 +000088 int exp_errno; /* expected error number */
89 char *exp_errval; /*Expected errorvalue string */
robbiew9a55a782002-12-26 20:45:16 +000090} testcase[] = {
subrata_modak56207ce2009-03-23 13:35:39 +000091 {
92 "Invalid option", EINVAL, "EINVAL"}, {
93 "Invalid filesystem name", EINVAL, "EINVAL "}, {
94 "Address is out of your address space", EFAULT, "EFAULT "}
robbiew9a55a782002-12-26 20:45:16 +000095};
subrata_modak56207ce2009-03-23 13:35:39 +000096int TST_TOTAL = sizeof(testcase) / sizeof(*testcase);
robbiew9a55a782002-12-26 20:45:16 +000097
vapier238755b2007-03-22 06:50:54 +000098int main(int ac, char **av)
robbiew9a55a782002-12-26 20:45:16 +000099{
vapier238755b2007-03-22 06:50:54 +0000100 int lc, i; /* loop counter */
101 char *msg; /* message returned from parse_opts */
robbiew9a55a782002-12-26 20:45:16 +0000102
103 /* parse standard options */
Garrett Cooper45e285d2010-11-22 12:19:25 -0800104 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
robbiew9a55a782002-12-26 20:45:16 +0000105 tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
robbiew9a55a782002-12-26 20:45:16 +0000106
107 /* perform global setup for test */
108 setup();
109
subrata_modak5e278252008-04-23 07:21:00 +0000110#ifdef __NR_sysfs
robbiew9a55a782002-12-26 20:45:16 +0000111 /* check looping state if -i option given */
112 for (lc = 0; TEST_LOOPING(lc); lc++) {
113
vapier238755b2007-03-22 06:50:54 +0000114 for (i = 0; i < TST_TOTAL; i++) {
robbiew9a55a782002-12-26 20:45:16 +0000115
116 /* reset Tst_count in case we are looping. */
117 Tst_count = 0;
vapier83de3272006-08-06 04:40:53 +0000118 TEST(syscall(__NR_sysfs, option[i], fsname[i]));
robbiew9a55a782002-12-26 20:45:16 +0000119
120 /* check return code */
subrata_modak56207ce2009-03-23 13:35:39 +0000121 if ((TEST_RETURN == -1)
122 && (TEST_ERRNO == testcase[i].exp_errno)) {
123 tst_resm(TPASS,
124 "sysfs(2) expected failure;"
vapier238755b2007-03-22 06:50:54 +0000125 " Got errno - %s : %s",
126 testcase[i].exp_errval,
127 testcase[i].err_desc);
robbiew9a55a782002-12-26 20:45:16 +0000128 } else {
129 tst_resm(TFAIL, "sysfs(2) failed to produce"
vapier238755b2007-03-22 06:50:54 +0000130 " expected error; %d, errno"
131 ": %s and got %d",
132 testcase[i].exp_errno,
133 testcase[i].exp_errval, TEST_ERRNO);
robbiew9a55a782002-12-26 20:45:16 +0000134 }
135 TEST_ERROR_LOG(TEST_ERRNO);
136
vapier238755b2007-03-22 06:50:54 +0000137 } /*End of TEST LOOPS */
138 } /* End of TEST_LOOPING */
subrata_modak5e278252008-04-23 07:21:00 +0000139#else
subrata_modak56207ce2009-03-23 13:35:39 +0000140 tst_resm(TWARN,
141 "This test can only run on kernels that support the sysfs system call");
subrata_modak5e278252008-04-23 07:21:00 +0000142#endif
robbiew9a55a782002-12-26 20:45:16 +0000143
vapier238755b2007-03-22 06:50:54 +0000144 /*Clean up and exit */
robbiew9a55a782002-12-26 20:45:16 +0000145 cleanup();
146
robbiew9a55a782002-12-26 20:45:16 +0000147 return 0;
vapier238755b2007-03-22 06:50:54 +0000148} /*End of main */
robbiew9a55a782002-12-26 20:45:16 +0000149
150/* setup() - performs all ONE TIME setup for this test */
vapier238755b2007-03-22 06:50:54 +0000151void setup()
robbiew9a55a782002-12-26 20:45:16 +0000152{
153 /* capture signals */
154 tst_sig(NOFORK, DEF_HANDLER, cleanup);
155
vapier238755b2007-03-22 06:50:54 +0000156 /* set the expected erronos */
robbiew9a55a782002-12-26 20:45:16 +0000157 TEST_EXP_ENOS(exp_enos);
158
159 /* Pause if that option was specified */
160 TEST_PAUSE;
vapier238755b2007-03-22 06:50:54 +0000161} /* End setup() */
robbiew9a55a782002-12-26 20:45:16 +0000162
163/*
164* cleanup() - Performs one time cleanup for this test at
165* completion or premature exit
166*/
vapier238755b2007-03-22 06:50:54 +0000167void cleanup()
robbiew9a55a782002-12-26 20:45:16 +0000168{
169 /*
vapier238755b2007-03-22 06:50:54 +0000170 * print timing stats if that option was specified.
171 * print errno log if that option was specified.
172 */
robbiew9a55a782002-12-26 20:45:16 +0000173 TEST_CLEANUP;
174
175 /* exit with return code appropriate for results */
176 tst_exit();
vapier238755b2007-03-22 06:50:54 +0000177} /* End cleanup() */