rmdir01.c revision 43088e16aa60d69e3ec5a69cdd8bdd45b8891127
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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. */
75extern int Tst_count;		/* Test Case counter for tst_* routines */
76
77char tstdir[100];
78
79int main(int ac, char **av)
80{
81	int lc;			/* loop counter */
82	char *msg;		/* message returned from parse_opts */
83	struct stat buf;
84
85	/*
86	 * parse standard options
87	 */
88	if ((msg = parse_opts(ac, av, NULL) {
89		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
90	}
91
92	/*
93	 * perform global setup for test
94	 */
95	setup();
96
97	/*
98	 * check looping state if -i option given
99	 */
100	for (lc = 0; TEST_LOOPING(lc); lc++) {
101
102		/* reset Tst_count in case we are looping. */
103		Tst_count = 0;
104
105		/*
106		 * TEST rmdir() base functionality
107		 */
108
109		/* Initialize the test directory name */
110
111		/* create a directory */
112		if (mkdir(tstdir, PERMS) == -1) {
113			tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) Failed",
114				 tstdir, PERMS);
115		 /*NOTREACHED*/}
116		/* call rmdir using TEST macro */
117
118		TEST(rmdir(tstdir));
119
120		if (TEST_RETURN == -1) {
121			tst_resm(TFAIL, "rmdir(%s) Failed", tstdir);
122			continue;
123		}
124
125		if (STD_FUNCTIONAL_TEST) {
126			/* check whether tstdir been removed */
127			if (stat(tstdir, &buf) != -1) {
128				tst_resm(TFAIL, "directory %s still exists",
129					 tstdir);
130				continue;
131			} else {
132				tst_resm(TPASS, "directory has been removed");
133			}
134		} else {
135			tst_resm(TPASS, "call succeeded");
136		}
137
138	}			/* End for TEST_LOOPING */
139
140	/*
141	 * cleanup and exit
142	 */
143	cleanup();
144
145	 /*NOTREACHED*/ return 0;
146
147}
148
149/*
150 * setup() - performs all ONE TIME setup for this test.
151 */
152void setup()
153{
154	/* capture signals */
155	tst_sig(NOFORK, DEF_HANDLER, cleanup);
156
157	/* Pause if that option was specified */
158	TEST_PAUSE;
159
160	/* Create a temporary directory and make it current. */
161	tst_tmpdir();
162
163	sprintf(tstdir, "./tstdir_%d", getpid());
164}
165
166/*
167 * cleanup() - performs all ONE TIME cleanup for this test at
168 *              completion or premature exit.
169 */
170void cleanup()
171{
172	/*
173	 * print timing stats if that option was specified.
174	 * print errno log if that option was specified.
175	 */
176	TEST_CLEANUP;
177
178	/*
179	 * Remove the temporary directory.
180	 */
181	tst_rmdir();
182
183	/*
184	 * Exit with return code appropriate for results.
185	 */
186	tst_exit();
187}
188