rmdir01.c revision d59a659cd639ca2780b00049d102acd2a783d585
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";		/* Test program identifier.    */
74int TST_TOTAL = 1;		/* Total number of test cases. */
75
76char tstdir[100];
77
78int main(int ac, char **av)
79{
80	int lc;
81	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 (STD_FUNCTIONAL_TEST) {
124			/* check whether tstdir been removed */
125			if (stat(tstdir, &buf) != -1) {
126				tst_resm(TFAIL, "directory %s still exists",
127					 tstdir);
128				continue;
129			} else {
130				tst_resm(TPASS, "directory has been removed");
131			}
132		} else {
133			tst_resm(TPASS, "call succeeded");
134		}
135
136	}
137
138	/*
139	 * cleanup and exit
140	 */
141	cleanup();
142	tst_exit();
143
144}
145
146/*
147 * setup() - performs all ONE TIME setup for this test.
148 */
149void setup()
150{
151
152	tst_sig(NOFORK, DEF_HANDLER, cleanup);
153
154	TEST_PAUSE;
155
156	/* Create a temporary directory and make it current. */
157	tst_tmpdir();
158
159	sprintf(tstdir, "./tstdir_%d", getpid());
160}
161
162/*
163 * cleanup() - performs all ONE TIME cleanup for this test at
164 *              completion or premature exit.
165 */
166void cleanup()
167{
168	/*
169	 * print timing stats if that option was specified.
170	 * print errno log if that option was specified.
171	 */
172	TEST_CLEANUP;
173
174	/*
175	 * Remove the temporary directory.
176	 */
177	tst_rmdir();
178
179	/*
180	 * Exit with return code appropriate for results.
181	 */
182
183}
184