blob: 986575fc16fe377fe034275856172e9e3ffa4beb [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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 Gaofed96412012-10-24 10:10:29 +080020 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars865695b2001-08-27 22:15:12 +000022 *
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_modak56207ce2009-03-23 13:35:39 +000033/* $Id: rmdir05.c,v 1.8 2009/03/23 13:36:01 subrata_modak Exp $ */
plars865695b2001-08-27 22:15:12 +000034/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000035 *
plars865695b2001-08-27 22:15:12 +000036 * OS Test - Silicon Graphics, Inc.
subrata_modak4bb656a2009-02-26 12:02:09 +000037 *
plars865695b2001-08-27 22:15:12 +000038 * TEST IDENTIFIER : rmdir05
subrata_modak4bb656a2009-02-26 12:02:09 +000039 *
plars865695b2001-08-27 22:15:12 +000040 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000041 *
plars865695b2001-08-27 22:15:12 +000042 * TEST TITLE : Functionality Tests for rmdir(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000043 *
plars865695b2001-08-27 22:15:12 +000044 * PARENT DOCUMENT : rmstds02
subrata_modak4bb656a2009-02-26 12:02:09 +000045 *
plars865695b2001-08-27 22:15:12 +000046 * TEST CASE TOTAL : 6
subrata_modak4bb656a2009-02-26 12:02:09 +000047 *
plars865695b2001-08-27 22:15:12 +000048 * WALL CLOCK TIME : 2
subrata_modak4bb656a2009-02-26 12:02:09 +000049 *
plars865695b2001-08-27 22:15:12 +000050 * CPU TYPES : ALL
subrata_modak4bb656a2009-02-26 12:02:09 +000051 *
plars865695b2001-08-27 22:15:12 +000052 * AUTHOR : Bill Branum
subrata_modak4bb656a2009-02-26 12:02:09 +000053 *
plars865695b2001-08-27 22:15:12 +000054 * CO-PILOT : Steve Shaw
subrata_modak4bb656a2009-02-26 12:02:09 +000055 *
plars865695b2001-08-27 22:15:12 +000056 * DATE STARTED : 4/23/92
subrata_modak4bb656a2009-02-26 12:02:09 +000057 *
plars865695b2001-08-27 22:15:12 +000058 * INITIAL RELEASE : UNICOS 7.0
subrata_modak4bb656a2009-02-26 12:02:09 +000059 *
plars865695b2001-08-27 22:15:12 +000060 * TEST CASES
subrata_modak56207ce2009-03-23 13:35:39 +000061 * rmdir(2) test for errno(s) EINVAL, EMLINK, EFAULT
subrata_modakbdbaec52009-02-26 12:14:51 +000062 *
plars865695b2001-08-27 22:15:12 +000063 * INPUT SPECIFICATIONS
subrata_modak56207ce2009-03-23 13:35:39 +000064 * The standard options for system call tests are accepted.
plars865695b2001-08-27 22:15:12 +000065 * (See the parse_opts(3) man page).
subrata_modak4bb656a2009-02-26 12:02:09 +000066 *
plars865695b2001-08-27 22:15:12 +000067 * ENVIRONMENTAL NEEDS
68 * No run-time environmental needs.
subrata_modak4bb656a2009-02-26 12:02:09 +000069 *
plars865695b2001-08-27 22:15:12 +000070 * DETAILED DESCRIPTION
71 * Verify that rmdir(2) returns a value of -1 and sets errno
72 * to indicate the error.
subrata_modak4bb656a2009-02-26 12:02:09 +000073 *
subrata_modak56207ce2009-03-23 13:35:39 +000074 * Setup:
75 * Setup signal handling.
plars865695b2001-08-27 22:15:12 +000076 * Create a temporary directory and make it current.
77 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000078 *
subrata_modak56207ce2009-03-23 13:35:39 +000079 * Test:
plars865695b2001-08-27 22:15:12 +000080 * Loop if the proper options are given.
subrata_modak56207ce2009-03-23 13:35:39 +000081 * Execute system call
plars865695b2001-08-27 22:15:12 +000082 * 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_modak4bb656a2009-02-26 12:02:09 +000086 *
subrata_modak56207ce2009-03-23 13:35:39 +000087 * Cleanup:
88 * Print errno log and/or timing stats if options given.
plars865695b2001-08-27 22:15:12 +000089 * Remove the temporary directory.
90 * Exit.
subrata_modak4bb656a2009-02-26 12:02:09 +000091 *
92 *
plars865695b2001-08-27 22:15:12 +000093 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
94
95#include <errno.h>
96#include <signal.h>
97#include <sys/types.h>
98#include <sys/stat.h>
plars1ad84512002-07-23 13:11:18 +000099#include <sys/mman.h>
plars865695b2001-08-27 22:15:12 +0000100#include <stdlib.h>
101#include <string.h>
102#include "test.h"
103#include "usctest.h"
104
plars865695b2001-08-27 22:15:12 +0000105void setup();
106void cleanup();
107
robbiewd34d5812005-07-11 22:28:09 +0000108#if !defined(UCLINUX)
plars865695b2001-08-27 22:15:12 +0000109extern char *get_high_address();
subrata_modak56207ce2009-03-23 13:35:39 +0000110int TST_TOTAL = 6;
robbiewd34d5812005-07-11 22:28:09 +0000111#else
subrata_modak56207ce2009-03-23 13:35:39 +0000112int TST_TOTAL = 4;
robbiewd34d5812005-07-11 22:28:09 +0000113#endif
plars865695b2001-08-27 22:15:12 +0000114
subrata_modak56207ce2009-03-23 13:35:39 +0000115char *TCID = "rmdir05"; /* Test program identifier. */
subrata_modak56207ce2009-03-23 13:35:39 +0000116struct stat stat_buf; /* Stat buffer used for verification. */
plars865695b2001-08-27 22:15:12 +0000117char dir_name[256]; /* Array to hold directory name. */
118
subrata_modak56207ce2009-03-23 13:35:39 +0000119char *bad_addr = 0;
plars865695b2001-08-27 22:15:12 +0000120
subrata_modak56207ce2009-03-23 13:35:39 +0000121int main(int argc, char **argv)
plars865695b2001-08-27 22:15:12 +0000122{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200123 int lc;
124 char *msg;
plars865695b2001-08-27 22:15:12 +0000125
126 /***************************************************************
127 * parse standard options
128 ***************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800129 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000130 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -0800131
subrata_modak56207ce2009-03-23 13:35:39 +0000132 }
plars865695b2001-08-27 22:15:12 +0000133
134 /***************************************************************
135 * perform global setup for test
136 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000137 setup();
plars865695b2001-08-27 22:15:12 +0000138
139 /***************************************************************
140 * check looping state if -c option given
141 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000142 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +0000143
subrata_modak56207ce2009-03-23 13:35:39 +0000144 Tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000145
subrata_modak56207ce2009-03-23 13:35:39 +0000146 /*
147 * TEST CASE: 1
148 * path points to the current directory
149 */
plars865695b2001-08-27 22:15:12 +0000150
subrata_modak56207ce2009-03-23 13:35:39 +0000151 /* Call rmdir(2) */
152 TEST(rmdir("."));
subrata_modakbdbaec52009-02-26 12:14:51 +0000153
subrata_modak56207ce2009-03-23 13:35:39 +0000154 /* check return code */
155 if (TEST_RETURN == -1) {
156 TEST_ERROR_LOG(TEST_ERRNO);
157 }
plars865695b2001-08-27 22:15:12 +0000158
159 /***************************************************************
160 * only perform functional verification if flag set (-f not given)
161 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000162 if (STD_FUNCTIONAL_TEST) {
plars865695b2001-08-27 22:15:12 +0000163
subrata_modak56207ce2009-03-23 13:35:39 +0000164 if (TEST_RETURN == -1) {
plars865695b2001-08-27 22:15:12 +0000165#if defined(sgi)
subrata_modak56207ce2009-03-23 13:35:39 +0000166 if (TEST_ERRNO == EINVAL) {
plars865695b2001-08-27 22:15:12 +0000167#elif defined(linux)
subrata_modak56207ce2009-03-23 13:35:39 +0000168 if (TEST_ERRNO & (EBUSY | ENOTEMPTY)) {
plars865695b2001-08-27 22:15:12 +0000169#endif
170
subrata_modak56207ce2009-03-23 13:35:39 +0000171 /* 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 {
plars865695b2001-08-27 22:15:12 +0000184#if defined(sgi)
subrata_modak56207ce2009-03-23 13:35:39 +0000185 tst_resm(TFAIL,
186 "rmdir(\".\") failed with errno %d : %s but expected %d (EINVAL)",
187 TEST_ERRNO,
188 strerror(TEST_ERRNO), EINVAL);
plars865695b2001-08-27 22:15:12 +0000189#elif defined(linux)
subrata_modak56207ce2009-03-23 13:35:39 +0000190 tst_resm(TFAIL,
191 "rmdir(\".\") failed with errno %d : %s but expected %d (EBUSY)",
192 TEST_ERRNO,
193 strerror(TEST_ERRNO), EBUSY);
plars865695b2001-08-27 22:15:12 +0000194#endif
subrata_modak56207ce2009-03-23 13:35:39 +0000195 }
196 } else {
197 tst_resm(TFAIL,
198 "rmdir(\".\") succeeded unexpectedly.");
199 }
200 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000201
subrata_modak56207ce2009-03-23 13:35:39 +0000202 /*
203 * TEST CASE: 2
204 * path points to the "." (dot) entry of a directory
205 */
plars865695b2001-08-27 22:15:12 +0000206#if defined(linux)
subrata_modak56207ce2009-03-23 13:35:39 +0000207 tst_resm(TCONF, "rmdir on \"dir/.\" supported on Linux");
plars865695b2001-08-27 22:15:12 +0000208#elif defined(sgi)
subrata_modak56207ce2009-03-23 13:35:39 +0000209 /* Call rmdir(2) */
210 TEST(rmdir("dir1/."));
subrata_modakbdbaec52009-02-26 12:14:51 +0000211
subrata_modak56207ce2009-03-23 13:35:39 +0000212 /* check return code */
213 if (TEST_RETURN == -1) {
214 TEST_ERROR_LOG(TEST_ERRNO);
215 }
plars865695b2001-08-27 22:15:12 +0000216
217 /***************************************************************
218 * only perform functional verification if flag set (-f not given)
219 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000220 if (STD_FUNCTIONAL_TEST) {
plars865695b2001-08-27 22:15:12 +0000221
subrata_modak56207ce2009-03-23 13:35:39 +0000222 if (TEST_RETURN == -1) {
223 if (TEST_ERRNO == EINVAL) {
plars865695b2001-08-27 22:15:12 +0000224
subrata_modak56207ce2009-03-23 13:35:39 +0000225 /* 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 }
plars865695b2001-08-27 22:15:12 +0000248#endif
subrata_modakbdbaec52009-02-26 12:14:51 +0000249
plars865695b2001-08-27 22:15:12 +0000250#if defined(sgi)
subrata_modak56207ce2009-03-23 13:35:39 +0000251 /*
252 * TEST CASE: 3
253 * the directory has been linked
254 */
255 tst_resm(TCONF, "linked directories not valid on IRIX");
plars865695b2001-08-27 22:15:12 +0000256#elif defined(linux)
subrata_modak56207ce2009-03-23 13:35:39 +0000257 tst_resm(TCONF,
258 "linked directories test not implemented on Linux");
plars865695b2001-08-27 22:15:12 +0000259#elif defined(CRAY)
260
subrata_modak56207ce2009-03-23 13:35:39 +0000261 /* Call rmdir(2) */
262 TEST(rmdir("dir2"));
plars865695b2001-08-27 22:15:12 +0000263
subrata_modak56207ce2009-03-23 13:35:39 +0000264 /* check return code */
265 if (TEST_RETURN == -1) {
266 TEST_ERROR_LOG(TEST_ERRNO);
267 }
plars865695b2001-08-27 22:15:12 +0000268
269 /***************************************************************
270 * only perform functional verification if flag set (-f not given)
271 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000272 if (STD_FUNCTIONAL_TEST) {
subrata_modakbdbaec52009-02-26 12:14:51 +0000273
subrata_modak56207ce2009-03-23 13:35:39 +0000274 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_modakbdbaec52009-02-26 12:14:51 +0000300
subrata_modak56207ce2009-03-23 13:35:39 +0000301 /*
302 * TEST CASE: 4
303 * path argument points below the minimum allocated address space
304 */
plars865695b2001-08-27 22:15:12 +0000305
subrata_modakbdbaec52009-02-26 12:14:51 +0000306#if !defined(UCLINUX)
subrata_modak56207ce2009-03-23 13:35:39 +0000307 /* Call rmdir(2) */
308 TEST(rmdir(bad_addr));
subrata_modakbdbaec52009-02-26 12:14:51 +0000309
subrata_modak56207ce2009-03-23 13:35:39 +0000310 /* check return code */
311 if (TEST_RETURN == -1) {
312 TEST_ERROR_LOG(TEST_ERRNO);
313 }
plars865695b2001-08-27 22:15:12 +0000314
315 /***************************************************************
316 * only perform functional verification if flag set (-f not given)
317 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000318 if (STD_FUNCTIONAL_TEST) {
subrata_modakbdbaec52009-02-26 12:14:51 +0000319
subrata_modak56207ce2009-03-23 13:35:39 +0000320 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 }
robbiewd34d5812005-07-11 22:28:09 +0000337
subrata_modak56207ce2009-03-23 13:35:39 +0000338 /*
339 * TEST CASE: 5
340 * path argument points above the maximum allocated address space
341 */
plars865695b2001-08-27 22:15:12 +0000342
subrata_modak56207ce2009-03-23 13:35:39 +0000343 /* Call rmdir(2) */
344 TEST(rmdir(get_high_address()));
plars865695b2001-08-27 22:15:12 +0000345
subrata_modak56207ce2009-03-23 13:35:39 +0000346 /* check return code */
347 if (TEST_RETURN == -1) {
348 TEST_ERROR_LOG(TEST_ERRNO);
349 }
plars865695b2001-08-27 22:15:12 +0000350
351 /***************************************************************
352 * only perform functional verification if flag set (-f not given)
353 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000354 if (STD_FUNCTIONAL_TEST) {
subrata_modakbdbaec52009-02-26 12:14:51 +0000355
subrata_modak56207ce2009-03-23 13:35:39 +0000356 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 }
robbiewd34d5812005-07-11 22:28:09 +0000373#endif
plars865695b2001-08-27 22:15:12 +0000374
subrata_modak56207ce2009-03-23 13:35:39 +0000375 /*
376 * TEST CASE: 6
377 * able to remove a directory
378 */
plars865695b2001-08-27 22:15:12 +0000379
subrata_modak56207ce2009-03-23 13:35:39 +0000380 /* 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 }
plars865695b2001-08-27 22:15:12 +0000386
subrata_modak56207ce2009-03-23 13:35:39 +0000387 /* Call rmdir(2) */
388 TEST(rmdir(dir_name));
subrata_modakbdbaec52009-02-26 12:14:51 +0000389
subrata_modak56207ce2009-03-23 13:35:39 +0000390 /* 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 {
plars865695b2001-08-27 22:15:12 +0000397
398 /***************************************************************
399 * only perform functional verification if flag set (-f not given)
400 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000401 if (STD_FUNCTIONAL_TEST) {
subrata_modakbdbaec52009-02-26 12:14:51 +0000402
subrata_modak56207ce2009-03-23 13:35:39 +0000403 /* 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_modakbdbaec52009-02-26 12:14:51 +0000415
Garrett Cooper2c282152010-12-16 00:55:50 -0800416 }
plars865695b2001-08-27 22:15:12 +0000417
418 /***************************************************************
419 * cleanup and exit
420 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000421 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800422 tst_exit();
plars865695b2001-08-27 22:15:12 +0000423
Garrett Cooper2c282152010-12-16 00:55:50 -0800424}
plars865695b2001-08-27 22:15:12 +0000425
426/***************************************************************
427 * setup() - performs all ONE TIME setup for this test.
428 ***************************************************************/
429void setup()
430{
Garrett Cooper2c282152010-12-16 00:55:50 -0800431
subrata_modak56207ce2009-03-23 13:35:39 +0000432 tst_sig(FORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000433
subrata_modak56207ce2009-03-23 13:35:39 +0000434 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000435
subrata_modak56207ce2009-03-23 13:35:39 +0000436 /* Create a temporary directory and make it current. */
437 tst_tmpdir();
plars865695b2001-08-27 22:15:12 +0000438
subrata_modak56207ce2009-03-23 13:35:39 +0000439 /* Create a directory. */
440 if (mkdir("dir1", 0777) == -1) {
441 tst_brkm(TBROK, cleanup, "mkdir() failed to create dir1.");
plars865695b2001-08-27 22:15:12 +0000442 }
subrata_modak56207ce2009-03-23 13:35:39 +0000443#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 }
plars865695b2001-08-27 22:15:12 +0000457
458#endif
459
subrata_modak56207ce2009-03-23 13:35:39 +0000460 /* Create a unique directory name. */
461 sprintf(dir_name, "./dir_%d", getpid());
plars865695b2001-08-27 22:15:12 +0000462
vapier62b16cf2007-02-09 20:48:23 +0000463#if !defined(UCLINUX)
subrata_modak56207ce2009-03-23 13:35:39 +0000464 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 }
vapier62b16cf2007-02-09 20:48:23 +0000469#endif
Garrett Cooper2c282152010-12-16 00:55:50 -0800470}
plars865695b2001-08-27 22:15:12 +0000471
472/***************************************************************
473 * cleanup() - performs all ONE TIME cleanup for this test at
474 * completion or premature exit.
475 ***************************************************************/
476void cleanup()
477{
subrata_modak56207ce2009-03-23 13:35:39 +0000478 /*
479 * print timing stats if that option was specified.
480 * print errno log if that option was specified.
481 */
482 TEST_CLEANUP;
plars865695b2001-08-27 22:15:12 +0000483
484#if defined(CRAY)
subrata_modak56207ce2009-03-23 13:35:39 +0000485 /* 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 }
plars865695b2001-08-27 22:15:12 +0000490#endif
491
subrata_modak56207ce2009-03-23 13:35:39 +0000492 /*
493 * Remove the temporary directory.
494 */
495 tst_rmdir();
plars865695b2001-08-27 22:15:12 +0000496
subrata_modak56207ce2009-03-23 13:35:39 +0000497 /*
498 * Exit with a return value appropriate for the results.
499 */
plars865695b2001-08-27 22:15:12 +0000500
Chris Dearmanec6edca2012-10-17 19:54:01 -0700501}