plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. 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 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * 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] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 22 | * |
| 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
| 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
| 30 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 31 | * |
| 32 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 33 | /* $Id: rmdir05.c,v 1.8 2009/03/23 13:36:01 subrata_modak Exp $ */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | /********************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 35 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 36 | * OS Test - Silicon Graphics, Inc. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 37 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 38 | * TEST IDENTIFIER : rmdir05 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 39 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 40 | * EXECUTED BY : anyone |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 41 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 42 | * TEST TITLE : Functionality Tests for rmdir(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 43 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 44 | * PARENT DOCUMENT : rmstds02 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 45 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 46 | * TEST CASE TOTAL : 6 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 47 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | * WALL CLOCK TIME : 2 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 49 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 50 | * CPU TYPES : ALL |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 51 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 52 | * AUTHOR : Bill Branum |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 53 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | * CO-PILOT : Steve Shaw |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 55 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | * DATE STARTED : 4/23/92 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 57 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | * INITIAL RELEASE : UNICOS 7.0 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 59 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | * TEST CASES |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 61 | * rmdir(2) test for errno(s) EINVAL, EMLINK, EFAULT |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 62 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 63 | * INPUT SPECIFICATIONS |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 64 | * The standard options for system call tests are accepted. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | * (See the parse_opts(3) man page). |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 66 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | * ENVIRONMENTAL NEEDS |
| 68 | * No run-time environmental needs. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 69 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | * DETAILED DESCRIPTION |
| 71 | * Verify that rmdir(2) returns a value of -1 and sets errno |
| 72 | * to indicate the error. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 73 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 74 | * Setup: |
| 75 | * Setup signal handling. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | * Create a temporary directory and make it current. |
| 77 | * Pause for SIGUSR1 if option specified. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 78 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 79 | * Test: |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | * Loop if the proper options are given. |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 81 | * Execute system call |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 82 | * Check return code, if system call failed (return=-1) |
| 83 | * Log the errno. |
| 84 | * If doing functional test |
| 85 | * check the errno returned and print result message |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 86 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 87 | * Cleanup: |
| 88 | * Print errno log and/or timing stats if options given. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 89 | * Remove the temporary directory. |
| 90 | * Exit. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 91 | * |
| 92 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 93 | *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ |
| 94 | |
| 95 | #include <errno.h> |
| 96 | #include <signal.h> |
| 97 | #include <sys/types.h> |
| 98 | #include <sys/stat.h> |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 99 | #include <sys/mman.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 100 | #include <stdlib.h> |
| 101 | #include <string.h> |
| 102 | #include "test.h" |
| 103 | #include "usctest.h" |
| 104 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 105 | void setup(); |
| 106 | void cleanup(); |
| 107 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 108 | #if !defined(UCLINUX) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 109 | extern char *get_high_address(); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 110 | int TST_TOTAL = 6; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 111 | #else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 112 | int TST_TOTAL = 4; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 113 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 114 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 115 | char *TCID = "rmdir05"; /* Test program identifier. */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 116 | struct stat stat_buf; /* Stat buffer used for verification. */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 117 | char dir_name[256]; /* Array to hold directory name. */ |
| 118 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 119 | char *bad_addr = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 120 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 121 | int main(int argc, char **argv) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 122 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 123 | int lc; |
| 124 | char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 125 | |
| 126 | /*************************************************************** |
| 127 | * parse standard options |
| 128 | ***************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 129 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 130 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 131 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 132 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 133 | |
| 134 | /*************************************************************** |
| 135 | * perform global setup for test |
| 136 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 137 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 138 | |
| 139 | /*************************************************************** |
| 140 | * check looping state if -c option given |
| 141 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 142 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 143 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 144 | Tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 145 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 146 | /* |
| 147 | * TEST CASE: 1 |
| 148 | * path points to the current directory |
| 149 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 150 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 151 | /* Call rmdir(2) */ |
| 152 | TEST(rmdir(".")); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 153 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 154 | /* check return code */ |
| 155 | if (TEST_RETURN == -1) { |
| 156 | TEST_ERROR_LOG(TEST_ERRNO); |
| 157 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 158 | |
| 159 | /*************************************************************** |
| 160 | * only perform functional verification if flag set (-f not given) |
| 161 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 162 | if (STD_FUNCTIONAL_TEST) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 163 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 164 | if (TEST_RETURN == -1) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 165 | #if defined(sgi) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 166 | if (TEST_ERRNO == EINVAL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 167 | #elif defined(linux) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 168 | if (TEST_ERRNO & (EBUSY | ENOTEMPTY)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 169 | #endif |
| 170 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 171 | /* For functionality tests, verify that the |
| 172 | * directory wasn't removed. |
| 173 | */ |
| 174 | if (stat(".", &stat_buf) == -1) { |
| 175 | tst_resm(TFAIL, |
| 176 | "rmdir(\".\") removed the current working directory when it should have failed."); |
| 177 | } else { |
| 178 | tst_resm(TPASS, |
| 179 | "rmdir(\".\") failed to remove the current working directory. Returned %d : %s", |
| 180 | TEST_ERRNO, |
| 181 | strerror(TEST_ERRNO)); |
| 182 | } |
| 183 | } else { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 184 | #if defined(sgi) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 185 | tst_resm(TFAIL, |
| 186 | "rmdir(\".\") failed with errno %d : %s but expected %d (EINVAL)", |
| 187 | TEST_ERRNO, |
| 188 | strerror(TEST_ERRNO), EINVAL); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 189 | #elif defined(linux) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 190 | tst_resm(TFAIL, |
| 191 | "rmdir(\".\") failed with errno %d : %s but expected %d (EBUSY)", |
| 192 | TEST_ERRNO, |
| 193 | strerror(TEST_ERRNO), EBUSY); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 194 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 195 | } |
| 196 | } else { |
| 197 | tst_resm(TFAIL, |
| 198 | "rmdir(\".\") succeeded unexpectedly."); |
| 199 | } |
| 200 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 201 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 202 | /* |
| 203 | * TEST CASE: 2 |
| 204 | * path points to the "." (dot) entry of a directory |
| 205 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 206 | #if defined(linux) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 207 | tst_resm(TCONF, "rmdir on \"dir/.\" supported on Linux"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 208 | #elif defined(sgi) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 209 | /* Call rmdir(2) */ |
| 210 | TEST(rmdir("dir1/.")); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 211 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 212 | /* check return code */ |
| 213 | if (TEST_RETURN == -1) { |
| 214 | TEST_ERROR_LOG(TEST_ERRNO); |
| 215 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 216 | |
| 217 | /*************************************************************** |
| 218 | * only perform functional verification if flag set (-f not given) |
| 219 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 220 | if (STD_FUNCTIONAL_TEST) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 221 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 222 | if (TEST_RETURN == -1) { |
| 223 | if (TEST_ERRNO == EINVAL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 224 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 225 | /* For functionality tests, verify that the |
| 226 | * directory wasn't removed. |
| 227 | */ |
| 228 | if (stat("dir1/.", &stat_buf) == -1) { |
| 229 | tst_resm(TFAIL, |
| 230 | "rmdir(\"dir1/.\") removed the \".\" entry of a directory when it should have failed."); |
| 231 | } else { |
| 232 | tst_resm(TPASS, |
| 233 | "rmdir(\"dir1/.\") failed to remove the \".\" entry of a directory. Returned %d : %s", |
| 234 | TEST_ERRNO, |
| 235 | strerror(TEST_ERRNO)); |
| 236 | } |
| 237 | } else { |
| 238 | tst_resm(TFAIL, |
| 239 | "rmdir(\"dir1/.\") failed with errno %d : %s but expected %d (EINVAL)", |
| 240 | TEST_ERRNO, |
| 241 | strerror(TEST_ERRNO), EINVAL); |
| 242 | } |
| 243 | } else { |
| 244 | tst_resm(TFAIL, |
| 245 | "rmdir(\"dir1/.\") - path points to the \".\" entry of a directory succeeded unexpectedly."); |
| 246 | } |
| 247 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 248 | #endif |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 249 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 250 | #if defined(sgi) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 251 | /* |
| 252 | * TEST CASE: 3 |
| 253 | * the directory has been linked |
| 254 | */ |
| 255 | tst_resm(TCONF, "linked directories not valid on IRIX"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 256 | #elif defined(linux) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 257 | tst_resm(TCONF, |
| 258 | "linked directories test not implemented on Linux"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 259 | #elif defined(CRAY) |
| 260 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 261 | /* Call rmdir(2) */ |
| 262 | TEST(rmdir("dir2")); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 263 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 264 | /* check return code */ |
| 265 | if (TEST_RETURN == -1) { |
| 266 | TEST_ERROR_LOG(TEST_ERRNO); |
| 267 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 268 | |
| 269 | /*************************************************************** |
| 270 | * only perform functional verification if flag set (-f not given) |
| 271 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 272 | if (STD_FUNCTIONAL_TEST) { |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 273 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 274 | if (TEST_RETURN == -1) { |
| 275 | if (TEST_ERRNO == EMLINK) { |
| 276 | /* For functionality tests, verify that the directory wasn't |
| 277 | * removed. |
| 278 | */ |
| 279 | if (stat("dir2", &stat_buf) == -1) { |
| 280 | tst_resm(TFAIL, |
| 281 | "rmdir(\"dir2\") removed a directory with multiple links when it should have failed."); |
| 282 | } else { |
| 283 | tst_resm(TPASS, |
| 284 | "rmdir(\"dir2\") failed to remove a directory with multiple links. Returned %d : %s", |
| 285 | TEST_ERRNO, |
| 286 | strerror(TEST_ERRNO)); |
| 287 | } |
| 288 | } else { |
| 289 | tst_resm(TFAIL, |
| 290 | "rmdir(\"dir2\") failed with errno %d : %s but expected %d (EMLINK)", |
| 291 | TEST_ERRNO, |
| 292 | strerror(TEST_ERRNO), EMLINK); |
| 293 | } |
| 294 | } else { |
| 295 | tst_resm(TFAIL, |
| 296 | "rmdir(\"dir2\") - the directory has been linked succeeded unexpectedly."); |
| 297 | } |
| 298 | } |
| 299 | #endif /* linux */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 300 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 301 | /* |
| 302 | * TEST CASE: 4 |
| 303 | * path argument points below the minimum allocated address space |
| 304 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 305 | |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 306 | #if !defined(UCLINUX) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 307 | /* Call rmdir(2) */ |
| 308 | TEST(rmdir(bad_addr)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 309 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 310 | /* check return code */ |
| 311 | if (TEST_RETURN == -1) { |
| 312 | TEST_ERROR_LOG(TEST_ERRNO); |
| 313 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 314 | |
| 315 | /*************************************************************** |
| 316 | * only perform functional verification if flag set (-f not given) |
| 317 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 318 | if (STD_FUNCTIONAL_TEST) { |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 319 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 320 | if (TEST_RETURN == -1) { |
| 321 | if (TEST_ERRNO == EFAULT) { |
| 322 | tst_resm(TPASS, |
| 323 | "rmdir() - path argument points below the minimum allocated address space failed as expected with errno %d : %s", |
| 324 | TEST_ERRNO, |
| 325 | strerror(TEST_ERRNO)); |
| 326 | } else { |
| 327 | tst_resm(TFAIL, |
| 328 | "rmdir() - path argument points below the minimum allocated address space failed with errno %d : %s but expected %d (EFAULT)", |
| 329 | TEST_ERRNO, |
| 330 | strerror(TEST_ERRNO), EFAULT); |
| 331 | } |
| 332 | } else { |
| 333 | tst_resm(TFAIL, |
| 334 | "rmdir() - path argument points below the minimum allocated address space succeeded unexpectedly."); |
| 335 | } |
| 336 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 337 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 338 | /* |
| 339 | * TEST CASE: 5 |
| 340 | * path argument points above the maximum allocated address space |
| 341 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 342 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 343 | /* Call rmdir(2) */ |
| 344 | TEST(rmdir(get_high_address())); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 345 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 346 | /* check return code */ |
| 347 | if (TEST_RETURN == -1) { |
| 348 | TEST_ERROR_LOG(TEST_ERRNO); |
| 349 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 350 | |
| 351 | /*************************************************************** |
| 352 | * only perform functional verification if flag set (-f not given) |
| 353 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 354 | if (STD_FUNCTIONAL_TEST) { |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 355 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 356 | if (TEST_RETURN == -1) { |
| 357 | if (TEST_ERRNO == EFAULT) { |
| 358 | tst_resm(TPASS, |
| 359 | "rmdir() - path argument points above the maximum allocated address space failed as expected with errno %d : %s", |
| 360 | TEST_ERRNO, |
| 361 | strerror(TEST_ERRNO)); |
| 362 | } else { |
| 363 | tst_resm(TFAIL, |
| 364 | "rmdir() - path argument points above the maximum allocated address space failed with errno %d : %s but expected %d (EFAULT)", |
| 365 | TEST_ERRNO, |
| 366 | strerror(TEST_ERRNO), EFAULT); |
| 367 | } |
| 368 | } else { |
| 369 | tst_resm(TFAIL, |
| 370 | "rmdir() - path argument points above the maximum allocated address space succeeded unexpectedly."); |
| 371 | } |
| 372 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 373 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 374 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 375 | /* |
| 376 | * TEST CASE: 6 |
| 377 | * able to remove a directory |
| 378 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 379 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 380 | /* Create a directory. */ |
| 381 | if (mkdir(dir_name, 0777) != 0) { |
| 382 | tst_brkm(TBROK, cleanup, |
| 383 | "mkdir(\"%s\") failed with errno %d : %s", |
| 384 | dir_name, errno, strerror(errno)); |
| 385 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 386 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 387 | /* Call rmdir(2) */ |
| 388 | TEST(rmdir(dir_name)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 389 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 390 | /* check return code */ |
| 391 | if (TEST_RETURN == -1) { |
| 392 | TEST_ERROR_LOG(TEST_ERRNO); |
| 393 | tst_resm(TFAIL, |
| 394 | "rmdir(\"%s\") failed when it should have passed. Returned %d : %s", |
| 395 | dir_name, TEST_ERRNO, strerror(TEST_ERRNO)); |
| 396 | } else { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 397 | |
| 398 | /*************************************************************** |
| 399 | * only perform functional verification if flag set (-f not given) |
| 400 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 401 | if (STD_FUNCTIONAL_TEST) { |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 402 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 403 | /* Verify the directory was removed. */ |
| 404 | if (stat(dir_name, &stat_buf) != 0) { |
| 405 | tst_resm(TPASS, |
| 406 | "rmdir(\"%s\") removed the directory as expected.", |
| 407 | dir_name); |
| 408 | } else { |
| 409 | tst_resm(TFAIL, |
| 410 | "rmdir(\"%s\") returned a zero exit status but failed to remove the directory.", |
| 411 | dir_name); |
| 412 | } |
| 413 | } |
| 414 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 415 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 416 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 417 | |
| 418 | /*************************************************************** |
| 419 | * cleanup and exit |
| 420 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 421 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 422 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 423 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 424 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 425 | |
| 426 | /*************************************************************** |
| 427 | * setup() - performs all ONE TIME setup for this test. |
| 428 | ***************************************************************/ |
| 429 | void setup() |
| 430 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 431 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 432 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 433 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 434 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 435 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 436 | /* Create a temporary directory and make it current. */ |
| 437 | tst_tmpdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 438 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 439 | /* Create a directory. */ |
| 440 | if (mkdir("dir1", 0777) == -1) { |
| 441 | tst_brkm(TBROK, cleanup, "mkdir() failed to create dir1."); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 442 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 443 | #if defined(CRAY) |
| 444 | /* NOTE: linking directories is NOT valid on IRIX */ |
| 445 | |
| 446 | /* Create a directory that has multiple links to it. */ |
| 447 | if (mkdir("dir2", 0777) == -1) { |
| 448 | tst_brkm(TBROK, cleanup, "mkdir() failed to create dir2."); |
| 449 | } else { |
| 450 | if (system |
| 451 | ("runcmd `get_attrib -A link` dir2 mlink_dir > link.out 2>&1") |
| 452 | != 0) { |
| 453 | tst_brk(TBROK, "link.out", cleanup, |
| 454 | "link failed to link dir2 and mlink_dir."); |
| 455 | } |
| 456 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 457 | |
| 458 | #endif |
| 459 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 460 | /* Create a unique directory name. */ |
| 461 | sprintf(dir_name, "./dir_%d", getpid()); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 462 | |
vapier | 62b16cf | 2007-02-09 20:48:23 +0000 | [diff] [blame] | 463 | #if !defined(UCLINUX) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 464 | bad_addr = mmap(0, 1, PROT_NONE, |
| 465 | MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); |
| 466 | if (bad_addr == MAP_FAILED) { |
| 467 | tst_brkm(TBROK, cleanup, "mmap failed"); |
| 468 | } |
vapier | 62b16cf | 2007-02-09 20:48:23 +0000 | [diff] [blame] | 469 | #endif |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 470 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 471 | |
| 472 | /*************************************************************** |
| 473 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 474 | * completion or premature exit. |
| 475 | ***************************************************************/ |
| 476 | void cleanup() |
| 477 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 478 | /* |
| 479 | * print timing stats if that option was specified. |
| 480 | * print errno log if that option was specified. |
| 481 | */ |
| 482 | TEST_CLEANUP; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 483 | |
| 484 | #if defined(CRAY) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 485 | /* NOTE: setup was not done on IRIX */ |
| 486 | /* Unlink the directory. */ |
| 487 | if (system("runcmd `get_attrib -A unlink` dir2 > unlink.out 2>&1") != 0) { |
| 488 | tst_res(TWARN, "unlink.out", "unlink failed to unlink dir2."); |
| 489 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 490 | #endif |
| 491 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 492 | /* |
| 493 | * Remove the temporary directory. |
| 494 | */ |
| 495 | tst_rmdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 496 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 497 | /* |
| 498 | * Exit with a return value appropriate for the results. |
| 499 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 500 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 501 | } |