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 |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
| 22 | * rename10 |
| 23 | * |
| 24 | * DESCRIPTION |
| 25 | * This test will verify that rename(2) syscall fails with ENAMETOOLONG |
| 26 | * and ENOENT |
| 27 | * |
| 28 | * ALGORITHM |
| 29 | * Setup: |
| 30 | * Setup signal handling. |
| 31 | * Create temporary directory. |
| 32 | * Pause for SIGUSR1 if option specified. |
| 33 | * create the "old" file |
| 34 | * |
| 35 | * Test: |
| 36 | * Loop if the proper options are given. |
| 37 | * 1. rename the "old" to the "new" file |
| 38 | * verify rename() failed with error ENAMETOOLONG |
| 39 | * |
| 40 | * 2. "new" path contains a directory that does not exist |
| 41 | * rename the "old" to the "new" |
| 42 | * verify rename() failed with error ENOENT |
| 43 | * Cleanup: |
| 44 | * Print errno log and/or timing stats if options given |
| 45 | * Delete the temporary directory created.* |
| 46 | * |
| 47 | * USAGE |
| 48 | * rename10 [-c n] [-e] [-i n] [-I x] [-P x] [-t] |
| 49 | * where, -c n : Run n copies concurrently. |
| 50 | * -e : Turn on errno logging. |
| 51 | * -i n : Execute test n times. |
| 52 | * -I x : Execute test for x seconds. |
| 53 | * -P x : Pause for x seconds between iterations. |
| 54 | * -t : Turn on syscall timing. |
| 55 | * |
| 56 | * HISTORY |
| 57 | * 07/2001 Ported by Wayne Boyer |
| 58 | * |
| 59 | * RESTRICTIONS |
| 60 | * None. |
| 61 | */ |
| 62 | #include <sys/types.h> |
| 63 | #include <sys/fcntl.h> |
| 64 | #include <unistd.h> |
| 65 | #include <errno.h> |
| 66 | |
| 67 | #include "test.h" |
| 68 | #include "usctest.h" |
| 69 | |
| 70 | void setup(); |
| 71 | void cleanup(); |
| 72 | extern void do_file_setup(char *); |
| 73 | |
| 74 | char *TCID="rename10"; /* Test program identifier. */ |
| 75 | int TST_TOTAL=2; /* Total number of test cases. */ |
| 76 | extern int Tst_count; /* Test Case counter for tst_* routines */ |
| 77 | |
| 78 | char badmname[] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz"; |
| 79 | |
| 80 | int exp_enos[]={ENAMETOOLONG, ENOENT, 0}; /* List must end with 0 */ |
| 81 | |
| 82 | int fd; |
| 83 | char fname[255], mname[255]; |
| 84 | char mdir[255]; |
| 85 | |
| 86 | struct test_case_t { |
| 87 | char *fd1; |
| 88 | char *fd2; |
| 89 | int error; |
| 90 | } TC[] = { |
| 91 | /* badmname is too long for a file name - ENAMETOOLONG */ |
| 92 | {fname, badmname, ENAMETOOLONG}, |
| 93 | |
| 94 | /* mname contains a directory component which does not exist - ENOENT */ |
| 95 | {fname, mname, ENOENT} |
| 96 | }; |
| 97 | |
| 98 | int |
| 99 | main(int ac, char **av) |
| 100 | { |
| 101 | int lc; /* loop counter */ |
| 102 | char *msg; /* message returned from parse_opts */ |
| 103 | int i; |
| 104 | |
| 105 | /* |
| 106 | * parse standard options |
| 107 | */ |
| 108 | if ((msg=parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL) { |
| 109 | tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | * perform global setup for test |
| 114 | */ |
| 115 | setup(); |
| 116 | |
| 117 | /* set the expected errnos... */ |
| 118 | TEST_EXP_ENOS(exp_enos); |
| 119 | |
| 120 | /* |
| 121 | * check looping state if -i option given |
| 122 | */ |
| 123 | for (lc=0; TEST_LOOPING(lc); lc++) { |
| 124 | |
| 125 | /* reset Tst_count in case we are looping. */ |
| 126 | Tst_count=0; |
| 127 | |
| 128 | /* loop through the test cases */ |
| 129 | for (i=0; i < TST_TOTAL; i++) { |
| 130 | |
| 131 | TEST(rename(TC[i].fd1, TC[i].fd2)); |
| 132 | |
| 133 | if (TEST_RETURN != -1) { |
| 134 | tst_resm(TFAIL, "call succeeded unexpectedly"); |
| 135 | continue; |
| 136 | } |
| 137 | |
| 138 | TEST_ERROR_LOG(TEST_ERRNO); |
| 139 | |
| 140 | if (TEST_ERRNO == TC[i].error) { |
| 141 | tst_resm(TPASS, "expected failure - " |
| 142 | "errno = %d : %s", TEST_ERRNO, |
| 143 | strerror(TEST_ERRNO)); |
| 144 | } else { |
| 145 | tst_resm(TFAIL, "unexpected error - %d : %s - " |
| 146 | "expected %d", TEST_ERRNO, |
| 147 | strerror(TEST_ERRNO), TC[i].error); |
| 148 | } |
| 149 | } |
| 150 | } /* End for TEST_LOOPING */ |
| 151 | |
| 152 | /* |
| 153 | * cleanup and exit |
| 154 | */ |
| 155 | cleanup(); |
| 156 | |
| 157 | /*NOTREACHED*/ |
robbiew | c2cbe20 | 2003-03-27 18:32:02 +0000 | [diff] [blame] | 158 | |
| 159 | return(0); |
| 160 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /* |
| 164 | * setup() - performs all ONE TIME setup for this test. |
| 165 | */ |
| 166 | void |
| 167 | setup() |
| 168 | { |
| 169 | /* capture signals */ |
| 170 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 171 | |
| 172 | /* Pause if that option was specified */ |
| 173 | TEST_PAUSE; |
| 174 | |
| 175 | /* Create a temporary directory and make it current. */ |
| 176 | tst_tmpdir(); |
| 177 | |
| 178 | sprintf(fname,"./tfile_%d",getpid()); |
| 179 | sprintf(mdir,"./rndir_%d",getpid()); |
| 180 | sprintf(mname,"%s/rnfile_%d",mdir,getpid()); |
| 181 | |
| 182 | do_file_setup(fname); |
| 183 | } |
| 184 | |
| 185 | /* |
| 186 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 187 | * completion or premature exit. |
| 188 | */ |
| 189 | void |
| 190 | cleanup() |
| 191 | { |
| 192 | /* |
| 193 | * print timing stats if that option was specified. |
| 194 | * print errno log if that option was specified. |
| 195 | */ |
| 196 | TEST_CLEANUP; |
| 197 | |
| 198 | /* |
| 199 | * Remove the temporary directory. |
| 200 | */ |
| 201 | tst_rmdir(); |
| 202 | |
| 203 | /* |
| 204 | * Exit with return code appropriate for results. |
| 205 | */ |
| 206 | tst_exit(); |
| 207 | } |