#!/bin/sh
# PCP QA Test No. 1784
# Exercise interactive pmlogconf saving changes.
#
# Copyright (c) 2021 Red Hat.
#

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=0	# success is the default!
$sudo rm -rf $tmp $tmp.* $seq.full
trap "_cleanup; exit \$status" 0 1 2 3 15

_filter()
{
    sed \
	-e "s,$tmp.config,TMP.config,g" \
	-e "s,$tmp.pmlogconf,GROUPDIR,g" \
	-e "s/[0-9][0-9]*-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:.*/TIMESTAMP/g" \
    # end
}

# real QA test starts here
LC_TIME=POSIX

echo "Create a well-known set of pmlogconf templates"
mkdir -p $tmp.pmlogconf/qa
cat >$tmp.pmlogconf/qa/mmv <<EOF
#pmlogconf-setup 2.0
ident	Instrumented applications summary information
probe	mmv.control.files exists ? include : exclude
	mmv
EOF
cat >$tmp.pmlogconf/qa/hinv <<EOF
#pmlogconf-setup 2.0
ident	Instrumented applications summary information
probe	hinv.ncpu > 1 ? include : exclude
	hinv
EOF
cat >$tmp.pmlogconf/qa/pmproxy <<EOF
#pmlogconf-setup 2.0
ident	Instrumented applications summary information
probe	pmproxy.control.files exists ? include : exclude
	pmproxy
EOF
head $tmp.pmlogconf/qa/* >> $here/$seq.full
pmlogconf -d $tmp.pmlogconf $tmp.config 2>&1 | _filter
echo "== Initial pmlogger config created" | tee -a $here/$seq.full
cat $tmp.config | tee -a $here/$seq.full | _filter

echo "== Modify deltas and ensure changed values persist"
cat >$tmp.expect <<EOF
yes
1 minute
yes
5 seconds
no
yes
EOF
cat $tmp.expect | pmlogconf -d $tmp.pmlogconf $tmp.config | _filter
echo
echo

echo "== Completed pmlogger configuration"
cat $tmp.config | _filter

# success, all done
exit
