robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 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 |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 13 | * with this program; if not, write the Free Software Foundation, Inc., |
| 14 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 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 <ustat.h> |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 25 | #include <errno.h> |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 26 | #include <sys/stat.h> |
| 27 | #include <sys/types.h> |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 28 | #include "test.h" |
| 29 | #include "usctest.h" |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 30 | #include "safe_macros.h" |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 31 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 32 | static void setup(void); |
| 33 | static void cleanup(void); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 34 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 35 | char *TCID = "ustat02"; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 36 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 37 | static int exp_enos[] = { EINVAL, EFAULT, 0 }; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 38 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 39 | static dev_t invalid_dev = -1; |
| 40 | static dev_t root_dev; |
| 41 | struct ustat ubuf; |
| 42 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 43 | static struct test_case_t { |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 44 | 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}, |
vapier | 7ec19d9 | 2006-02-27 04:38:56 +0000 | [diff] [blame] | 51 | #ifndef UCLINUX |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 52 | {"Bad address", EFAULT, "EFAULT", &root_dev, (void*)-1} |
vapier | 7ec19d9 | 2006-02-27 04:38:56 +0000 | [diff] [blame] | 53 | #endif |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 56 | int TST_TOTAL = ARRAY_SIZE(tc); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 57 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 58 | int main(int ac, char **av) |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 59 | { |
| 60 | |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 61 | int lc, i; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame^] | 62 | const char *msg; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 63 | |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 64 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 65 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 66 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 67 | setup(); |
| 68 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 69 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 70 | tst_count = 0; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 71 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 72 | for (i = 0; i < TST_TOTAL; i++) { |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 73 | TEST(ustat(*tc[i].dev, tc[i].buf)); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 74 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 75 | if ((TEST_RETURN == -1) |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 76 | && (TEST_ERRNO == tc[i].exp_errno)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 77 | tst_resm(TPASS, |
| 78 | "ustat(2) expected failure;" |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 79 | " Got errno - %s : %s", |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 80 | tc[i].exp_errval, tc[i].err_desc); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 81 | } else { |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 82 | tst_resm(TFAIL | TTERRNO, |
| 83 | "ustat(2) failed to produce" |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 84 | " expected error; %d, errno" |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 85 | ": %s", |
| 86 | tc[i].exp_errno, tc[i].exp_errval); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | TEST_ERROR_LOG(TEST_ERRNO); |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 90 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 91 | } |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 92 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 93 | cleanup(); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 94 | tst_exit(); |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 95 | } |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 96 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 97 | static void setup(void) |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 98 | { |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 99 | struct stat buf; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 100 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 101 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 102 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 103 | TEST_EXP_ENOS(exp_enos); |
| 104 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 105 | TEST_PAUSE; |
| 106 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 107 | /* Find a valid device number */ |
| 108 | SAFE_STAT(cleanup, "/", &buf); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 109 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 110 | root_dev = buf.st_dev; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 111 | } |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 112 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 113 | static void cleanup(void) |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 114 | { |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 115 | TEST_CLEANUP; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 116 | } |