#! /bin/sh
# PCP QA Test No. 1051 (formerly 582)
# pmieconf dumps core
#
# Copyright (c) 2015 Red Hat.
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

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

which pmieconf >/dev/null 2>&1 || _notrun "No pmieconf binary installed"
[ -f $PCP_PMDAS_DIR/shping/pmdashping ] || _notrun "shping pmda not installed"

rm -f $seq.out
case $PCP_PLATFORM
in
    linux|darwin|solaris)
	ln $seq.out.$PCP_PLATFORM $seq.out || exit 1
	;;
    *)
	_notrun "Need qualified output for $PCP_PLATFORM"
	;;
esac

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

cat <<End-of-File >$tmp.conf
// pmieconf-pmie 1 $PCP_VAR_DIR/config/pmieconf
// 0 global delta = "1 min"
// 0 global hosts = ""
// 1 cpu.excess_fpe enabled = yes
// 1 cpu.load_average enabled = yes
// 1 cpu.syscall enabled = yes
// 1 cpu.system enabled = yes
// 1 cpu.util enabled = yes
// 1 craylink.node_cb_errs enabled = yes
// 1 craylink.router_cb_errs enabled = yes
// 1 filesys.buffer_cache enabled = yes
// 1 filesys.filling enabled = yes
// 1 memory.exhausted enabled = yes
// 1 memory.swap_low enabled = yes
// 1 network.buffers enabled = yes
// 1 network.tcp_drop_connects enabled = yes
// 1 network.tcp_retransmit enabled = yes
// 1 shping.status enabled = yes
// end
//
// --- START GENERATED SECTION (do not change this section) ---
//     generated by pmieconf on:  Wed May 19 10:35:42 1999
//

End-of-File

_filter()
{
    sed \
	-e '/not currently available/d' \
	-e '/Unknown or illegal metric identifier/d' \
	-e '/not in namespace/d' \
	-e '/Unknown metric name/d'
}

$sudo rm -f core* $seq.core* $seq.full

# real QA test starts here

pmieconf -f $tmp.conf m global syslog_prefix '$bogus_macro_name$' 2>&1 \
| tee $seq.full \
| _filter

echo >>$seq.full
echo "=== configured rules ===" >>$seq.full
cat $tmp.conf >>$seq.full
echo >>$seq.full
echo "=== pmie output ===" >>$seq.full

_check_core

if [ $status = 0 ]
then
    pmie -C $tmp.conf 2>&1 \
    | tee -a $seq.full \
    | _filter
fi

exit
