71ebca83a97e6795f48024d86f3dc5af098ef3c3
[xfstests-dev.git] / bench
1 #!/bin/sh
2
3 # Wrapper for automating benchmarking runs.
4 # Usage:   bench [passes] [uid] [gid] [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 seq=bench
54 here=`pwd`
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 }
66
67 trap "_cleanup; exit \$status" 0 1 2 3 15
68
69 ROOT="."
70 LOG="$ROOT/soak.log"
71 FULL="$ROOT/soak.full"
72
73 _log()
74 {
75     echo "$*" 1>&2
76     echo "$*" >>$LOG
77     echo "$*" >>$FULL
78     sync
79 }
80
81 _logp()
82 {
83     tee -a $FULL
84 }
85
86 _fail()
87 {
88     _log "$*"
89     status=1
90     exit 1
91 }
92
93 _run_benchmark()
94 {
95     pass=1
96     
97     while [ $pass -le $passes -o $passes -lt 0 ]
98     do
99         _log "        *** clean scratch device [starting pass $pass]"
100         mkfs_xfs -f $SCRATCH_DEV 2>&1 |  _fix_malloc >>$FULL \
101                         || _fail "            !!! failed to mkfs SCRATCH_DEV"
102
103         _log "        *** mounting scratch device"
104         mount -t xfs $SCRATCH_DEV $SCRATCH_MNT \
105                             || _fail "            !!! failed to mount"
106         
107         _log "        *** mkdir"
108         mkdir $SCRATCH_MNT/bench \
109                             || _fail "            !!! couldn't mkdir bench dir"
110         chown -R $user.$group $SCRATCH_MNT/bench \
111                             || _fail "            !!! couldn't chown bench dir"
112         cd $SCRATCH_MNT/bench
113
114         _log "        *** bench"
115         $here/src/runas -u $user -g $group $here/run.$bench > $FULL
116         [ $? -eq 0 ]        || _fail "            !!! non-zero $bench exit code"
117         cd $here
118
119         _log "        *** unmounting scratch device"
120         umount $SCRATCH_DEV 2>&1 | _logp \
121                             || _fail "            !!! failed to umount"
122
123         _log "        *** post-umount filesystem check"
124         _check_fs $SCRATCH_DEV
125         
126         let "pass = pass + 1"
127     done
128 }
129
130 # real QA test starts here
131
132 _require_scratch
133
134 passes=-1
135 user=root
136 group=root
137 benches=`echo run.*`
138
139 [ $# -gt 0 ] && passes=$1
140 [ $# -gt 1 ] && user=$3
141 [ $# -gt 2 ] && group=$4
142 [ $# -gt 3 ] && benches=$2
143
144 for bench in "$benches"
145 do 
146     echo "" >$FULL
147     echo "" >$LOG
148     _log "*** benchmark started (passes=$passes, benchmark=$bench)"
149     _log "***     (`date`)"
150     _log "        *** unmounting scratch device"
151     umount $SCRATCH_DEV 2>&1 |  _fix_malloc >>$FULL
152     
153     _run_benchmark  # $passes $bench $user $group
154
155     _log "*** done $bench"
156 done