#! /bin/sh
# PCP QA Test No. 392
# Rebuild problems with duplicates and check irix.* and hw.* culling
# when -u used
#
# Since Rebuild is being enhanced for irix namespace stripping, the 'irix' names 
# have been replaced with 'hpux' names to maintain the purpose of the test, but 
# to prevent the unwanted translation from an irix namespace to non-irix.
# hpux was chosed since it is 'replaced' in the old and new Rebuilds.
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

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

seq=`basename $0`

rm -f $seq.out
if [ $PCP_VER -lt 3600 ]
then
    ln $seq.out.1 $seq.out || exit 1
else
    ln $seq.out.2 $seq.out || exit 1
fi

echo "QA output created by $seq"

status=1	# failure is the default!
trap "cd $here; rm -rf $tmp; exit \$status" 0 1 2 3 15

_filter()
{
	sed -e '/^Rebuild/s/\/.*pmnsmerge/pmnsmerge/g'
}

_copy_Rebuild()
{
    scr_src=$PCP_VAR_DIR/pmns/
    cp $scr_src/Rebuild $1
    if [ -f $scr_src/Xlate-irix-names ]
    then
	cp $scr_src/Xlate-irix-names $1
    fi
}

mkdir $tmp
cd $tmp
cat <<'End-of-File' >root.start
root {
	hw
	hpux
	foo
}
hw {
	old_hw	1:44:0
	both_hw	1:44:1
}
foo {
	bar	1:2:0
}
hpux {
	old_irix 1:10:0
	both_irix 1:10:1
	hub
}
hpux.hub {
	nasid	1:44:8
}
End-of-File

cat <<'End-of-File' >root_irix
root {
	hw
	hpux
}
hw {
	both_hw	1:44:1
	new_hw	1:44:2
	hub
}
hw.hub {
	nasid	1:44:8
}
hpux {
	both_irix 1:10:1
	new_irix 1:10:2
}
End-of-File


# Rebuild will write a message to SYSLOG when it fails,
# so write a message to SYSLOG that this is expected, and generated by QA
#
logger -p user.notice -t PCP "qa/$seq running ... expect SYSLOG entry from Rebuild failure"

_copy_Rebuild .

# real QA test starts here
#
echo "=== Rebuild ==="
echo "(expect Duplicate PMID failure)"
rm -f root root.bin
cp root.start root
$sudo ./Rebuild 2>&1 \
| sed \
    -e 's;/private/;/;' \
    -e "s;$tmp;.;" \
| _filter
if [ $PCP_VER -lt 3600 ]
then
    [ -f root.bin ] && echo "root.bin created"
    pminfo -m -n root
else
    pminfo -m -N root
fi

echo
echo "=== Rebuild -d ==="
rm -f root root.bin
cp root.start root
$sudo ./Rebuild -d | _filter
if [ $PCP_VER -lt 3600 ]
then
    [ -f root.bin ] && echo "root.bin created"
    pminfo -m -n root
else
    pminfo -m -N root
fi

echo
echo "=== Rebuild -du ==="
rm -f root root.bin
cp root.start root
$sudo ./Rebuild -du | _filter
if [ $PCP_VER -lt 3600 ]
then
    [ -f root.bin ] && echo "root.bin created"
    pminfo -m -n root
else
    pminfo -m -N root
fi

# success, all done
status=0
exit
