#! /bin/sh
# PCP QA Test No. 068
# pmNewContext() bad error status if pmcd is not running
#
# Note: this is the simplest test to get the pmcd start/stop filtering
#	to be correct ... use this to tune _filter_pcp_start() and
#	_filter_pcp_stop() in common.filter
#
# 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

_needclean=true
LOCALHOST=`hostname`

trap "_cleanup" 0 1 2 3 15

# don't need to regenerate config.default with pmlogconf
#
export PMLOGGER_CHECK_SKIP_LOGCONF=yes

_stop_auto_restart pmcd

if [ -d $PCP_LOG_DIR/pmlogger ]
then
    LOGGING_DIR=$PCP_LOG_DIR/pmlogger
else
    LOGGING_DIR=$PCP_LOG_DIR
fi

_cleanup()
{
    echo >>$seq.full
    echo "--- cleanup ---" >>$seq.full
    if [ $_needclean ]
    then
	pmafm $LOGGING_DIR/$LOCALHOST/Latest remove >$tmp.cmd 2>&1 \
	&& $sudo sh $tmp.cmd
	echo >>$seq.full
	echo "--- pcp stop ---" >>$here/$seq.full
	_service pcp stop >>$here/$seq.full 2>&1
	echo "--- pcp start ---" >>$here/$seq.full
	_service pcp start 2>&1 | tee -a $here/$seq.full | _filter_pcp_start
	_restore_auto_restart pmcd
	echo >>$here/$seq.full
	echo "--- _wait_for_pmcd ---" >>$here/$seq.full
	_wait_for_pmcd | tee -a $here/$seq.full
	echo >>$here/$seq.full
	echo "--- _wait_for_pmlogger ---" >>$here/$seq.full
	_wait_for_pmlogger | tee -a $here/$seq.full
    fi
    rm -f $tmp.*
    exit 0
}

rm -f $seq.full

# real QA test starts here
echo "--- pcp stop ---" >>$here/$seq.full
_service pcp stop | tee -a $here/$seq.full | _filter_pcp_stop
echo >>$here/$seq.full
echo "--- run pmcdgone ---" >>$here/$seq.full
$sudo src/pmcdgone | tee -a $here/$seq.full
