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