2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
7 # Random file copier to produce chains of identical files so the head
8 # and the tail can be diff'd at the end of each iteration.
10 # Exercises creat, write and unlink for a variety of directory sizes, and
11 # checks for data corruption.
15 # config has one line per file with filename and byte size, else use
16 # the default one below.
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
22 # get standard environment, filters and checks
30 trap "_cleanup; rm -f $tmp.*; exit \$status" 0 1 2 3 15
32 # real QA test starts here
37 verify=$here/verify_fill
41 # use the default config
43 cat <<End-of-File >$tmp.config
44 # pathname size in bytes
92 echo "Error: cannot open config \"$1\""
96 echo "Usage: run [config]"
100 ncopy=200 # number of file copies in the chain step
101 udf_fsize=20240 # number of sectors for UDF
105 if mkdir -p $TEST_DIR/$$
109 echo "Error: cannot mkdir \"$TEST_DIR/$$\""
114 $verbose && echo -n "setup "
115 sed -e '/^#/d' $tmp.config \
116 | while read file nbytes
128 echo "Error: cannot mkdir \"$dir\""
134 if $here/src/fill $file $file $nbytes
139 echo "Error: cannot create \"$file\""
142 $verbose && echo -n "."
149 $verbose && echo -n "mark_iteration "
150 sed -e '/^#/d' $tmp.config \
151 | while read file nbytes
156 echo "Error: $file vanished!"
160 sed -e "s/ [0-9][0-9]* / $1 /" <$file >$file.tmp
162 $verbose && echo -n "."
167 # for each file, make a number of copies forming a chain like foo.0,
168 # foo.1, foo.2, ... foo.N
170 # files are chosen at random, so the lengths of the chains are different
172 # then rename foo.N to foo.last and remove all of the other files in
177 $AWK_PROG -v full_file=$seqres.full -v verify=$verify <$tmp.config '
187 for (i=0; i < '$ncopy'; i++) {
188 # choose a file at random, and add one copy to that chain
190 while (j < 0 || j >= nfile)
191 j = int(rand() * nfile)
193 # previous should already exist and next one should not exist
194 printf "if [ ! -f %s ]; then echo \"%s missing!\"; exit; fi\n",file[j],file[j]
195 printf "if [ -f %s.0 ]; then echo \"%s.0 already present!\"; exit; fi\n",file[j],file[j]
196 printf "cp %s %s.0 || exit 1\n",file[j],file[j]
197 printf "ls -i %s.0\n", file[j] >full_file;
198 total_size += size[j]
199 printf "# total size = %d\n", total_size
202 # previous should already exist and next one should not exist
203 printf "if [ ! -f %s.%d ]; then echo \"%s.%d missing!\"; exit; fi\n",file[j],link[j]-1,file[j],link[j]-1
204 printf "if [ -f %s.%d ]; then echo \"%s.%d already present!\"; exit; fi\n",file[j],link[j],file[j],link[j]
205 printf "cp %s.%d %s.%d || exit 1\n",file[j],link[j]-1,file[j],link[j]
206 printf "ls -i %s.%d\n", file[j], link[j] >full_file;
207 total_size += size[j]
208 printf "# total size = %d\n", total_size
212 # close all the chains,
213 # if have at least one copy then move the last copy to "file[j].last"
214 # and remove all of the other files except the head of the chain
215 for (j=0; j<nfile; j++) {
217 printf "mv %s.%d %s.last\n",file[j],link[j]-1,file[j]
218 printf "ls -i %s.last\n", file[j] >full_file;
220 for (i=0; i<link[j]-1; i++) {
221 printf "rm -f %s.%d\n",file[j],i
225 | tee -a $seqres.full | sh
231 $verbose && echo -n "check "
232 sed -e '/^#/d' $tmp.config \
233 | while read file nbytes
235 # the file is never removed so it should exist
239 echo "Error: $file vanished!"
243 # checks that the file and its last copy are the same
246 if cmp $file $file.last >/dev/null 2>&1
248 $verbose && echo -n "."
251 echo "Error: corruption for $file ..."
252 diff -c $file $file.last
256 $verbose && echo -n "."
269 elif [ $status -eq 0 ]
271 $verbose && echo "cleanup"
288 for iter in 1 2 3 4 5
290 echo -n "iter $iter chain ... "
291 echo "iter $iter" >> $seqres.full
296 echo "Fatal error: test abandoned without changes"