diff --git a/examples2/automaton/DFSM1IS.xml b/examples2/automaton/DFSM1IS.xml index ded0536a9862ed421112b7bba32acdd966932b6e..f96552bbb98f7d126190e7d6a4537280554c8be3 100644 --- a/examples2/automaton/DFSM1IS.xml +++ b/examples2/automaton/DFSM1IS.xml @@ -10,9 +10,9 @@ <LabeledSymbol><PrimitiveLabel><Character>0</Character></PrimitiveLabel></LabeledSymbol> <LabeledSymbol><PrimitiveLabel><Character>1</Character></PrimitiveLabel></LabeledSymbol> </inputAlphabet> - <initialStates> + <initialState> <PrimitiveLabel><String>['S']</String></PrimitiveLabel> - </initialStates> + </initialState> <finalStates> <PrimitiveLabel><String>['A', 'C', 'S']</String></PrimitiveLabel> </finalStates> diff --git a/examples2/automaton/FSM.xml b/examples2/automaton/FSM.xml index 0e48fb790f056c89388d139b3be865051133ad9e..bbd2b2250fd63f57f238820c941246f402dd5c14 100644 --- a/examples2/automaton/FSM.xml +++ b/examples2/automaton/FSM.xml @@ -9,6 +9,12 @@ <LabeledSymbol><PrimitiveLabel><Character>0</Character></PrimitiveLabel></LabeledSymbol> <LabeledSymbol><PrimitiveLabel><Character>1</Character></PrimitiveLabel></LabeledSymbol> </inputAlphabet> + <initialState> + <PrimitiveLabel><String>one</String></PrimitiveLabel> + </initialState> + <finalStates> + <PrimitiveLabel><String>one</String></PrimitiveLabel> + </finalStates> <transitions> <transition> <from><PrimitiveLabel><String>four</String></PrimitiveLabel></from> @@ -51,10 +57,4 @@ <to><PrimitiveLabel><String>two</String></PrimitiveLabel></to> </transition> </transitions> - <initialStates> - <PrimitiveLabel><String>one</String></PrimitiveLabel> - </initialStates> - <finalStates> - <PrimitiveLabel><String>one</String></PrimitiveLabel> - </finalStates> </DFA> diff --git a/examples2/regexp/regexp.xml b/examples2/regexp/regexp.xml index d23d63e18f00a157679defe6c4a4b2b1aa9e4248..0f186abdf941afe4308185bc43c1a52f31bb8702 100644 --- a/examples2/regexp/regexp.xml +++ b/examples2/regexp/regexp.xml @@ -2,6 +2,8 @@ <alphabet> <LabeledSymbol><PrimitiveLabel><Integer>0</Integer></PrimitiveLabel></LabeledSymbol> <LabeledSymbol><PrimitiveLabel><Integer>1</Integer></PrimitiveLabel></LabeledSymbol> + <LabeledSymbol><PrimitiveLabel><Integer>11</Integer></PrimitiveLabel></LabeledSymbol> + <LabeledSymbol><PrimitiveLabel><Integer>10</Integer></PrimitiveLabel></LabeledSymbol> </alphabet> <concatenation> <LabeledSymbol><PrimitiveLabel><Integer>0</Integer></PrimitiveLabel></LabeledSymbol> @@ -13,4 +15,4 @@ <LabeledSymbol><PrimitiveLabel><Integer>10</Integer></PrimitiveLabel></LabeledSymbol> </alternation> </concatenation> -</regexp> +</UnboundedRegExp> diff --git a/examples2/regexp/regexp2.xml b/examples2/regexp/regexp2.xml index 416b2944d424f1854b076db29ea6696db176d89b..ea05ae8ae75a475437302b1a69c748c538ce8411 100644 --- a/examples2/regexp/regexp2.xml +++ b/examples2/regexp/regexp2.xml @@ -2,6 +2,8 @@ <alphabet> <LabeledSymbol><PrimitiveLabel><Integer>0</Integer></PrimitiveLabel></LabeledSymbol> <LabeledSymbol><PrimitiveLabel><Integer>1</Integer></PrimitiveLabel></LabeledSymbol> + <LabeledSymbol><PrimitiveLabel><Integer>11</Integer></PrimitiveLabel></LabeledSymbol> + <LabeledSymbol><PrimitiveLabel><Integer>10</Integer></PrimitiveLabel></LabeledSymbol> </alphabet> <concatenation> <LabeledSymbol><PrimitiveLabel><Integer>0</Integer></PrimitiveLabel></LabeledSymbol> @@ -21,4 +23,4 @@ </iteration> </alternation> </concatenation> -</regexp> +</UnboundedRegExp> diff --git a/examples2/regexp/regexp4.xml b/examples2/regexp/regexp4.xml index 66d982807e4e1dc6233db9313d3c2a74a262eda0..0814207514d578b7efec6e5c60724ba2f57198ec 100644 --- a/examples2/regexp/regexp4.xml +++ b/examples2/regexp/regexp4.xml @@ -24,4 +24,4 @@ </iteration> </alternation> </concatenation> -</regexp> +</UnboundedRegExp> diff --git a/makefile b/makefile index 0d9c6b4d220e3aa83d3c255aae06909e3241c489..81db1d4c6a9e9d84fa17df96e9168658bb843f21 100644 --- a/makefile +++ b/makefile @@ -70,6 +70,7 @@ debug : all-debug for dir in $(SUBDIRS_BINS); do \ cp $$dir/bin-debug/* $(addsuffix -debug, $(BINFOLDER)); \ done + ./tests.examples.sh debug ./tests.aconversion.sh debug ./tests.aderivation.aintegral.sh debug @@ -82,6 +83,7 @@ release: all-release for dir in $(SUBDIRS_BINS); do \ cp $$dir/bin-release/* $(addsuffix -release, $(BINFOLDER)); \ done + ./tests.examples.sh release ./tests.aconversion.sh release ./tests.aderivation.aintegral.sh release diff --git a/tests.aconversion.sh b/tests.aconversion.sh index 1e7defbdd67b924560d0d6ab31172079ee40167e..233819baf8b227722f54181ece8c9616f23e4a5b 100755 --- a/tests.aconversion.sh +++ b/tests.aconversion.sh @@ -141,9 +141,9 @@ function runTest { do runTest2 "$1" "$(generateNFA)" registerResult $? - done + done - outputResults + outputResults } # FA -> RG -> FA diff --git a/tests.aderivation.aintegral.sh b/tests.aderivation.aintegral.sh index a7b5b0ef6c4c704bfd52f5a39a8e0d6473c161b6..f904f66e8c2ac1efcfa47eda1dba17e24cd92b11 100755 --- a/tests.aderivation.aintegral.sh +++ b/tests.aderivation.aintegral.sh @@ -25,8 +25,8 @@ function regexpToMDFA { } function compareRegexp { - regexpToMDFA "$1" > tmp1.xml - regexpToMDFA "$2" > tmp2.xml + regexpToMDFA "$1" > tmp1.xml + regexpToMDFA "$2" > tmp2.xml # relies on ret code by adiff.automaton ./acompare2 tmp1.xml tmp2.xml > /dev/null @@ -40,7 +40,7 @@ function compareRegexp { # $1 - input regexp # $2 - output regexp function runTest { - compareRegexp "$1" "$2" + compareRegexp "$1" "$2" TEST_EXITVALUE=$? @@ -59,24 +59,24 @@ function runTest { } function runTestD { - FILE_REGEXP_ORIG=$(echo "$1") - FILE_REGEXP_RESULT=$(echo "$2") - shift 2 + FILE_REGEXP_ORIG=$(echo "$1") + FILE_REGEXP_RESULT=$(echo "$2") + shift 2 - REGEXP_DERIVATIVE=$(./aconvert2 --string_from_string <<< "$1" | ./aderivations2 -r $TESTS_DIR/$FILE_REGEXP_ORIG -s - ) - REGEXP_RESULT=$(cat $TESTS_DIR/$FILE_REGEXP_RESULT) - runTest "$REGEXP_DERIVATIVE" "$REGEXP_RESULT" + REGEXP_DERIVATIVE=$(./aconvert2 --string_from_string <<< "$1" | ./aderivations2 -r $TESTS_DIR/$FILE_REGEXP_ORIG -s - ) + REGEXP_RESULT=$(cat $TESTS_DIR/$FILE_REGEXP_RESULT) + runTest "$REGEXP_DERIVATIVE" "$REGEXP_RESULT" } function runTestI { - FILE_REGEXP_ORIG=$(echo "$1") - FILE_REGEXP_RESULT=$(echo "$2") - shift 2 + FILE_REGEXP_ORIG=$(echo "$1") + FILE_REGEXP_RESULT=$(echo "$2") + shift 2 - REGEXP_INTEGRAL=$(./aconvert2 --string_from_string <<< "$1" | ./aintegral2 -r $TESTS_DIR/$FILE_REGEXP_ORIG -s - ) - REGEXP_RESULT=$(cat $TESTS_DIR/$FILE_REGEXP_RESULT) + REGEXP_INTEGRAL=$(./aconvert2 --string_from_string <<< "$1" | ./aintegral2 -r $TESTS_DIR/$FILE_REGEXP_ORIG -s - ) + REGEXP_RESULT=$(cat $TESTS_DIR/$FILE_REGEXP_RESULT) - runTest "$REGEXP_INTEGRAL" "$REGEXP_RESULT" + runTest "$REGEXP_INTEGRAL" "$REGEXP_RESULT" } diff --git a/tests.examples.sh b/tests.examples.sh new file mode 100755 index 0000000000000000000000000000000000000000..89b648ed41c04a08ca3d0f5be529865b65c4817d --- /dev/null +++ b/tests.examples.sh @@ -0,0 +1,133 @@ +#!/usr/bin/env bash + +# $1 test dir suffix (debug / release) + +# SETTINGS +TESTCASE_TIMEOUT=10 +LOGFILE="log_tests.txt" + +EXECUTABLES="aecho2" +TESTS_DIR="../examples2" + +RES_GOOD=0 +RES_FAIL=0 +RES_TIME=0 +RES_SEGV=0 +RES_UNKN=0 + + +# ---------------------------- + +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 + echo "$3" >> $LOGFILE + echo "command out:" >> $LOGFILE + echo "$4" >> $LOGFILE +} + +# $1 = command for conversion. Output of such command must be (eps-)NFA !! +# $2 = automaton +function runTest2 { + TMPNFA="nfa.xml" + echo "$2" > $TMPNFA + + OUT=`timeout $TESTCASE_TIMEOUT bash -c "cat $TMPNFA | ./aecho2 "` + RET=$? + + if [ $RET == 0 ]; then # ok + rm $TMPNFA + return 0 + fi + + log "$1" $RET "$(cat $TMPNFA)" "$OUT" + rm $TMPNFA + + 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 "." + ((RES_GOOD++)) + ;; + 1) + echo -n "x" + ((RES_FAIL++)) + ;; + 2) + echo -n "T" + ((RES_TIME++)) + ;; + 3) + echo -n "E" + ((RES_SEGV++)) + ;; + *) + echo -n "?" + ((RES_UNKN++)) + ;; + esac +} + +function clearResults { + RES_GOOD=0 + RES_FAIL=0 + RES_TIME=0 + RES_SEGV=0 + RES_UNKN=0 +} + +function outputResults { + # summary + echo -ne "\n\t" + echo "RES: GOOD:" $RES_GOOD ", FAIL:" $RES_FAIL ", TIME:" $RES_TIME ", SEGV:" $RES_SEGV, "UNKN:" $RES_UNKN + echo "" +} + +# $1 - aconversions2 sequence +function runTest { + echo $1 + echo -ne "\t" + + clearResults + + # predefined tests first + for FILE in `ls $TESTS_DIR/$1/*.xml`; do + runTest2 "$1" "$(cat $FILE)" + registerResult $? + done + + outputResults +} + +runTest "automaton" +runTest "grammar" +runTest "regexp" +runTest "string" +