common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / dmapi / src / suite2 / bindir / test_allocinfo_2
1 #!/bin/ksh
2 #
3 # Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 #       Dump the same holey file a random number of times, each time
6 #       using one less extent structure than the previous time.  
7 #       The grep and diff code checks to make sure that you get the
8 #       same answer each time, no matter how many extents you use.
9
10 typeset -i offset
11 typeset -i length
12 typeset -i max
13
14 # Verify correct usage
15 if [[ $# != 2 ]] 
16 then print "usage:  ${0##*/} bindir testdir"
17      exit 1
18 fi
19
20 # Check bindir for needed programs.
21 if [[ ! ( -r "$1/wf" ) ]]
22 then print "Aborting: necessary program wf is not in $1/."
23      if [[ ! ( -r "$1/dump_allocinfo" ) ]]
24      then print "          necessary program dump_allocinfo is also missing."
25      fi
26      exit 1
27 fi
28 if [[ ! ( -r "$1/dump_allocinfo" ) ]]
29 then print "Aborting: necessary program dump_allocinfo is not in $1/."
30      exit 1
31 fi
32
33 print "Multiple-buffer-sizes test of get_allocinfo beginning..."
34
35 RANDOM=$SECONDS
36 offset=0
37 length=$RANDOM
38 filename=DMAPI_alloc_test_2
39 ((max = $RANDOM/256))
40 count=$max
41
42 # Holey file creation: put about $max holes into the file.
43 while (( count > 0 ))
44 do 
45         $1/wf -l $length -L $offset -b 512 $2/$filename > /dev/null
46         (( offset = RANDOM * 512 + offset + length )) 
47         (( length = RANDOM ))
48         (( count = count - 1 ))
49 done
50 count=$max
51
52 # Now count down from $max to 1 and try dump_allocinfo with a buffer that
53 # can hold that many dm_extent_t structures.
54 while [[ $count > 0 ]]
55 do
56         $1/dump_allocinfo -n $count $2/$filename | grep '\[' > $2/x.$count
57         if (( count < max ))
58         then diff $2/x.$count $2/x.$max > /dev/null
59              if [[ $? != 0 ]]
60              then print "ERROR in trial #$count:"
61                   diff $2/x.$count $2/x.$max
62              fi
63              rm $2/x.$count
64         fi
65         (( count = count - 1 ))
66 done
67
68 rm $2/x.$max
69 rm $2/$filename
70
71 print "Test complete."