5 # Random file copier to produce chains of identical files so the head
6 # and the tail cna be diff'd at then end of each iteration.
8 # Exercises creat, write and unlink for a variety of directory sizes, and
9 # checks for data corruption.
13 # config has one line per file with filename and byte size, else use
14 # the default one below.
16 #-----------------------------------------------------------------------
17 # Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
19 # This program is free software; you can redistribute it and/or modify it
20 # under the terms of version 2 of the GNU General Public License as
21 # published by the Free Software Foundation.
23 # This program is distributed in the hope that it would be useful, but
24 # WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 # Further, this software is distributed without any warranty that it is
28 # free of the rightful claim of any third person regarding infringement
29 # or the like. Any license provided herein, whether implied or
30 # otherwise, applies only to this software file. Patent licenses, if
31 # any, provided herein do not apply to combinations of this program with
32 # other software, or any other product whatsoever.
34 # You should have received a copy of the GNU General Public License along
35 # with this program; if not, write the Free Software Foundation, Inc., 59
36 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
38 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
39 # Mountain View, CA 94043, or:
43 # For further information regarding this notice, see:
45 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
46 #-----------------------------------------------------------------------
52 echo "QA output created by $seq"
54 # get standard environment, filters and checks
62 trap "_cleanup; rm -f $tmp.*; exit \$status" 0 1 2 3 15
64 # real QA test starts here
70 # use the default config
72 cat <<End-of-File >$tmp.config
73 # pathname size in bytes
121 echo "Error: cannot open config \"$1\""
125 echo "Usage: run [config]"
129 ncopy=200 # number of file copies in the chain step
133 if mkdir -p $TEST_DIR/$$
137 echo "Error: cannot mkdir \"$TEST_DIR/$$\""
142 $verbose && echo -n "setup "
143 sed -e '/^#/d' $tmp.config \
144 | while read file nbytes
156 echo "Error: cannot mkdir \"$dir\""
162 if $here/src/fill $file $file $nbytes
167 echo "Error: cannot create \"$file\""
170 $verbose && echo -n "."
177 $verbose && echo -n "mark_iteration "
178 sed -e '/^#/d' $tmp.config \
179 | while read file nbytes
184 echo "Error: $file vanished!"
188 sed -e "s/ [0-9][0-9]* / $1 /" <$file >$file.tmp
190 $verbose && echo -n "."
195 # for each file, make a number of copies forming a chain like foo.0,
196 # foo.1, foo.2, ... foo.N
198 # files are chosen at random, so the lengths of the chains are different
200 # then rename foo.N to foo.last and remove all of the other files in
205 $AWK_PROG <$tmp.config '
213 for (i=0; i < '$ncopy'; i++) {
214 # choose a file at random, and add one copy to that chain
216 while (j < 0 || j >= nfile)
217 j = int(rand() * nfile)
219 printf "if [ ! -f %s ]; then echo \"%s missing!\"; exit; fi\n",file[j],file[j]
220 printf "if [ -f %s.0 ]; then echo \"%s.0 already present!\"; exit; fi\n",file[j],file[j]
221 printf "cp %s %s.0\n",file[j],file[j]
224 printf "if [ ! -f %s.%d ]; then echo \"%s.%d missing!\"; exit; fi\n",file[j],link[j]-1,file[j],link[j]-1
225 printf "if [ -f %s.%d ]; then echo \"%s.%d already present!\"; exit; fi\n",file[j],link[j],file[j],link[j]
226 printf "cp %s.%d %s.%d\n",file[j],link[j]-1,file[j],link[j]
230 # close all the chains, and remove all of the files except
231 # the head of the chain
232 for (j=0; j<nfile; j++) {
234 printf "mv %s.%d %s.last\n",file[j],link[j]-1,file[j]
235 for (i=0; i<link[j]-1; i++) {
236 printf "rm -f %s.%d\n",file[j],i
246 $verbose && echo -n "check "
247 sed -e '/^#/d' $tmp.config \
248 | while read file nbytes
253 echo "Error: $file vanished!"
259 if cmp $file $file.last >/dev/null 2>&1
261 $verbose && echo -n "."
264 echo "Error: corruption for $file ..."
265 diff -c $file $file.last
269 $verbose && echo -n "."
282 elif [ $status -eq 0 ]
284 $verbose && echo "cleanup"
300 for iter in 1 2 3 4 5
302 echo -n "iter $iter chain ... "
307 echo "Fatal error: test abandoned without changes"