2 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # Copyright 2004-2008 Jean Privat <jean@pryen.org>
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # This shell script compile, run and verify Nit program files
20 # Set lang do default to avoid failed tests because of locale
23 export NIT_TESTING
=true
28 # Get the first Java lib available
30 JAVA_HOME
=$
(dirname $
(dirname $
(readlink
-f $
(which javac
))))
32 paths
=`echo $JAVA_HOME/jre/lib/*/{client,server}/`
34 JNI_LIB_PATH
=${paths[0]}
38 compdir
=".nit_compile"
44 Usage
: $e [options
] modulenames
45 -o option Pass option to the engine
46 -v Verbose
(show tests steps
)
48 --engine Use a specific engine
(default
=nitc
)
49 --noskip Do not skip a
test even
if the .skip
file matches
50 --outdir Use a specific output folder
(default
=out
/)
51 --compdir Use a specific temporary compilation folder
(default
=.nit_compile
)
52 --node Run as a node
in parallel
, will not output context information
56 # Run a command with a timeout and a time count.
58 # -o file write the user time into file (REQUIRED). see `-o` in `man time`
59 # -a append the time to the file (instead of overwriting it). see `-a` in `man time`
65 while [ $stop = false
]; do
67 -o
) o
="$2"; shift; shift;;
72 if test -n
"$TIME"; then
73 $TIME -o
"$o" $a $TIMEOUT "$@"
75 if test -n
"$a"; then echo 0 >> "$o"; else echo 0 > "$o"; fi
80 # Output a timestamp attribute for XML, or an empty line
83 if test -n
"$TIMESTAMP"; then
84 echo "timestamp='`$TIMESTAMP`'"
91 # Get platform specific commands ##########################
93 # Detect a working timeout
94 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
95 TIMEOUT
="timelimit -t 600"
96 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
97 TIMEOUT
="timeout 600s"
99 echo "No timelimit or timeout command detected. Tests may hang :("
102 # Detect a working time command
103 if env
time --quiet
-f
%U true
2>/dev
/null
; then
104 TIME
="env time --quiet -f%U"
105 elif env
time -f
%U true
2>/dev
/null
; then
111 # Detect a working date command
112 if date -Iseconds
>/dev
/null
2>&1; then
113 TIMESTAMP
="date -Iseconds"
118 # $1 is the pattern of the test
119 # $2 is the file to compare to
121 # 0: if the file to compare to do not exists
122 # 1: if the file match
123 # 2: if the file match with soso
124 # 3: if the file do not match
125 function compare_to_result
()
129 if [ ! -r
"$sav" ]; then return 0; fi
130 test "`cat -- "$sav"`" = "UNDEFINED" && return 1
131 diff -u
-- "$sav" "$outdir/$pattern.res" > "$outdir/$pattern.diff.sav.log"
132 if [ "$?" == 0 ]; then
135 sed '/[Ww]arning/d;/[Ee]rror/d' "$outdir/$pattern.res" > "$outdir/$pattern.res2"
136 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "$outdir/$pattern.sav2"
137 grep '[Ee]rror' "$outdir/$pattern.res" >/dev
/null
&& echo "Error" >> "$outdir/$pattern.res2"
138 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "$outdir/$pattern.sav2"
139 diff -u
"$outdir/$pattern.sav2" "$outdir/$pattern.res2" > "$outdir/$pattern.diff.sav.log2"
140 if [ "$?" == 0 ]; then
149 sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g'<<EOF
154 # As argument: the pattern used for the file
155 function process_result
()
172 echo >>$xml "<testcase classname='`xmlesc "$pack"`' name='`xmlesc "$description"`' time='`cat -- "$outdir/$pattern.
time.out
"`' `timestamp`>"
173 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
174 for savdir
in $savdirs; do
175 sav
=$savdir/fixme
/$pattern.res
176 compare_to_result
"$pattern" "$sav"
186 if [ -z
"$FIRST" ]; then
193 if [ -z
"$FIRST" ]; then
201 sav
=$savdir/$pattern.res
202 compare_to_result
"$pattern" "$sav"
212 if [ -z
"$FIRST" ]; then
219 if [ -z
"$FIRST" ]; then
227 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
228 grep 'NOT YET IMPLEMENTED' "$outdir/$pattern.res" >/dev
/null
230 if [ -n
"$SAV" ]; then
231 if [ -n
"$OLD" ]; then
232 echo "[*ok*] $outdir/$pattern.res $SAV - but $OLD remains!"
233 echo >>$xml "<error message='`xmlesc "ok
$outdir/$pattern.res
- but
$OLD remains
"`'/>"
234 remains
="$remains $OLD"
236 echo "[ok] $outdir/$pattern.res $SAV"
239 elif [ -n
"$FIXME" ]; then
240 if [ -n
"$OLD" ]; then
241 echo "[*fixme*] $outdir/$pattern.res $FIXME - but $OLD remains!"
242 echo >>$xml "<error message='`xmlesc "ok
$outdir/$pattern.res
- but
$OLD remains
"`'/>"
243 remains
="$remains $OLD"
245 echo "[fixme] $outdir/$pattern.res $FIXME"
246 echo >>$xml "<skipped/>"
248 todos
="$todos $pattern"
249 elif [ "x$NYI" = "x0" ]; then
250 echo "[todo] $outdir/$pattern.res -> not yet implemented"
251 echo >>$xml "<skipped/>"
252 todos
="$todos $pattern"
253 elif [ -n
"$SOSO" ]; then
254 echo "[======= soso $outdir/$pattern.res $SOSO =======]"
255 echo >>$xml "<error message='`xmlesc "soso
$outdir/$pattern.res
$SOSO"`'/>"
256 echo >>$xml "<system-out><![CDATA["
257 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
258 echo >>$xml "]]></system-out>"
260 echo "$ii" >> "$ERRLIST"
261 elif [ -n
"$SOSOF" ]; then
262 echo "[======= fixme soso $outdir/$pattern.res $SOSOF =======]"
263 echo >>$xml "<error message='`xmlesc "soso
$outdir/$pattern.res
$SOSO"`'/>"
264 echo >>$xml "<system-out><![CDATA["
265 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
266 echo >>$xml "]]></system-out>"
268 echo "$ii" >> "$ERRLIST"
269 elif [ -n
"$NSAV" ]; then
270 echo "[======= fail $outdir/$pattern.res $NSAV =======]"
271 echo >>$xml "<error message='`xmlesc "fail
$outdir/$pattern.res
$NSAV"`'/>"
272 echo >>$xml "<system-out><![CDATA["
273 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
274 echo >>$xml "]]></system-out>"
276 echo "$ii" >> "$ERRLIST"
277 elif [ -n
"$NFIXME" ]; then
278 echo "[======= changed $outdir/$pattern.res $NFIXME ======]"
279 echo >>$xml "<error message='`xmlesc "changed
$outdir/$pattern.res
$NFIXME"`'/>"
280 echo >>$xml "<system-out><![CDATA["
281 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
282 echo >>$xml "]]></system-out>"
284 echo "$ii" >> "$ERRLIST"
285 elif [ -s
"$outdir/$pattern.res" ]; then
286 echo "[=== no sav ===] $outdir/$pattern.res is not empty"
287 echo >>$xml "<error message='no sav and not empty'/>"
288 echo >>$xml "<system-out><![CDATA["
289 cat -v
>>$xml -- "$outdir/$pattern.res"
290 echo >>$xml "]]></system-out>"
292 echo "$ii" >> "$ERRLIST"
294 # no sav but empty res
295 echo "[0k] $outdir/$pattern.res is empty"
298 if test -s
"$outdir/$pattern.cmp.err"; then
299 echo >>$xml "<system-err><![CDATA["
300 cat -v
>>$xml -- "$outdir/$pattern.cmp.err"
301 echo >>$xml "]]></system-err>"
303 echo >>$xml "</testcase>"
308 test "$noskip" = true
&& return 1
309 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
311 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
314 if test -n
"$isinterpret" && echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
315 echo "=> $2: [skip exec]"
316 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
324 test "$noskip" = true
&& return 1
325 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
334 test "$noskip" = true
&& return 1
335 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
343 name
="$enginebinname"
344 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
345 if [[ "x$recent" == "x" ]]; then
346 echo "Could not find binary for engine $engine, aborting"
349 if [ "x$isnode" = "xfalse" ]; then
350 echo "Found binary for engine $engine: $recent $OPT"
361 while [ $stop = false
]; do
363 -o
) OPT
="$OPT $2"; shift; shift;;
364 -v
) verbose
=true
; shift;;
366 --engine
) engine
="$2"; shift; shift;;
367 --noskip
) noskip
=true
; shift;;
368 --outdir
) outdir
="$2"; shift; shift;;
369 --compdir
) compdir
="$2"; shift; shift;;
370 --node
) isnode
=true
; shift;;
374 enginebinname
=$engine
380 OPT
="--separate $OPT --compile-dir $compdir"
381 savdirs
="sav/nitg-common/"
385 OPT
="--separate $OPT --compile-dir $compdir"
386 savdirs
="sav/nitg-common/"
390 OPT
="--erasure $OPT --compile-dir $compdir"
391 savdirs
="sav/nitg-common/"
395 OPT
="--semi-global $OPT --compile-dir $compdir"
396 savdirs
="sav/nitg-common/"
400 OPT
="--global $OPT --compile-dir $compdir"
401 savdirs
="sav/nitg-common/"
417 OPT
="-m emscripten_nodejs.nit --semi-global $OPT --compile-dir $compdir"
418 savdirs
="sav/nitg-sg/"
421 echo "disabled engine $engine"
425 echo "unknown engine $engine"
430 savdirs
="sav/$engine $savdirs sav/"
432 # The default nitc compiler
433 [ -z
"$NITC" ] && find_nitc
435 # Set NIT_DIR if needed
436 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
438 # Mark to distinguish files among tests
446 # CLEAN the out directory
447 rm -rf
"$outdir/" 2>/dev
/null
448 mkdir
"$outdir" 2>/dev
/null
450 # File where error tests are outputed
451 # Old ERRLIST is backuped
452 ERRLIST
=${ERRLIST:-errlist}
453 ERRLIST_TARGET
=$ERRLIST
455 # Initiate new ERRLIST
456 if [ "x$ERRLIST" = "x" ]; then
467 if [ "x$XMLDIR" = "x" ]; then
468 xml
="tests-$engine.xml"
470 sum=`echo $@ | md5sum | cut -f1 -d " "`
471 xml
="$XMLDIR/tests-$engine-$sum.xml"
475 echo >$xml "<testsuites><testsuite>"
478 if [ ! -f
"$ii" ]; then
479 echo "File '$ii' does not exist."
482 f
=`basename -- "$ii" .nit`
484 pack
="tests.${engine}".
`echo $ii | perl -p -e 's|^../([^/]*)/([a-zA-Z_]*).*|\1.\2| || s|^([a-zA-Z]*)[^_]*_([a-zA-Z]*).*|\1.\2| || s|\W*([a-zA-Z_]*).*|\1|'`
486 # Sould we skip the file for this engine?
487 need_skip
"$f" "$f" "$pack" && continue
490 if [ "x$tmp" = "x$ii" ]; then
491 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
496 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' -- "$ii"`; do
497 bf
=`basename -- "$i" .nit`
500 # Sould we skip the alternative for this engine?
501 need_skip
"$bf" "$bf" "$pack" && continue
505 if [ -f
"$f.inputs" ]; then
507 export MNIT_READ_INPUT
="$f.inputs"
510 export MNIT_READ_INPUT
=/dev
/null
514 if [ "$engine" = "emscripten" ]; then
518 if [ -n
"$isinterpret" ]; then
519 cat > "$ff.bin" <<END
520 exec $NITC --no
-color
$OPT $includes -- $
(printf '%q' "$i") "\$@"
526 echo 0.0 > "$ff.time.out"
528 if skip_cc
"$bf"; then
534 if [ "x$verbose" = "xtrue" ]; then
536 echo $NITC --no
-color
$OPT -o
"$ffout" "$includes" $nocc "$i"
538 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
539 saferun
-o
"$ff.time.out" $NITC --no
-color
$OPT -o
"$ffout" $includes $nocc "$i" 2> "$ff.cmp.err" > "$ff.compile.log"
541 if [ "x$verbose" = "xtrue" ]; then
542 cat -- "$ff.compile.log"
543 cat >&2 -- "$ff.cmp.err"
546 if [ "$engine" = "emscripten" ]; then
547 echo > "$ff.bin" "nodejs $ffout \"\$@\""
549 if grep "Fatal Error: more than one primitive class" "$ff.compile.log" > /dev
/null
; then
550 echo " [skip] do no not imports kernel"
551 echo >>$xml "<testcase classname='`xmlesc "$pack"`' name='`xmlesc "$bf"`' `timestamp`><skipped/></testcase>"
555 if [ "$ERR" != 0 ]; then
557 cat -- "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
558 process_result
"$bf" "$bf" "$pack"
559 elif [ -n
"$nocc" ]; then
563 process_result
"$bf" "$bf" "$pack"
564 elif [ -x
"$ff.bin" ]; then
565 if skip_exec
"$bf"; then
568 process_result
"$bf" "$bf" "$pack"
574 if [ "x$verbose" = "xtrue" ]; then
576 echo "NIT_NO_STACK=1 $ff.bin" $args
578 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
579 saferun
-a
-o
"$ff.time.out" "$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
580 mv "$ff.time.out" "$ff.times.out"
581 awk '{ SUM += $1} END { print SUM }' "$ff.times.out" > "$ff.time.out"
583 if [ "x$verbose" = "xtrue" ]; then
587 if [ -f
"$ff.write" ]; then
588 cat -- "$ff.write" >> "$ff.res"
589 elif [ -d
"$ff.write" ]; then
590 LANG
=C
/bin
/ls -F
"$ff.write" >> "$ff.res"
592 cp -- "$ff.res" "$ff.res2"
593 cat -- "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
594 process_result
"$bf" "$bf" "$pack"
596 if [ -f
"$f.args" ]; then
604 name
="$bf args $cptr"
606 # Sould we skip the input for this engine?
607 need_skip
"$bff" " $name" "$pack" && continue
609 # use a specific inputs file, if required
610 if [ -f
"$bff.inputs" ]; then
611 ffinputs
="$bff.inputs"
616 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
617 if [ "x$verbose" = "xtrue" ]; then
619 echo "NIT_NO_STACK=1 $ff.bin" $args
622 echo "$ff.bin $args" > "$fff.bin"
624 WRITE
="$fff.write" saferun
-o
"$fff.time.out" sh
-c
"NIT_NO_STACK=1 $fff.bin < $ffinputs > $fff.res 2>$fff.err"
625 if [ "x$verbose" = "xtrue" ]; then
627 cat >&2 -- "$fff.err"
629 if [ -f
"$fff.write" ]; then
630 cat -- "$fff.write" >> "$fff.res"
631 elif [ -d
"$fff.write" ]; then
632 LANG
=C
/bin
/ls -F
-- "$fff.write" >> "$fff.res"
634 if [ -s
"$fff.err" ]; then
635 cp -- "$fff.res" "$fff.res2"
636 cat -- "$fff.err" "$fff.res2" > "$fff.res"
638 process_result
"$bff" " $name" "$pack"
641 elif [ -f
"$ff.bin" ]; then
642 #Not executable (platform?)"
644 process_result
"$bf" "$bf" "$pack"
647 cat -- "$ff.cmp.err" > "$ff.res"
648 echo "Compilation error" > "$ff.res"
649 process_result
"$bf" "$bf" "$pack"
654 if [ "x$isnode" = "xfalse" ]; then
655 echo "engine: $engine ($enginebinname $OPT)"
656 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
658 if [ -n
"$nok" ]; then
660 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
662 if [ -n
"$nos" ]; then
665 if [ -n
"$todos" ]; then
666 echo "todo/fixme: $todos"
668 if [ -n
"$remains" ]; then
669 echo "sav that remains: $remains"
674 if [ "x$ERRLIST" != "x" ]; then
675 if [ -f
"$ERRLIST_TARGET" ]; then
676 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
678 uniq $ERRLIST > $ERRLIST_TARGET
682 echo >>$xml "</testsuite></testsuites>"
684 if [ -n
"$nok" ]; then