#! /bin/sh
# PCP QA Test No. 638
# pmnsdel concurrency issues - pv #826904
#
# 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=0	# success is the default!
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15

_del()
{
    while true
    do
	pmlock $tmp.root.lock && break
	sleep 1
    done
    pmnsdel -n $tmp.root $1
    rm -f $tmp.root.lock
}

cat <<End-of-File >$tmp.master
/*
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
*/
root {
    one
    two
    three
    keep1 	1:0:1
    d1		1:1:1
    keep2 	2:0:2
}
/*
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
*/

one {
    d2		2:1:2
    one
}
/*
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
*/

one.one {
    d3		3:1:3
    one
    d6		6:1:6
    d7		7:1:7
    d8		8:1:8
}
/*
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
*/

one.one.one {
    keep4	4:0:4
}
/*
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
*/

two {
    keep3 	3:0:3
    d4		4:1:4
    d9		9:1:9
}
/*
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
*/

three {
    one
}
/*
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
*/

three.one {
    d5		5:1:5
}
/*
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
*/
End-of-File


# real QA test starts here
echo "Initial state ..."
pminfo -m -n $tmp.master

echo
echo "Serial deletions ..."
cp $tmp.master $tmp.root
for m in d1 one.d2 one.one.d3 two.d4 three.one.d5 one.one.d6 \
	 one.one.d7 one.one.d8 two.d9
do
    pmnsdel -n $tmp.root $m 2>&1
done \
| grep ' leaf' \
| LC_COLLATE=POSIX sort -nr
echo
pminfo -m -n $tmp.root

echo
echo "Parallel deletions ..."
cp $tmp.master $tmp.root
rm -f $tmp.out
for m in d1 one.d2 one.one.d3 two.d4 three.one.d5 one.one.d6 \
	 one.one.d7 one.one.d8 two.d9
do
    _del $m >$tmp.out.$m 2>&1 &
done
wait

cat $tmp.out.* \
| grep ' leaf' \
| LC_COLLATE=POSIX sort -nr
echo

for f in $tmp.out.*
do
    echo >>$seq.full
    echo "=== $f ===" >>$seq.full
    cat $f >>$seq.full
done

pminfo -m -n $tmp.root

# success, all done
exit
