Fix qa test 033 - if we have to retry mkfs with a different inode size,
[xfstests-dev.git] / bench
1 #!/bin/sh
2
3 # Wrapper for automating benchmarking runs.
4 # Usage:   bench passes user group [script]
5
6 # ..where passes is the number of times to run each script; uid/gid
7 # gives credentials to use when running the script; and script is a
8 # simple wrapper around each actual benchmark tool (eg. see run.*),
9 # if this is ommited, all run.* scripts are used in turn.
10
11 # Each run.foo script should report a comma-separated-value list of
12 # benchmark results on stdout or fail with a non-zero exit code;
13 # unless the -i option is supplied in which case it should instead
14 # report a comma-separated-value list of column headers (for report
15 # generation purposes).
16
17 #-----------------------------------------------------------------------
18 # Copyright (c) 2002 Silicon Graphics, Inc.  All Rights Reserved.
19
20 # This program is free software; you can redistribute it and/or modify it
21 # under the terms of version 2 of the GNU General Public License as
22 # published by the Free Software Foundation.
23
24 # This program is distributed in the hope that it would be useful, but
25 # WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27
28 # Further, this software is distributed without any warranty that it is
29 # free of the rightful claim of any third person regarding infringement
30 # or the like.  Any license provided herein, whether implied or
31 # otherwise, applies only to this software file.  Patent licenses, if
32 # any, provided herein do not apply to combinations of this program with
33 # other software, or any other product whatsoever.
34
35 # You should have received a copy of the GNU General Public License along
36 # with this program; if not, write the Free Software Foundation, Inc., 59
37 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
38
39 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
40 # Mountain View, CA  94043, or:
41
42 # http://www.sgi.com 
43
44 # For further information regarding this notice, see: 
45
46 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
47 #-----------------------------------------------------------------------
48 #
49 # creator
50 owner=nathans@sgi.com
51
52 tmp=/tmp/$$
53 here=`pwd`; export here
54 status=1        # failure is the default!
55
56 # get standard environment, filters and checks
57 . ./common.rc
58 . ./common.filter
59
60 _cleanup()
61 {
62     echo "        *** umount"
63     umount $SCRATCH_DEV >/dev/null 2>&1
64 }
65
66 OUT="bench.out"
67 LOG="bench.log"
68 FULL="bench.full"
69
70 _log()
71 {
72     echo "$*" 1>&2
73     echo "$*" >>$LOG
74     echo "$*" >>$FULL
75     sync
76 }
77
78 _logp()
79 {
80     tee -a $FULL
81 }
82
83 _fail()
84 {
85     _log "$*"
86     status=1
87     exit 1
88 }
89
90 bench_mkfs_xfs()
91 {
92     mkfs_xfs -f $extra_mkfs_options $@
93 }
94
95 bench_mount_xfs()
96 {
97     mount -t xfs $extra_mount_options $@
98 }
99
100 _run_benchmark()
101 {
102     pass=1
103     uid=`id -u $user`
104     gid=`id -g $group`
105     
106     while [ $pass -le $passes -o $passes -lt 0 ]
107     do
108         _log "        *** clean scratch device [$bench starting, pass $pass]"
109         bench_mkfs_xfs  $SCRATCH_DEV 2>&1 | _fix_malloc >>$FULL \
110                             || _fail "            !!! mkfs SCRATCH_DEV failed"
111
112         _log "        *** mounting scratch device"
113         bench_mount_xfs $SCRATCH_DEV $SCRATCH_MNT \
114                             || _fail "            !!! failed to mount"
115         
116         _log "        *** mkdir"
117         mkdir $SCRATCH_MNT/bench \
118                             || _fail "            !!! couldn't mkdir benchdir"
119         chown -R $user.$group $SCRATCH_MNT/bench \
120                             || _fail "            !!! couldn't chown benchdir"
121
122         cd $SCRATCH_MNT/bench
123         seq=`perl -e 'printf "results.%s.%03d\n", '$bench', '$pass`
124         rm -f $seq $tmp.out
125
126         _log "        *** bench [$seq]"
127         $here/src/runas -u $uid -g $gid $here/run.$bench >$tmp.out 2>>$FULL
128         [ $? -eq 0 ]        || _fail "            !!! $bench pass $pass failed"
129
130         cd $here
131         _fix_malloc < $tmp.out > $seq
132
133         _log "        *** unmounting scratch device"
134         umount $SCRATCH_DEV 2>&1 | _logp \
135                             || _fail "            !!! failed to umount"
136
137         _log "        *** post-umount filesystem check"
138         _check_fs $SCRATCH_DEV
139         
140         let "pass = pass + 1"
141     done
142 }
143
144 _merge_results()
145 {
146     echo Results for $bench benchmark
147     headers=`$here/run.$bench -h`
148     echo "[$headers]"
149     echo results.$bench.* | sort -nu | xargs cat
150     echo
151 }
152
153 # real QA test starts here
154
155 if [ $# -lt 3 ]; then
156     echo Usage:  bench passes user group [script]
157     exit 1
158 fi
159
160 passes=$1
161 user=$2
162 group=$3
163 shift; shift; shift
164
165 if [ $# -gt 0 ]; then
166         benches="$@"
167 else
168         benches=`echo run.* | sed -e 's/run\.//g'`
169 fi
170 [ -z "$benches" -o "$benches" = "*" ] && _fail "no benchmark scripts found"
171
172 trap "_cleanup; exit \$status" 0 1 2 3 15
173
174 _require_scratch
175 rm -f bench.* results.*
176
177 if [ ! -z "$SCRATCH_LOGDEV" -a ! -z "$USE_SCRATCH_LOGDEV" ]
178 then
179         extra_log_options="-l $SCRATCH_LOGDEV"
180         extra_mkfs_options="-llogdev=$SCRATCH_LOGDEV"
181         extra_mount_options="-ologdev=$SCRATCH_LOGDEV"
182 fi
183
184 # $OUT is the report which will ultimately be sent, keep it tidy.
185 cat >$OUT <<EOF
186 bench: MKFS_OPTIONS=$MKFS_OPTIONS $extra_mkfs_options
187 bench: MOUNT_OPTIONS=$MOUNT_OPTIONS $extra_mount_options
188
189 EOF
190
191 for bench in $benches
192 do
193     echo "" >$FULL
194     echo "" >$LOG
195     _log "*** benchmark started [passes=$passes, benchmark=$bench]"
196     _log "*** (`date`)"
197     _log "*** MKFS_OPTIONS=$MKFS_OPTIONS"
198     _log "*** MOUNT_OPTIONS=$MOUNT_OPTIONS"
199     _log "        *** unmounting scratch device"
200     umount $SCRATCH_DEV 2>&1 | _fix_malloc >>$FULL
201
202     _run_benchmark | _fix_malloc
203     _merge_results >>$OUT
204
205     _log "*** done $bench"
206 done
207 status=0