#!/bin/sh
# PCP QA Test No. 479
# coverage for libpcp/logmeta.c
#
# Copyright (c) 2011 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

rm -f $seq.out
if [ $PCP_VER -lt 30600 ]
then
    ln $seq.out.1 $seq.out || exit 1
else
    ln $seq.out.2 $seq.out || exit 1
fi

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

_filter()
{
    sed \
	-e "s;$tmp;TMP;g" \
	-e '/addindom( /s/[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9]/TIMESTAMP/' \
	-e '/searchindom( /s/[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9]/TIMESTAMP/'
}

_filter2()
{
    _filter_pmie_log \
    | sed -e '/Info: evaluator exiting/d' \
    | _filter
}

cp src/bozo.client_v2.* $tmp
mv $tmp/bozo.client_v2.meta $tmp/bozo.client_v2.save

# real QA test starts here
for bad in $tmp/bozo.client_v2.meta.bad.*
do
    echo
    echo "=== bad #`echo $bad | sed -e 's/.*\.bad\.//'` ==="
    cp $bad $tmp/bozo.client_v2.meta
    pmdumplog -z -a -Dlogmeta $tmp/bozo.client_v2 2>&1 \
    | _filter
done

for size in 100 132 136 160 164 407 440 512
do
    echo
    echo "=== size $size ==="
    dd if=$tmp/bozo.client_v2.save bs=1 count=$size of=$tmp/bozo.client_v2.meta >/dev/null 2>&1
    pmdumplog -z -a -Dlogmeta $tmp/bozo.client_v2 2>&1 \
    | _filter
done

echo
echo "torture_indom ... silence is golden"
src/torture_indom -a src/ace_v2 disk.dev.total

echo
echo "pmie archive meta data exercises ..."
echo 'some_inst disk.dev.total > 0 -> print "active disks:" " %i"' \
| pmie -z -t 2sec -a src/ace_v2 2>&1 \
| _filter2
echo
echo 'some_inst disk.dev.total #dks1d1 #dks1d7 > 0 -> print "active disks: " "%i"' \
| pmie -Dlogmeta -z -t 2sec -a src/ace_v2 2>&1 \
| _filter2

echo
echo "pmval archive meta data exercises ..."
pmval -z -t 5sec -Dlogmeta -a src/ac15 kernel.all.load 2>&1 | _filter
echo
pmval -z -t 5sec -Dlogmeta -a src/ac15 -i '"15 minute","5","1 minute"' kernel.all.load 2>&1 | _filter

echo
echo "torture ..."
src/torture_logmeta -Dlogmeta src/ac15 60 2 123 2>&1 \
| tee -a $seq.full \
| _filter

# success, all done
exit
