1#!/bin/sh 2# $FreeBSD: releng/10.2/bin/mv/tests/legacy_test.sh 259210 2013-12-11 04:09:17Z jmmv $ 3 4# A directory in a device different from that where the tests are run 5TMPDIR=/tmp/regress.$$ 6COUNT=0 7 8# Begin an individual test 9begin() 10{ 11 COUNT=`expr $COUNT + 1` 12 OK=1 13 if [ -z "$FS" ] 14 then 15 NAME="$1" 16 else 17 NAME="$1 (cross device)" 18 fi 19 rm -rf testdir $TMPDIR/testdir 20 mkdir -p testdir $TMPDIR/testdir 21 cd testdir 22} 23 24# End an individual test 25end() 26{ 27 if [ $OK = 1 ] 28 then 29 printf 'ok ' 30 else 31 printf 'not ok ' 32 fi 33 echo "$COUNT - $NAME" 34 cd .. 35 rm -rf testdir $TMPDIR/testdir 36} 37 38# Make a file that can later be verified 39mkf() 40{ 41 CN=`basename $1` 42 echo "$CN-$CN" >$1 43} 44 45# Verify that the file specified is correct 46ckf() 47{ 48 if [ -f $2 ] && echo "$1-$1" | diff - $2 >/dev/null 49 then 50 ok 51 else 52 notok 53 fi 54} 55 56# Make a fifo that can later be verified 57mkp() 58{ 59 mkfifo $1 60} 61 62# Verify that the file specified is correct 63ckp() 64{ 65 if [ -p $2 ] 66 then 67 ok 68 else 69 notok 70 fi 71} 72 73# Make a directory that can later be verified 74mkd() 75{ 76 CN=`basename $1` 77 mkdir -p $1/"$CN-$CN" 78} 79 80# Verify that the directory specified is correct 81ckd() 82{ 83 if [ -d $2/$1-$1 ] 84 then 85 ok 86 else 87 notok 88 fi 89} 90 91# Verify that the specified file does not exist 92# (is not there) 93cknt() 94{ 95 if [ -r $1 ] 96 then 97 notok 98 else 99 ok 100 fi 101} 102 103# A part of a test succeeds 104ok() 105{ 106 : 107} 108 109# A part of a test fails 110notok() 111{ 112 OK=0 113} 114 115# Verify that the exit code passed is for unsuccessful termination 116ckfail() 117{ 118 if [ $1 -gt 0 ] 119 then 120 ok 121 else 122 notok 123 fi 124} 125 126# Verify that the exit code passed is for successful termination 127ckok() 128{ 129 if [ $1 -eq 0 ] 130 then 131 ok 132 else 133 notok 134 fi 135} 136 137# Run all tests locally and across devices 138echo 1..32 139for FS in '' $TMPDIR/testdir/ 140do 141 begin 'Rename file' 142 mkf fa 143 mv fa ${FS}fb 144 ckok $? 145 ckf fa ${FS}fb 146 cknt fa 147 end 148 149 begin 'Move files into directory' 150 mkf fa 151 mkf fb 152 mkdir -p ${FS}1/2/3 153 mv fa fb ${FS}1/2/3 154 ckok $? 155 ckf fa ${FS}1/2/3/fa 156 ckf fb ${FS}1/2/3/fb 157 cknt fa 158 cknt fb 159 end 160 161 begin 'Move file from directory to file' 162 mkdir -p 1/2/3 163 mkf 1/2/3/fa 164 mv 1/2/3/fa ${FS}fb 165 ckok $? 166 ckf fa ${FS}fb 167 cknt 1/2/3/fa 168 end 169 170 begin 'Move file from directory to existing file' 171 mkdir -p 1/2/3 172 mkf 1/2/3/fa 173 :> ${FS}fb 174 mv 1/2/3/fa ${FS}fb 175 ckok $? 176 ckf fa ${FS}fb 177 cknt 1/2/3/fa 178 end 179 180 begin 'Move file from directory to existing directory' 181 mkdir -p 1/2/3 182 mkf 1/2/3/fa 183 mkdir -p ${FS}db/fa 184 # Should fail per POSIX step 3a: 185 # Destination path is a file of type directory and 186 # source_file is not a file of type directory 187 mv 1/2/3/fa ${FS}db 2>/dev/null 188 ckfail $? 189 ckf fa 1/2/3/fa 190 end 191 192 begin 'Move file from directory to directory' 193 mkdir -p da1/da2/da3 194 mkdir -p ${FS}db1/db2/db3 195 mkf da1/da2/da3/fa 196 mv da1/da2/da3/fa ${FS}db1/db2/db3/fb 197 ckok $? 198 ckf fa ${FS}db1/db2/db3/fb 199 cknt da1/da2/da3/fa 200 end 201 202 begin 'Rename directory' 203 mkd da 204 mv da ${FS}db 205 ckok $? 206 ckd da ${FS}db 207 cknt da 208 end 209 210 begin 'Move directory to directory name' 211 mkd da1/da2/da3/da 212 mkdir -p ${FS}db1/db2/db3 213 mv da1/da2/da3/da ${FS}db1/db2/db3/db 214 ckok $? 215 ckd da ${FS}db1/db2/db3/db 216 cknt da1/da2/da3/da 217 end 218 219 begin 'Move directory to directory' 220 mkd da1/da2/da3/da 221 mkdir -p ${FS}db1/db2/db3 222 mv da1/da2/da3/da ${FS}db1/db2/db3 223 ckok $? 224 ckd da ${FS}db1/db2/db3/da 225 cknt da1/da2/da3/da 226 end 227 228 begin 'Move directory to existing empty directory' 229 mkd da1/da2/da3/da 230 mkdir -p ${FS}db1/db2/db3/da 231 mv da1/da2/da3/da ${FS}db1/db2/db3 232 ckok $? 233 ckd da ${FS}db1/db2/db3/da 234 cknt da1/da2/da3/da 235 end 236 237 begin 'Move directory to existing non-empty directory' 238 mkd da1/da2/da3/da 239 mkdir -p ${FS}db1/db2/db3/da/full 240 # Should fail (per the semantics of rename(2)) 241 mv da1/da2/da3/da ${FS}db1/db2/db3 2>/dev/null 242 ckfail $? 243 ckd da da1/da2/da3/da 244 end 245 246 begin 'Move directory to existing file' 247 mkd da1/da2/da3/da 248 mkdir -p ${FS}db1/db2/db3 249 :> ${FS}db1/db2/db3/da 250 # Should fail per POSIX step 3b: 251 # Destination path is a file not of type directory 252 # and source_file is a file of type directory 253 mv da1/da2/da3/da ${FS}db1/db2/db3/da 2>/dev/null 254 ckfail $? 255 ckd da da1/da2/da3/da 256 end 257 258 begin 'Rename fifo' 259 mkp fa 260 mv fa ${FS}fb 261 ckok $? 262 ckp fa ${FS}fb 263 cknt fa 264 end 265 266 begin 'Move fifos into directory' 267 mkp fa 268 mkp fb 269 mkdir -p ${FS}1/2/3 270 mv fa fb ${FS}1/2/3 271 ckok $? 272 ckp fa ${FS}1/2/3/fa 273 ckp fb ${FS}1/2/3/fb 274 cknt fa 275 cknt fb 276 end 277 278 begin 'Move fifo from directory to fifo' 279 mkdir -p 1/2/3 280 mkp 1/2/3/fa 281 mv 1/2/3/fa ${FS}fb 282 ckok $? 283 ckp fa ${FS}fb 284 cknt 1/2/3/fa 285 end 286 287 begin 'Move fifo from directory to directory' 288 mkdir -p da1/da2/da3 289 mkdir -p ${FS}db1/db2/db3 290 mkp da1/da2/da3/fa 291 mv da1/da2/da3/fa ${FS}db1/db2/db3/fb 292 ckok $? 293 ckp fa ${FS}db1/db2/db3/fb 294 cknt da1/da2/da3/fa 295 end 296done 297