robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) Wipro Technologies Ltd, 2003. 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 | * Check that ustat() succeeds given correct parameters. |
| 20 | */ |
| 21 | |
| 22 | #include <unistd.h> |
| 23 | #include <ustat.h> |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 24 | #include <errno.h> |
| 25 | #include <sys/types.h> |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 26 | #include <sys/stat.h> |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 27 | #include "test.h" |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 28 | #include "safe_macros.h" |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 29 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 30 | static void setup(void); |
| 31 | static void cleanup(void); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 32 | |
| 33 | char *TCID = "ustat01"; |
| 34 | int TST_TOTAL = 1; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 35 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 36 | static dev_t dev_num; |
| 37 | static struct ustat ubuf; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 38 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 39 | int main(int argc, char *argv[]) |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 40 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 41 | int lc, i; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 42 | const char *msg; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 43 | |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 44 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 45 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 46 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 47 | setup(); |
| 48 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 49 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 50 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 51 | tst_count = 0; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 52 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 53 | for (i = 0; i < TST_TOTAL; i++) { |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 54 | TEST(ustat(dev_num, &ubuf)); |
| 55 | |
Frediano Ziglio | 194168d | 2015-01-05 13:38:16 +0000 | [diff] [blame] | 56 | if (TEST_RETURN == -1 && TEST_ERRNO == ENOSYS) |
| 57 | tst_brkm(TCONF, cleanup, "ustat not supported"); |
| 58 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 59 | if (TEST_RETURN == -1) { |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 60 | tst_resm(TFAIL, "ustat(2) failed and set" |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 61 | "the errno to %d : %s", |
| 62 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 63 | } else { |
| 64 | tst_resm(TPASS, "ustat(2) passed"); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 65 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 66 | } |
| 67 | } |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 68 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 69 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 70 | tst_exit(); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 73 | static void setup(void) |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 74 | { |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 75 | struct stat buf; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 76 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 77 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 78 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 79 | TEST_PAUSE; |
| 80 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 81 | /* Find a valid device number */ |
| 82 | SAFE_STAT(cleanup, "/", &buf); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 83 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 84 | dev_num = buf.st_dev; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 85 | } |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 86 | |
Cyril Hrubis | 19121ad | 2014-02-26 16:54:09 +0100 | [diff] [blame] | 87 | static void cleanup(void) |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 88 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 89 | } |