#!/bin/sh
# PCP QA Test No. 121
# check that pmlogconf finds new groups, pv 893249
#
# Copyright (c) 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

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


# real QA test starts here
pmlogconf $tmp.in >/dev/null 2>&1
echo "--- default config ---" >>$seq_full
cat $tmp.in >>$seq_full
cp $tmp.in $seq_full.in

# strip comments, access control, empty lines and then strip the groups:
#	disk/summary
#	kernel/bufcache-all to memory/swap
sed <$tmp.in >$tmp.ref \
    -e '/^#$/d' \
    -e '/^# /d' \
    -e '/^\[access\]/d' \
    -e '/^disallow /d' \
    -e '/^allow /d' \
    -e '/^[ 	]*$/d'
cat <<End-of-File >>$tmp.ref

# DO NOT UPDATE THE FILE ABOVE THIS LINE
# Otherwise any changes may be lost the next time pmlogconf is
# used on this file.
#
# It is safe to make additions from here on ...
#
End-of-File

$PCP_AWK_PROG <$tmp.ref >$tmp.tmp '
/^#\+ disk\/summary/	{ state = 1; next }
state == 1 && /^#----/	{ state = 0; next }
/^#\+ kernel\/bufcache-all/		{ state = 2; next }
state == 2 && /^#\+ memory\/swap/{ state = 1; next }
state == 0		{ print }'
cp $tmp.tmp $tmp.in
echo >>$seq_full
echo "--- culled and stripped config ---" >>$seq_full
cat $tmp.in >>$seq_full
cp $tmp.in $seq_full.cull

# now process again ... the diffs should be small
#
echo >>$seq_full
echo "--- pmlogconf ---" >>$seq_full
( echo q; echo y ) | pmlogconf -v $tmp.in >>$seq_full 2>&1

grep Error: $seq_full

echo >>$seq_full
echo "--- final config ---" >>$seq_full
cat $tmp.in >>$seq_full
cp $tmp.in $seq_full.out

echo "Expect few differences ..."
sed -e '/^[ 	]*$/d' $tmp.ref | LC_COLLATE=POSIX sort >$tmp.ref.sort
sed -e '/^[ 	]*$/d' $tmp.in | LC_COLLATE=POSIX sort >$tmp.in.sort
diff $tmp.ref.sort $tmp.in.sort

# success, all done
exit
