#! /bin/sh
# PCP QA Test No. 261
# pmlogextract -S updates the label record?
# also exposed interp.c and pmval problems
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

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

# get standard filters
. ./common.product
. ./common.filter
. ./common.check

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

_filter()
{
    sed \
	-e '/^\[[0-9]* bytes]/d'
}

echo >$seq.full

# real QA test starts here
pmdumplog -z -l archives/mirage
pmdumplog -z -a archives/mirage 2>&1 >>$seq.full

pmlogextract -S 5min -T 5min archives/mirage $tmp

echo "--- copyied archive ---" >>$seq.full
pmdumplog -z -a $tmp | tee -a $seq.full | _filter

# Note on the bizarre 4.0001m termination intervals below ...
# Using _exactly_ 4m introduces a floating point arithmetic instability
# where the number of pmval samples could be 8 or 9 depending on how
# the compiler chooses to generate code (different gcc versions produce
# different answers) ...  making it _slightly_ bigger avoids this problem
#
echo
echo "Check metrics using pmval ..."
for metric in sample.mirage
do
    echo "$metric:"
    pmval -z -t 30 -S @10:51:07.407 -T 4.0001min -a archives/mirage -i m-00,m-21,m-22,m-23,m-24 $metric >$tmp.orig
    pmval -z -t 30 -T 4.0001min -a $tmp -i m-00,m-21,m-22,m-23,m-24 $metric >$tmp.new
    sed -e "s;$tmp;TMP;g" $tmp.new \
    | diff -c $tmp.orig - \
    | sed -e "s;$tmp;TMP;g" \
	  -e '1,2s/	.*/	TODAY/' \
	  -e 's/--- -/--- Standard Input/'
    echo "--- $metric, archives/mirage archive, instances" >>$seq.full
    cat $tmp.orig >>$seq.full
    echo "--- $metric, copied archive, instances" >>$seq.full
    cat $tmp.new >>$seq.full
done

echo
for metric in sample.bin sample.drift
do
    echo "$metric:"
    pmval -z -t 30 -S @10:51:07.407 -T 4.0001min -a archives/mirage $metric >$tmp.orig
    pmval -z -t 30 -T 4.0001min -a $tmp $metric >$tmp.new
    sed -e "s;$tmp;TMP;g" $tmp.new \
    | diff -c $tmp.orig - \
    | sed -e "s;$tmp;TMP;g" \
	  -e '1,2s/	.*/	TODAY/' \
	  -e 's/--- -/--- Standard Input/'
    echo "--- $metric, archives/mirage archive, NO instances" >>$seq.full
    cat $tmp.orig >>$seq.full
    echo "--- $metric, copied archive, NO instances" >>$seq.full
    cat $tmp.new >>$seq.full
done

# success, all done
status=0
exit
