#! /bin/sh
# PCP QA Test No. 298
# exercise pmie2col
#
# Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

rm -f $seq.out $seq.full
if [ $PCP_PLATFORM = darwin ]
then
    ln $seq.out.2 $seq.out
else
    ln $seq.out.1 $seq.out
fi

echo "QA output created by $seq"

status=0	# success is the default!
$sudo rm -rf $tmp.*
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15

cat <<'End-of-File' >$tmp.config
loadav = kernel.all.load #'1 minute';
'%usr' = kernel.all.cpu.user;
'%sys' = kernel.all.cpu.sys;
'%wio' = kernel.all.cpu.wait.total;
'%idle' = kernel.all.cpu.idle;
'maxiops' = max_inst(disk.dev.total);
End-of-File

_filter()
{
    sed \
	-e 's/^[A-Z][a-z][a-z] [A-Z][a-z][a-z]  *[0-9][0-9]* [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [0-9][0-9][0-9][0-9] /DATE /' \
	-e 's/  *[0-9][0-9.]*/ N/g'
}

_filter_err()
{
    sed \
	-e '/not in namespace/s/for host .*/for host LOCALHOST/'
}

# real QA test starts here
echo "=== live ===" | tee -a $seq.full
pmie -v -t 1 -T 3 <$tmp.config >$tmp.out 2>$tmp.tmp
cat $tmp.out >>$seq.full
sed -e '/Info: evaluator exiting/d' <$tmp.tmp >$tmp.err
if [ -s $tmp.err ]
then
    echo "pmie errors ..."
    _filter_err <$tmp.err
fi
cat $tmp.out \
| pmie2col \
| tee -a $seq.full \
| _filter

echo | tee -a $seq.full
echo "=== live, pmie -e ===" | tee -a $seq.full
pmie -v -e -t 1 -T 3 <$tmp.config >$tmp.out 2>$tmp.tmp
cat $tmp.out >>$seq.full
sed -e '/Info: evaluator exiting/d' <$tmp.tmp >$tmp.err
if [ -s $tmp.err ]
then
    echo "pmie errors ..."
    _filter_err <$tmp.err
fi
cat $tmp.out \
| pmie2col \
| tee -a $seq.full \
| _filter

echo | tee -a $seq.full
echo "=== archive and pmie2col -w ===" | tee -a $seq.full
pmie -v -z -A 30m -t 30m -a src/kenj-pc-1 <$tmp.config >$tmp.out 2>$tmp.tmp
cat $tmp.out >>$seq.full
sed -e '/Info: evaluator exiting/d' <$tmp.tmp >$tmp.err
if [ -s $tmp.err ]
then
    echo "pmie errors ..."
    _filter_err <$tmp.err
fi
cat $tmp.out \
| pmie2col -w 8 \
| tee -a $seq.full

# success, all done
exit
