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 | */ |
| 17 | /************************************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 19 | * TEST IDENTIFIER : ustat02 |
| 20 | * |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 21 | * |
| 22 | * EXECUTED BY : Anyone |
| 23 | * |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 24 | * TEST TITLE : Test checking for basic error conditions |
| 25 | * for ustat(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 27 | * TEST CASE TOTAL : 2 |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 28 | * $ |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 29 | * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 30 | * |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 31 | * SIGNALS |
| 32 | * Uses SIGUSR1 to pause before test if option set. |
| 33 | * (See the parse_opts(3) man page). |
| 34 | * |
| 35 | * DESCRIPTION |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 36 | * This test case checks whether ustat(2) system call returns |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 37 | * appropriate error number for invalid |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 38 | * dev_t parameter. Next, it checks for bad address paramater. |
| 39 | * |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 40 | * Setup: |
| 41 | * Setup signal handling. |
| 42 | * Pause for SIGUSR1 if option specified. |
| 43 | * For testing error on invalid parameter, set dev_num to -1 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 44 | * |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 45 | * Test: |
| 46 | * Loop if the proper options are given. |
| 47 | * Execute system call with invaid flag parameter |
| 48 | * and then for invalid user |
| 49 | * Check return code, if system call fails with errno == expected errno |
| 50 | * Issue syscall passed with expected errno |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 51 | * Otherwise, |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 52 | * Issue syscall failed to produce expected errno |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 53 | * |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 54 | * Cleanup: |
| 55 | * Do cleanup for the test. |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 56 | * $ |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 57 | * USAGE: <for command-line> |
| 58 | * ustat02 [-c n] [-e] [-i n] [-I x] [-p x] [-t] [-h] [-f] [-p] |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 59 | * where |
| 60 | * -c n: run n copies simultaneously |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 61 | * -e : Turn on errno logging. |
| 62 | * -i n : Execute test n times. |
| 63 | * -I x : Execute test for x seconds. |
| 64 | * -p : Pause for SIGUSR1 before starting |
| 65 | * -P x : Pause for x seconds between iterations. |
| 66 | * -t : Turn on syscall timing. |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 67 | * |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 68 | *RESTRICTIONS: None |
| 69 | *****************************************************************************/ |
| 70 | #include <errno.h> |
| 71 | #include "test.h" |
| 72 | #include "usctest.h" |
| 73 | #include <sys/types.h> |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 74 | #include <unistd.h> /* libc[45] */ |
| 75 | #include <ustat.h> /* glibc2 */ |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 76 | #include <sys/stat.h> |
| 77 | |
| 78 | static void setup(); |
| 79 | static void cleanup(); |
| 80 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame^] | 81 | char *TCID = "ustat02"; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 82 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 83 | static int exp_enos[] = { EINVAL, EFAULT, 0 }; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 84 | |
| 85 | static struct test_case_t { |
| 86 | char *err_desc; /*error description */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 87 | int exp_errno; /* expected error number */ |
| 88 | char *exp_errval; /*Expected errorvalue string */ |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 89 | } testcase[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 90 | { |
| 91 | "Invalid parameter", EINVAL, "EINVAL"}, |
vapier | 7ec19d9 | 2006-02-27 04:38:56 +0000 | [diff] [blame] | 92 | #ifndef UCLINUX |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 93 | /* Skip since uClinux does not implement memory protection */ |
| 94 | { |
| 95 | "Bad address", EFAULT, "EFAULT"} |
vapier | 7ec19d9 | 2006-02-27 04:38:56 +0000 | [diff] [blame] | 96 | #endif |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame^] | 99 | int TST_TOTAL = sizeof(testcase) / sizeof(*testcase); |
vapier | 83b1dda | 2006-02-27 04:01:36 +0000 | [diff] [blame] | 100 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 101 | dev_t dev_num[2]; |
| 102 | struct ustat *ubuf; |
| 103 | struct stat *buf; |
| 104 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 105 | int main(int ac, char **av) |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 106 | { |
| 107 | |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 108 | int lc, i; |
| 109 | char *msg; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 110 | |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 111 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 112 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 113 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 114 | setup(); |
| 115 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 116 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 117 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 118 | tst_count = 0; |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 119 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 120 | for (i = 0; i < TST_TOTAL; i++) { |
| 121 | if (i == 0) { |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 122 | TEST(ustat(dev_num[i], ubuf)); |
| 123 | } else { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 124 | TEST(ustat(dev_num[i], (struct ustat *)-1)); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 127 | if ((TEST_RETURN == -1) |
| 128 | && (TEST_ERRNO == testcase[i].exp_errno)) { |
| 129 | tst_resm(TPASS, |
| 130 | "ustat(2) expected failure;" |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 131 | " Got errno - %s : %s", |
| 132 | testcase[i].exp_errval, |
| 133 | testcase[i].err_desc); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 134 | } else { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 135 | tst_resm(TFAIL, "ustat(2) failed to produce" |
| 136 | " expected error; %d, errno" |
| 137 | ": %s and got %d", |
| 138 | testcase[i].exp_errno, |
| 139 | testcase[i].exp_errval, TEST_ERRNO); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | TEST_ERROR_LOG(TEST_ERRNO); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 143 | } /*End of TEST LOOPS */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 144 | } |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 145 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 146 | /*Clean up and exit */ |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 147 | cleanup(); |
| 148 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 149 | tst_exit(); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 150 | } /*End of main */ |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 151 | |
| 152 | /* setup() - performs all ONE TIME setup for this test */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 153 | void setup() |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 154 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 155 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 156 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 157 | |
| 158 | /* set the expected errnos... */ |
| 159 | TEST_EXP_ENOS(exp_enos); |
| 160 | |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 161 | TEST_PAUSE; |
| 162 | |
| 163 | dev_num[0] = -1; |
| 164 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 165 | /* Allocating memory for ustat and stat structure variables */ |
| 166 | if ((ubuf = (struct ustat *)malloc(sizeof(struct ustat))) == NULL) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 167 | tst_brkm(TBROK, NULL, "Failed to allocate Memory"); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 168 | } |
| 169 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 170 | if ((buf = (struct stat *)malloc(sizeof(struct stat))) == NULL) { |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 171 | free(ubuf); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 172 | tst_brkm(TBROK, NULL, "Failed to allocate Memory"); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 173 | } |
| 174 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 175 | /* Finding out a valid device number */ |
| 176 | if (stat("/", buf) != 0) { |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 177 | free(buf); |
| 178 | free(ubuf); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 179 | tst_brkm(TBROK, NULL, "stat(2) failed. Exiting without" |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 180 | "invoking ustat(2)"); |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 181 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 182 | dev_num[1] = buf->st_dev; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 183 | } |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 184 | |
| 185 | /* |
| 186 | * cleanup() - Performs one time cleanup for this test at |
| 187 | * completion or premature exit |
| 188 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 189 | void cleanup() |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 190 | { |
| 191 | free(ubuf); |
| 192 | free(buf); |
| 193 | /* |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 194 | * print timing stats if that option was specified. |
| 195 | * print errno log if that option was specified. |
| 196 | */ |
robbiew | 3c55732 | 2003-03-03 16:01:42 +0000 | [diff] [blame] | 197 | TEST_CLEANUP; |
| 198 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 199 | } |