#!/bin/sh
# PCP QA Test No. 905
# Interoperability with PCP 2.7 version protocols
#
# Copyright (c) 2016 Ken McDonell.  All Rights Reserved.
#

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

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

downrev=`getpmcdhosts -L -n 1 -v 'pcp>=2.7' -v 'pcp<2.8'`
[ -n "$downrev" ] || _notrun "Cannot find a PCP 2.7 QA host"

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

rm -f $seq.out
case $PCP_PLATFORM
in
    linux)
	ln $seq.out.linux $seq.out || exit 1
	;;
    darwin)
	ln $seq.out.darwin $seq.out || exit 1
	;;
    *)
	_notrun "Need qualified $seq.out.$PCP_PLATFORM"
	;;
esac

localhost=`hostname`

_filter()
{
    sed \
	-e '/^host:/{
s/'"$downrev"'/DOWNREV/
s/'"$localhost"'/LOCALHOST/
}' \
	-e '/^Name space load:/s/[0-9][0-9.]*/N.NN/' \
    # end
}

# real QA test starts here
( echo "downrev=$downrev"; pminfo -f -h "$downrev" pmcd.version ) >>$seq_full

echo "Clients locally, down-rev remote pmcd ..."
echo --- pmval ---
pmval -h $downrev -i bin-100,bin-500,bin-900 -s 2 -t 0.25 sample.bin 2>&1 \
| _filter
echo
echo --- torture_api ---
src/torture_api -s 2 -h $downrev -n $seq.pmns 2>&1 \
| _filter

# Note:
# 	For PCP 2.7.x, the QA suite was in a separate git tree and the
# 	directory structure was not the same, so paths to PCP QA binaries
# 	may be different
echo
echo "Clients on down-rev host, local pmcd ..."
echo --- pmval ---
ssh pcpqa@$downrev pmval -h $localhost -i bin-100,bin-500,bin-900 -s 2 -t 0.25 sample.bin 2>&1 \
| _filter
echo
echo --- torture_api ---
ssh pcpqa@$downrev qa/src-oss/torture_api -s 2 -h $localhost 2>&1 \
| _filter

# success, all done
status=0

exit
