#!/bin/sh
# PCP QA Test No. 061
# exercise the logging state compatibility matrix
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

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

# get standard filters
. ./common.product
. ./common.filter
. ./common.check

trap "$sudo rm -f $tmp.*; exit" 0 1 2 3 15
signal=$PCP_BINADM_DIR/pmsignal

# Note1 - this line changed from msec to usec in 3.5.9:
# state: not in log, unavail, mand, on delta: 0 usec numpmid: 1
#
# Note2 - the first (posn=132) logputresult is the preamble
# and size of this result is influenced by hostname length.
#
_filter_pmlogger()
{
    _filter_pmlogger_log \
    | sed \
	-e '/[Ss]ignalled (signal=.*), exiting/d' \
	-e '/Warning: AF event queue is empty, nothing /d' \
	-e "/Warning /s/[0-9]*-[0-9]*\.config/SEQ-MYPID.config/" \
	-e 's/0x00000000/NULL/g' \
	-e 's/0x[0-9a-f]*/ADDR/g' \
	-e 's/(nil)/ADDR/g' \
	-e 's/value [0-9]*/value INT/g' \
	-e 's/[0-2][0-9]:00:00.000/TIME/' \
	-e '/logputresult/{
s/output len=[0-9]* posn=132/output len=NNN posn=132/g
s/len=[0-9]*/len=NNN/
s/posn=[0-9]*/posn=NNN/
}' \
	-e '/__pmLogPutIndex/{
s/stamp=[0-9][0-9]*\.[0-9][0-9]*/stamp=NNN.NNNNNN/
s/posn=[0-9]*/posn=NNN/g
}' \
	-e 's/msec numpmid/usec numpmid/'
}

_filter_dumplog()
{
    sed \
	-e '/pmResult/s/ .* numpmid/ ... numpmid/' \
	-e '/inst /{
s/inst \[[0-9][0-9]* or "dks..."]/inst [DISK]/
s;inst \[[0-9][0-9]* or "/dev/[^"]*"];inst [DISK];
s;inst \[[0-9][0-9]* or ".*/dbs/.*\.dbf"];inst [FILE];
}' \
	-e '/value /{
s/value [0-9][0-9]*\.[0-9][0-9]*e.[0-9][0-9]*/value NUMBER/
s/value [0-9][0-9]*\.[0-9][0-9]*/value NUMBER/
s/value [0-9][0-9]*e.[0-9][0-9]*/value NUMBER/
s/value [0-9][0-9]*/value NUMBER/
s/value \[.*]/value AGGREGATE/
s/value ".*"/value STRING/
}' \
	-e '/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/s/[^ ]*/TIMESTAMP/' \
	-e "/pmcd\.pmlogger\./s/$logger_pid/LOGGER_PID/g" \
	-e '/pmcd\.pmlogger\.port/s/value .*/value PORT/' \
	-e '/pmcd\.pmlogger\.host/s/value ".*/value "HOST"/' \
	-e '/pmcd\.pmlogger\.archive/s/value ".*/value "PATH"/' \
	-e "/\"$logger_pid\"/s/$logger_pid/LOGGER_PID/g" \
    | $PCP_AWK_PROG '
$1 == "TIMESTAMP" && NF == 4	{ print "TIMESTAMP       0       OFFSET       OFFSET"; next }
				{ print }'
}

# real QA test starts here

TZ=GMT
export TZ

for ctl in mandatory advisory
do
    for state in "on once" maybe off
    do
	[ "$ctl $state" = "advisory maybe" ] && continue
	for req_ctl in mandatory advisory
	do
	    for req_state in "on once" maybe off
	    do
		[ "$req_ctl $req_state" = "advisory maybe" ] && continue
		echo ""
		echo "$ctl $state -> $req_ctl $req_state"
		cat >$tmp.config <<End-of-File
log $ctl $state {
    sample.colour [ "blue" ]
}

log $req_ctl $req_state {
    sample.colour [ "blue" ]
}
End-of-File
		$sudo rm -f $tmp.0 $tmp.meta $tmp.index
		_start_up_pmlogger -L -D 640 -c $tmp.config -l $tmp.out $tmp >$tmp.err 2>&1
		logger_pid=$pid
		_wait_for_pmlogger $logger_pid $tmp.out
		src/logcontrol -p $logger_pid enquire sample.colour
		$sudo $signal -s TERM $logger_pid
		_wait_pmlogger_end $logger_pid
		cat $tmp.err $tmp.out | _filter_pmlogger
		if [ -s $tmp.0 ]
		then
		    pmdumplog $tmp | _filter_dumplog
		else
		    echo "Archive log is empty"
		fi
	    done
	done
    done
done

exit
