4 # Random file copier to produce chains of identical files so the head
5 # and the tail can be diff'd at the end of each iteration.
7 # Exercises creat, write and unlink for a variety of directory sizes, and
8 # checks for data corruption.
12 # config has one line per file with filename and byte size, else use
13 # the default one below.
15 #-----------------------------------------------------------------------
16 # Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
17 #-----------------------------------------------------------------------
23 echo "QA output created by $seq"
25 # get standard environment, filters and checks
33 trap "_cleanup; rm -f $tmp.*; exit \$status" 0 1 2 3 15
35 # real QA test starts here
36 _supported_fs xfs udf nfs
37 _supported_os IRIX Linux
40 verify=$here/verify_fill
44 # use the default config
46 cat <<End-of-File >$tmp.config
47 # pathname size in bytes
95 echo "Error: cannot open config \"$1\""
99 echo "Usage: run [config]"
103 ncopy=200 # number of file copies in the chain step
104 udf_fsize=20240 # number of sectors for UDF
108 if mkdir -p $testdir/$$
112 echo "Error: cannot mkdir \"$testdir/$$\""
117 $verbose && echo -n "setup "
118 sed -e '/^#/d' $tmp.config \
119 | while read file nbytes
131 echo "Error: cannot mkdir \"$dir\""
137 if $here/src/fill $file $file $nbytes
142 echo "Error: cannot create \"$file\""
145 $verbose && echo -n "."
152 $verbose && echo -n "mark_iteration "
153 sed -e '/^#/d' $tmp.config \
154 | while read file nbytes
159 echo "Error: $file vanished!"
163 sed -e "s/ [0-9][0-9]* / $1 /" <$file >$file.tmp
165 $verbose && echo -n "."
170 # for each file, make a number of copies forming a chain like foo.0,
171 # foo.1, foo.2, ... foo.N
173 # files are chosen at random, so the lengths of the chains are different
175 # then rename foo.N to foo.last and remove all of the other files in
180 $AWK_PROG -v full_file=$here/$seq.full -v verify=$verify <$tmp.config '
190 for (i=0; i < '$ncopy'; i++) {
191 # choose a file at random, and add one copy to that chain
193 while (j < 0 || j >= nfile)
194 j = int(rand() * nfile)
196 # previous should already exist and next one should not exist
197 printf "if [ ! -f %s ]; then echo \"%s missing!\"; exit; fi\n",file[j],file[j]
198 printf "if [ -f %s.0 ]; then echo \"%s.0 already present!\"; exit; fi\n",file[j],file[j]
199 printf "cp %s %s.0 || exit 1\n",file[j],file[j]
200 printf "ls -i %s.0\n", file[j] >full_file;
201 total_size += size[j]
202 printf "# total size = %d\n", total_size
205 # previous should already exist and next one should not exist
206 printf "if [ ! -f %s.%d ]; then echo \"%s.%d missing!\"; exit; fi\n",file[j],link[j]-1,file[j],link[j]-1
207 printf "if [ -f %s.%d ]; then echo \"%s.%d already present!\"; exit; fi\n",file[j],link[j],file[j],link[j]
208 printf "cp %s.%d %s.%d || exit 1\n",file[j],link[j]-1,file[j],link[j]
209 printf "ls -i %s.%d\n", file[j], link[j] >full_file;
210 total_size += size[j]
211 printf "# total size = %d\n", total_size
215 # close all the chains,
216 # if have at least one copy then move the last copy to "file[j].last"
217 # and remove all of the other files except the head of the chain
218 for (j=0; j<nfile; j++) {
220 printf "mv %s.%d %s.last\n",file[j],link[j]-1,file[j]
221 printf "ls -i %s.last\n", file[j] >full_file;
223 for (i=0; i<link[j]-1; i++) {
224 printf "rm -f %s.%d\n",file[j],i
228 | tee -a $here/$seq.full | sh
234 $verbose && echo -n "check "
235 sed -e '/^#/d' $tmp.config \
236 | while read file nbytes
238 # the file is never removed so it should exist
242 echo "Error: $file vanished!"
246 # checks that the file and its last copy are the same
249 if cmp $file $file.last >/dev/null 2>&1
251 $verbose && echo -n "."
254 echo "Error: corruption for $file ..."
255 diff -c $file $file.last
259 $verbose && echo -n "."
272 elif [ $status -eq 0 ]
274 $verbose && echo "cleanup"
282 rm -f $here/$seq.full
293 for iter in 1 2 3 4 5
295 echo -n "iter $iter chain ... "
296 echo "iter $iter" >> $here/$seq.full
301 echo "Fatal error: test abandoned without changes"