qa: update 660 to generate index.html, fixing pcp-testsuite runs
[pcp.git] / qa / 252
blobcc92a8afeef89bac39ec798919a734ed9845b7fe
1 #! /bin/sh
2 # PCP QA Test No. 252
3 # pmlogger with its new formats for -s and -T stopping conditions
5 # Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved.
8 seq=`basename $0`
9 echo "QA output created by $seq"
11 # get standard filters
12 . ./common.product
13 . ./common.filter
15 status=1 # failure is the default!
16 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
18 pmdumplog='pmdumplog'
19 pmlogger='pmlogger'
20 SECS_TOL=2 # number of seconds tolerance
21 BYTES_TOL=1000 # number of bytes tolerance
22 #debug=1 # give extra debugging info
25 _clean_archive()
27 rm -f $tmp.log $tmp.0 $tmp.index $tmp.meta
30 # Is given value within tolerance of expected value
31 _tolerance()
33 expected=$1
34 given=$2
35 tolerance=$3
36 upper_limit=`expr $expected + $tolerance`
37 [ $expected -le $given -a $given -le $upper_limit ]
40 _num_recs()
42 num_recs=`$pmdumplog $tmp | egrep -c '^[0-9][0-9]:[0-9][0-9]:'`
43 # subtract 1 for the preamble
44 num_recs=`expr $num_recs - 1`
45 [ $debug ] && echo "found $num_recs samples after the preamble"
48 _test_sample_size()
50 size_arg=$1
51 $pmlogger -s $size_arg -c $tmp.config -l $tmp.log $tmp
53 _num_recs
54 echo "Expected log sample size: $size_arg"
55 echo "Actual log sample size: $num_recs"
56 _clean_archive
59 _test_file_size_old()
61 size_arg=$1
62 num_bytes=$2 # bytes version of size_arg
63 $pmlogger -s $size_arg -c $tmp.config -l $tmp.log $tmp
64 if [ -f $tmp.0 ]
65 then
66 actual_size=`ls -l $tmp.0 | $PCP_AWK_PROG ' {print $5} '`
67 else
68 actual_size=-1
70 echo "Expected log size of approx: $size_arg"
71 [ $debug ] && echo "Actual log size: $actual_size bytes"
72 if _tolerance $num_bytes $actual_size $BYTES_TOL
73 then
74 echo "Log size is within tolerance"
75 else
76 echo "Log size is outside tolerance ($actual_size bytes)"
78 _clean_archive
81 # Find out number of records, n, for given size
82 # Then make sure for (n-1) records that the size is smaller
83 _test_file_size()
85 size_arg=$1
86 num_bytes=$2 # bytes version of size_arg
87 $pmlogger -s $size_arg -c $tmp.config -l $tmp.log $tmp
88 if [ -f $tmp.0 ]
89 then
90 bigger_size=`ls -l $tmp.0 | $PCP_AWK_PROG ' {print $5} '`
91 else
92 bigger_size=-1
94 _num_recs
95 num_recs=`expr $num_recs - 1`
96 if [ $num_recs -gt 0 ]
97 then
98 _clean_archive
99 $pmlogger -s $num_recs -c $tmp.config -l $tmp.log $tmp
100 if [ -f $tmp.0 ]
101 then
102 smaller_size=`ls -l $tmp.0 | $PCP_AWK_PROG ' {print $5} '`
103 else
104 smaller_size=-1
106 else
107 smaller_size=-1
109 [ $debug ] && echo "Range: $smaller_size .. $bigger_size"
110 if [ $smaller_size -le $num_bytes -a $num_bytes -le $bigger_size ]
111 then
112 echo "Log size for $size_arg is correct"
113 else
114 echo "$num_bytes is not within range $smaller_size - $bigger_size"
116 _clean_archive
119 _time_me ()
121 # return time in seconds
123 # /usr/bin/time IS bloody important - dont port-sh it. EVER!
124 /usr/bin/time $* 2>&1 >/dev/null | \
125 if [ $PCP_PLATFORM = linux ]
126 then
127 # 0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 2752maxresident)k
128 tr ' ' "\n" | $PCP_AWK_PROG '/elapsed$/ { sub("elapsed", "", $1);
129 split ($1,tt,"[:.]");
130 print (tt[1]*60)+tt[2];}'
131 elif [ $PCP_PLATFORM = darwin ]
132 then
133 # 0.00 real 0.00 user 0.00 sys
134 $PCP_AWK_PROG '{print $1}' | sed -e 's/\..*//'
135 else
136 # real 0.0
137 # user 0.0
138 # sys 0.0
139 $PCP_AWK_PROG '/^real/ {print $2}' | sed -e 's/\..*//'
143 # Note: size arg should be given in secs for comparison with /usr/bin/time
144 _test_time_size()
146 size_arg=$1
147 num_secs=$2 # secs version of size_arg
148 time=`_time_me $pmlogger -s $size_arg -c $tmp.config -l $tmp.log $tmp`
149 [ -z "$time" ] && time=-1
150 echo "Expected time size of: $size_arg"
151 [ $debug ] && echo "Actual time : $time"
152 if _tolerance $num_secs $time $SECS_TOL
153 then
154 echo "Log time is within tolerance"
155 else
156 echo "Log time is outside tolerance - $time secs"
158 _clean_archive
163 # Note: size arg should be given in secs for comparison with /usr/bin/time
164 _test_time_end()
166 size_arg=$1
167 num_secs=$2 # secs version of size_arg
168 time=`_time_me $pmlogger -T $size_arg -c $tmp.config -l $tmp.log $tmp`
169 [ -z "$time" ] && time=-1
170 echo "Expected time size of: $size_arg"
171 [ $debug ] && echo "Actual time : $time"
172 if _tolerance $num_secs $time $SECS_TOL
173 then
174 echo "Log time is within tolerance"
175 else
176 echo "Log time is outside tolerance - $time secs"
178 _clean_archive
181 # real QA test starts here
184 # Create a simple configuration file for testing
185 cat <<EOF >$tmp.config
186 # pmlogger(1) configuration file for doing QA tests
188 log mandatory on 100 msec {
189 sample.control
190 sample.milliseconds
191 sample.load
192 sample.colour
193 sample.bin
194 sample.bucket
195 sample.drift
196 sample.step
197 sample.write_me
198 sample.lights
199 sample.magnitude
200 sample.pdu
201 sample.recv_pdu
202 sample.xmit_pdu
203 sample.noinst
207 # Test out -s
208 _test_file_size 4000bytes 4000
209 _test_file_size 4K 4096
210 _test_file_size 4194B 4194
211 _test_sample_size 2
212 _test_time_size 3secs 3
214 # Test out -T
215 _test_time_end 3secs 3
217 # success, all done
218 status=0
219 exit