#!/bin/sh
# PCP QA Test No. 1556
# pmlogconf "force" clause
# 
# see https://github.com/performancecopilot/pcp/issues/2114
#
# Copyright (c) 2025 Ken McDonell.  All Rights Reserved.
#

if [ $# -eq 0 ]
then
    seq=`basename $0`
    echo "QA output created by $seq"
else
    # use $seq from caller, unless not set
    [ -n "$seq" ] || seq=`basename $0`
    echo "QA output created by `basename $0` $*"
fi

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

do_valgrind=false
if [ "$1" = "--valgrind" ]
then
    _check_valgrind
    do_valgrind=true
fi

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

status=0	# success is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

_filter()
{
    sed \
	-e "s@$tmp@TMP@g" \
	-e 's/^\*\*\* TMP.conf	.*/*** TMP.conf .../' \
	-e 's/^--- TMP.conf.new	.*/*** TMP.conf.new .../' \
    # end
}

# real QA test starts here
mkdir $tmp || exit

cat <<End-of-File >$tmp/bar
#pmlogconf-setup 2.0
ident	bar - force available
force	available
	sample.long
End-of-File
cat <<End-of-File >$tmp/foo
#pmlogconf-setup 2.0
ident	foo - probe
probe	sample.longlong.one exists ? available : exclude
	sample.longlong
End-of-File
cat <<End-of-File >$tmp/fumble
#pmlogconf-setup 2.0
ident	fumble - force include
force	include
	sample.float
End-of-File
cat <<End-of-File >$tmp/mumble
#pmlogconf-setup 2.0
ident	mumble - force exclude
force	exclude
	sample.double
End-of-File

ls -lf $tmp >>$seq_full

# answers to expected prompts when pmlogconf run for the second time
#
cat <<End-of-File >$tmp.ans
y

y

y
End-of-File

# initial setup ...
#
pmlogconf -d $tmp $tmp.conf 2>&1 | _filter
_filter <$tmp.conf

if $do_valgrind
then
    _run_valgrind ...your test goes here...
else
    pmlogconf <$tmp.ans -d $tmp $tmp.conf 2>&1
fi \
| _filter

echo
_filter <$tmp.conf

# success, all done
exit
