blob: 6d1bd21b702dbf3c9eebd7f7ed8c2e5605ecff13 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
22 * rmdir01
23 *
24 * DESCRIPTION
25 * This test will verify that rmdir(2) syscall basic functionality.
26 * verify rmdir(2) returns a value of 0 and the directory being
subrata_modak4bb656a2009-02-26 12:02:09 +000027 * removed
plars865695b2001-08-27 22:15:12 +000028 *
29 * ALGORITHM
30 * Setup:
31 * Setup signal handling.
32 * Create temporary directory.
33 * Pause for SIGUSR1 if option specified.
34 *
35 * Test:
36 * Loop if the proper options are given.
37 * make a directory tstdir
38 * call rmdir(tstdir), check the return value
39 * verify the directory tstdir does not exists.
40 *
41 * Cleanup:
42 * Print errno log and/or timing stats if options given
43 * Delete the temporary directory created.*
44 * USAGE
45 * rmdir01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
46 * where, -c n : Run n copies concurrently.
47 * -f : Turn off functionality Testing.
48 * -i n : Execute test n times.
49 * -I x : Execute test for x seconds.
50 * -P x : Pause for x seconds between iterations.
51 * -t : Turn on syscall timing.
52 *
53 * HISTORY
54 * 07/2001 Ported by Wayne Boyer
55 *
56 * RESTRICTIONS
57 * None.
58 */
59#include <errno.h>
60#include <string.h>
61#include <sys/stat.h>
62#include <sys/types.h>
63#include <fcntl.h>
64#include <unistd.h>
subrata_modak4bb656a2009-02-26 12:02:09 +000065#include "test.h"
plars865695b2001-08-27 22:15:12 +000066
67void setup();
68void cleanup();
69
70#define PERMS 0777
71
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020072char *TCID = "rmdir01";
73int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000074
subrata_modak56207ce2009-03-23 13:35:39 +000075char tstdir[100];
plars865695b2001-08-27 22:15:12 +000076
subrata_modak56207ce2009-03-23 13:35:39 +000077int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000078{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020079 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020080 const char *msg;
subrata_modakbdbaec52009-02-26 12:14:51 +000081 struct stat buf;
plars865695b2001-08-27 22:15:12 +000082
83 /*
84 * parse standard options
85 */
Garrett Cooper45e285d2010-11-22 12:19:25 -080086 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080087 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000088 }
89
90 /*
91 * perform global setup for test
92 */
93 setup();
subrata_modakbdbaec52009-02-26 12:14:51 +000094
plars865695b2001-08-27 22:15:12 +000095 /*
96 * check looping state if -i option given
97 */
subrata_modak56207ce2009-03-23 13:35:39 +000098 for (lc = 0; TEST_LOOPING(lc); lc++) {
99
Caspar Zhangd59a6592013-03-07 14:59:12 +0800100 tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000101
102 /*
103 * TEST rmdir() base functionality
104 */
105
106 /* Initialize the test directory name */
107
108 /* create a directory */
subrata_modak56207ce2009-03-23 13:35:39 +0000109 if (mkdir(tstdir, PERMS) == -1) {
plars865695b2001-08-27 22:15:12 +0000110 tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) Failed",
111 tstdir, PERMS);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800112 }
plars865695b2001-08-27 22:15:12 +0000113 /* call rmdir using TEST macro */
114
115 TEST(rmdir(tstdir));
116
subrata_modak56207ce2009-03-23 13:35:39 +0000117 if (TEST_RETURN == -1) {
plars865695b2001-08-27 22:15:12 +0000118 tst_resm(TFAIL, "rmdir(%s) Failed", tstdir);
119 continue;
120 }
121
Cyril Hrubise38b9612014-06-02 17:20:57 +0200122 if (stat(tstdir, &buf) != -1) {
123 tst_resm(TFAIL, "directory %s still exists",
124 tstdir);
125 continue;
plars865695b2001-08-27 22:15:12 +0000126 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200127 tst_resm(TPASS, "directory has been removed");
plars865695b2001-08-27 22:15:12 +0000128 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800129 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000130
plars865695b2001-08-27 22:15:12 +0000131 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800132 tst_exit();
plars865695b2001-08-27 22:15:12 +0000133}
134
135/*
136 * setup() - performs all ONE TIME setup for this test.
137 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400138void setup(void)
plars865695b2001-08-27 22:15:12 +0000139{
Garrett Cooper2c282152010-12-16 00:55:50 -0800140
plars865695b2001-08-27 22:15:12 +0000141 tst_sig(NOFORK, DEF_HANDLER, cleanup);
142
plars865695b2001-08-27 22:15:12 +0000143 TEST_PAUSE;
144
145 /* Create a temporary directory and make it current. */
146 tst_tmpdir();
subrata_modakbdbaec52009-02-26 12:14:51 +0000147
subrata_modak56207ce2009-03-23 13:35:39 +0000148 sprintf(tstdir, "./tstdir_%d", getpid());
plars865695b2001-08-27 22:15:12 +0000149}
150
151/*
152 * cleanup() - performs all ONE TIME cleanup for this test at
153 * completion or premature exit.
154 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400155void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000156{
plars865695b2001-08-27 22:15:12 +0000157
158 /*
159 * Remove the temporary directory.
160 */
161 tst_rmdir();
subrata_modakbdbaec52009-02-26 12:14:51 +0000162
plars865695b2001-08-27 22:15:12 +0000163 /*
164 * Exit with return code appropriate for results.
165 */
Garrett Cooper2c282152010-12-16 00:55:50 -0800166
Chris Dearmanec6edca2012-10-17 19:54:01 -0700167}