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
38 verify=$here/verify_fill
42 # use the default config
44 cat <<End-of-File >$tmp.config
45 # pathname size in bytes
93 echo "Error: cannot open config \"$1\""
97 echo "Usage: run [config]"
101 ncopy=200 # number of file copies in the chain step
102 udf_fsize=20240 # number of sectors for UDF
106 if mkdir -p $TEST_DIR/$$
110 echo "Error: cannot mkdir \"$TEST_DIR/$$\""
115 $verbose && echo -n "setup "
116 sed -e '/^#/d' $tmp.config \
117 | while read file nbytes
129 echo "Error: cannot mkdir \"$dir\""
135 if $here/src/fill $file $file $nbytes
140 echo "Error: cannot create \"$file\""
143 $verbose && echo -n "."
150 $verbose && echo -n "mark_iteration "
151 sed -e '/^#/d' $tmp.config \
152 | while read file nbytes
157 echo "Error: $file vanished!"
161 sed -e "s/ [0-9][0-9]* / $1 /" <$file >$file.tmp
163 $verbose && echo -n "."
168 # for each file, make a number of copies forming a chain like foo.0,
169 # foo.1, foo.2, ... foo.N
171 # files are chosen at random, so the lengths of the chains are different
173 # then rename foo.N to foo.last and remove all of the other files in
178 $AWK_PROG -v full_file=$seqres.full -v verify=$verify <$tmp.config '
188 for (i=0; i < '$ncopy'; i++) {
189 # choose a file at random, and add one copy to that chain
191 while (j < 0 || j >= nfile)
192 j = int(rand() * nfile)
194 # previous should already exist and next one should not exist
195 printf "if [ ! -f %s ]; then echo \"%s missing!\"; exit; fi\n",file[j],file[j]
196 printf "if [ -f %s.0 ]; then echo \"%s.0 already present!\"; exit; fi\n",file[j],file[j]
197 printf "cp %s %s.0 || exit 1\n",file[j],file[j]
198 printf "ls -i %s.0\n", file[j] >full_file;
199 total_size += size[j]
200 printf "# total size = %d\n", total_size
203 # previous should already exist and next one should not exist
204 printf "if [ ! -f %s.%d ]; then echo \"%s.%d missing!\"; exit; fi\n",file[j],link[j]-1,file[j],link[j]-1
205 printf "if [ -f %s.%d ]; then echo \"%s.%d already present!\"; exit; fi\n",file[j],link[j],file[j],link[j]
206 printf "cp %s.%d %s.%d || exit 1\n",file[j],link[j]-1,file[j],link[j]
207 printf "ls -i %s.%d\n", file[j], link[j] >full_file;
208 total_size += size[j]
209 printf "# total size = %d\n", total_size
213 # close all the chains,
214 # if have at least one copy then move the last copy to "file[j].last"
215 # and remove all of the other files except the head of the chain
216 for (j=0; j<nfile; j++) {
218 printf "mv %s.%d %s.last\n",file[j],link[j]-1,file[j]
219 printf "ls -i %s.last\n", file[j] >full_file;
221 for (i=0; i<link[j]-1; i++) {
222 printf "rm -f %s.%d\n",file[j],i
226 | tee -a $seqres.full | sh
232 $verbose && echo -n "check "
233 sed -e '/^#/d' $tmp.config \
234 | while read file nbytes
236 # the file is never removed so it should exist
240 echo "Error: $file vanished!"
244 # checks that the file and its last copy are the same
247 if cmp $file $file.last >/dev/null 2>&1
249 $verbose && echo -n "."
252 echo "Error: corruption for $file ..."
253 diff -c $file $file.last
257 $verbose && echo -n "."
270 elif [ $status -eq 0 ]
272 $verbose && echo "cleanup"
289 for iter in 1 2 3 4 5
291 echo -n "iter $iter chain ... "
292 echo "iter $iter" >> $seqres.full
297 echo "Fatal error: test abandoned without changes"