rmdir01.c revision e38b961c385192f0d804914b77bd590734b42e75
1/*
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
17 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
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
27 *	removed
28 *
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>
65#include "test.h"
66#include "usctest.h"
67
68void setup();
69void cleanup();
70
71#define PERMS		0777
72
73char *TCID = "rmdir01";
74int TST_TOTAL = 1;
75
76char tstdir[100];
77
78int main(int ac, char **av)
79{
80	int lc;
81	const char *msg;
82	struct stat buf;
83
84	/*
85	 * parse standard options
86	 */
87	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
88		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
89	}
90
91	/*
92	 * perform global setup for test
93	 */
94	setup();
95
96	/*
97	 * check looping state if -i option given
98	 */
99	for (lc = 0; TEST_LOOPING(lc); lc++) {
100
101		tst_count = 0;
102
103		/*
104		 * TEST rmdir() base functionality
105		 */
106
107		/* Initialize the test directory name */
108
109		/* create a directory */
110		if (mkdir(tstdir, PERMS) == -1) {
111			tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) Failed",
112				 tstdir, PERMS);
113		}
114		/* call rmdir using TEST macro */
115
116		TEST(rmdir(tstdir));
117
118		if (TEST_RETURN == -1) {
119			tst_resm(TFAIL, "rmdir(%s) Failed", tstdir);
120			continue;
121		}
122
123		if (stat(tstdir, &buf) != -1) {
124			tst_resm(TFAIL, "directory %s still exists",
125				 tstdir);
126			continue;
127		} else {
128			tst_resm(TPASS, "directory has been removed");
129		}
130	}
131
132	cleanup();
133	tst_exit();
134}
135
136/*
137 * setup() - performs all ONE TIME setup for this test.
138 */
139void setup(void)
140{
141
142	tst_sig(NOFORK, DEF_HANDLER, cleanup);
143
144	TEST_PAUSE;
145
146	/* Create a temporary directory and make it current. */
147	tst_tmpdir();
148
149	sprintf(tstdir, "./tstdir_%d", getpid());
150}
151
152/*
153 * cleanup() - performs all ONE TIME cleanup for this test at
154 *              completion or premature exit.
155 */
156void cleanup(void)
157{
158	/*
159	 * print timing stats if that option was specified.
160	 * print errno log if that option was specified.
161	 */
162	TEST_CLEANUP;
163
164	/*
165	 * Remove the temporary directory.
166	 */
167	tst_rmdir();
168
169	/*
170	 * Exit with return code appropriate for results.
171	 */
172
173}
174