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