#! /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.
#

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

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

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 ==="
rm -f root root.bin
cp root.start root
$sudo ./Rebuild | _filter
pminfo -m -n root

echo
echo "=== Rebuild -u ==="
rm -f root root.bin
cp root.start root
$sudo ./Rebuild -u | _filter
pminfo -m -n root

# success, all done
status=0
exit
