4b5a5410d2c3c170c5977cf4aa98db1b99de5d9d
[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     rm -f $tmp.*
65 }
66
67 OUT="bench.out"
68 LOG="bench.log"
69 FULL="bench.full"
70
71 _log()
72 {
73     echo "$*" 1>&2
74     echo "$*" >>$LOG
75     echo "$*" >>$FULL
76     sync
77 }
78
79 _logp()
80 {
81     tee -a $FULL
82 }
83
84 _fail()
85 {
86     _log "$*"
87     status=1
88     exit 1
89 }
90
91 bench_mkfs_xfs()
92 {
93     mkfs_xfs -f $extra_mkfs_options $@
94     [ $? -ne 0 ] && _fail "mkfs [$extra_mkfs_options] FAILED"
95 }
96
97 bench_mount_xfs()
98 {
99     mount -t xfs $extra_mount_options $@
100     [ $? -ne 0 ] && _fail "mount [$extra_mount_options] FAILED"
101 }
102
103 _run_benchmark()
104 {
105     pass=1
106     uid=`id -u $user`
107     gid=`id -g $group`
108     
109     while [ $pass -le $passes -o $passes -lt 0 ]
110     do
111         _log "        *** clean scratch device [$bench starting, pass $pass]"
112         bench_mkfs_xfs  $SCRATCH_DEV 2>&1 | _fix_malloc >>$FULL \
113                             || _fail "            !!! mkfs SCRATCH_DEV failed"
114
115         _log "        *** mounting scratch device"
116         bench_mount_xfs $SCRATCH_DEV $SCRATCH_MNT \
117                             || _fail "            !!! failed to mount"
118         
119         _log "        *** mkdir"
120         mkdir $SCRATCH_MNT/bench \
121                             || _fail "            !!! couldn't mkdir benchdir"
122         chown -R $user.$group $SCRATCH_MNT/bench \
123                             || _fail "            !!! couldn't chown benchdir"
124
125         cd $SCRATCH_MNT/bench
126         seq=`perl -e 'printf "results.%s.%03d\n", '$bench', '$pass`
127         rm -f $seq $tmp.out
128
129         _log "        *** bench [$seq]"
130         $here/src/runas -u $uid -g $gid $here/run.$bench >$tmp.out 2>>$FULL
131         [ $? -eq 0 ]        || _fail "            !!! $bench pass $pass failed"
132
133         cd $here
134         _fix_malloc < $tmp.out > $seq
135
136         _log "        *** unmounting scratch device"
137         umount $SCRATCH_DEV 2>&1 | _logp \
138                             || _fail "            !!! failed to umount"
139
140         _log "        *** post-umount filesystem check"
141         _check_fs $SCRATCH_DEV
142         
143         let "pass = pass + 1"
144     done
145 }
146
147 _merge_results()
148 {
149     echo Results for $bench benchmark
150     headers=`$here/run.$bench -h`
151     echo "[$headers]"
152     echo results.$bench.* | sort -nu | xargs cat
153     echo
154 }
155
156 # real QA test starts here
157
158 if [ $# -lt 3 ]; then
159     echo Usage:  bench passes user group [script]
160     exit 1
161 fi
162
163 passes=$1
164 user=$2
165 group=$3
166 shift; shift; shift
167
168 if [ $# -gt 0 ]; then
169         benches="$@"
170 else
171         benches=`echo run.* | sed -e 's/run\.//g'`
172 fi
173 [ -z "$benches" -o "$benches" = "*" ] && _fail "no benchmark scripts found"
174
175 trap "_cleanup; exit \$status" 0 1 2 3 15
176
177 _require_scratch
178 rm -f bench.* results.*
179
180 if [ ! -z "$SCRATCH_LOGDEV" -a ! -z "$USE_SCRATCH_LOGDEV" ]
181 then
182         extra_log_options="-l $SCRATCH_LOGDEV"
183         extra_mkfs_options="-llogdev=$SCRATCH_LOGDEV"
184         extra_mount_options="-ologdev=$SCRATCH_LOGDEV"
185 fi
186
187 # $OUT is the report which will ultimately be sent, keep it tidy.
188 cat >$OUT <<EOF
189 bench: MKFS_OPTIONS=$MKFS_OPTIONS $extra_mkfs_options
190 bench: MOUNT_OPTIONS=$MOUNT_OPTIONS $extra_mount_options
191
192 EOF
193
194 for bench in $benches
195 do
196     echo "" >$FULL
197     echo "" >$LOG
198     _log "*** benchmark started [passes=$passes, benchmark=$bench]"
199     _log "*** (`date`)"
200     _log "*** MKFS_OPTIONS=$MKFS_OPTIONS"
201     _log "*** MOUNT_OPTIONS=$MOUNT_OPTIONS"
202     _log "        *** unmounting scratch device"
203     umount $SCRATCH_DEV 2>&1 | _fix_malloc >>$FULL
204
205     _run_benchmark | _fix_malloc
206     _merge_results >>$OUT
207
208     _log "*** done $bench"
209 done
210 status=0