#! /bin/sh
# PCP QA Test No. 287
# handling of wrapping counters with pmlogreduce
#
# Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`

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

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

rm -f $seq.out
case "`uname -m`"
in
    i?86|athlon)
	if [ $PCP_PLATFORM = darwin ]
	then
	    # apps are 64-bit on my Mac OS X
	    ln $seq.out.x86_64 $seq.out || exit 1
	else
	    ln $seq.out.i386 $seq.out || exit 1
	fi
	;;
    x86_64|ia64)
	ln $seq.out.x86_64 $seq.out || exit 1
	;;
    *)
	echo "Arrgh ... need qualified output for CPU type \"`uname -p`\""
	exit 1
	;;
esac

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

# real QA test starts here

_filter()
{
    sed -e "s;$tmp;TMP;"
}

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

# real QA test starts here

for interval in 2sec 5sec 15sec
do
    echo
    rm -f $tmp.*
    pmlogreduce -t $interval src/uwrap $tmp
    echo "-- raw reduce -t $interval --"
    pmval -z -r -w 15 -f 0 -t $interval -U $tmp sample.wrap.ulong 2>&1 \
    | _filter
    echo "-- rate converted, reduce -t $interval --"
    pmval -z -w 15 -f 0 -t $interval -a $tmp sample.wrap.ulong 2>&1 \
    | _filter
done

echo
echo "-- raw input archive --"
pmval -z -r -w 15 -f 0 -U src/uwrap sample.wrap.ulong

echo
echo "-- input archive, rate converted with PCP_COUNTER_WRAP set --"
PCP_COUNTER_WRAP=on
export PCP_COUNTER_WRAP
pmval -z -w 15 -f 0 -a src/uwrap -t 1sec sample.wrap.ulong

echo
echo "-- input metric descriptor --"
pminfo -d -a src/uwrap sample.wrap.ulong
echo
echo "-- output metric descriptor --"
pminfo -d -a $tmp sample.wrap.ulong

# success, all done
exit
