1# $NetBSD: t_rename.sh,v 1.1 2007/11/12 15:18:25 jmmv Exp $ 2# 3# Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 3. All advertising materials mentioning features or use of this software 15# must display the following acknowledgement: 16# This product includes software developed by the NetBSD 17# Foundation, Inc. and its contributors. 18# 4. Neither the name of The NetBSD Foundation nor the names of its 19# contributors may be used to endorse or promote products derived 20# from this software without specific prior written permission. 21# 22# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 23# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 26# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32# POSSIBILITY OF SUCH DAMAGE. 33# 34 35# 36# Verifies that the rename operation works (either by renaming entries or 37# by moving them). 38# 39 40atf_test_case dots 41dots_head() { 42 atf_set "descr" "Tests that '.' and '..' cannot be renamed" 43 atf_set "require.user" "root" 44} 45dots_body() { 46 test_mount 47 48 atf_check 'mkdir a' 0 null null 49 atf_check 'mv a/. c' 1 null ignore 50 atf_check 'mv a/.. c' 1 null ignore 51 atf_check 'rmdir a' 0 null null 52 53 test_unmount 54} 55 56atf_test_case crossdev 57crossdev_head() { 58 atf_set "descr" "Tests that cross-device renames do not work" 59 atf_set "require.user" "root" 60} 61crossdev_body() { 62 test_mount 63 64 atf_check 'mkdir a' 0 null null 65 atf_check '$(atf_get_srcdir)/h_tools rename a /var/tmp/a' \ 66 1 null stderr 67 atf_check 'grep "Cross-device link" ../stderr' 0 ignore null 68 atf_check 'test -d a' 0 null null 69 atf_check 'rmdir a' 0 null null 70 71 test_unmount 72} 73 74atf_test_case basic 75basic_head() { 76 atf_set "descr" "Tests that basic renames work" 77 atf_set "require.user" "root" 78} 79basic_body() { 80 test_mount 81 82 atf_check 'mkdir a' 0 null null 83 atf_check 'mv a c' 0 null null 84 atf_check 'test -d a' 1 null null 85 atf_check 'test -d c' 0 null null 86 atf_check 'rmdir c' 0 null null 87 88 test_unmount 89} 90 91atf_test_case dotdot 92dotdot_head() { 93 atf_set "descr" "Tests that the '..' entry is properly updated" \ 94 "during moves" 95 atf_set "require.user" "root" 96} 97dotdot_body() { 98 test_mount 99 100 echo "Checking if the '..' entry is updated after moves" 101 atf_check 'mkdir a' 0 null null 102 atf_check 'mkdir b' 0 null null 103 atf_check 'mv b a' 0 null null 104 atf_check 'test -d a/b/../b' 0 null null 105 atf_check 'test -d a/b/../../a' 0 null null 106 eval $(stat -s a/b) 107 [ ${st_nlink} = 2 ] || atf_fail "Incorrect number of links" 108 eval $(stat -s a) 109 [ ${st_nlink} = 3 ] || atf_fail "Incorrect number of links" 110 atf_check 'rmdir a/b' 0 null null 111 atf_check 'rmdir a' 0 null null 112 113 echo "Checking if the '..' entry is correct after renames" 114 atf_check 'mkdir a' 0 null null 115 atf_check 'mkdir b' 0 null null 116 atf_check 'mv b a' 0 null null 117 atf_check 'mv a c' 0 null null 118 atf_check 'test -d c/b/../b' 0 null null 119 atf_check 'test -d c/b/../../c' 0 null null 120 atf_check 'rmdir c/b' 0 null null 121 atf_check 'rmdir c' 0 null null 122 123 echo "Checking if the '..' entry is correct after multiple moves" 124 atf_check 'mkdir a' 0 null null 125 atf_check 'mkdir b' 0 null null 126 atf_check 'mv b a' 0 null null 127 atf_check 'mv a c' 0 null null 128 atf_check 'mv c/b d' 0 null null 129 atf_check 'test -d d/../c' 0 null null 130 atf_check 'rmdir d' 0 null null 131 atf_check 'rmdir c' 0 null null 132 133 test_unmount 134} 135 136atf_test_case dir_to_emptydir 137dir_to_emptydir_head() { 138 atf_set "descr" "Tests that renaming a directory to override an" \ 139 "empty directory works" 140 atf_set "require.user" "root" 141} 142dir_to_emptydir_body() { 143 test_mount 144 145 atf_check 'mkdir a' 0 null null 146 atf_check 'touch a/c' 0 null null 147 atf_check 'mkdir b' 0 null null 148 atf_check '$(atf_get_srcdir)/h_tools rename a b' 0 null null 149 atf_check 'test -e a' 1 null null 150 atf_check 'test -d b' 0 null null 151 atf_check 'test -f b/c' 0 null null 152 rm b/c 153 rmdir b 154 155 test_unmount 156} 157 158atf_test_case dir_to_fulldir 159dir_to_fulldir_head() { 160 atf_set "descr" "Tests that renaming a directory to override a" \ 161 "non-empty directory fails" 162 atf_set "require.user" "root" 163} 164dir_to_fulldir_body() { 165 test_mount 166 167 atf_check 'mkdir a' 0 null null 168 atf_check 'touch a/c' 0 null null 169 atf_check 'mkdir b' 0 null null 170 atf_check 'touch b/d' 0 null null 171 atf_check '$(atf_get_srcdir)/h_tools rename a b' 1 null stderr 172 atf_check 'grep "Directory not empty" ../stderr' 0 ignore null 173 atf_check 'test -d a' 0 null null 174 atf_check 'test -f a/c' 0 null null 175 atf_check 'test -d b' 0 null null 176 atf_check 'test -f b/d' 0 null null 177 rm a/c 178 rm b/d 179 rmdir a 180 rmdir b 181 182 test_unmount 183} 184 185atf_test_case dir_to_file 186dir_to_file_head() { 187 atf_set "descr" "Tests that renaming a directory to override a" \ 188 "file fails" 189 atf_set "require.user" "root" 190} 191dir_to_file_body() { 192 test_mount 193 194 atf_check 'mkdir a' 0 null null 195 atf_check 'touch b' 0 null null 196 atf_check '$(atf_get_srcdir)/h_tools rename a b' 1 null stderr 197 atf_check 'grep "Not a directory" ../stderr' 0 ignore null 198 atf_check 'test -d a' 0 null null 199 atf_check 'test -f b' 0 null null 200 rmdir a 201 rm b 202 203 test_unmount 204} 205 206atf_test_case file_to_dir 207file_to_dir_head() { 208 atf_set "descr" "Tests that renaming a file to override a" \ 209 "directory fails" 210 atf_set "require.user" "root" 211} 212file_to_dir_body() { 213 test_mount 214 215 atf_check 'touch a' 0 null null 216 atf_check 'mkdir b' 0 null null 217 atf_check '$(atf_get_srcdir)/h_tools rename a b' 1 null stderr 218 atf_check 'grep "Is a directory" ../stderr' 0 ignore null 219 atf_check 'test -f a' 0 null null 220 atf_check 'test -d b' 0 null null 221 rm a 222 rmdir b 223 224 test_unmount 225} 226 227atf_test_case kqueue 228kqueue_head() { 229 atf_set "descr" "Tests that moving and renaming files raise the" \ 230 "correct kqueue events" 231 atf_set "require.user" "root" 232} 233kqueue_body() { 234 test_mount 235 236 atf_check 'mkdir dir' 0 null null 237 atf_check 'touch dir/a' 0 null null 238 echo 'mv dir/a dir/b' | kqueue_monitor 2 dir dir/a 239 kqueue_check dir/a NOTE_RENAME 240 kqueue_check dir NOTE_WRITE 241 atf_check 'rm dir/b' 0 null null 242 atf_check 'rmdir dir' 0 null null 243 244 atf_check 'mkdir dir' 0 null null 245 atf_check 'touch dir/a' 0 null null 246 atf_check 'touch dir/b' 0 null null 247 echo 'mv dir/a dir/b' | kqueue_monitor 3 dir dir/a dir/b 248 kqueue_check dir/a NOTE_RENAME 249 kqueue_check dir NOTE_WRITE 250 kqueue_check dir/b NOTE_DELETE 251 atf_check 'rm dir/b' 0 null null 252 atf_check 'rmdir dir' 0 null null 253 254 atf_check 'mkdir dir1' 0 null null 255 atf_check 'mkdir dir2' 0 null null 256 atf_check 'touch dir1/a' 0 null null 257 echo 'mv dir1/a dir2/a' | kqueue_monitor 3 dir1 dir1/a dir2 258 kqueue_check dir1/a NOTE_RENAME 259 kqueue_check dir1 NOTE_WRITE 260 kqueue_check dir2 NOTE_WRITE 261 atf_check 'rm dir2/a' 0 null null 262 atf_check 'rmdir dir1' 0 null null 263 atf_check 'rmdir dir2' 0 null null 264 265 test_unmount 266} 267 268atf_init_test_cases() { 269 . $(atf_get_srcdir)/../h_funcs.subr 270 . $(atf_get_srcdir)/h_funcs.subr 271 272 atf_add_test_case dots 273 atf_add_test_case crossdev 274 atf_add_test_case basic 275 atf_add_test_case dotdot 276 atf_add_test_case dir_to_emptydir 277 atf_add_test_case dir_to_fulldir 278 atf_add_test_case dir_to_file 279 atf_add_test_case file_to_dir 280 atf_add_test_case kqueue 281} 282