blob: 90dad141075a53b575e26856b3a04822c3c76fb1 [file] [log] [blame]
robbiew3c557322003-03-03 16:01:42 +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.
robbiew3c557322003-03-03 16:01:42 +000015 *
16 */
Cyril Hrubis19121ad2014-02-26 16:54:09 +010017
18/*
19 * Test whether ustat(2) system call returns appropriate error number for
20 * invalid dev_t parameter and for bad address paramater.
21 */
22
23#include <unistd.h>
24#include <ustat.h>
robbiew3c557322003-03-03 16:01:42 +000025#include <errno.h>
Cyril Hrubis19121ad2014-02-26 16:54:09 +010026#include <sys/stat.h>
27#include <sys/types.h>
robbiew3c557322003-03-03 16:01:42 +000028#include "test.h"
29#include "usctest.h"
Cyril Hrubis19121ad2014-02-26 16:54:09 +010030#include "safe_macros.h"
robbiew3c557322003-03-03 16:01:42 +000031
Cyril Hrubis19121ad2014-02-26 16:54:09 +010032static void setup(void);
33static void cleanup(void);
robbiew3c557322003-03-03 16:01:42 +000034
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020035char *TCID = "ustat02";
robbiew3c557322003-03-03 16:01:42 +000036
subrata_modak56207ce2009-03-23 13:35:39 +000037static int exp_enos[] = { EINVAL, EFAULT, 0 };
robbiew3c557322003-03-03 16:01:42 +000038
Cyril Hrubis19121ad2014-02-26 16:54:09 +010039static dev_t invalid_dev = -1;
40static dev_t root_dev;
41struct ustat ubuf;
42
robbiew3c557322003-03-03 16:01:42 +000043static struct test_case_t {
Cyril Hrubis19121ad2014-02-26 16:54:09 +010044 char *err_desc;
45 int exp_errno;
46 char *exp_errval;
47 dev_t *dev;
48 struct ustat *buf;
49} tc[] = {
50 {"Invalid parameter", EINVAL, "EINVAL", &invalid_dev, &ubuf},
vapier7ec19d92006-02-27 04:38:56 +000051#ifndef UCLINUX
Cyril Hrubis19121ad2014-02-26 16:54:09 +010052 {"Bad address", EFAULT, "EFAULT", &root_dev, (void*)-1}
vapier7ec19d92006-02-27 04:38:56 +000053#endif
robbiew3c557322003-03-03 16:01:42 +000054};
55
Cyril Hrubis19121ad2014-02-26 16:54:09 +010056int TST_TOTAL = ARRAY_SIZE(tc);
robbiew3c557322003-03-03 16:01:42 +000057
subrata_modak56207ce2009-03-23 13:35:39 +000058int main(int ac, char **av)
robbiew3c557322003-03-03 16:01:42 +000059{
60
Cyril Hrubis89af32a2012-10-24 16:39:11 +020061 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020062 const char *msg;
robbiew3c557322003-03-03 16:01:42 +000063
Garrett Coopera9e49f12010-12-16 10:54:03 -080064 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080065 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew3c557322003-03-03 16:01:42 +000066
robbiew3c557322003-03-03 16:01:42 +000067 setup();
68
robbiew3c557322003-03-03 16:01:42 +000069 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080070 tst_count = 0;
robbiew3c557322003-03-03 16:01:42 +000071
subrata_modak56207ce2009-03-23 13:35:39 +000072 for (i = 0; i < TST_TOTAL; i++) {
Cyril Hrubis19121ad2014-02-26 16:54:09 +010073 TEST(ustat(*tc[i].dev, tc[i].buf));
robbiew3c557322003-03-03 16:01:42 +000074
Wanlong Gao354ebb42012-12-07 10:10:04 +080075 if ((TEST_RETURN == -1)
Cyril Hrubis19121ad2014-02-26 16:54:09 +010076 && (TEST_ERRNO == tc[i].exp_errno)) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080077 tst_resm(TPASS,
78 "ustat(2) expected failure;"
subrata_modak56207ce2009-03-23 13:35:39 +000079 " Got errno - %s : %s",
Cyril Hrubis19121ad2014-02-26 16:54:09 +010080 tc[i].exp_errval, tc[i].err_desc);
robbiew3c557322003-03-03 16:01:42 +000081 } else {
Cyril Hrubis19121ad2014-02-26 16:54:09 +010082 tst_resm(TFAIL | TTERRNO,
83 "ustat(2) failed to produce"
subrata_modak56207ce2009-03-23 13:35:39 +000084 " expected error; %d, errno"
Cyril Hrubis19121ad2014-02-26 16:54:09 +010085 ": %s",
86 tc[i].exp_errno, tc[i].exp_errval);
robbiew3c557322003-03-03 16:01:42 +000087 }
88
89 TEST_ERROR_LOG(TEST_ERRNO);
Cyril Hrubis19121ad2014-02-26 16:54:09 +010090 }
Garrett Cooper2c282152010-12-16 00:55:50 -080091 }
robbiew3c557322003-03-03 16:01:42 +000092
robbiew3c557322003-03-03 16:01:42 +000093 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -080094 tst_exit();
Cyril Hrubis19121ad2014-02-26 16:54:09 +010095}
robbiew3c557322003-03-03 16:01:42 +000096
Cyril Hrubis19121ad2014-02-26 16:54:09 +010097static void setup(void)
robbiew3c557322003-03-03 16:01:42 +000098{
Cyril Hrubis19121ad2014-02-26 16:54:09 +010099 struct stat buf;
Garrett Cooper2c282152010-12-16 00:55:50 -0800100
robbiew3c557322003-03-03 16:01:42 +0000101 tst_sig(NOFORK, DEF_HANDLER, cleanup);
102
robbiew3c557322003-03-03 16:01:42 +0000103 TEST_EXP_ENOS(exp_enos);
104
robbiew3c557322003-03-03 16:01:42 +0000105 TEST_PAUSE;
106
Cyril Hrubis19121ad2014-02-26 16:54:09 +0100107 /* Find a valid device number */
108 SAFE_STAT(cleanup, "/", &buf);
robbiew3c557322003-03-03 16:01:42 +0000109
Cyril Hrubis19121ad2014-02-26 16:54:09 +0100110 root_dev = buf.st_dev;
Garrett Cooper2c282152010-12-16 00:55:50 -0800111}
robbiew3c557322003-03-03 16:01:42 +0000112
Cyril Hrubis19121ad2014-02-26 16:54:09 +0100113static void cleanup(void)
robbiew3c557322003-03-03 16:01:42 +0000114{
robbiew3c557322003-03-03 16:01:42 +0000115 TEST_CLEANUP;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700116}