#!/bin/ksh
#
#ident	"@(#)stop	1.8	04/12/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# Original Author: Michael Koller
#
# This is the script that is called by the web page "STOP TESTS" button.
# It marks each test module log file with a line starting with
# the keyword "ERROR", which when found by the test monitoring process,
# will cause an abort of the test run, and mark all test modules as FAIL.

# variables
hctsdir=SUNWhcts			# base directory
hname=$1			# test system
mdir=menu			# menu directory
act=				# action to be taken
bname=`basename $0`		# shell name
gotocgi="http://$HTTP_HOST/cgi-bin/$hctsdir/$mdir/$bname"	# program name
prgdir=prgs			# program directory
stafrdir=/opt/SUNWstaf/reports	# STAF base directory
i=0				# loop counter

# functions

# do function
go_fun()
{
	$prgdir/funcs "$*" 2>&1
}

### MAIN ###

# change to base directory
cd `dirname $0`
while [ `basename $PWD` != $hctsdir ]
do
	cd ..
done

# parse input 
if [ -n "$CONTENT_LENGTH" ]
then
	eval `$prgdir/pq.p`
	CONTENT_LENGTH=
fi

# Stop Running Tests
if [ -z "$act" ]
then
	if [ -a $stafrdir/$hname/staf.rpt ]
	then
		for i in `ls $stafrdir/$hname/*.log.*`
		do
		# Mark each and every log file with a line containing "ERROR".
		# The test monitor framework continuously does a grep command
 		# looking for the keyword "ERROR" in all log files.
		# If "ERROR" is found, the monitoring process will abort all
		# running tests and shut down the test suite.
		# This is a simple way to do a user shutdown button.
                        echo "!ERROR: User STOP command issued. Shutting down." >> $i
                        echo "!ERROR: All test modules will be marked as FAIL." 
		done
		sleep 5
	fi
	exec $mdir/menu13 $hname
fi
