#!/bin/sh
# PCP QA Test No. 691
# derived metrics & instance filtering - garbage collection check
#
# Copyright (c) 2018 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

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

_filter()
{
    sed -n \
	-e '/instances/{
s/.*regex//
s/0x[0-9a-f]*/<addr>/
p
}' \
    # end
}

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

# real QA test starts here
cat <<'End-of-File' >$tmp.config
qa.a = matchinst(/^m-/, sample.mirage)
End-of-File

export PCP_DERIVED_CONFIG=$tmp.config
pmval -t 20msec -a archives/mirage-3 sample.mirage >$tmp.out.base 2>$tmp.err
if [ -s $tmp.err ]
then
    echo "+++ unexpected errors from baseline test +++"
    cat $tmp.err
fi

pmval -t 20msec -a archives/mirage-3 -Dderive,appl2,logmeta qa.a >$tmp.out 2>$tmp.err
echo "Diffs b/n sample.mirage and (derived) qa.a ..."
diff $tmp.out.base $tmp.out
echo >>$here/$seq.full
cat $tmp.out >>$here/$seq.full

echo
cat $tmp.err >>$here/$seq.full
_filter <$tmp.err

# success, all done
status=0
exit
