Skip to content
Snippets Groups Projects
tests.adeterminize.sh 2.92 KiB
Newer Older
#!/usr/bin/env bash

# $1 test dir suffix (debug / release)

# SETTINGS
TESTCASE_TIMEOUT=10
LOGFILE="log_tests.txt"

EXECUTABLES="aepsilon2 atrim2 adeterminize2 aminimize2 anormalize2 acompare2"
TESTS_DIR="`pwd`/examples2/automaton"
RES_GOOD=
RES_FAIL=
RES_TIME=
RES_SEGV=
RES_UNKN=


# ----------------------------

for FILE in $EXECUTABLES; do
	if [ ! -f bin-$1/$FILE ]; then
		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
		exit 1
	fi
done

cd bin-$1/
rm -f $LOGFILE

# ----------------------------

# $1 = conv command
# $2 = return code
# $3 = input automaton
# $4 = output of conversion
function log {
	echo "----------------------------------------------------------" >> $LOGFILE
	echo "conv: " $1 >> $LOGFILE
	echo "ret: " $2 >> $LOGFILE
	echo "input automaton:" >> $LOGFILE
Jan Trávníček's avatar
Jan Trávníček committed
	cat  "$3" >> $LOGFILE
	echo "command out:" >> $LOGFILE
	echo "$4" >> $LOGFILE
# $1 = what is beeing done (name)
# $2 = command for conversion. Output of such command must be (eps-)NFA !!
# $3 = automaton
# $4 = automaton to compare with
function runTest2 {
Jan Trávníček's avatar
Jan Trávníček committed
	OUT=`timeout $TESTCASE_TIMEOUT bash -c "./acompare2 <(cat $3 | $2 ) $4"`
	RET=$?

	if [ $RET == 0 ]; then # ok
		return 0
	fi

Jan Trávníček's avatar
Jan Trávníček committed
	log "$1" $RET "$3" "$OUT"

	if [ $RET == 124 ]; then # timeout
		return 2
	elif [ $RET -ge 124 ]; then #segv
		return 3
	else
		return 1
	fi
function registerResult {
	case $1 in
		0)
			echo -n "."
			echo -n "+1" >> $RES_GOOD
			echo -n "+1" >> $RES_FAIL
			echo -n "+1" >> $RES_TIME
			echo -n "+1" >> $RES_SEGV
			echo -n "+1" >> $RES_UNKN
function initResults {
	RES_GOOD=$(mktemp)
	echo -n "0" > $RES_GOOD
	RES_FAIL=$(mktemp)
	echo -n "0" > $RES_FAIL
	RES_TIME=$(mktemp)
	echo -n "0" > $RES_TIME
	RES_SEGV=$(mktemp)
	echo -n "0" > $RES_SEGV
	RES_UNKN=$(mktemp)
	echo -n "0" > $RES_UNKN
}

function clearResults {
	rm $RES_GOOD
	rm $RES_FAIL
	rm $RES_TIME
	rm $RES_SEGV
	rm $RES_UNKN
function outputResults {
	echo "" >> $RES_GOOD
	echo "" >> $RES_FAIL
	echo "" >> $RES_TIME
	echo "" >> $RES_SEGV
	echo "" >> $RES_UNKN

	# summary
	echo -ne "\n\t"
	echo "RES: GOOD:" $(bc < $RES_GOOD) ", FAIL:" $(bc < $RES_FAIL) ", TIME:" $(bc < $RES_TIME) ", SEGV:" $(bc < $RES_SEGV), "UNKN:" $(bc < $RES_UNKN)
# $1 - aconversions2 sequence
function runTest {
	echo $1 \($2\)
	echo -ne "\t"
	initResults
	# predefined tests first
	for FILE in `ls $TESTS_DIR/$1*.xml | grep -v DET`; do
Jan Trávníček's avatar
Jan Trávníček committed
		DET_FILE=${FILE%.xml}.DET.xml
		if [ -f ${DET_FILE} ]; then
			runTest2 $1 "$2" "$FILE" "$DET_FILE"
			registerResult $?
		fi
	done
	outputResults
	clearResults
runTest "NFSM" "./adeterminize2 | ./atrim2"
runTest "ENFSM" "./aepsilon2 | ./adeterminize2"
Jan Trávníček's avatar
Jan Trávníček committed
runTest "NIDPDA" "./adeterminize2"
runTest "NPDA" "./adeterminize2 | ./anormalize2 --labels automaton"
runTest "NVPA" "./adeterminize2"
runTest "RHDPDA" "./adeterminize2"
runTest "NFTA" "./adeterminize2"