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