#! /bin/sh
# PCP QA Test No. 307
# pv:936084 - nasflush from nasmgr causes high rate of tcp drops
# (because it uses pmlc a lot)
#
# Copyright (c) 2005 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

pminfo network.tcp 2>/dev/null | grep drop | grep -v dropped >$tmp.metrics
[ -s $tmp.metrics ] || _notrun "no network.tcp.*drop* metrics"
# restrict the pmie expression to "drop" metrics that have
# values
rm -f $tmp.pmie
pmprobe -v `cat $tmp.metrics` 2>/dev/null \
| while read metric numval fluff
do
    [ "$numval" -le 0 ] && continue
    if [ ! -s $tmp.pmie ]
    then
	echo "$metric" >$tmp.pmie
    else
	echo "+ $metric" >>$tmp.pmie
    fi
done
if [ ! -s $tmp.pmie ]
then
    pmprobe -v `cat $tmp.metrics` >>$seq_full 2>&1
    _notrun "no values for network.tcp.*drop* metrics"
fi
echo ' > 10;' >>$tmp.pmie
cat $tmp.pmie >>$seq_full

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

_filter()
{
    sed \
        -e '/Connected to primary pmlogger /d' \
        -e '/Goodbye/d'
}

pmie -v -t 0.25sec -T 1sec -c $tmp.pmie >$tmp.trace 2>&1 &

# real QA test starts here

# quit to pmlc
#
i=0
while [ $i -lt 10 ]
do
    echo quit | pmlc -P 2>&1 | _filter
    i=`expr $i + 1`
done

# E-O-F to pmlc
#
i=0
while [ $i -lt 10 ]
do
    pmlc -P </dev/null 2>&1 | _filter
    i=`expr $i + 1`
done

# reconnect to pmlc
#
i=0
while [ $i -lt 10 ]
do
    echo "connect primary"
    i=`expr $i + 1`
done \
| pmlc -P 2>&1 | _filter

wait

sed -e 's/.* Info: evaluator exiting/pmie: note - evaluator exiting/g' <$tmp.trace \
| sort -u
cat $tmp.trace >>$seq_full

# success, all done
exit
