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.
18 # This program is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU General Public License as
20 # published by the Free Software Foundation.
22 # This program is distributed in the hope that it would be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write the Free Software Foundation,
29 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #-----------------------------------------------------------------------
35 seqres=$RESULT_DIR/$seq
36 echo "QA output created by $seq"
38 # get standard environment, filters and checks
46 trap "_cleanup; rm -f $tmp.*; exit \$status" 0 1 2 3 15
48 # real QA test starts here
50 _supported_os IRIX Linux
54 verify=$here/verify_fill
58 # use the default config
60 cat <<End-of-File >$tmp.config
61 # pathname size in bytes
109 echo "Error: cannot open config \"$1\""
113 echo "Usage: run [config]"
117 ncopy=200 # number of file copies in the chain step
118 udf_fsize=20240 # number of sectors for UDF
122 if mkdir -p $TEST_DIR/$$
126 echo "Error: cannot mkdir \"$TEST_DIR/$$\""
131 $verbose && echo -n "setup "
132 sed -e '/^#/d' $tmp.config \
133 | while read file nbytes
145 echo "Error: cannot mkdir \"$dir\""
151 if $here/src/fill $file $file $nbytes
156 echo "Error: cannot create \"$file\""
159 $verbose && echo -n "."
166 $verbose && echo -n "mark_iteration "
167 sed -e '/^#/d' $tmp.config \
168 | while read file nbytes
173 echo "Error: $file vanished!"
177 sed -e "s/ [0-9][0-9]* / $1 /" <$file >$file.tmp
179 $verbose && echo -n "."
184 # for each file, make a number of copies forming a chain like foo.0,
185 # foo.1, foo.2, ... foo.N
187 # files are chosen at random, so the lengths of the chains are different
189 # then rename foo.N to foo.last and remove all of the other files in
194 $AWK_PROG -v full_file=$seqres.full -v verify=$verify <$tmp.config '
204 for (i=0; i < '$ncopy'; i++) {
205 # choose a file at random, and add one copy to that chain
207 while (j < 0 || j >= nfile)
208 j = int(rand() * nfile)
210 # previous should already exist and next one should not exist
211 printf "if [ ! -f %s ]; then echo \"%s missing!\"; exit; fi\n",file[j],file[j]
212 printf "if [ -f %s.0 ]; then echo \"%s.0 already present!\"; exit; fi\n",file[j],file[j]
213 printf "cp %s %s.0 || exit 1\n",file[j],file[j]
214 printf "ls -i %s.0\n", file[j] >full_file;
215 total_size += size[j]
216 printf "# total size = %d\n", total_size
219 # previous should already exist and next one should not exist
220 printf "if [ ! -f %s.%d ]; then echo \"%s.%d missing!\"; exit; fi\n",file[j],link[j]-1,file[j],link[j]-1
221 printf "if [ -f %s.%d ]; then echo \"%s.%d already present!\"; exit; fi\n",file[j],link[j],file[j],link[j]
222 printf "cp %s.%d %s.%d || exit 1\n",file[j],link[j]-1,file[j],link[j]
223 printf "ls -i %s.%d\n", file[j], link[j] >full_file;
224 total_size += size[j]
225 printf "# total size = %d\n", total_size
229 # close all the chains,
230 # if have at least one copy then move the last copy to "file[j].last"
231 # and remove all of the other files except 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 printf "ls -i %s.last\n", file[j] >full_file;
237 for (i=0; i<link[j]-1; i++) {
238 printf "rm -f %s.%d\n",file[j],i
242 | tee -a $seqres.full | sh
248 $verbose && echo -n "check "
249 sed -e '/^#/d' $tmp.config \
250 | while read file nbytes
252 # the file is never removed so it should exist
256 echo "Error: $file vanished!"
260 # checks that the file and its last copy are the same
263 if cmp $file $file.last >/dev/null 2>&1
265 $verbose && echo -n "."
268 echo "Error: corruption for $file ..."
269 diff -c $file $file.last
273 $verbose && echo -n "."
286 elif [ $status -eq 0 ]
288 $verbose && echo "cleanup"
305 for iter in 1 2 3 4 5
307 echo -n "iter $iter chain ... "
308 echo "iter $iter" >> $seqres.full
313 echo "Fatal error: test abandoned without changes"