blob: 116d6c7650bee49dd92c78157e891eb5425dd805 [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
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
robbiew9a55a782002-12-26 20:45:16 +000015 *
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"
robbiew9a55a782002-12-26 20:45:16 +000075
76static void setup();
77static void cleanup();
78
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020079char *TCID = "sysfs05";
vapier238755b2007-03-22 06:50:54 +000080static int option[3] = { 1, 4, 1 }; /* valid and invalid option */
81static char *fsname[] = { "ext0", " ext2", (char *)-1 };
robbiew9a55a782002-12-26 20:45:16 +000082
83static struct test_case_t {
84 char *err_desc; /*error description */
vapier238755b2007-03-22 06:50:54 +000085 int exp_errno; /* expected error number */
86 char *exp_errval; /*Expected errorvalue string */
robbiew9a55a782002-12-26 20:45:16 +000087} testcase[] = {
subrata_modak56207ce2009-03-23 13:35:39 +000088 {
89 "Invalid option", EINVAL, "EINVAL"}, {
90 "Invalid filesystem name", EINVAL, "EINVAL "}, {
91 "Address is out of your address space", EFAULT, "EFAULT "}
robbiew9a55a782002-12-26 20:45:16 +000092};
Wanlong Gao354ebb42012-12-07 10:10:04 +080093
Cyril Hrubisb863a0b2014-09-24 13:15:29 +020094int TST_TOTAL = ARRAY_SIZE(testcase);
robbiew9a55a782002-12-26 20:45:16 +000095
vapier238755b2007-03-22 06:50:54 +000096int main(int ac, char **av)
robbiew9a55a782002-12-26 20:45:16 +000097{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020098 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020099 const char *msg;
robbiew9a55a782002-12-26 20:45:16 +0000100
Garrett Cooper45e285d2010-11-22 12:19:25 -0800101 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800102 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew9a55a782002-12-26 20:45:16 +0000103
robbiew9a55a782002-12-26 20:45:16 +0000104 setup();
105
subrata_modak5e278252008-04-23 07:21:00 +0000106#ifdef __NR_sysfs
Garrett Cooper2c282152010-12-16 00:55:50 -0800107
robbiew9a55a782002-12-26 20:45:16 +0000108 for (lc = 0; TEST_LOOPING(lc); lc++) {
109
vapier238755b2007-03-22 06:50:54 +0000110 for (i = 0; i < TST_TOTAL; i++) {
robbiew9a55a782002-12-26 20:45:16 +0000111
Caspar Zhangd59a6592013-03-07 14:59:12 +0800112 tst_count = 0;
vapier83de3272006-08-06 04:40:53 +0000113 TEST(syscall(__NR_sysfs, option[i], fsname[i]));
robbiew9a55a782002-12-26 20:45:16 +0000114
115 /* check return code */
subrata_modak56207ce2009-03-23 13:35:39 +0000116 if ((TEST_RETURN == -1)
117 && (TEST_ERRNO == testcase[i].exp_errno)) {
118 tst_resm(TPASS,
119 "sysfs(2) expected failure;"
vapier238755b2007-03-22 06:50:54 +0000120 " Got errno - %s : %s",
121 testcase[i].exp_errval,
122 testcase[i].err_desc);
robbiew9a55a782002-12-26 20:45:16 +0000123 } else {
124 tst_resm(TFAIL, "sysfs(2) failed to produce"
vapier238755b2007-03-22 06:50:54 +0000125 " expected error; %d, errno"
126 ": %s and got %d",
127 testcase[i].exp_errno,
128 testcase[i].exp_errval, TEST_ERRNO);
robbiew9a55a782002-12-26 20:45:16 +0000129 }
robbiew9a55a782002-12-26 20:45:16 +0000130
vapier238755b2007-03-22 06:50:54 +0000131 } /*End of TEST LOOPS */
Garrett Cooper2c282152010-12-16 00:55:50 -0800132 }
subrata_modak5e278252008-04-23 07:21:00 +0000133#else
subrata_modak56207ce2009-03-23 13:35:39 +0000134 tst_resm(TWARN,
135 "This test can only run on kernels that support the sysfs system call");
subrata_modak5e278252008-04-23 07:21:00 +0000136#endif
robbiew9a55a782002-12-26 20:45:16 +0000137
vapier238755b2007-03-22 06:50:54 +0000138 /*Clean up and exit */
robbiew9a55a782002-12-26 20:45:16 +0000139 cleanup();
140
Garrett Cooper2c282152010-12-16 00:55:50 -0800141 tst_exit();
vapier238755b2007-03-22 06:50:54 +0000142} /*End of main */
robbiew9a55a782002-12-26 20:45:16 +0000143
144/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400145void setup(void)
robbiew9a55a782002-12-26 20:45:16 +0000146{
Garrett Cooper2c282152010-12-16 00:55:50 -0800147
robbiew9a55a782002-12-26 20:45:16 +0000148 tst_sig(NOFORK, DEF_HANDLER, cleanup);
149
robbiew9a55a782002-12-26 20:45:16 +0000150 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -0800151}
robbiew9a55a782002-12-26 20:45:16 +0000152
153/*
154* cleanup() - Performs one time cleanup for this test at
155* completion or premature exit
156*/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400157void cleanup(void)
robbiew9a55a782002-12-26 20:45:16 +0000158{
robbiew9a55a782002-12-26 20:45:16 +0000159
Chris Dearmanec6edca2012-10-17 19:54:01 -0700160}