fstatfs02.c revision fa31d55d3486830313bd044f7333697ce6124d22
1865695bbc89088b9526ea9045410e5afb70a985cplars/* 2865695bbc89088b9526ea9045410e5afb70a985cplars * 3865695bbc89088b9526ea9045410e5afb70a985cplars * Copyright (c) International Business Machines Corp., 2001 4865695bbc89088b9526ea9045410e5afb70a985cplars * 5865695bbc89088b9526ea9045410e5afb70a985cplars * This program is free software; you can redistribute it and/or modify 6865695bbc89088b9526ea9045410e5afb70a985cplars * it under the terms of the GNU General Public License as published by 7865695bbc89088b9526ea9045410e5afb70a985cplars * the Free Software Foundation; either version 2 of the License, or 8865695bbc89088b9526ea9045410e5afb70a985cplars * (at your option) any later version. 9865695bbc89088b9526ea9045410e5afb70a985cplars * 10865695bbc89088b9526ea9045410e5afb70a985cplars * This program is distributed in the hope that it will be useful, 11865695bbc89088b9526ea9045410e5afb70a985cplars * but WITHOUT ANY WARRANTY; without even the implied warranty of 12865695bbc89088b9526ea9045410e5afb70a985cplars * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13865695bbc89088b9526ea9045410e5afb70a985cplars * the GNU General Public License for more details. 14865695bbc89088b9526ea9045410e5afb70a985cplars * 15865695bbc89088b9526ea9045410e5afb70a985cplars * You should have received a copy of the GNU General Public License 16865695bbc89088b9526ea9045410e5afb70a985cplars * along with this program; if not, write to the Free Software 17865695bbc89088b9526ea9045410e5afb70a985cplars * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18865695bbc89088b9526ea9045410e5afb70a985cplars */ 19865695bbc89088b9526ea9045410e5afb70a985cplars 20865695bbc89088b9526ea9045410e5afb70a985cplars/* 21865695bbc89088b9526ea9045410e5afb70a985cplars * NAME 22fa31d55d3486830313bd044f7333697ce6124d22nstraz * fstatfs02.c 23865695bbc89088b9526ea9045410e5afb70a985cplars * 24865695bbc89088b9526ea9045410e5afb70a985cplars * DESCRIPTION 25865695bbc89088b9526ea9045410e5afb70a985cplars * Testcase to check fstatfs() sets errno correctly. 26865695bbc89088b9526ea9045410e5afb70a985cplars * 27865695bbc89088b9526ea9045410e5afb70a985cplars * ALGORITHM 28865695bbc89088b9526ea9045410e5afb70a985cplars * 1. Pass -1 as the "fd" parameter for fstatfs(), and expect EBADF. 29865695bbc89088b9526ea9045410e5afb70a985cplars * 2. Pass an invalid address (outside the address space of the process), 30865695bbc89088b9526ea9045410e5afb70a985cplars * as the buf paramter of fstatfs(), and expect EFAULT. 31865695bbc89088b9526ea9045410e5afb70a985cplars * 32865695bbc89088b9526ea9045410e5afb70a985cplars * USAGE: <for command-line> 33fa31d55d3486830313bd044f7333697ce6124d22nstraz * fstatfs02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] 34865695bbc89088b9526ea9045410e5afb70a985cplars * where, -c n : Run n copies concurrently. 35865695bbc89088b9526ea9045410e5afb70a985cplars * -e : Turn on errno logging. 36865695bbc89088b9526ea9045410e5afb70a985cplars * -i n : Execute test n times. 37865695bbc89088b9526ea9045410e5afb70a985cplars * -I x : Execute test for x seconds. 38865695bbc89088b9526ea9045410e5afb70a985cplars * -P x : Pause for x seconds between iterations. 39865695bbc89088b9526ea9045410e5afb70a985cplars * -t : Turn on syscall timing. 40865695bbc89088b9526ea9045410e5afb70a985cplars * 41865695bbc89088b9526ea9045410e5afb70a985cplars * HISTORY 42865695bbc89088b9526ea9045410e5afb70a985cplars * 07/2001 Ported by Wayne Boyer 43865695bbc89088b9526ea9045410e5afb70a985cplars * 44865695bbc89088b9526ea9045410e5afb70a985cplars * RESTRICTIONS 45865695bbc89088b9526ea9045410e5afb70a985cplars * NONE 46865695bbc89088b9526ea9045410e5afb70a985cplars */ 47865695bbc89088b9526ea9045410e5afb70a985cplars 48865695bbc89088b9526ea9045410e5afb70a985cplars#include <sys/vfs.h> 49865695bbc89088b9526ea9045410e5afb70a985cplars#include <sys/types.h> 50865695bbc89088b9526ea9045410e5afb70a985cplars#include <sys/statfs.h> 51865695bbc89088b9526ea9045410e5afb70a985cplars#include <errno.h> 52865695bbc89088b9526ea9045410e5afb70a985cplars#include <test.h> 53865695bbc89088b9526ea9045410e5afb70a985cplars#include <usctest.h> 54865695bbc89088b9526ea9045410e5afb70a985cplars 55865695bbc89088b9526ea9045410e5afb70a985cplarsvoid setup(void); 56865695bbc89088b9526ea9045410e5afb70a985cplarsvoid cleanup(void); 57865695bbc89088b9526ea9045410e5afb70a985cplars 58fa31d55d3486830313bd044f7333697ce6124d22nstrazchar *TCID = "fstatfs02"; 59865695bbc89088b9526ea9045410e5afb70a985cplarsint TST_TOTAL = 2; 60865695bbc89088b9526ea9045410e5afb70a985cplarsextern int Tst_count; 61865695bbc89088b9526ea9045410e5afb70a985cplars 62865695bbc89088b9526ea9045410e5afb70a985cplarsint exp_enos[]={EBADF, EFAULT, 0}; 63865695bbc89088b9526ea9045410e5afb70a985cplars 64865695bbc89088b9526ea9045410e5afb70a985cplarsstruct statfs buf; 65865695bbc89088b9526ea9045410e5afb70a985cplars 66865695bbc89088b9526ea9045410e5afb70a985cplarsstruct test_case_t { 67865695bbc89088b9526ea9045410e5afb70a985cplars int fd; 68865695bbc89088b9526ea9045410e5afb70a985cplars struct statfs *sbuf; 69865695bbc89088b9526ea9045410e5afb70a985cplars int error; 70865695bbc89088b9526ea9045410e5afb70a985cplars} TC[] = { 71865695bbc89088b9526ea9045410e5afb70a985cplars /* EBADF - fd is invalid */ 72865695bbc89088b9526ea9045410e5afb70a985cplars {-1, &buf, EBADF}, 73865695bbc89088b9526ea9045410e5afb70a985cplars 74865695bbc89088b9526ea9045410e5afb70a985cplars /* EFAULT - address for buf is invalid */ 75865695bbc89088b9526ea9045410e5afb70a985cplars {1, (void *)-1, EFAULT} 76865695bbc89088b9526ea9045410e5afb70a985cplars}; 77865695bbc89088b9526ea9045410e5afb70a985cplars 78865695bbc89088b9526ea9045410e5afb70a985cplarsmain(int ac, char **av) 79865695bbc89088b9526ea9045410e5afb70a985cplars{ 80865695bbc89088b9526ea9045410e5afb70a985cplars int lc; /* loop counter */ 81865695bbc89088b9526ea9045410e5afb70a985cplars int i; 82865695bbc89088b9526ea9045410e5afb70a985cplars char *msg; /* message returned from parse_opts */ 83865695bbc89088b9526ea9045410e5afb70a985cplars 84865695bbc89088b9526ea9045410e5afb70a985cplars /* parse standard options */ 85865695bbc89088b9526ea9045410e5afb70a985cplars if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ 86865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); 87865695bbc89088b9526ea9045410e5afb70a985cplars } 88865695bbc89088b9526ea9045410e5afb70a985cplars 89865695bbc89088b9526ea9045410e5afb70a985cplars setup(); 90865695bbc89088b9526ea9045410e5afb70a985cplars 91865695bbc89088b9526ea9045410e5afb70a985cplars /* set up the expected errnos */ 92865695bbc89088b9526ea9045410e5afb70a985cplars TEST_EXP_ENOS(exp_enos); 93865695bbc89088b9526ea9045410e5afb70a985cplars 94865695bbc89088b9526ea9045410e5afb70a985cplars /* check looping state if -i option given */ 95865695bbc89088b9526ea9045410e5afb70a985cplars for (lc = 0; TEST_LOOPING(lc); lc++) { 96865695bbc89088b9526ea9045410e5afb70a985cplars 97865695bbc89088b9526ea9045410e5afb70a985cplars /* reset Tst_count in case we are looping. */ 98865695bbc89088b9526ea9045410e5afb70a985cplars Tst_count = 0; 99865695bbc89088b9526ea9045410e5afb70a985cplars 100865695bbc89088b9526ea9045410e5afb70a985cplars /* loop through the test cases */ 101865695bbc89088b9526ea9045410e5afb70a985cplars for (i = 0; i < TST_TOTAL; i++) { 102865695bbc89088b9526ea9045410e5afb70a985cplars 103865695bbc89088b9526ea9045410e5afb70a985cplars TEST(fstatfs(TC[i].fd, TC[i].sbuf)); 104865695bbc89088b9526ea9045410e5afb70a985cplars 105865695bbc89088b9526ea9045410e5afb70a985cplars if (TEST_RETURN != -1) { 106865695bbc89088b9526ea9045410e5afb70a985cplars tst_resm(TFAIL, "call succeeded unexpectedly"); 107865695bbc89088b9526ea9045410e5afb70a985cplars continue; 108865695bbc89088b9526ea9045410e5afb70a985cplars } 109865695bbc89088b9526ea9045410e5afb70a985cplars 110865695bbc89088b9526ea9045410e5afb70a985cplars TEST_ERROR_LOG(TEST_ERRNO); 111865695bbc89088b9526ea9045410e5afb70a985cplars 112865695bbc89088b9526ea9045410e5afb70a985cplars if (TEST_ERRNO == TC[i].error) { 113865695bbc89088b9526ea9045410e5afb70a985cplars tst_resm(TPASS, "expected failure - " 114865695bbc89088b9526ea9045410e5afb70a985cplars "errno = %d : %s", TEST_ERRNO, 115865695bbc89088b9526ea9045410e5afb70a985cplars strerror(TEST_ERRNO)); 116865695bbc89088b9526ea9045410e5afb70a985cplars } else { 117865695bbc89088b9526ea9045410e5afb70a985cplars tst_resm(TFAIL, "unexpected error - %d : %s - " 118865695bbc89088b9526ea9045410e5afb70a985cplars "expected %d", TEST_ERRNO, 119865695bbc89088b9526ea9045410e5afb70a985cplars strerror(TEST_ERRNO), TC[i].error); 120865695bbc89088b9526ea9045410e5afb70a985cplars } 121865695bbc89088b9526ea9045410e5afb70a985cplars } 122865695bbc89088b9526ea9045410e5afb70a985cplars } 123865695bbc89088b9526ea9045410e5afb70a985cplars cleanup(); 124865695bbc89088b9526ea9045410e5afb70a985cplars 125865695bbc89088b9526ea9045410e5afb70a985cplars /*NOTREACHED*/ 126865695bbc89088b9526ea9045410e5afb70a985cplars} 127865695bbc89088b9526ea9045410e5afb70a985cplars 128865695bbc89088b9526ea9045410e5afb70a985cplars/* 129865695bbc89088b9526ea9045410e5afb70a985cplars * setup() - performs all ONE TIME setup for this test. 130865695bbc89088b9526ea9045410e5afb70a985cplars */ 131865695bbc89088b9526ea9045410e5afb70a985cplarsvoid 132865695bbc89088b9526ea9045410e5afb70a985cplarssetup() 133865695bbc89088b9526ea9045410e5afb70a985cplars{ 134865695bbc89088b9526ea9045410e5afb70a985cplars /* capture signals */ 135865695bbc89088b9526ea9045410e5afb70a985cplars tst_sig(NOFORK, DEF_HANDLER, cleanup); 136865695bbc89088b9526ea9045410e5afb70a985cplars 137865695bbc89088b9526ea9045410e5afb70a985cplars /* Pause if that option was specified */ 138865695bbc89088b9526ea9045410e5afb70a985cplars TEST_PAUSE; 139865695bbc89088b9526ea9045410e5afb70a985cplars 140865695bbc89088b9526ea9045410e5afb70a985cplars /* make a temporary directory and cd to it */ 141865695bbc89088b9526ea9045410e5afb70a985cplars tst_tmpdir(); 142865695bbc89088b9526ea9045410e5afb70a985cplars} 143865695bbc89088b9526ea9045410e5afb70a985cplars 144865695bbc89088b9526ea9045410e5afb70a985cplars 145865695bbc89088b9526ea9045410e5afb70a985cplars/* 146865695bbc89088b9526ea9045410e5afb70a985cplars * cleanup() - performs all ONE TIME cleanup for this test at 147865695bbc89088b9526ea9045410e5afb70a985cplars * completion or premature exit. 148865695bbc89088b9526ea9045410e5afb70a985cplars */ 149865695bbc89088b9526ea9045410e5afb70a985cplarsvoid 150865695bbc89088b9526ea9045410e5afb70a985cplarscleanup() 151865695bbc89088b9526ea9045410e5afb70a985cplars{ 152865695bbc89088b9526ea9045410e5afb70a985cplars /* 153865695bbc89088b9526ea9045410e5afb70a985cplars * print timing stats if that option was specified. 154865695bbc89088b9526ea9045410e5afb70a985cplars * print errno log if that option was specified. 155865695bbc89088b9526ea9045410e5afb70a985cplars */ 156865695bbc89088b9526ea9045410e5afb70a985cplars TEST_CLEANUP; 157865695bbc89088b9526ea9045410e5afb70a985cplars 158865695bbc89088b9526ea9045410e5afb70a985cplars /* delete the test directory created in setup() */ 159865695bbc89088b9526ea9045410e5afb70a985cplars tst_rmdir(); 160865695bbc89088b9526ea9045410e5afb70a985cplars 161865695bbc89088b9526ea9045410e5afb70a985cplars /* exit with return code appropriate for results */ 162865695bbc89088b9526ea9045410e5afb70a985cplars tst_exit(); 163865695bbc89088b9526ea9045410e5afb70a985cplars} 164865695bbc89088b9526ea9045410e5afb70a985cplars 165