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 _begin_fstest rw dir udf auto quick
21 # Import common functions.
26 _register_cleanup "_cleanup; rm -f $tmp.*"
28 # real QA test starts here
33 verify=$here/verify_fill
37 # use the default config
39 cat <<End-of-File >$tmp.config
40 # pathname size in bytes
88 echo "Error: cannot open config \"$1\""
92 echo "Usage: run [config]"
96 ncopy=200 # number of file copies in the chain step
97 udf_fsize=20240 # number of sectors for UDF
101 if mkdir -p $TEST_DIR/$$
105 echo "Error: cannot mkdir \"$TEST_DIR/$$\""
110 $verbose && echo -n "setup "
111 sed -e '/^#/d' $tmp.config \
112 | while read file nbytes
124 echo "Error: cannot mkdir \"$dir\""
130 if $here/src/fill $file $file $nbytes
135 echo "Error: cannot create \"$file\""
138 $verbose && echo -n "."
145 $verbose && echo -n "mark_iteration "
146 sed -e '/^#/d' $tmp.config \
147 | while read file nbytes
152 echo "Error: $file vanished!"
156 sed -e "s/ [0-9][0-9]* / $1 /" <$file >$file.tmp
158 $verbose && echo -n "."
163 # for each file, make a number of copies forming a chain like foo.0,
164 # foo.1, foo.2, ... foo.N
166 # files are chosen at random, so the lengths of the chains are different
168 # then rename foo.N to foo.last and remove all of the other files in
173 $AWK_PROG -v full_file=$seqres.full -v verify=$verify <$tmp.config '
183 for (i=0; i < '$ncopy'; i++) {
184 # choose a file at random, and add one copy to that chain
186 while (j < 0 || j >= nfile)
187 j = int(rand() * nfile)
189 # previous should already exist and next one should not exist
190 printf "if [ ! -f %s ]; then echo \"%s missing!\"; exit; fi\n",file[j],file[j]
191 printf "if [ -f %s.0 ]; then echo \"%s.0 already present!\"; exit; fi\n",file[j],file[j]
192 printf "cp %s %s.0 || exit 1\n",file[j],file[j]
193 printf "ls -i %s.0\n", file[j] >full_file;
194 total_size += size[j]
195 printf "# total size = %d\n", total_size
198 # previous should already exist and next one should not exist
199 printf "if [ ! -f %s.%d ]; then echo \"%s.%d missing!\"; exit; fi\n",file[j],link[j]-1,file[j],link[j]-1
200 printf "if [ -f %s.%d ]; then echo \"%s.%d already present!\"; exit; fi\n",file[j],link[j],file[j],link[j]
201 printf "cp %s.%d %s.%d || exit 1\n",file[j],link[j]-1,file[j],link[j]
202 printf "ls -i %s.%d\n", file[j], link[j] >full_file;
203 total_size += size[j]
204 printf "# total size = %d\n", total_size
208 # close all the chains,
209 # if have at least one copy then move the last copy to "file[j].last"
210 # and remove all of the other files except the head of the chain
211 for (j=0; j<nfile; j++) {
213 printf "mv %s.%d %s.last\n",file[j],link[j]-1,file[j]
214 printf "ls -i %s.last\n", file[j] >full_file;
216 for (i=0; i<link[j]-1; i++) {
217 printf "rm -f %s.%d\n",file[j],i
221 | tee -a $seqres.full | sh
227 $verbose && echo -n "check "
228 sed -e '/^#/d' $tmp.config \
229 | while read file nbytes
231 # the file is never removed so it should exist
235 echo "Error: $file vanished!"
239 # checks that the file and its last copy are the same
242 if cmp $file $file.last >/dev/null 2>&1
244 $verbose && echo -n "."
247 echo "Error: corruption for $file ..."
248 diff -c $file $file.last
252 $verbose && echo -n "."
258 # Override the default cleanup function.
266 elif [ $status -eq 0 ]
268 $verbose && echo "cleanup"
284 for iter in 1 2 3 4 5
286 echo -n "iter $iter chain ... "
287 echo "iter $iter" >> $seqres.full
292 echo "Fatal error: test abandoned without changes"