Use test dir for XFS runs, not localhost /tmp dir.
[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 iam=bench
53 tmp=/tmp/$$
54 here=`pwd`; export here
55 status=1        # failure is the default!
56
57 # get standard environment, filters and checks
58 . ./common.rc
59 . ./common.filter
60
61 _cleanup()
62 {
63     echo "        *** umount"
64     umount $SCRATCH_DEV >/dev/null 2>&1
65     rm -f $tmp.*
66 }
67
68 OUT="bench.out"
69 LOG="bench.log"
70 FULL="bench.full"
71
72 _log()
73 {
74     echo "$*" 1>&2
75     echo "$*" >>$LOG
76     echo "$*" >>$FULL
77     sync
78 }
79
80 _logp()
81 {
82     tee -a $FULL
83 }
84
85 _fail()
86 {
87     _log "$*"
88     status=1
89     exit 1
90 }
91
92 _run_benchmark()
93 {
94     pass=1
95     uid=`id -u $user`
96     gid=`id -g $group`
97     
98     while [ $pass -le $passes -o $passes -lt 0 ]
99     do
100         _log "        *** clean scratch device [$bench starting, pass $pass]"
101         _scratch_mkfs 2>&1 | _fix_malloc >>$FULL
102         _log "        *** mounting scratch device"
103         _scratch_mount      || _fail "            !!! failed to mount"
104         
105         _log "        *** mkdir"
106         mkdir $SCRATCH_MNT/bench \
107                             || _fail "            !!! couldn't mkdir benchdir"
108         chown -R $user.$group $SCRATCH_MNT/bench \
109                             || _fail "            !!! couldn't chown benchdir"
110
111         cd $SCRATCH_MNT/bench
112         seq=`perl -e 'printf "results.%s.%03d\n", '$bench', '$pass`
113         rm -f $seq $tmp.out
114
115         _log "        *** bench [$seq]"
116         $here/src/runas -u $uid -g $gid $here/run.$bench >$tmp.out 2>>$FULL
117         [ $? -eq 0 ]        || _fail "            !!! $bench pass $pass failed"
118
119         cd $here
120         _fix_malloc < $tmp.out > $seq
121
122         _log "        *** unmounting scratch device"
123         umount $SCRATCH_DEV 2>&1 | _logp \
124                             || _fail "            !!! failed to umount"
125
126         _log "        *** post-umount filesystem check"
127         _check_scratch_fs
128         
129         let "pass = pass + 1"
130     done
131 }
132
133 _merge_results()
134 {
135     echo Results for $bench benchmark
136     $here/run.$bench -h
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_FSTYP_DETAILS=`_full_fstyp_details`
166 FULL_HOST_DETAILS=`_full_platform_details`
167 FULL_MKFS_OPTIONS=`_scratch_mkfs_options`
168 FULL_MOUNT_OPTIONS=`_scratch_mount_options`
169
170 # $OUT is the report which will ultimately be sent, keep it tidy.
171 cat >$OUT <<EOF
172 FSTYP         -- $FULL_FSTYP_DETAILS
173 PLATFORM      -- $FULL_HOST_DETAILS
174 MKFS_OPTIONS  -- $FULL_MKFS_OPTIONS
175 MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS
176
177 EOF
178
179 for bench in $benches
180 do
181     echo "" >>$FULL
182     echo "" >$LOG
183     _log "*** benchmark started [passes=$passes, benchmark=$bench]"
184     _log "*** (`date`)"
185     _log "MKFS_OPTIONS  -- $FULL_MKFS_OPTIONS"
186     _log "MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS"
187     _log "        *** unmounting scratch device"
188     umount $SCRATCH_DEV 2>&1 | _fix_malloc >>$FULL
189
190     _run_benchmark | _fix_malloc
191     _merge_results >>$OUT
192
193     _log "*** done $bench"
194 done
195 status=0