heptagon/test/check

335 lines
6.5 KiB
Text
Raw Permalink Normal View History

2010-06-21 12:11:06 +02:00
#!/bin/bash
2011-01-05 15:48:09 +01:00
checkdir=_check_builds
2010-07-02 16:03:04 +02:00
# TODO: rewrite in OCaml or something better than sh
2010-06-21 12:11:06 +02:00
shopt -s nullglob
# script de test
2011-01-05 15:48:09 +01:00
compilo=../../heptc
2011-11-02 17:23:23 +01:00
coption="-O"
2010-06-21 12:11:06 +02:00
# compilateurs utilises pour les tests de gen. de code
CAMLC=ocamlc
JAVAC=javac
LUSTREC=lustre
CC="gcc -std=c99 -I../../../lib/c -I../t1_c"
2010-06-21 12:11:06 +02:00
# par defaut : pas de test de generation de code
2011-07-06 09:50:51 +02:00
tomato=0
2012-01-25 10:10:17 +01:00
memalloc=0
2010-06-21 12:11:06 +02:00
java=0
lustre=0
2010-06-21 12:11:06 +02:00
c=0
minils=0
vhdl=0
2010-06-21 12:11:06 +02:00
score=0
max=0
verbose=0
2011-01-12 16:08:33 +01:00
clean=0
2010-06-21 12:11:06 +02:00
compile () {
2010-07-16 11:19:56 +02:00
args_comp=""
2010-07-02 16:03:04 +02:00
assert_node=$(eval grep CHECK $1 | awk '{ print $3 }')
if [ -n "$assert_node" ]; then
args_comp="-assert $assert_node"
fi
if [ $verbose != 0 ]; then
args_comp="$args_comp -v"
fi
if grep "node main()" $1 >/dev/null; then
args_comp="$args_comp -s main"
fi
if [ $verbose != 0 ]; then
2011-01-12 16:08:33 +01:00
logfile=`basename $1`.log
echo "Compile -i $coption $args_comp $1"
$compilo $coption -I good $args_comp $1 >$logfile 2>&1
2010-07-02 16:03:04 +02:00
else
2010-12-15 23:22:34 +01:00
if [ $2 == 1 ]; then
$compilo $coption -I good $args_comp $1 >/dev/null 2>&1
else
$compilo $coption -I good $args_comp $1 2>&1
fi
2010-07-02 16:03:04 +02:00
fi
failed=$?
return $failed
2010-06-21 12:11:06 +02:00
}
launch_check () {
2010-07-02 16:03:04 +02:00
score=0
max=0
2010-06-21 12:11:06 +02:00
2011-01-12 16:08:33 +01:00
if [ $clean = 1 ]; then
rm -r $checkdir
exit 0
fi
if [ ! -d $checkdir ]; then
mkdir $checkdir
fi
cd $checkdir
2010-06-21 12:11:06 +02:00
2010-07-02 16:03:04 +02:00
# les mauvais
2011-01-12 16:08:33 +01:00
echo "Tests bads"
2011-01-05 15:48:09 +01:00
for f in ../bad/*.ept ; do
if [ $verbose = 0 ]; then
echo -n "."
fi
2010-06-21 12:11:06 +02:00
max=`expr $max + 1`;
2010-12-15 23:22:34 +01:00
if compile $f 1; then
2010-07-02 16:03:04 +02:00
echo
echo "ERROR on "$f" (should fail to compile)";
2010-06-21 12:11:06 +02:00
else
2010-07-02 16:03:04 +02:00
score=`expr $score + 1`;
2010-06-21 12:11:06 +02:00
fi
2010-07-02 16:03:04 +02:00
done
echo
2011-01-12 16:08:33 +01:00
echo "Tests goods"
2011-03-11 14:49:47 +01:00
for f in ../good/*.ept; do
2010-06-21 12:11:06 +02:00
echec=0
if [ $verbose = 0 ]; then
echo -n "."
fi
2010-06-21 12:11:06 +02:00
max=`expr $max + 1`;
base_f=`basename $f .ept`
2010-12-15 23:22:34 +01:00
if compile $f 0; then
2010-06-21 12:11:06 +02:00
echec=0
else
echec=1
fi
# Compil. minils ?
if [[ ($echec == 0) && ($minils == 1) ]]; then
2010-07-16 11:19:56 +02:00
if $MLC ${base_f}.mls > /dev/null 2>&1; then
2010-06-21 12:11:06 +02:00
echec=0
else
echec=2
fi
fi
# Compil. java ?
if [[ ($echec == 0) && ($java == 1) ]]; then
pushd "java/$(echo ${base_f} | sed 's/^./\u&/')" > /dev/null
if $JAVAC -cp ../../../../lib/java:../ *.java > /dev/null
then
echec=0
else
echec=3
fi
popd > /dev/null
fi
# Compil. caml ?
if [[ ($echec == 0) && ($caml == 1) ]]; then
if $CAMLC -c ${base_f}.ml > /dev/null; then
echec=0
else
echec=4
fi
fi
2010-06-21 12:11:06 +02:00
# Compil. c ?
if [[ ($echec == 0) && ($c == 1) ]]; then
2010-07-16 11:19:56 +02:00
pushd ${base_f}_c >/dev/null
2010-07-02 16:03:04 +02:00
for cf in *.c; do
$CC -c $cf >/dev/null 2>&1
if [ $? = 0 -a $echec != 5 ]; then
2010-12-15 23:22:34 +01:00
echec=0
2010-07-02 16:03:04 +02:00
else
echec=5
fi
done
#echo "Compilation $f vers C = $echec"
2010-07-02 16:03:04 +02:00
if [ $echec != 5 ]; then
if egrep "(node main\(\))|(CHECK)" ../${base_f}.ept >/dev/null 2>&1
then
if $CC *.o -o ${base_f} 2>&1; then
2010-12-15 23:22:34 +01:00
echec=0
2010-07-02 16:03:04 +02:00
else
echec=6
fi
if [ $echec != 6 ]; then
step_count=`grep CHECK ../$base_f.ept | awk '{ print $4 }'`
if [ -n "$step_count" ]; then
if ./${base_f} $step_count >/dev/null 2>&1; then
2010-12-15 23:22:34 +01:00
echec=0
2010-07-02 16:03:04 +02:00
else
echec=7
fi
fi
fi
fi
2010-06-21 12:11:06 +02:00
fi
2010-07-02 16:03:04 +02:00
popd >/dev/null
2010-06-21 12:11:06 +02:00
fi
# Compil. VHDL ?
if [[ ($echec == 0) && ($vhdl == 1) ]]; then
pushd ${base_f}_vhdl > /dev/null
for vhdl_file in *.vhd; do
if $VHDLC -a ${vhdl_file} && $VHDLC -e ${vhdl_file} > /dev/null 2>&1
then
echec=${echec}
else
echec=8
fi
done
fi
2010-06-21 12:11:06 +02:00
if [[ $echec == 0 ]]; then
2010-07-02 16:03:04 +02:00
score=`expr $score + 1`;
2010-06-21 12:11:06 +02:00
else
2010-07-02 16:03:04 +02:00
echo
echo "ERROR on \"$f\" (should compile)";
case $echec in
1 )
2010-12-15 23:22:34 +01:00
echo "Compilation failed.";;
2 )
echo "Compilation to Minils failed.";;
2010-07-02 16:03:04 +02:00
3 )
echo "Compilation to Java failed.";;
4 )
echo "Compilation to Caml failed.";;
2010-07-02 16:03:04 +02:00
5 )
2010-12-15 23:22:34 +01:00
echo "C compilation failed.";;
2010-07-02 16:03:04 +02:00
6 )
echo "Link failure.";;
7 )
echo "Run-time assertion failure.";;
esac
2010-06-21 12:11:06 +02:00
fi
2010-07-02 16:03:04 +02:00
done
echo
2010-06-21 12:11:06 +02:00
2010-07-02 16:03:04 +02:00
percent=`expr 100 \* $score / $max`;
2010-06-21 12:11:06 +02:00
2010-07-02 16:03:04 +02:00
echo -n "Test: $score/$max : $percent%";
2010-06-21 12:11:06 +02:00
}
2011-01-12 16:08:33 +01:00
activate_clean () {
clean=1
}
2010-06-21 12:11:06 +02:00
activate_minils () {
2010-07-02 16:03:04 +02:00
minils=1
2010-06-21 12:11:06 +02:00
}
activate_java () {
2010-07-02 16:03:04 +02:00
java=1
coption="$coption -target java"
2010-06-21 12:11:06 +02:00
}
activate_caml () {
caml=1
coption="$coption -target caml"
}
activate_vhdl () {
vhdl=1
coption="$coption -target vhdl"
}
2010-06-21 12:11:06 +02:00
activate_c () {
2010-07-02 16:03:04 +02:00
c=1
coption="$coption -target c"
2010-06-21 12:11:06 +02:00
}
2011-07-06 09:50:51 +02:00
activate_tomato () {
tomato=1
coption="$coption -tomato"
}
2012-01-25 10:10:17 +01:00
activate_memalloc () {
memalloc=1
caption="$coption -memalloc"
}
2010-06-21 12:11:06 +02:00
activate_all () {
2012-01-25 10:10:17 +01:00
activate_tomato
activate_memalloc
2010-07-02 16:03:04 +02:00
activate_java
activate_c
2010-06-21 12:11:06 +02:00
}
activate_boolean () {
coption="$coption -bool"
}
activate_deadcode () {
coption="$coption -deadcode"
}
2010-06-21 12:11:06 +02:00
while [ $# -gt 0 ]; do
2010-07-02 16:03:04 +02:00
case $1 in
2011-01-12 16:08:33 +01:00
"-clean" )
activate_clean
shift;;
2010-07-02 16:03:04 +02:00
"-v" )
2010-06-21 12:11:06 +02:00
verbose=1;
shift;;
2010-07-02 16:03:04 +02:00
"-all" )
2010-06-21 12:11:06 +02:00
activate_all
shift;;
2010-07-02 16:03:04 +02:00
"-java" )
2010-06-21 12:11:06 +02:00
activate_java
shift;;
2010-07-02 16:03:04 +02:00
"-c" )
2010-06-21 12:11:06 +02:00
activate_c
shift;;
"-caml" )
activate_caml
shift;;
"-vhdl" )
activate_vhdl
shift;;
2010-07-02 16:03:04 +02:00
"-mls" )
2010-06-21 12:11:06 +02:00
activate_minils
shift;;
2011-07-06 09:50:51 +02:00
"-tomato" )
activate_tomato
shift;;
2012-01-25 10:10:17 +01:00
"-memalloc")
activate_memalloc
shift;;
"-bool" )
activate_boolean
shift;;
"-deadcode" )
activate_deadcode
shift;;
2010-07-02 16:03:04 +02:00
"-h" )
2010-06-21 12:11:06 +02:00
echo "usage : $0 <options> <compilo>"
echo "options : "
echo "-clean : clean build dir"
2010-06-21 12:11:06 +02:00
echo "-java : test of code generation (java code)"
echo "-caml : test of code generation (caml code)"
echo "-lustre : test of code generation (lustre code)"
echo "-vhdl : test of code generation (vhdl)"
echo "-bool : test of boolean translation"
echo "-deadcode : test of deadcode removal"
echo "-tomato : test of automata minimization"
2012-01-25 10:10:17 +01:00
echo "-memalloc : test of memory allocation"
2010-06-21 12:11:06 +02:00
echo "-c : test of code generation (c code)"
echo "-all : test all"
echo "-v : verbose"
exit 0;;
2010-07-02 16:03:04 +02:00
* )
2010-06-21 12:11:06 +02:00
compilo=$1
shift
coption="$coption $*"
break
2010-07-02 16:03:04 +02:00
esac
2010-06-21 12:11:06 +02:00
done
launch_check
echo