fstatfs02.c revision 89af32a63ce8a780ea39337339e14caae244b5a4
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
174548c6cf9bcdd96d8303caa4130ab638b61f8a30Wanlong Gao *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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>
52e8530df4da095b0ea36a9ff8118ab5ce906b3e84Garrett Cooper#include "test.h"
53e8530df4da095b0ea36a9ff8118ab5ce906b3e84Garrett Cooper#include "usctest.h"
54865695bbc89088b9526ea9045410e5afb70a985cplars
55865695bbc89088b9526ea9045410e5afb70a985cplarsvoid setup(void);
56865695bbc89088b9526ea9045410e5afb70a985cplarsvoid cleanup(void);
57865695bbc89088b9526ea9045410e5afb70a985cplars
58fa31d55d3486830313bd044f7333697ce6124d22nstrazchar *TCID = "fstatfs02";
59865695bbc89088b9526ea9045410e5afb70a985cplars
6056207cec7732e09c216c751c0b5f88a242bacae6subrata_modakint exp_enos[] = { EBADF, EFAULT, 0 };
61865695bbc89088b9526ea9045410e5afb70a985cplars
62865695bbc89088b9526ea9045410e5afb70a985cplarsstruct statfs buf;
63865695bbc89088b9526ea9045410e5afb70a985cplars
64865695bbc89088b9526ea9045410e5afb70a985cplarsstruct test_case_t {
6556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int fd;
6656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	struct statfs *sbuf;
6756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	int error;
68865695bbc89088b9526ea9045410e5afb70a985cplars} TC[] = {
69865695bbc89088b9526ea9045410e5afb70a985cplars	/* EBADF - fd is invalid */
7056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	{
7156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	-1, &buf, EBADF},
727ec19d9c95d491394401f8e2d88ec94f13f596dfvapier#ifndef UCLINUX
7356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	    /* Skip since uClinux does not implement memory protection */
7456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	    /* EFAULT - address for buf is invalid */
7556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	{
7656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak	1, (void *)-1, EFAULT}
777ec19d9c95d491394401f8e2d88ec94f13f596dfvapier#endif
78865695bbc89088b9526ea9045410e5afb70a985cplars};
79865695bbc89088b9526ea9045410e5afb70a985cplars
8056207cec7732e09c216c751c0b5f88a242bacae6subrata_modakint TST_TOTAL = sizeof(TC) / sizeof(*TC);
8183b1dda4c6fd8b22bdd2593fdd2d4cac34278f19vapier
825aab8a773ae811e815dcbe0ea5c4fee3f0a04f1erobbiewint main(int ac, char **av)
83865695bbc89088b9526ea9045410e5afb70a985cplars{
8489af32a63ce8a780ea39337339e14caae244b5a4Cyril Hrubis	int lc;
85865695bbc89088b9526ea9045410e5afb70a985cplars	int i;
8689af32a63ce8a780ea39337339e14caae244b5a4Cyril Hrubis	char *msg;
87865695bbc89088b9526ea9045410e5afb70a985cplars
8845e285d46ab47b0ff76c88acb5ba97b0bd5f753dGarrett Cooper	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
8960fa8014af7534eaefa901200c8df4b74ce422e6Garrett Cooper		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
90865695bbc89088b9526ea9045410e5afb70a985cplars	}
91865695bbc89088b9526ea9045410e5afb70a985cplars
92865695bbc89088b9526ea9045410e5afb70a985cplars	setup();
93865695bbc89088b9526ea9045410e5afb70a985cplars
94865695bbc89088b9526ea9045410e5afb70a985cplars	/* set up the expected errnos */
95865695bbc89088b9526ea9045410e5afb70a985cplars	TEST_EXP_ENOS(exp_enos);
96865695bbc89088b9526ea9045410e5afb70a985cplars
97865695bbc89088b9526ea9045410e5afb70a985cplars	for (lc = 0; TEST_LOOPING(lc); lc++) {
98865695bbc89088b9526ea9045410e5afb70a985cplars
99865695bbc89088b9526ea9045410e5afb70a985cplars		Tst_count = 0;
100865695bbc89088b9526ea9045410e5afb70a985cplars
101865695bbc89088b9526ea9045410e5afb70a985cplars		/* loop through the test cases */
102865695bbc89088b9526ea9045410e5afb70a985cplars		for (i = 0; i < TST_TOTAL; i++) {
103865695bbc89088b9526ea9045410e5afb70a985cplars
104865695bbc89088b9526ea9045410e5afb70a985cplars			TEST(fstatfs(TC[i].fd, TC[i].sbuf));
105865695bbc89088b9526ea9045410e5afb70a985cplars
10656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			if (TEST_RETURN != -1) {
10756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak				tst_resm(TFAIL, "call succeeded unexpectedly");
10856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak				continue;
10956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			}
11056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak
11156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			TEST_ERROR_LOG(TEST_ERRNO);
11256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak
11356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			if (TEST_ERRNO == TC[i].error) {
11456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak				tst_resm(TPASS, "expected failure - "
11556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak					 "errno = %d : %s", TEST_ERRNO,
11656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak					 strerror(TEST_ERRNO));
11756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak			} else {
11856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak				tst_resm(TFAIL, "unexpected error - %d : %s - "
11956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak					 "expected %d", TEST_ERRNO,
12056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak					 strerror(TEST_ERRNO), TC[i].error);
121865695bbc89088b9526ea9045410e5afb70a985cplars			}
122865695bbc89088b9526ea9045410e5afb70a985cplars		}
123865695bbc89088b9526ea9045410e5afb70a985cplars	}
124865695bbc89088b9526ea9045410e5afb70a985cplars	cleanup();
125865695bbc89088b9526ea9045410e5afb70a985cplars
1267d0a4a57fbcd47f72b67c08df532e8ef47f6fdaeGarrett Cooper	tst_exit();
127865695bbc89088b9526ea9045410e5afb70a985cplars}
128865695bbc89088b9526ea9045410e5afb70a985cplars
129865695bbc89088b9526ea9045410e5afb70a985cplars/*
130865695bbc89088b9526ea9045410e5afb70a985cplars * setup() - performs all ONE TIME setup for this test.
131865695bbc89088b9526ea9045410e5afb70a985cplars */
13256207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid setup()
133865695bbc89088b9526ea9045410e5afb70a985cplars{
1342c28215423293e443469a07ae7011135d058b671Garrett Cooper
135865695bbc89088b9526ea9045410e5afb70a985cplars	tst_sig(NOFORK, DEF_HANDLER, cleanup);
136865695bbc89088b9526ea9045410e5afb70a985cplars
137865695bbc89088b9526ea9045410e5afb70a985cplars	TEST_PAUSE;
138865695bbc89088b9526ea9045410e5afb70a985cplars
139865695bbc89088b9526ea9045410e5afb70a985cplars	/* make a temporary directory and cd to it */
140865695bbc89088b9526ea9045410e5afb70a985cplars	tst_tmpdir();
141865695bbc89088b9526ea9045410e5afb70a985cplars}
142865695bbc89088b9526ea9045410e5afb70a985cplars
143865695bbc89088b9526ea9045410e5afb70a985cplars/*
144865695bbc89088b9526ea9045410e5afb70a985cplars * cleanup() - performs all ONE TIME cleanup for this test at
145865695bbc89088b9526ea9045410e5afb70a985cplars *	       completion or premature exit.
146865695bbc89088b9526ea9045410e5afb70a985cplars */
14756207cec7732e09c216c751c0b5f88a242bacae6subrata_modakvoid cleanup()
148865695bbc89088b9526ea9045410e5afb70a985cplars{
149865695bbc89088b9526ea9045410e5afb70a985cplars	/*
150865695bbc89088b9526ea9045410e5afb70a985cplars	 * print timing stats if that option was specified.
151865695bbc89088b9526ea9045410e5afb70a985cplars	 * print errno log if that option was specified.
152865695bbc89088b9526ea9045410e5afb70a985cplars	 */
153865695bbc89088b9526ea9045410e5afb70a985cplars	TEST_CLEANUP;
154865695bbc89088b9526ea9045410e5afb70a985cplars
155865695bbc89088b9526ea9045410e5afb70a985cplars	/* delete the test directory created in setup() */
156865695bbc89088b9526ea9045410e5afb70a985cplars	tst_rmdir();
157865695bbc89088b9526ea9045410e5afb70a985cplars
158ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman}
159