Update xfstests control scripts to allow multiple kernel versions and multiple archit...
[xfstests-dev.git] / 031
1 #! /bin/sh
2 # XFS QA Test No. 031
3 #
4 # exercise xfs_repair - ensure repeated use doesn't corrupt
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
8
9 # This program is free software; you can redistribute it and/or modify it
10 # under the terms of version 2 of the GNU General Public License as
11 # published by the Free Software Foundation.
12
13 # This program is distributed in the hope that it would be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17 # Further, this software is distributed without any warranty that it is
18 # free of the rightful claim of any third person regarding infringement
19 # or the like.  Any license provided herein, whether implied or
20 # otherwise, applies only to this software file.  Patent licenses, if
21 # any, provided herein do not apply to combinations of this program with
22 # other software, or any other product whatsoever.
23
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write the Free Software Foundation, Inc., 59
26 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
27
28 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
29 # Mountain View, CA  94043, or:
30
31 # http://www.sgi.com 
32
33 # For further information regarding this notice, see: 
34
35 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #-----------------------------------------------------------------------
37 #
38 # creator
39 owner=nathans@sgi.com
40
41 seq=`basename $0`
42 echo "QA output created by $seq"
43
44 here=`pwd`
45 tmp=/tmp/$$
46 status=1        # failure is the default!
47 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
48 rm -f $seq.full
49
50 # get standard environment, filters and checks
51 . ./common.rc
52 . ./common.filter
53
54 _check_repair()
55 {
56         _scratch_xfs_repair >$tmp.0 2>&1
57         for i in 1 2 3 4
58         do
59                 echo "Repairing, iteration $i" | tee -a $seq.full
60                 _scratch_xfs_repair 2>&1 | tee -a $seq.full >$tmp.$i
61                 diff $tmp.0 $tmp.$i >> $seq.full
62                 if [ $? -ne 0 ]; then
63                         echo "ERROR: repair round $i differs (see $seq.full)"
64                         break
65                 fi
66                 # echo all interesting stuff...
67                 perl -ne '
68                         s/(rebuilding directory inode) (\d+)/\1 INO/g;
69                         s/internal log/<TYPEOF> log/g;
70                         s/external log on \S+/<TYPEOF> log/g;
71                         /^\S+/ && print;
72                 ' $tmp.$i
73         done
74         echo
75 }
76
77 # prototype file to create various directory forms
78 _create_proto()
79 {
80         total=$1
81         count=0
82
83         # take inode size into account for non-shortform directories...
84         [ $total -gt 0 ] && total=`expr $total \* $isize / 512`
85
86         cat >$tmp.proto <<EOF
87 DUMMY1
88 0 0
89 : root directory
90 d--777 3 1
91 lost+found d--755 3 1
92 $
93 EOF
94
95         while [ $count -lt $total ]
96         do
97                 count=`expr $count + 1`
98                 cat >>$tmp.proto <<EOF
99 ${count}_of_${total}_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ---755 3 1 /bin/true
100 EOF
101         done
102         echo '$' >>$tmp.proto
103 }
104
105 # real QA test starts here
106
107 _require_nobigloopfs
108 _require_scratch
109
110 MKFSV1="-p $tmp.proto -n version=1"
111 MKFSV2="-p $tmp.proto -n version=2"
112
113 # sanity test - default + one root directory entry
114 # Note: must do this proto/mkfs now for later inode size calcs
115 _create_proto 0
116 echo "=== version 1, one entry"
117 _scratch_mkfs_xfs $MKFSV1 >$tmp.mkfs0 2>&1
118 _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
119 source $tmp.mkfs
120 _check_repair
121 echo "=== version 2, one entry (shortform)"
122 _scratch_mkfs_xfs $MKFSV2 | _filter_mkfs >/dev/null 2>&1
123 _check_repair
124
125 # block-form root directory & repeat
126 _create_proto 20
127 echo "=== version 1, twenty entries"
128 _scratch_mkfs_xfs $MKFSV1 | _filter_mkfs >/dev/null 2>&1
129 _check_repair
130 echo "=== version 2, twenty entries (block form)"
131 _scratch_mkfs_xfs $MKFSV2 | _filter_mkfs >/dev/null 2>&1
132 _check_repair
133
134 # leaf-form root directory & repeat
135 _create_proto 1000
136 echo "=== version 1, thousand entries"
137 _scratch_mkfs_xfs $MKFSV1 | _filter_mkfs >/dev/null 2>&1
138 _check_repair
139 echo "=== version 2, thousand entries (leaf form)"
140 _scratch_mkfs_xfs $MKFSV2 | _filter_mkfs >/dev/null 2>&1
141 _check_repair
142
143 # success, all done
144 status=0
145 exit