#! /bin/sh
# PCP QA Test No. 174
# validate profile cacheing in dbpmda matches that in libpcp
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

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

sampledso=$PCP_PMDAS_DIR/sample/pmda_sample.$DSO_SUFFIX
username=`id -u -n`
pipeargs=""
id pcp >/dev/null 2>&1 && pipeargs="-U $username"

_filter()
{
    sed \
	-e '/pmResult/s/ 0x.* numpmid/ ... numpmid/' \
	-e '/^dbpmda> $/d' \
	-e "s/ -U $username//g" \
        -e "s;$sampledso;SAMPLEDSO;g" \
	-e "s;$PCP_PMDAS_DIR;\$PCP_PMDAS_DIR;g"
}

# filter out GetPDUs and pmResult dumps
_filter_stderr()
{
    # strange sed's are for endian differences in hex dumps
    #
    sed \
	-e 's/ fd=[0-9][0-9]*/ fd=<n>/g' \
	-e '/pmResult/,/numval: /d' \
	-e '/ inst /d' \
	-e '/ value /d' \
	-e 's/^\[[0-9][0-9]*]/[PID]/' \
	-e '/^000:/s/ 700\(.\) ......../ 700\1     XPID/' \
	-e 's/  1000000      201/        1  1020000/' \
	-e 's/  1000000  6004007/        1  7400006/' \
	-e 's/  1000000  1000000/        1        1/' \
	-e 's/  1000000  2000000/        1        2/' \
	-e 's/ c8000000 90010000/       c8      190/' \
	-e 's/        0 c8000000/        0       c8/' \
	-e 's/     XPID  6004007/     XPID  7400006/' \
	-e 's/  1000000        0  2004007/        1        0  7400002/' \
	-e '/\(DSO init .*->\)0x[0-9a-f]*()/s//\1VADDR()/' \
	-e '/DSO init .*->/s/pmda_interface=0x[0-9a-f][0-9a-f]*/pmda_interface=0xXXXX/' \
	-e '/DSO has domain/s/pmda_interface=[5-9]/pmda_interface=X/' |
    $PCP_AWK_PROG '
	/pmGetPDU/  {gotGetPDU=1; next}
	gotGetPDU==1 && $1 ~ /[0-9][0-9][0-9]:/ { next }
			{gotGetPDU=0; print}'
}

trap "rm -f $tmp.*; exit" 0 1 2 3 15

# real QA test starts here

dbpmda -ie <<End-of-File 2>$tmp.stderr | _filter
debug 1
getdesc on
open pipe $PCP_PMDAS_DIR/sample/pmdasample $pipeargs -d 29
fetch 29.0.6
fetch 29.0.6
fetch 29.0.6
profile 29.2 none
profile 29.2 add 200
fetch 29.0.6
fetch 29.0.6
fetch 29.0.6
profile 29.2 add 400
fetch 29.0.6
fetch 29.0.6
fetch 29.0.6
open dso $sampledso sample_init 30
fetch 30.0.6
fetch 30.0.6
fetch 30.0.6
profile 30.2 none
profile 30.2 add 100
fetch 30.0.6
fetch 30.0.6
fetch 30.0.6
profile 30.2 add 300
fetch 30.0.6
fetch 30.0.6
fetch 30.0.6
End-of-File

echo
echo "PDUs sent ..."
_filter_stderr <$tmp.stderr


exit 0
