#!/bin/sh
# PCP QA Test No. 799
# checkout pmlogrewrite -q
#
# non-valgrind dual of qa/1476
#
# Copyright (c) 2019 Ken McDonell.  All Rights Reserved.
#
# check-group-exclude: pmdumplog
#

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.*
}

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

export PCP_DERIVED_CONFIG=

# real QA test starts here
echo "log mandatory on once {" >$tmp.config
pminfo \
| sed \
    -e 's/\..*//' \
| sort \
| uniq >>$tmp.config
echo "}" >>$tmp.config

pmlogger -l $tmp.log -c $tmp.config -s 1 $tmp
cat $tmp.log >>$seq.full

echo "values in the archive ..." >>$seq.full
textgrep=""
[ $PCP_PLATFORM = linux ] && textgrep="-a"
pmdumplog $tmp \
| grep $textgrep ' value ' \
| wc -l >>$seq.full

echo "=== no change ==="
pmlogrewrite -c $PCP_VAR_DIR/config/pmlogrewrite -Dappl0,appl3 -q -i $tmp 2>&1
pmlogcheck -w $tmp

echo
echo "=== one type change ==="
cat <<'End-of-File' >$tmp.config
metric sample.load {
    sem -> discrete
}
End-of-File
pminfo -d -a $tmp sample.load
pmlogrewrite -c $tmp.config -v -q -i $tmp 2>&1
pmlogcheck -w $tmp
pminfo -d -a $tmp sample.load

# success, all done
status=0
exit
