_scratch_mkfs_geom(): Filter out 'k' suffix from fs block size
[xfstests-dev.git] / dmapi / src / suite2 / bindir / test_allocinfo_1
1 #!/bin/ksh
2 #
3 # Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 #       Dump the same holey file using both xfs_bmap and 
6 #       dump_allocinfo (a C wrapper for get_allocinfo).
7 #       Run awk on the xfs_bmap output, since xfs_bmap
8 #       gives specific block allocation info that get_allocinfo
9 #       does not.  Then diff the two outputs.
10
11 if [[ $# != 2 ]]
12 then    print "USAGE:  ${0##*/} bindir testdir"
13         exit 1
14 fi
15
16 # Check bindir for needed programs.
17 if [[ ! ( -r "$1/wf" ) ]]
18 then print "Aborting: necessary program wf is not in $1/."
19      if [[ ! ( -r "$1/dump_allocinfo" ) ]]
20      then print "          necessary program dump_allocinfo is also missing."
21      fi
22      exit 1
23 fi
24 if [[ ! ( -r "$1/dump_allocinfo" ) ]]
25 then print "Aborting: necessary program dump_allocinfo is not in $1/."
26      exit 1
27 fi
28
29 print "Comparison test (get_allocinfo vs. xfs_bmap) beginning..."
30
31 typeset -i offset
32 typeset -i length
33 typeset -i count
34
35 RANDOM=$SECONDS
36 offset=0
37 length=$RANDOM
38 count=100
39 filename=DMAPI_test_allocinfo
40
41 # Create a random holey file
42 while (( count > 0 ))
43 do 
44         $1/wf -l $length -L $offset -b 512 $2/$filename > /dev/null
45         (( offset = RANDOM * 512 + offset + length )) 
46         (( length = RANDOM ))
47         (( count = count - 1 ))
48 done
49
50 # Get output from xfs_bmap
51 xfs_bmap $2/DMAPI_test_allocinfo > $2/$filename.xfs
52
53 # Get output from dump_allocinfo (DMAPI)
54 $1/dump_allocinfo $2/DMAPI_test_allocinfo > $2/$filename.da
55         
56 # Alter xfs_bmap ouput to match get_allocinfo
57 awk '{ if (NR > 1)
58         if ($3 == "hole") 
59                 print $1, $2, $3
60         else
61                 print $1, $2, "resv"
62 }' $2/DMAPI_test_allocinfo.xfs > $2/$filename.ok
63
64 # Compare the ouput
65 diff -w $2/$filename.ok $2/$filename.da
66
67 # Remove the test file
68 rm $2/$filename*
69
70 print "Test complete."