#!/bin/bash
# This script installs ltp and runs the regression tests
###SHELLPACK preamble ltp-bench full-20120104
LTP_RUN_TESTS="controllers"

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargParam --ltp-tests LTP_RUN_TESTS
###SHELLPACK parseargParam --ltp-args LTP_RUN_ARGS
###SHELLPACK parseargParam --ltp-iterations LTP_RUN_ITERATIONS
###SHELLPACK parseargEnd

###SHELLPACK check_install_required ltp-${VERSION}

# Run the testsuite
cd $SHELLPACK_SOURCES/ltp-${VERSION}-installed || die Failed to cd to ltp install directory
export LTPROOT=`pwd`
export PATH=$PATH:$LTPROOT/testcases/bin

if [ "$LTP_RUN_ITERATIONS" = "" ]; then
	LTP_RUN_ITERATIONS=1
fi

for TEST in $LTP_RUN_TESTS; do
	echo Executing $TEST LTP test
	RESULTS="$LOGDIR_RESULTS"
	mkdir -p $RESULTS

	for ITER in `seq 1 $LTP_RUN_ITERATIONS`; do
		if [ "$TEST" = "test-direct-process" ]; then
			# This is part of a CPU hotplug reproduction case. It hammers
			# process creation and is intended as a scheduler stress test
			( ./testcases/bin/process -b 10 -d 5 || die ltp $TEST failed ) | tee $RESULTS/log-$TEST.txt
		elif [ -e runtest/$TEST ]; then
			( ./runltp -f $TEST $LTP_RUN_ARGS 2>&1 || die ltp $TEST failed ) | tee $RESULTS/log-$TEST.txt
		elif [ -e testcases/bin/$TEST ]; then
			( ./testcases/bin/$TEST $LTP_RUN_ARGS 2>&1 || die ltp $TEST failed ) | tee $RESULTS/log-$TEST.txt
		else
			( ./runltp $TEST $LTP_RUN_ARGS 2>&1 || die ltp $TEST failed ) | tee $RESULTS/log-$TEST.txt
		fi
	done

	# Check for failures
	#grep -v PASS $RESULTS/log-$TEST.txt > $RESULTS/failed_tests.txt
	#TEST=`cat $RESULTS/failed_tests.txt`
	#if [ "$TEST" != "" ]; then
	#	echo
	#	echo Some ltp regression tests reported failure | tee -a $LOGDIR/summary
	#	cat $RESULTS/failed_tests.txt | tee -a $LOGDIR/summary
	#	echo
	#
	#	echo ltp successfully installed but some regression tests failed | tee -a $LOGDIR/summary
	#	exit $SHELLPACK_ERROR
	#fi
done

echo
exit $SHELLPACK_SUCCESS
