#!/bin/sh
# PCP QA Test No. 1407
# test pmchart with Iostat view
#
# Copyright (c) 2018 Red Hat.  All Rights Reserved.
#

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

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

which pmchart >/dev/null 2>&1 || _notrun "pmchart not installed"
[ -z "$DISPLAY" -a -z "$PCPQA_CLOSE_X_SERVER" ] && _notrun "need DISPLAY or PCPQA_CLOSE_X_SERVER"

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

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

if [ -z "$DISPLAY" ]
then
    export DISPLAY=$PCPQA_CLOSE_X_SERVER
fi

_filter()
{
    sed -e '/^QStandardPaths: XDG_RUNTIME_DIR not set.*/d'
}

_checkerr()
{
    sed <$tmp.err \
	-e '/libGL error: No matching fbConfigs/d' \
	-e '/libGL error: failed to load driver: swrast/d' \
    | _filter > $tmp.tmp
    if [ -s $tmp.tmp ]
    then
	echo "Arrgh ... stderr from pmchart ..."
	cat $tmp.err
	exit
    fi
}

# check pmchart can parse Iostat view
#
export PCP_STDERR=$tmp.err
pmchart -C -c Iostat 2>&1 | _filter
[ -s $tmp.err ] && _checkerr

echo expect no output, especially no qt/scaling or divide by zero exceptions
pmchart -z -a $here/archives/zero_disk_activity -c Iostat -t 0.1 -O'@fri jul 13 00:11:40' -o $tmp.out.png 2>>$tmp.err
_checkerr

# success, all done
status=0
exit
