plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 27 | * removed |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 65 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 66 | |
| 67 | void setup(); |
| 68 | void cleanup(); |
| 69 | |
| 70 | #define PERMS 0777 |
| 71 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 72 | char *TCID = "rmdir01"; |
| 73 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 75 | char tstdir[100]; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 77 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 79 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 80 | const char *msg; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 81 | struct stat buf; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * parse standard options |
| 85 | */ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 86 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 87 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* |
| 91 | * perform global setup for test |
| 92 | */ |
| 93 | setup(); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 94 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 95 | /* |
| 96 | * check looping state if -i option given |
| 97 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 99 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 100 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | |
| 102 | /* |
| 103 | * TEST rmdir() base functionality |
| 104 | */ |
| 105 | |
| 106 | /* Initialize the test directory name */ |
| 107 | |
| 108 | /* create a directory */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 109 | if (mkdir(tstdir, PERMS) == -1) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) Failed", |
| 111 | tstdir, PERMS); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 112 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 113 | /* call rmdir using TEST macro */ |
| 114 | |
| 115 | TEST(rmdir(tstdir)); |
| 116 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 117 | if (TEST_RETURN == -1) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 118 | tst_resm(TFAIL, "rmdir(%s) Failed", tstdir); |
| 119 | continue; |
| 120 | } |
| 121 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 122 | if (stat(tstdir, &buf) != -1) { |
| 123 | tst_resm(TFAIL, "directory %s still exists", |
| 124 | tstdir); |
| 125 | continue; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 126 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 127 | tst_resm(TPASS, "directory has been removed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 128 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 129 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 130 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 131 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 132 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /* |
| 136 | * setup() - performs all ONE TIME setup for this test. |
| 137 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 138 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 140 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 141 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 142 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 143 | TEST_PAUSE; |
| 144 | |
| 145 | /* Create a temporary directory and make it current. */ |
| 146 | tst_tmpdir(); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 147 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 148 | sprintf(tstdir, "./tstdir_%d", getpid()); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* |
| 152 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 153 | * completion or premature exit. |
| 154 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 155 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 156 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * Remove the temporary directory. |
| 160 | */ |
| 161 | tst_rmdir(); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 162 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 163 | /* |
| 164 | * Exit with return code appropriate for results. |
| 165 | */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 166 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 167 | } |