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 (at) 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 name. 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 and for 47 * invalid filesystem name 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 * sysfs05 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-f] [-h] [-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 *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 "linux_syscall_numbers.h" 76 77 static void setup(); 78 static void cleanup(); 79 80 char *TCID = "sysfs05"; 81 static int option[3] = { 1, 4, 1 }; /* valid and invalid option */ 82 static char *fsname[] = { "ext0", " ext2", (char *)-1 }; 83 84 static struct test_case_t { 85 char *err_desc; /*error description */ 86 int exp_errno; /* expected error number */ 87 char *exp_errval; /*Expected errorvalue string */ 88 } testcase[] = { 89 { 90 "Invalid option", EINVAL, "EINVAL"}, { 91 "Invalid filesystem name", EINVAL, "EINVAL "}, { 92 "Address is out of your address space", EFAULT, "EFAULT "} 93 }; 94 95 int TST_TOTAL = ARRAY_SIZE(testcase); 96 97 int main(int ac, char **av) 98 { 99 int lc, i; 100 101 tst_parse_opts(ac, av, NULL, NULL); 102 103 setup(); 104 105 for (lc = 0; TEST_LOOPING(lc); lc++) { 106 107 for (i = 0; i < TST_TOTAL; i++) { 108 109 tst_count = 0; 110 TEST(ltp_syscall(__NR_sysfs, option[i], fsname[i])); 111 112 /* check return code */ 113 if ((TEST_RETURN == -1) 114 && (TEST_ERRNO == testcase[i].exp_errno)) { 115 tst_resm(TPASS, 116 "sysfs(2) expected failure;" 117 " Got errno - %s : %s", 118 testcase[i].exp_errval, 119 testcase[i].err_desc); 120 } else { 121 tst_resm(TFAIL, "sysfs(2) failed to produce" 122 " expected error; %d, errno" 123 ": %s and got %d", 124 testcase[i].exp_errno, 125 testcase[i].exp_errval, TEST_ERRNO); 126 } 127 128 } /*End of TEST LOOPS */ 129 } 130 131 /*Clean up and exit */ 132 cleanup(); 133 134 tst_exit(); 135 } /*End of main */ 136 137 /* setup() - performs all ONE TIME setup for this test */ 138 void setup(void) 139 { 140 141 tst_sig(NOFORK, DEF_HANDLER, cleanup); 142 143 TEST_PAUSE; 144 } 145 146 /* 147 * cleanup() - Performs one time cleanup for this test at 148 * completion or premature exit 149 */ 150 void cleanup(void) 151 { 152 153 } 154