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
53 --autosav Copy the .res files directly
in the sav folder overriding existing .res files
57 # Run a command with a timeout and a time count.
59 # -o file write the user time into file (REQUIRED). see `-o` in `man time`
60 # -a append the time to the file (instead of overwriting it). see `-a` in `man time`
66 while [ $stop = false
]; do
68 -o
) o
="$2"; shift; shift;;
75 elif test -n
"$TIME"; then
76 $TIME -o
"$o" $a $TIMEOUT "$@"
78 if test -n
"$a"; then echo 0 >> "$o"; else echo 0 > "$o"; fi
83 # Output a timestamp attribute for XML, or an empty line
86 if test -n
"$TIMESTAMP"; then
87 echo "timestamp='`$TIMESTAMP`'"
94 # Get platform specific commands ##########################
96 # Detect a working timeout
97 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
98 TIMEOUT
="timelimit -t 600"
99 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
100 TIMEOUT
="timeout 600s"
102 echo "No timelimit or timeout command detected. Tests may hang :("
105 # Detect a working time command
106 if env
time --quiet
-f
%U true
2>/dev
/null
; then
107 TIME
="env time --quiet -f%U"
108 elif env
time -f
%U true
2>/dev
/null
; then
114 # Detect a working date command
115 if date -Iseconds
>/dev
/null
2>&1; then
116 TIMESTAMP
="date -Iseconds"
121 # $1 is the pattern of the test
122 # $2 is the file to compare to
124 # 0: if the file to compare to do not exists
125 # 1: if the file match
126 # 2: if the file match with soso
127 # 3: if the file do not match
128 function compare_to_result
()
132 if [ ! -r
"$sav" ]; then return 0; fi
133 test "`cat -- "$sav"`" = "UNDEFINED" && return 1
134 diff -u
-- "$sav" "$outdir/$pattern.res" > "$outdir/$pattern.diff.sav.log"
135 if [ "$?" == 0 ]; then
138 sed '/[Ww]arning/d;/[Ee]rror/d' "$outdir/$pattern.res" > "$outdir/$pattern.res2"
139 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "$outdir/$pattern.sav2"
140 grep '[Ee]rror' "$outdir/$pattern.res" >/dev
/null
&& echo "Error" >> "$outdir/$pattern.res2"
141 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "$outdir/$pattern.sav2"
142 diff -u
"$outdir/$pattern.sav2" "$outdir/$pattern.res2" > "$outdir/$pattern.diff.sav.log2"
143 if [ "$?" == 0 ]; then
152 sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g'<<EOF
157 # As argument: the pattern used for the file
158 function process_result
()
175 echo >>$xml "<testcase classname='`xmlesc "$pack"`' name='`xmlesc "$description"`' time='`cat -- "$outdir/$pattern.
time.out
"`' `timestamp`>"
176 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
177 for savdir
in $savdirs; do
178 sav
=$savdir/fixme
/$pattern.res
179 compare_to_result
"$pattern" "$sav"
189 if [ -z
"$FIRST" ]; then
196 if [ -z
"$FIRST" ]; then
204 sav
=$savdir/$pattern.res
205 compare_to_result
"$pattern" "$sav"
215 if [ -z
"$FIRST" ]; then
222 if [ -z
"$FIRST" ]; then
230 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
231 grep 'NOT YET IMPLEMENTED' "$outdir/$pattern.res" >/dev
/null
233 if [ -n
"$SAV" ]; then
234 if [ -n
"$OLD" ]; then
235 echo "[*ok*] $outdir/$pattern.res $SAV - but $OLD remains!"
236 echo >>$xml "<error message='`xmlesc "ok
$outdir/$pattern.res
- but
$OLD remains
"`'/>"
237 remains
="$remains $OLD"
238 test "$autosav" = "true" && rm "$OLD"
240 echo "[ok] $outdir/$pattern.res $SAV"
243 elif [ -n
"$FIXME" ]; then
244 if [ -n
"$OLD" ]; then
245 echo "[*fixme*] $outdir/$pattern.res $FIXME - but $OLD remains!"
246 echo >>$xml "<error message='`xmlesc "ok
$outdir/$pattern.res
- but
$OLD remains
"`'/>"
247 remains
="$remains $OLD"
248 test "$autosav" = "true" && rm "$OLD"
250 echo "[fixme] $outdir/$pattern.res $FIXME"
251 echo >>$xml "<skipped/>"
253 todos
="$todos $pattern"
254 elif [ "x$NYI" = "x0" ]; then
255 echo "[todo] $outdir/$pattern.res -> not yet implemented"
256 echo >>$xml "<skipped/>"
257 todos
="$todos $pattern"
258 elif [ -n
"$SOSO" ]; then
259 echo "[======= soso $outdir/$pattern.res $SOSO =======]"
260 echo >>$xml "<error message='`xmlesc "soso
$outdir/$pattern.res
$SOSO"`'/>"
261 echo >>$xml "<system-out><![CDATA["
262 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
263 echo >>$xml "]]></system-out>"
265 echo "$ii" >> "$ERRLIST"
266 test "$autosav" = "true" && cp "$outdir/$pattern.res" "$SOSO"
267 elif [ -n
"$SOSOF" ]; then
268 echo "[======= fixme soso $outdir/$pattern.res $SOSOF =======]"
269 echo >>$xml "<error message='`xmlesc "soso
$outdir/$pattern.res
$SOSO"`'/>"
270 echo >>$xml "<system-out><![CDATA["
271 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
272 echo >>$xml "]]></system-out>"
274 echo "$ii" >> "$ERRLIST"
275 test "$autosav" = "true" && cp "$outdir/$pattern.res" && "$SOSO"
276 elif [ -n
"$NSAV" ]; then
277 echo "[======= fail $outdir/$pattern.res $NSAV =======]"
278 echo >>$xml "<error message='`xmlesc "fail
$outdir/$pattern.res
$NSAV"`'/>"
279 echo >>$xml "<system-out><![CDATA["
280 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
281 echo >>$xml "]]></system-out>"
283 echo "$ii" >> "$ERRLIST"
284 test "$autosav" = "true" && cp "$outdir/$pattern.res" "$NSAV"
285 elif [ -n
"$NFIXME" ]; then
286 echo "[======= changed $outdir/$pattern.res $NFIXME ======]"
287 echo >>$xml "<error message='`xmlesc "changed
$outdir/$pattern.res
$NFIXME"`'/>"
288 echo >>$xml "<system-out><![CDATA["
289 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
290 echo >>$xml "]]></system-out>"
292 echo "$ii" >> "$ERRLIST"
293 test "$autosav" = "true" && cp "$outdir/$pattern.res" "$NFIXME"
294 elif [ -s
"$outdir/$pattern.res" ]; then
295 echo "[=== no sav ===] $outdir/$pattern.res is not empty"
296 echo >>$xml "<error message='no sav and not empty'/>"
297 echo >>$xml "<system-out><![CDATA["
298 cat -v
>>$xml -- "$outdir/$pattern.res"
299 echo >>$xml "]]></system-out>"
301 echo "$ii" >> "$ERRLIST"
302 test "$autosav" = "true" && cp "$outdir/$pattern.res" "sav/"
304 # no sav but empty res
305 echo "[0k] $outdir/$pattern.res is empty"
308 if test -s
"$outdir/$pattern.cmp.err"; then
309 echo >>$xml "<system-err><![CDATA["
310 cat -v
>>$xml -- "$outdir/$pattern.cmp.err"
311 echo >>$xml "]]></system-err>"
313 echo >>$xml "</testcase>"
318 test "$noskip" = true
&& return 1
319 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
321 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
324 if test -n
"$isinterpret" && echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
325 echo "=> $2: [skip exec]"
326 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
331 os_skip_file
=`uname`.skip
332 if test -e
$os_skip_file && echo "$1" |
grep -f
"$os_skip_file" >/dev
/null
2>&1; then
333 echo "=> $2: [skip os]"
334 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
342 test "$noskip" = true
&& return 1
343 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
352 test "$noskip" = true
&& return 1
353 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
361 name
="$enginebinname"
362 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
363 if [[ "x$recent" == "x" ]]; then
364 echo "Could not find binary for engine $engine, aborting"
367 if [ "x$isnode" = "xfalse" ]; then
368 echo "Found binary for engine $engine: $recent $OPT"
380 while [ $stop = false
]; do
382 -o
) OPT
="$OPT $2"; shift; shift;;
383 -v
) verbose
=true
; shift;;
385 --engine
) engine
="$2"; shift; shift;;
386 --noskip
) noskip
=true
; shift;;
387 --outdir
) outdir
="$2"; shift; shift;;
388 --compdir
) compdir
="$2"; shift; shift;;
389 --node
) isnode
=true
; shift;;
390 --autosav
) autosav
=true
; shift;;
394 enginebinname
=$engine
400 OPT
="--separate $OPT --compile-dir $compdir"
401 savdirs
="sav/nitg-common/"
405 OPT
="--separate $OPT --compile-dir $compdir"
406 savdirs
="sav/nitg-common/"
410 OPT
="--erasure $OPT --compile-dir $compdir"
411 savdirs
="sav/nitg-common/"
415 OPT
="--semi-global $OPT --compile-dir $compdir"
416 savdirs
="sav/nitg-common/"
420 OPT
="--global $OPT --compile-dir $compdir"
421 savdirs
="sav/nitg-common/"
439 OPT
="-m emscripten_nodejs.nit --semi-global $OPT --compile-dir $compdir"
440 savdirs
="sav/nitg-sg/"
443 echo "disabled engine $engine"
447 echo "unknown engine $engine"
452 savdirs
="sav/$engine $savdirs sav/"
454 # The default nitc compiler
455 [ -z
"$NITC" ] && find_nitc
457 # Set NIT_DIR if needed
458 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
460 # Mark to distinguish files among tests
468 # CLEAN the out directory
469 rm -rf
"$outdir/" 2>/dev
/null
470 mkdir
"$outdir" 2>/dev
/null
472 # File where error tests are outputed
473 # Old ERRLIST is backuped
474 ERRLIST
=${ERRLIST:-errlist}
475 ERRLIST_TARGET
=$ERRLIST
477 # Initiate new ERRLIST
478 if [ "x$ERRLIST" = "x" ]; then
489 if [ "x$XMLDIR" = "x" ]; then
490 xml
="tests-$engine.xml"
492 sum=`echo $@ | md5sum | cut -f1 -d " "`
493 xml
="$XMLDIR/tests-$engine-$sum.xml"
497 echo >$xml "<testsuites><testsuite>"
500 if [ ! -f
"$ii" ]; then
501 echo "File '$ii' does not exist."
504 f
=`basename -- "$ii" .nit`
506 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|'`
508 # Sould we skip the file for this engine?
509 need_skip
"$f" "$f" "$pack" && continue
512 if [ "x$tmp" = "x$ii" ]; then
513 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
518 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' -- "$ii"`; do
519 bf
=`basename -- "$i" .nit`
522 # Sould we skip the alternative for this engine?
523 need_skip
"$bf" "$bf" "$pack" && continue
527 if [ -f
"$f.inputs" ]; then
529 export MNIT_READ_INPUT
="$f.inputs"
532 export MNIT_READ_INPUT
=/dev
/null
536 if [ "$engine" = "emscripten" ]; then
540 if [ -n
"$isinterpret" ]; then
541 cat > "$ff.bin" <<END
542 exec $NITC --no
-color
$OPT $includes -- $
(printf '%q' "$i") "\$@"
548 echo 0.0 > "$ff.time.out"
550 if skip_cc
"$bf"; then
556 if [ "x$verbose" = "xtrue" ]; then
558 echo $NITC --no
-color
$OPT -o
"$ffout" "$includes" $nocc "$i"
560 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
561 saferun
-o
"$ff.time.out" $NITC --no
-color
$OPT -o
"$ffout" $includes $nocc "$i" 2> "$ff.cmp.err" > "$ff.compile.log"
563 if [ "x$verbose" = "xtrue" ]; then
564 cat -- "$ff.compile.log"
565 cat >&2 -- "$ff.cmp.err"
568 if [ "$engine" = "emscripten" ]; then
569 echo > "$ff.bin" "nodejs $ffout \"\$@\""
571 if grep "Fatal Error: more than one primitive class" "$ff.compile.log" > /dev
/null
; then
572 echo " [skip] do no not imports kernel"
573 echo >>$xml "<testcase classname='`xmlesc "$pack"`' name='`xmlesc "$bf"`' `timestamp`><skipped/></testcase>"
577 if [ "$ERR" != 0 ]; then
579 cat -- "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
580 process_result
"$bf" "$bf" "$pack"
581 elif [ -n
"$nocc" ]; then
585 process_result
"$bf" "$bf" "$pack"
586 elif [ -x
"$ff.bin" ]; then
587 if skip_exec
"$bf"; then
590 process_result
"$bf" "$bf" "$pack"
596 if [ "x$verbose" = "xtrue" ]; then
598 echo "NIT_NO_STACK=1 $ff.bin" $args
600 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
601 saferun
-a
-o
"$ff.time.out" "$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
602 mv "$ff.time.out" "$ff.times.out"
603 awk '{ SUM += $1} END { print SUM }' "$ff.times.out" > "$ff.time.out"
605 if [ "x$verbose" = "xtrue" ]; then
609 if [ -f
"$ff.write" ]; then
610 cat -- "$ff.write" >> "$ff.res"
611 elif [ -d
"$ff.write" ]; then
612 LANG
=C
/bin
/ls -F
"$ff.write" >> "$ff.res"
614 cp -- "$ff.res" "$ff.res2"
615 cat -- "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
616 process_result
"$bf" "$bf" "$pack"
618 if [ -f
"$f.args" ]; then
626 name
="$bf args $cptr"
628 # Sould we skip the input for this engine?
629 need_skip
"$bff" " $name" "$pack" && continue
631 # use a specific inputs file, if required
632 if [ -f
"$bff.inputs" ]; then
633 ffinputs
="$bff.inputs"
638 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
639 if [ "x$verbose" = "xtrue" ]; then
641 echo "NIT_NO_STACK=1 $ff.bin" $args
644 echo "$ff.bin $args" > "$fff.bin"
646 WRITE
="$fff.write" saferun
-o
"$fff.time.out" sh
-c
"NIT_NO_STACK=1 $fff.bin < $ffinputs > $fff.res 2>$fff.err"
647 if [ "x$verbose" = "xtrue" ]; then
649 cat >&2 -- "$fff.err"
651 if [ -f
"$fff.write" ]; then
652 cat -- "$fff.write" >> "$fff.res"
653 elif [ -d
"$fff.write" ]; then
654 LANG
=C
/bin
/ls -F
-- "$fff.write" >> "$fff.res"
656 if [ -s
"$fff.err" ]; then
657 cp -- "$fff.res" "$fff.res2"
658 cat -- "$fff.err" "$fff.res2" > "$fff.res"
660 process_result
"$bff" " $name" "$pack"
663 elif [ -f
"$ff.bin" ]; then
664 #Not executable (platform?)"
666 process_result
"$bf" "$bf" "$pack"
669 cat -- "$ff.cmp.err" > "$ff.res"
670 echo "Compilation error" > "$ff.res"
671 process_result
"$bf" "$bf" "$pack"
676 if [ "x$isnode" = "xfalse" ]; then
677 echo "engine: $engine ($enginebinname $OPT)"
678 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
680 if [ -n
"$nok" ]; then
682 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
684 if [ -n
"$nos" ]; then
687 if [ -n
"$todos" ]; then
688 echo "todo/fixme: $todos"
690 if [ -n
"$remains" ]; then
691 echo "sav that remains: $remains"
696 if [ "x$ERRLIST" != "x" ]; then
697 if [ -f
"$ERRLIST_TARGET" ]; then
698 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
700 uniq $ERRLIST > $ERRLIST_TARGET
704 echo >>$xml "</testsuite></testsuites>"
706 if [ -n
"$nok" ]; then