#!/bin/sh
# kmchart QA Test No. 008
# Copyright (c) 2008 Aconex.  All Rights Reserved.
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#
# Metrics class error handling, instance matching etc.
#
seq=`basename $0`
echo "QA output created by $seq"

# get standard filters
. ./common.filter

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

# real QA test starts here
localhost=`hostname`
otherhost=no.such.host
dump="kmdumptext -s 1"
tz=`pmprobe -v pmcd.timezone | sed -e 's/.* "//' -e 's/"//'`

_filter()
{
    sed \
    	-e "s/$otherhost[\.a-zA-Z0-9\-]*/OTHER_HOST/g" \
    	-e "s/$localhost[\.a-zA-Z0-9\-]*/THIS_HOST/g" \
	-e "s#$tz#TZ#"
}

echo "--- bogus host ---"
$dump -h bogus.host.i.hope hinv.ncpu 2>&1 | _filter
$dump bogus.host.i.hope:hinv.ncpu 2>&1 | _filter

echo "--- bogus archive ---"
$dump -a bogus_archive_i_hope 2>&1 | _filter
$dump bogus_archive_i_hope/hinv.ncpu 2>&1 | _filter

echo "--- bogus metric ---"
$dump go.faster 2>&1 | _filter

echo "--- bogus instance ---"
$dump "kernel.percpu.cpu.user[cpu999999]" 2>&1 | _filter

echo "--- metric has no instances ---"
$dump "hinv.ncpu[cpu0]" 2>&1 | _filter

echo "--- matching instances up to leading space ---"
$dump -imC "kernel.all.load[15,5,1]" 2>&1 | _filter

echo "--- two archives from the same host ---"
$dump -a archives/gap,archives/gap2 hinv.ncpu 2>&1 | _filter
$dump -a archives/gap2 archives/gap/hinv.ncpu 2>&1 | _filter

echo "--- no matching archive for host ---"
$dump -a archives/gap ${otherhost}:hinv.ncpu 2>&1 | _filter

echo "--- live and archive contexts ---"
$dump -h $localhost archives/gap/hinv.ncpu 2>&1 | _filter

echo "--- handle a string or aggregate metric ---"
$dump -f "TIME:" pmcd.timezone sample.sysinfo 2>&1 | _filter

# success, all done
status=0
exit
