xfstests: resolve compiler warnings
[xfstests-dev.git] / bench
1 #!/bin/bash
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
21 # modify it under the terms 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,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 # GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write the Free Software Foundation,
31 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
32 #
33 #-----------------------------------------------------------------------
34 #
35 # creator
36 owner=nathans@sgi.com
37
38 iam=bench
39 tmp=/tmp/$$
40 here=`pwd`; export here
41 status=1        # failure is the default!
42
43 # get standard environment, filters and checks
44 . ./common.rc
45 . ./common.filter
46
47 _cleanup()
48 {
49     echo "        *** umount"
50     umount $SCRATCH_DEV >/dev/null 2>&1
51     rm -f $tmp.*
52 }
53
54 OUT="bench.out"
55 LOG="bench.log"
56 FULL="bench.full"
57
58 _log()
59 {
60     echo "$*" 1>&2
61     echo "$*" >>$LOG
62     echo "$*" >>$FULL
63     sync
64 }
65
66 _logp()
67 {
68     tee -a $FULL
69 }
70
71 _fail()
72 {
73     _log "$*"
74     status=1
75     exit 1
76 }
77
78 _run_benchmark()
79 {
80     pass=1
81     uid=`id -u $user`
82     gid=`id -g $group`
83     
84     while [ $pass -le $passes -o $passes -lt 0 ]
85     do
86         _log "        *** clean scratch device [$bench starting, pass $pass]"
87         _scratch_mkfs 2>&1 | _fix_malloc >>$FULL
88         _log "        *** mounting scratch device"
89         _scratch_mount      || _fail "            !!! failed to mount"
90         
91         _log "        *** mkdir"
92         mkdir $SCRATCH_MNT/bench \
93                             || _fail "            !!! couldn't mkdir benchdir"
94         chown -R $user.$group $SCRATCH_MNT/bench \
95                             || _fail "            !!! couldn't chown benchdir"
96
97         cd $SCRATCH_MNT/bench
98         seq=`perl -e 'printf "results.%s.%03d\n", '$bench', '$pass`
99         rm -f $seq $tmp.out
100
101         _log "        *** bench [$seq]"
102         $here/src/runas -u $uid -g $gid $here/run.$bench >$tmp.out 2>>$FULL
103         [ $? -eq 0 ]        || _fail "            !!! $bench pass $pass failed"
104
105         cd $here
106         _fix_malloc < $tmp.out > $seq
107
108         _log "        *** unmounting scratch device"
109         umount $SCRATCH_DEV 2>&1 | _logp \
110                             || _fail "            !!! failed to umount"
111
112         _log "        *** post-umount filesystem check"
113         _check_scratch_fs
114         
115         let "pass = pass + 1"
116     done
117 }
118
119 _merge_results()
120 {
121     echo Results for $bench benchmark
122     $here/run.$bench -h
123     echo results.$bench.* | sort -nu | xargs cat
124     echo
125 }
126
127 # real QA test starts here
128
129 if [ $# -lt 3 ]; then
130     echo Usage:  bench passes user group [script]
131     exit 1
132 fi
133
134 passes=$1
135 user=$2
136 group=$3
137 shift; shift; shift
138
139 if [ $# -gt 0 ]; then
140     benches="$@"
141 else
142     benches=`echo run.* | sed -e 's/run\.//g'`
143 fi
144 [ -z "$benches" -o "$benches" = "*" ] && _fail "no benchmark scripts found"
145
146 trap "_cleanup; exit \$status" 0 1 2 3 15
147
148 _require_scratch
149 rm -f bench.* results.*
150
151 FULL_FSTYP_DETAILS=`_full_fstyp_details`
152 FULL_HOST_DETAILS=`_full_platform_details`
153 FULL_MKFS_OPTIONS=`_scratch_mkfs_options`
154 FULL_MOUNT_OPTIONS=`_scratch_mount_options`
155
156 # $OUT is the report which will ultimately be sent, keep it tidy.
157 cat >$OUT <<EOF
158 FSTYP         -- $FULL_FSTYP_DETAILS
159 PLATFORM      -- $FULL_HOST_DETAILS
160 MKFS_OPTIONS  -- $FULL_MKFS_OPTIONS
161 MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS
162
163 EOF
164
165 for bench in $benches
166 do
167     echo "" >>$FULL
168     echo "" >$LOG
169     _log "*** benchmark started [passes=$passes, benchmark=$bench]"
170     _log "*** (`date`)"
171     _log "MKFS_OPTIONS  -- $FULL_MKFS_OPTIONS"
172     _log "MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS"
173     _log "        *** unmounting scratch device"
174     umount $SCRATCH_DEV 2>&1 | _fix_malloc >>$FULL
175
176     _run_benchmark | _fix_malloc
177     _merge_results >>$OUT
178
179     _log "*** done $bench"
180 done
181 status=0