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
53 verify=$here/verify_fill
57 # use the default config
59 cat <<End-of-File >$tmp.config
60 # pathname size in bytes
108 echo "Error: cannot open config \"$1\""
112 echo "Usage: run [config]"
116 ncopy=200 # number of file copies in the chain step
117 udf_fsize=20240 # number of sectors for UDF
121 if mkdir -p $testdir/$$
125 echo "Error: cannot mkdir \"$testdir/$$\""
130 $verbose && echo -n "setup "
131 sed -e '/^#/d' $tmp.config \
132 | while read file nbytes
144 echo "Error: cannot mkdir \"$dir\""
150 if $here/src/fill $file $file $nbytes
155 echo "Error: cannot create \"$file\""
158 $verbose && echo -n "."
165 $verbose && echo -n "mark_iteration "
166 sed -e '/^#/d' $tmp.config \
167 | while read file nbytes
172 echo "Error: $file vanished!"
176 sed -e "s/ [0-9][0-9]* / $1 /" <$file >$file.tmp
178 $verbose && echo -n "."
183 # for each file, make a number of copies forming a chain like foo.0,
184 # foo.1, foo.2, ... foo.N
186 # files are chosen at random, so the lengths of the chains are different
188 # then rename foo.N to foo.last and remove all of the other files in
193 $AWK_PROG -v full_file=$seqres.full -v verify=$verify <$tmp.config '
203 for (i=0; i < '$ncopy'; i++) {
204 # choose a file at random, and add one copy to that chain
206 while (j < 0 || j >= nfile)
207 j = int(rand() * nfile)
209 # previous should already exist and next one should not exist
210 printf "if [ ! -f %s ]; then echo \"%s missing!\"; exit; fi\n",file[j],file[j]
211 printf "if [ -f %s.0 ]; then echo \"%s.0 already present!\"; exit; fi\n",file[j],file[j]
212 printf "cp %s %s.0 || exit 1\n",file[j],file[j]
213 printf "ls -i %s.0\n", file[j] >full_file;
214 total_size += size[j]
215 printf "# total size = %d\n", total_size
218 # previous should already exist and next one should not exist
219 printf "if [ ! -f %s.%d ]; then echo \"%s.%d missing!\"; exit; fi\n",file[j],link[j]-1,file[j],link[j]-1
220 printf "if [ -f %s.%d ]; then echo \"%s.%d already present!\"; exit; fi\n",file[j],link[j],file[j],link[j]
221 printf "cp %s.%d %s.%d || exit 1\n",file[j],link[j]-1,file[j],link[j]
222 printf "ls -i %s.%d\n", file[j], link[j] >full_file;
223 total_size += size[j]
224 printf "# total size = %d\n", total_size
228 # close all the chains,
229 # if have at least one copy then move the last copy to "file[j].last"
230 # and remove all of the other files except the head of the chain
231 for (j=0; j<nfile; j++) {
233 printf "mv %s.%d %s.last\n",file[j],link[j]-1,file[j]
234 printf "ls -i %s.last\n", file[j] >full_file;
236 for (i=0; i<link[j]-1; i++) {
237 printf "rm -f %s.%d\n",file[j],i
241 | tee -a $seqres.full | sh
247 $verbose && echo -n "check "
248 sed -e '/^#/d' $tmp.config \
249 | while read file nbytes
251 # the file is never removed so it should exist
255 echo "Error: $file vanished!"
259 # checks that the file and its last copy are the same
262 if cmp $file $file.last >/dev/null 2>&1
264 $verbose && echo -n "."
267 echo "Error: corruption for $file ..."
268 diff -c $file $file.last
272 $verbose && echo -n "."
285 elif [ $status -eq 0 ]
287 $verbose && echo "cleanup"
306 for iter in 1 2 3 4 5
308 echo -n "iter $iter chain ... "
309 echo "iter $iter" >> $seqres.full
314 echo "Fatal error: test abandoned without changes"