blob: 0569ea4eba340e5ee47ae2e76b8d5d38fa2ce966 [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"
Cyril Hrubis19121ad2014-02-26 16:54:09 +010029#include "safe_macros.h"
robbiew3c557322003-03-03 16:01:42 +000030
Cyril Hrubis19121ad2014-02-26 16:54:09 +010031static void setup(void);
32static void cleanup(void);
robbiew3c557322003-03-03 16:01:42 +000033
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020034char *TCID = "ustat02";
robbiew3c557322003-03-03 16:01:42 +000035
Cyril Hrubis19121ad2014-02-26 16:54:09 +010036static dev_t invalid_dev = -1;
37static dev_t root_dev;
38struct ustat ubuf;
39
robbiew3c557322003-03-03 16:01:42 +000040static struct test_case_t {
Cyril Hrubis19121ad2014-02-26 16:54:09 +010041 char *err_desc;
42 int exp_errno;
43 char *exp_errval;
44 dev_t *dev;
45 struct ustat *buf;
46} tc[] = {
47 {"Invalid parameter", EINVAL, "EINVAL", &invalid_dev, &ubuf},
vapier7ec19d92006-02-27 04:38:56 +000048#ifndef UCLINUX
Cyril Hrubis19121ad2014-02-26 16:54:09 +010049 {"Bad address", EFAULT, "EFAULT", &root_dev, (void*)-1}
vapier7ec19d92006-02-27 04:38:56 +000050#endif
robbiew3c557322003-03-03 16:01:42 +000051};
52
Cyril Hrubis19121ad2014-02-26 16:54:09 +010053int TST_TOTAL = ARRAY_SIZE(tc);
robbiew3c557322003-03-03 16:01:42 +000054
subrata_modak56207ce2009-03-23 13:35:39 +000055int main(int ac, char **av)
robbiew3c557322003-03-03 16:01:42 +000056{
57
Cyril Hrubis89af32a2012-10-24 16:39:11 +020058 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020059 const char *msg;
robbiew3c557322003-03-03 16:01:42 +000060
Garrett Coopera9e49f12010-12-16 10:54:03 -080061 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080062 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew3c557322003-03-03 16:01:42 +000063
robbiew3c557322003-03-03 16:01:42 +000064 setup();
65
robbiew3c557322003-03-03 16:01:42 +000066 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080067 tst_count = 0;
robbiew3c557322003-03-03 16:01:42 +000068
subrata_modak56207ce2009-03-23 13:35:39 +000069 for (i = 0; i < TST_TOTAL; i++) {
Cyril Hrubis19121ad2014-02-26 16:54:09 +010070 TEST(ustat(*tc[i].dev, tc[i].buf));
robbiew3c557322003-03-03 16:01:42 +000071
Frediano Ziglio194168d2015-01-05 13:38:16 +000072 if (TEST_RETURN == -1 && TEST_ERRNO == ENOSYS)
73 tst_brkm(TCONF, cleanup, "ustat not supported");
74
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 }
Cyril Hrubis19121ad2014-02-26 16:54:09 +010088 }
Garrett Cooper2c282152010-12-16 00:55:50 -080089 }
robbiew3c557322003-03-03 16:01:42 +000090
robbiew3c557322003-03-03 16:01:42 +000091 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -080092 tst_exit();
Cyril Hrubis19121ad2014-02-26 16:54:09 +010093}
robbiew3c557322003-03-03 16:01:42 +000094
Cyril Hrubis19121ad2014-02-26 16:54:09 +010095static void setup(void)
robbiew3c557322003-03-03 16:01:42 +000096{
Cyril Hrubis19121ad2014-02-26 16:54:09 +010097 struct stat buf;
Garrett Cooper2c282152010-12-16 00:55:50 -080098
robbiew3c557322003-03-03 16:01:42 +000099 tst_sig(NOFORK, DEF_HANDLER, cleanup);
100
robbiew3c557322003-03-03 16:01:42 +0000101 TEST_PAUSE;
102
Cyril Hrubis19121ad2014-02-26 16:54:09 +0100103 /* Find a valid device number */
104 SAFE_STAT(cleanup, "/", &buf);
robbiew3c557322003-03-03 16:01:42 +0000105
Cyril Hrubis19121ad2014-02-26 16:54:09 +0100106 root_dev = buf.st_dev;
Garrett Cooper2c282152010-12-16 00:55:50 -0800107}
robbiew3c557322003-03-03 16:01:42 +0000108
Cyril Hrubis19121ad2014-02-26 16:54:09 +0100109static void cleanup(void)
robbiew3c557322003-03-03 16:01:42 +0000110{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700111}