#!/bin/sh
# PCP QA Test No. 1000
# pmdumptext segv
# https://bugzilla.redhat.com/show_bug.cgi?id=1131779
#
# Copyright (c) 2014 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

which pmdumptext >/dev/null 2>&1 || _notrun "pmdumptext not installed"

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

# filter ...
# Fri Aug 22 20:04:55	7950508.000
#
_filter1()
{
    sed \
	-e 's/[A-Z][a-z][a-z] [A-Z][a-z][a-z]  *[0-9][0-9]* [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/DATE/' \
	-e 's/[ 	][ 	]*[0-9][0-9]*\.[0-9][0-9]*/ NUMBER/'
}

# hostname(1)
#
_filter2()
{
    sed -e "s/`hostname`/MYHOSTNAME/g"
}

# real QA test starts here
echo "=== expect output ==="
pmdumptext -s 1 'localhost:mem.util.used' | _filter1

echo
echo "=== expect No route to host, no valid metrics ==="
pmdumptext -s 1 'no.such.host.pcp.io:mem.util.used'

echo
echo "=== expect No route to host, no valid metrics [instance case] ==="
pmdumptext -s 1 'no.such.host.pcp.io:proc.psinfo.utime[12345]'

echo
echo "=== expect No route to host, no valid metrics -h [instance case] ==="
pmdumptext -s 1 -h no.such.host.pcp.io 'proc.psinfo.utime[12345]'

$sudo $PCP_RC_DIR/pcp stop >/dev/null
echo
echo "=== pmcd not running, default case ==="
pmdumptext -s 1 'sample.bin[bin-300]' 2>&1 | _filter2
echo
echo "=== pmcd not running, host in metricspec case ==="
pmdumptext -s 1 'localhost:proc.psinfo.utime[12345]'
echo
echo "=== pmcd not running, -h localhost case ==="
pmdumptext -s 1 -h localhost 'proc.psinfo.utime[12345]'
$sudo $PCP_RC_DIR/pcp start >/dev/null

# success, all done
status=0

exit
