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 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 <errno.h>
25 #include <sys/ustat.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include "test.h"
29 #include "safe_macros.h"
30
31 static void setup(void);
32
33 char *TCID = "ustat02";
34
35 static dev_t invalid_dev = -1;
36 static dev_t root_dev;
37 struct ustat ubuf;
38
39 static struct test_case_t {
40 char *err_desc;
41 int exp_errno;
42 char *exp_errval;
43 dev_t *dev;
44 struct ustat *buf;
45 } tc[] = {
46 {"Invalid parameter", EINVAL, "EINVAL", &invalid_dev, &ubuf},
47 #ifndef UCLINUX
48 {"Bad address", EFAULT, "EFAULT", &root_dev, (void*)-1}
49 #endif
50 };
51
52 int TST_TOTAL = ARRAY_SIZE(tc);
53
main(int ac,char ** av)54 int main(int ac, char **av)
55 {
56
57 int lc, i;
58
59 tst_parse_opts(ac, av, NULL, NULL);
60
61 setup();
62
63 for (lc = 0; TEST_LOOPING(lc); lc++) {
64 tst_count = 0;
65
66 for (i = 0; i < TST_TOTAL; i++) {
67 TEST(ustat(*tc[i].dev, tc[i].buf));
68
69 if (TEST_RETURN == -1 && TEST_ERRNO == ENOSYS)
70 tst_brkm(TCONF, NULL, "ustat not supported");
71
72 if ((TEST_RETURN == -1)
73 && (TEST_ERRNO == tc[i].exp_errno)) {
74 tst_resm(TPASS,
75 "ustat(2) expected failure;"
76 " Got errno - %s : %s",
77 tc[i].exp_errval, tc[i].err_desc);
78 } else {
79 tst_resm(TFAIL | TTERRNO,
80 "ustat(2) failed to produce"
81 " expected error; %d, errno"
82 ": %s",
83 tc[i].exp_errno, tc[i].exp_errval);
84 }
85 }
86 }
87
88 tst_exit();
89 }
90
setup(void)91 static void setup(void)
92 {
93 struct stat buf;
94
95 tst_sig(NOFORK, DEF_HANDLER, NULL);
96
97 TEST_PAUSE;
98
99 /* Find a valid device number */
100 SAFE_STAT(NULL, "/", &buf);
101
102 root_dev = buf.st_dev;
103 }
104