#!/bin/ksh
#
#ident	"@(#)txrx.stf	1.8	04/12/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# This file is the control program for the test case of txrx.
#
# Variables
prgdir=../prgs                  # program directory
maxwarn=80   
rhname=$1

#functions
cleanup()
{
	echo "txrx ending!"
	kill -17 $txid
	rsh $rhname "pkill -x rx"
}

# Main
if [ $# -lt 4 ]
then
	#echo "!ERROR: $0 <ppp_client> <local_device_name> <remote_device_name> <baud_rate>"
	echo "!ERROR: $0 <rhname> <local_device_name> <remote_device_name> <baud_rate>"
	echo "!ERROR: $0 called with bad arguments."
	exit 1
fi

# SET LOGFILE FLAG FOR MAX WARNING COUNT
# This is checked by staf.eng, and if exceeded, staf.eng will kill this module.
echo "maxwarnings=${maxwarn}"

#ppp_client=$1
l_device=$2
r_device=$3
b_rate=$4

#ping $ppp_client 300
ping $rhname
if [ $? -ne 0 ]
then
	echo "!ERROR: Cannot ping ppp_client $ppp_client"
	exit 1
fi

#start the test case
rsh -l root $rhname "cd `pwd` ; txrx/bin/rx -d $r_device -b $b_rate >/dev/null &" &
rxid=$!
sleep 4
txrx/bin/tx -d $l_device -b $b_rate
wait $rxid 

rcp $rhname:/tmp/rx.tmp /tmp/rx.$rhname.tmp

cmp -s /tmp/rx.$rhname.tmp /tmp/tx.tmp

if [ $? -ne 0 ]
then
        echo "!PASS: The test could pass txrx test. \n"
else
        echo "!ERROR: The test could not pass txrx test. \n"
        rsh -l root $rhname rm -f /tmp/rx.tmp 
        rm -f /tmp/tx.tmp  /tmp/rx.$rhname.tmp
        exit 1
fi
        
rsh -l root $rhname rm -f /tmp/rx.tmp 
rm -f /tmp/tx.tmp  /tmp/rx.$rhname.tmp

