Home | History | Annotate | Download | only in rmdir
      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 "safe_macros.h"
     67 
     68 void setup();
     69 void cleanup();
     70 
     71 #define PERMS		0777
     72 
     73 char *TCID = "rmdir01";
     74 int TST_TOTAL = 1;
     75 
     76 char tstdir[100];
     77 
     78 int main(int ac, char **av)
     79 {
     80 	int lc;
     81 	struct stat buf;
     82 
     83 	/*
     84 	 * parse standard options
     85 	 */
     86 	tst_parse_opts(ac, av, NULL, NULL);
     87 
     88 	/*
     89 	 * perform global setup for test
     90 	 */
     91 	setup();
     92 
     93 	/*
     94 	 * check looping state if -i option given
     95 	 */
     96 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     97 
     98 		tst_count = 0;
     99 
    100 		/*
    101 		 * TEST rmdir() base functionality
    102 		 */
    103 
    104 		/* Initialize the test directory name */
    105 
    106 		/* create a directory */
    107 		SAFE_MKDIR(cleanup, tstdir, PERMS);
    108 		/* call rmdir using TEST macro */
    109 
    110 		TEST(rmdir(tstdir));
    111 
    112 		if (TEST_RETURN == -1) {
    113 			tst_resm(TFAIL, "rmdir(%s) Failed", tstdir);
    114 			continue;
    115 		}
    116 
    117 		if (stat(tstdir, &buf) != -1) {
    118 			tst_resm(TFAIL, "directory %s still exists",
    119 				 tstdir);
    120 			continue;
    121 		} else {
    122 			tst_resm(TPASS, "directory has been removed");
    123 		}
    124 	}
    125 
    126 	cleanup();
    127 	tst_exit();
    128 }
    129 
    130 /*
    131  * setup() - performs all ONE TIME setup for this test.
    132  */
    133 void setup(void)
    134 {
    135 
    136 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    137 
    138 	TEST_PAUSE;
    139 
    140 	/* Create a temporary directory and make it current. */
    141 	tst_tmpdir();
    142 
    143 	sprintf(tstdir, "./tstdir_%d", getpid());
    144 }
    145 
    146 /*
    147  * cleanup() - performs all ONE TIME cleanup for this test at
    148  *              completion or premature exit.
    149  */
    150 void cleanup(void)
    151 {
    152 
    153 	/*
    154 	 * Remove the temporary directory.
    155 	 */
    156 	tst_rmdir();
    157 
    158 	/*
    159 	 * Exit with return code appropriate for results.
    160 	 */
    161 
    162 }
    163