#! /bin/sh
# PCP QA Test No. 1045 (formerly 526)
# exercise pmieconf version control (pmie config/rules)
#
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#
# creator
owner=nathans

seq=`basename $0`

if which pmieconf >/dev/null 2>&1
then
    :
else
    echo "No pmieconf binary installed" >$seq.notrun
    echo "$seq: [not run] `cat $seq.notrun`"
    exit 0
fi

echo "QA output created by $seq"

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

_filter_date()
{
    # ctime format: Thu Dec 17 15:26:15 1998
    sed -e 's/[A-Z][a-z][a-z] [A-Z][a-z][a-z] *[0-9][0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]/[DATE]/g'
}

_filter_pmie()
{
    if [ $PCP_PLATFORM = darwin ]
    then
	sed \
	    -e '/metric swap.pagesout not in namespace/d' \
	    -e '/pmLookupName failed: Unknown metric name/d'
    elif [ $PCP_PLATFORM = solaris ]
    then
	sed \
	    -e '/metric swap.pagesout not in namespace/d' \
	    -e '/metric filesys.used not in namespace/d' \
	    -e '/metric filesys.capacity not in namespace/d' \
	    -e '/metric filesys.used not in namespace/d' \
	    -e '/pmLookupName failed: Unknown metric name/d'
    else
	cat
    fi
}

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

# real QA test starts here
cat > $tmp.pmie <<EOF
// pmieconf-pmie 0 ./pconf
// end
EOF
echo
echo "=== check unsupported pmie config  version"
pmieconf -F -r ./pconf -f $tmp.pmie 2>$tmp.stderr
sed -e "s/$$/[PID]/g" $tmp.stderr
echo status=$?

cat > $tmp.pmie <<EOF
// pmieconf-pmie 1 ./pconf
// 1 filesys.buffer_cache threshold = 81.500%
// 1 filesys.buffer_cache hosts = "moomba wobbly"
// 1 filesys.buffer_cache sss_action = yes
// 1 filesys.buffer_cache user_command = "pmpost \$rule\$^ %v@%h"
// 1 filesys.buffer_cache holdoff = 20
// 2 filesys.buffer_cache holdoff = 20
// 2 filesys.buffer_cache delta = 1908
// 3 filesys.buffer_cache enabled = yes
// 1 filesys.capacity delta = 60
// 1 network.interface_bytes holdoff = 30
// 1 network.tcp_dropped_conns holdoff = 30
// 1 network.tcp_retransmit holdoff = 30
// end

// 1 cpu.aggregate_util
sample.float.one;

// 1 cpu.load_average
sample.float.ten;

// 1 filesys.buffer_cache
sample.float.hundred;
EOF
cp $tmp.pmie $tmp.pmie1

echo
echo "=== check that unneeded changes for unsupported versions are dumped"
pmieconf -r ./pconf -f $tmp.pmie1 m filesys.buffer_cache sss_action no >/dev/null
echo status=$?
pmie -C $tmp.pmie1 >$tmp.out 2>&1
sts=$?
_filter_pmie <$tmp.out
echo status=$sts
_filter_date < $tmp.pmie1

# APPEND this to the above file
cat >> $tmp.pmie <<EOF
// 2 filesys.buffer_cache
sample.drift;

sample.double.one;
EOF
cp $tmp.pmie $tmp.pmie2

echo
echo "=== check that changes for unsupported versions are moved to end"
pmieconf -r ./pconf -f $tmp.pmie2 m network.interface_bytes holdoff 40 >/dev/null
echo status=$?
pmie -C $tmp.pmie2 >$tmp.out 2>&1
sts=$?
_filter_pmie <$tmp.out
echo status=$sts
_filter_date < $tmp.pmie2

cp $tmp.pmie $tmp.pmie3
$sudo mv ./pconf/cpu/load_average $tmp.load
echo
echo "=== check that changes for unsupported rules are moved to end"
pmieconf -r ./pconf -f $tmp.pmie3 m filesys.buffer_cache holdoff 120 >/dev/null
$sudo mv $tmp.load ./pconf/cpu/load_average
echo status=$?
pmie -C $tmp.pmie3 >$tmp.out 2>&1
sts=$?
_filter_pmie <$tmp.out
echo status=$sts
_filter_date < $tmp.pmie3

# success, all done
status=0
exit
