#!/bin/sh
# PCP QA Test No. 444
# pmid and desc caching in pmevent
#
# Copyright (c) 2011 Ken McDonell.  All Rights Reserved.
#

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

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

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

# real QA test starts here
pmstore sample.event.reset 0 >/dev/null 2>&1
pmevent -Dpdu,derive -t 10msec -s 20 sample.event.records >$tmp.out 2>&1
cat $tmp.out >>$seq.full

# Need to make this not host specific ...
#  2.6.0 (pmcd.client.whoami): numval: 1 valfmt: 2 vlist[]:
#   value "bozo-laptop (127.0.0.1) pmevent -Dpdu -t 10msec -s 20 sample.event.records"
# pmXmitPDU: RESULT fd=<fd> len=124
#
sed <$tmp.out \
    -e '/^[0-9][0-9]*:/d' \
    -e 's/^\[[0-9]*]//' \
    -e '/pmResult/s/ .* numpmid/ ... numpmid/' \
    -e "s/   value \"$host\"/   value \"HOST\"/g" \
    -e "s/host:      $host/host:      localhost/g" \
    -e 's/[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9]/TIMESTAMP/g' \
    -e 's/fd=[0-9][0-9]*/fd=<fd>/g' \
| $PCP_AWK_PROG ' BEGIN { hostskip=0 }
/^pmXmitPDU: FETCH fd=<fd> len=/	{ hostskip++; }
/^pmGetPDU: RESULT fd=<fd> len=/	{ if (hostskip < 2) { next } }
/pmcd.client.whoami/	{ print; skip=2; next }
skip > 0		{ print "blah blah ..."; skip--; next }
			{ print }'

# success, all done
exit
