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