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}/libjvm.so`
34 JNI_LIB_PATH
=`dirname ${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>"
321 os_skip_file
=`uname`.skip
322 if test -e
$os_skip_file && echo "$1" |
grep -f
"$os_skip_file" >/dev
/null
2>&1; then
323 echo "=> $2: [skip os]"
324 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
332 test "$noskip" = true
&& return 1
333 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
342 test "$noskip" = true
&& return 1
343 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
351 name
="$enginebinname"
352 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
353 if [[ "x$recent" == "x" ]]; then
354 echo "Could not find binary for engine $engine, aborting"
357 if [ "x$isnode" = "xfalse" ]; then
358 echo "Found binary for engine $engine: $recent $OPT"
369 while [ $stop = false
]; do
371 -o
) OPT
="$OPT $2"; shift; shift;;
372 -v
) verbose
=true
; shift;;
374 --engine
) engine
="$2"; shift; shift;;
375 --noskip
) noskip
=true
; shift;;
376 --outdir
) outdir
="$2"; shift; shift;;
377 --compdir
) compdir
="$2"; shift; shift;;
378 --node
) isnode
=true
; shift;;
382 enginebinname
=$engine
388 OPT
="--separate $OPT --compile-dir $compdir"
389 savdirs
="sav/nitg-common/"
393 OPT
="--separate $OPT --compile-dir $compdir"
394 savdirs
="sav/nitg-common/"
398 OPT
="--erasure $OPT --compile-dir $compdir"
399 savdirs
="sav/nitg-common/"
403 OPT
="--semi-global $OPT --compile-dir $compdir"
404 savdirs
="sav/nitg-common/"
408 OPT
="--global $OPT --compile-dir $compdir"
409 savdirs
="sav/nitg-common/"
427 OPT
="-m emscripten_nodejs.nit --semi-global $OPT --compile-dir $compdir"
428 savdirs
="sav/nitg-sg/"
431 echo "disabled engine $engine"
435 echo "unknown engine $engine"
440 savdirs
="sav/$engine $savdirs sav/"
442 # The default nitc compiler
443 [ -z
"$NITC" ] && find_nitc
445 # Set NIT_DIR if needed
446 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
448 # Mark to distinguish files among tests
456 # CLEAN the out directory
457 rm -rf
"$outdir/" 2>/dev
/null
458 mkdir
"$outdir" 2>/dev
/null
460 # File where error tests are outputed
461 # Old ERRLIST is backuped
462 ERRLIST
=${ERRLIST:-errlist}
463 ERRLIST_TARGET
=$ERRLIST
465 # Initiate new ERRLIST
466 if [ "x$ERRLIST" = "x" ]; then
477 if [ "x$XMLDIR" = "x" ]; then
478 xml
="tests-$engine.xml"
480 sum=`echo $@ | md5sum | cut -f1 -d " "`
481 xml
="$XMLDIR/tests-$engine-$sum.xml"
485 echo >$xml "<testsuites><testsuite>"
488 if [ ! -f
"$ii" ]; then
489 echo "File '$ii' does not exist."
492 f
=`basename -- "$ii" .nit`
494 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|'`
496 # Sould we skip the file for this engine?
497 need_skip
"$f" "$f" "$pack" && continue
500 if [ "x$tmp" = "x$ii" ]; then
501 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
506 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' -- "$ii"`; do
507 bf
=`basename -- "$i" .nit`
510 # Sould we skip the alternative for this engine?
511 need_skip
"$bf" "$bf" "$pack" && continue
515 if [ -f
"$f.inputs" ]; then
517 export MNIT_READ_INPUT
="$f.inputs"
520 export MNIT_READ_INPUT
=/dev
/null
524 if [ "$engine" = "emscripten" ]; then
528 if [ -n
"$isinterpret" ]; then
529 cat > "$ff.bin" <<END
530 exec $NITC --no
-color
$OPT $includes -- $
(printf '%q' "$i") "\$@"
536 echo 0.0 > "$ff.time.out"
538 if skip_cc
"$bf"; then
544 if [ "x$verbose" = "xtrue" ]; then
546 echo $NITC --no
-color
$OPT -o
"$ffout" "$includes" $nocc "$i"
548 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
549 saferun
-o
"$ff.time.out" $NITC --no
-color
$OPT -o
"$ffout" $includes $nocc "$i" 2> "$ff.cmp.err" > "$ff.compile.log"
551 if [ "x$verbose" = "xtrue" ]; then
552 cat -- "$ff.compile.log"
553 cat >&2 -- "$ff.cmp.err"
556 if [ "$engine" = "emscripten" ]; then
557 echo > "$ff.bin" "nodejs $ffout \"\$@\""
559 if grep "Fatal Error: more than one primitive class" "$ff.compile.log" > /dev
/null
; then
560 echo " [skip] do no not imports kernel"
561 echo >>$xml "<testcase classname='`xmlesc "$pack"`' name='`xmlesc "$bf"`' `timestamp`><skipped/></testcase>"
565 if [ "$ERR" != 0 ]; then
567 cat -- "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
568 process_result
"$bf" "$bf" "$pack"
569 elif [ -n
"$nocc" ]; then
573 process_result
"$bf" "$bf" "$pack"
574 elif [ -x
"$ff.bin" ]; then
575 if skip_exec
"$bf"; then
578 process_result
"$bf" "$bf" "$pack"
584 if [ "x$verbose" = "xtrue" ]; then
586 echo "NIT_NO_STACK=1 $ff.bin" $args
588 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
589 saferun
-a
-o
"$ff.time.out" "$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
590 mv "$ff.time.out" "$ff.times.out"
591 awk '{ SUM += $1} END { print SUM }' "$ff.times.out" > "$ff.time.out"
593 if [ "x$verbose" = "xtrue" ]; then
597 if [ -f
"$ff.write" ]; then
598 cat -- "$ff.write" >> "$ff.res"
599 elif [ -d
"$ff.write" ]; then
600 LANG
=C
/bin
/ls -F
"$ff.write" >> "$ff.res"
602 cp -- "$ff.res" "$ff.res2"
603 cat -- "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
604 process_result
"$bf" "$bf" "$pack"
606 if [ -f
"$f.args" ]; then
614 name
="$bf args $cptr"
616 # Sould we skip the input for this engine?
617 need_skip
"$bff" " $name" "$pack" && continue
619 # use a specific inputs file, if required
620 if [ -f
"$bff.inputs" ]; then
621 ffinputs
="$bff.inputs"
626 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
627 if [ "x$verbose" = "xtrue" ]; then
629 echo "NIT_NO_STACK=1 $ff.bin" $args
632 echo "$ff.bin $args" > "$fff.bin"
634 WRITE
="$fff.write" saferun
-o
"$fff.time.out" sh
-c
"NIT_NO_STACK=1 $fff.bin < $ffinputs > $fff.res 2>$fff.err"
635 if [ "x$verbose" = "xtrue" ]; then
637 cat >&2 -- "$fff.err"
639 if [ -f
"$fff.write" ]; then
640 cat -- "$fff.write" >> "$fff.res"
641 elif [ -d
"$fff.write" ]; then
642 LANG
=C
/bin
/ls -F
-- "$fff.write" >> "$fff.res"
644 if [ -s
"$fff.err" ]; then
645 cp -- "$fff.res" "$fff.res2"
646 cat -- "$fff.err" "$fff.res2" > "$fff.res"
648 process_result
"$bff" " $name" "$pack"
651 elif [ -f
"$ff.bin" ]; then
652 #Not executable (platform?)"
654 process_result
"$bf" "$bf" "$pack"
657 cat -- "$ff.cmp.err" > "$ff.res"
658 echo "Compilation error" > "$ff.res"
659 process_result
"$bf" "$bf" "$pack"
664 if [ "x$isnode" = "xfalse" ]; then
665 echo "engine: $engine ($enginebinname $OPT)"
666 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
668 if [ -n
"$nok" ]; then
670 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
672 if [ -n
"$nos" ]; then
675 if [ -n
"$todos" ]; then
676 echo "todo/fixme: $todos"
678 if [ -n
"$remains" ]; then
679 echo "sav that remains: $remains"
684 if [ "x$ERRLIST" != "x" ]; then
685 if [ -f
"$ERRLIST_TARGET" ]; then
686 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
688 uniq $ERRLIST > $ERRLIST_TARGET
692 echo >>$xml "</testsuite></testsuites>"
694 if [ -n
"$nok" ]; then