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 paths
=`echo /usr/lib/jvm/*/`
34 paths
=`echo $JAVA_HOME/jre/lib/*/{client,server}/`
36 JNI_LIB_PATH
=${paths[0]}
40 compdir
=".nit_compile"
46 Usage
: $e [options
] modulenames
47 -o option Pass option to the engine
48 -v Verbose
(show tests steps
)
50 --engine Use a specific engine
(default
=nitg
)
51 --noskip Do not skip a
test even
if the .skip
file matches
52 --outdir Use a specific output folder
(default
=out
/)
53 --compdir Use a specific temporary compilation folder
(default
=.nit_compile
)
54 --node Run as a node
in parallel
, will not output context information
58 # $1 is the pattern of the test
59 # $2 is the file to compare to
61 # 0: if the file to compare to do not exists
62 # 1: if the file match
63 # 2: if the file match with soso
64 # 3: if the file do not match
65 function compare_to_result
()
69 if [ ! -r
"$sav" ]; then return 0; fi
70 test "`cat "$sav"`" = "UNDEFINED" && return 1
71 diff -u
"$sav" "$outdir/$pattern.res" > "$outdir/$pattern.diff.sav.log"
72 if [ "$?" == 0 ]; then
75 sed '/[Ww]arning/d;/[Ee]rror/d' "$outdir/$pattern.res" > "$outdir/$pattern.res2"
76 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "$outdir/$pattern.sav2"
77 grep '[Ee]rror' "$outdir/$pattern.res" >/dev
/null
&& echo "Error" >> "$outdir/$pattern.res2"
78 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "$outdir/$pattern.sav2"
79 diff -u
"$outdir/$pattern.sav2" "$outdir/$pattern.res2" > "$outdir/$pattern.diff.sav.log2"
80 if [ "$?" == 0 ]; then
87 # As argument: the pattern used for the file
88 function process_result
()
105 echo >>$xml "<testcase classname='$pack' name='$description' time='`cat $outdir/$pattern.time.out`' timestamp='`date -Iseconds`'>"
106 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
107 for savdir
in $savdirs; do
108 sav
=$savdir/fixme
/$pattern.res
109 compare_to_result
"$pattern" "$sav"
119 if [ -z
"$FIRST" ]; then
126 if [ -z
"$FIRST" ]; then
134 sav
=$savdir/$pattern.res
135 compare_to_result
"$pattern" "$sav"
145 if [ -z
"$FIRST" ]; then
152 if [ -z
"$FIRST" ]; then
160 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
161 grep 'NOT YET IMPLEMENTED' "$outdir/$pattern.res" >/dev
/null
163 if [ -n
"$SAV" ]; then
164 if [ -n
"$OLD" ]; then
165 echo "[*ok*] $outdir/$pattern.res $SAV - but $OLD remains!"
166 echo >>$xml "<error message='ok $outdir/$pattern.res - but $OLD remains'/>"
167 remains
="$remains $OLD"
169 echo "[ok] $outdir/$pattern.res $SAV"
172 elif [ -n
"$FIXME" ]; then
173 if [ -n
"$OLD" ]; then
174 echo "[*fixme*] $outdir/$pattern.res $FIXME - but $OLD remains!"
175 echo >>$xml "<error message='ok $outdir/$pattern.res - but $OLD remains'/>"
176 remains
="$remains $OLD"
178 echo "[fixme] $outdir/$pattern.res $FIXME"
179 echo >>$xml "<skipped/>"
181 todos
="$todos $pattern"
182 elif [ "x$NYI" = "x0" ]; then
183 echo "[todo] $outdir/$pattern.res -> not yet implemented"
184 echo >>$xml "<skipped/>"
185 todos
="$todos $pattern"
186 elif [ -n
"$SOSO" ]; then
187 echo "[======= soso $outdir/$pattern.res $SOSO =======]"
188 echo >>$xml "<error message='soso $outdir/$pattern.res $SOSO'/>"
189 echo >>$xml "<system-out><![CDATA["
190 cat -v
$outdir/$pattern.
diff.sav.log |
head >>$xml -n
50
191 echo >>$xml "]]></system-out>"
193 echo "$ii" >> "$ERRLIST"
194 elif [ -n
"$SOSOF" ]; then
195 echo "[======= fixme soso $outdir/$pattern.res $SOSOF =======]"
196 echo >>$xml "<error message='soso $outdir/$pattern.res $SOSO'/>"
197 echo >>$xml "<system-out><![CDATA["
198 cat -v
$outdir/$pattern.
diff.sav.log |
head >>$xml -n
50
199 echo >>$xml "]]></system-out>"
201 echo "$ii" >> "$ERRLIST"
202 elif [ -n
"$NSAV" ]; then
203 echo "[======= fail $outdir/$pattern.res $NSAV =======]"
204 echo >>$xml "<error message='fail $outdir/$pattern.res $NSAV'/>"
205 echo >>$xml "<system-out><![CDATA["
206 cat -v
$outdir/$pattern.
diff.sav.log |
head >>$xml -n
50
207 echo >>$xml "]]></system-out>"
209 echo "$ii" >> "$ERRLIST"
210 elif [ -n
"$NFIXME" ]; then
211 echo "[======= changed $outdir/$pattern.res $NFIXME ======]"
212 echo >>$xml "<error message='changed $outdir/$pattern.res $NFIXME'/>"
213 echo >>$xml "<system-out><![CDATA["
214 cat -v
$outdir/$pattern.
diff.sav.log |
head >>$xml -n
50
215 echo >>$xml "]]></system-out>"
217 echo "$ii" >> "$ERRLIST"
218 elif [ -s
$outdir/$pattern.res
]; then
219 echo "[=== no sav ===] $outdir/$pattern.res is not empty"
220 echo >>$xml "<error message='no sav and not empty'/>"
221 echo >>$xml "<system-out><![CDATA["
222 cat -v
>>$xml $outdir/$pattern.res
223 echo >>$xml "]]></system-out>"
225 echo "$ii" >> "$ERRLIST"
227 # no sav but empty res
228 echo "[0k] $outdir/$pattern.res is empty"
231 if test -s
$outdir/$pattern.
cmp.err
; then
232 echo >>$xml "<system-err><![CDATA["
233 cat -v
>>$xml $outdir/$pattern.
cmp.err
234 echo >>$xml "]]></system-err>"
236 echo >>$xml "</testcase>"
241 test "$noskip" = true
&& return 1
242 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
244 echo >>$xml "<testcase classname='$3' name='$2' timestamp='`date -Iseconds`'><skipped/></testcase>"
247 if test -n
"$isinterpret" && echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
248 echo "=> $2: [skip exec]"
249 echo >>$xml "<testcase classname='$3' name='$2' timestamp='`date -Iseconds`'><skipped/></testcase>"
257 test "$noskip" = true
&& return 1
258 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
267 test "$noskip" = true
&& return 1
268 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
276 name
="$enginebinname"
277 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
278 if [[ "x$recent" == "x" ]]; then
279 echo "Could not find binary for engine $engine, aborting"
282 if [ "x$isnode" = "xfalse" ]; then
283 echo "Found binary for engine $engine: $recent $OPT"
294 while [ $stop = false
]; do
296 -o
) OPT
="$OPT $2"; shift; shift;;
297 -v
) verbose
=true
; shift;;
299 --engine
) engine
="$2"; shift; shift;;
300 --noskip
) noskip
=true
; shift;;
301 --outdir
) outdir
="$2"; shift; shift;;
302 --compdir
) compdir
="$2"; shift; shift;;
303 --node
) isnode
=true
; shift;;
307 enginebinname
=$engine
313 OPT
="--separate $OPT --compile-dir $compdir"
317 OPT
="--separate $OPT --compile-dir $compdir"
321 OPT
="--erasure $OPT --compile-dir $compdir"
325 OPT
="--semi-global $OPT --compile-dir $compdir"
329 OPT
="--global $OPT --compile-dir $compdir"
345 OPT
="-m emscripten_nodejs.nit --semi-global $OPT --compile-dir $compdir"
346 savdirs
="sav/nitg-sg/"
349 echo "disabled engine $engine"
353 echo "unknown engine $engine"
358 savdirs
="sav/$engine $savdirs sav/"
360 # The default nitc compiler
361 [ -z
"$NITC" ] && find_nitc
363 # Set NIT_DIR if needed
364 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
366 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
367 TIMEOUT
="timelimit -t 600"
368 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
369 TIMEOUT
="timeout 600s"
371 echo "No timelimit or timeout command detected. Tests may hang :("
374 # Mark to distinguish files among tests
382 # CLEAN the out directory
383 rm -rf
"$outdir/" 2>/dev
/null
384 mkdir
"$outdir" 2>/dev
/null
386 # File where error tests are outputed
387 # Old ERRLIST is backuped
388 ERRLIST
=${ERRLIST:-errlist}
389 ERRLIST_TARGET
=$ERRLIST
391 # Initiate new ERRLIST
392 if [ "x$ERRLIST" = "x" ]; then
402 xml
="tests-$engine.xml"
403 echo >$xml "<testsuites><testsuite>"
406 if [ ! -f
$ii ]; then
407 echo "File '$ii' does not exist."
410 f
=`basename "$ii" .nit`
412 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|'`
414 # Sould we skip the file for this engine?
415 need_skip
$f $f $pack && continue
418 if [ "x$tmp" = "x$ii" ]; then
419 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
424 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
425 bf
=`basename $i .nit`
428 # Sould we skip the alternative for this engine?
429 need_skip
$bf $bf $pack && continue
433 if [ -f
"$f.inputs" ]; then
435 export MNIT_READ_INPUT
="$f.inputs"
438 export MNIT_READ_INPUT
=/dev
/null
442 if [ "$engine" = "emscripten" ]; then
446 if [ -n
"$isinterpret" ]; then
447 cat > "$ff.bin" <<END
448 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
454 echo 0.0 > "$ff.time.out"
456 if skip_cc
"$bf"; then
462 if [ "x$verbose" = "xtrue" ]; then
464 echo $NITC --no
-color
$OPT -o
"$ffout" "$i" "$includes" $nocc
466 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
467 /usr
/bin
/time -f
%U
-o
"$ff.time.out" $TIMEOUT $NITC --no
-color
$OPT -o
"$ffout" "$i" $includes $nocc 2> "$ff.cmp.err" > "$ff.compile.log"
469 if [ "x$verbose" = "xtrue" ]; then
470 cat "$ff.compile.log"
471 cat >&2 "$ff.cmp.err"
474 if [ "$engine" = "emscripten" ]; then
475 echo > "$ff.bin" "nodejs $ffout \"\$@\""
477 if grep "Fatal Error: more than one primitive class" "$ff.compile.log" > /dev
/null
; then
478 echo " [skip] do no not imports kernel"
479 echo >>$xml "<testcase classname='$pack' name='$bf' timestamp='`date -Iseconds`'><skipped/></testcase>"
483 if [ "$ERR" != 0 ]; then
485 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
486 process_result
$bf $bf $pack
487 elif [ -n
"$nocc" ]; then
491 process_result
$bf $bf $pack
492 elif [ -x
"$ff.bin" ]; then
493 if skip_exec
"$bf"; then
496 process_result
$bf $bf $pack
502 if [ "x$verbose" = "xtrue" ]; then
504 echo "NIT_NO_STACK=1 $ff.bin" $args
506 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
507 /usr
/bin
/time -f
%U
-a
-o
"$ff.time.out" $TIMEOUT "$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
508 mv $ff.
time.out
$ff.
times.out
509 awk '{ SUM += $1} END { print SUM }' $ff.
times.out
> $ff.
time.out
511 if [ "x$verbose" = "xtrue" ]; then
515 if [ -f
"$ff.write" ]; then
516 cat "$ff.write" >> "$ff.res"
517 elif [ -d
"$ff.write" ]; then
518 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
520 cp "$ff.res" "$ff.res2"
521 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
522 process_result
$bf $bf $pack
524 if [ -f
"$f.args" ]; then
532 name
="$bf args $cptr"
534 # Sould we skip the input for this engine?
535 need_skip
$bff " $name" $pack && continue
537 # use a specific inputs file, if required
538 if [ -f
"$bff.inputs" ]; then
539 ffinputs
="$bff.inputs"
544 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
545 if [ "x$verbose" = "xtrue" ]; then
547 echo "NIT_NO_STACK=1 $ff.bin" $args
550 echo "$ff.bin $args" > "$fff.bin"
552 WRITE
="$fff.write" /usr
/bin
/time -f
%U
-o
"$fff.time.out" sh
-c
"NIT_NO_STACK=1 $TIMEOUT $fff.bin < $ffinputs > $fff.res 2>$fff.err"
553 if [ "x$verbose" = "xtrue" ]; then
557 if [ -f
"$fff.write" ]; then
558 cat "$fff.write" >> "$fff.res"
559 elif [ -d
"$fff.write" ]; then
560 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
562 if [ -s
"$fff.err" ]; then
563 cp "$fff.res" "$fff.res2"
564 cat "$fff.err" "$fff.res2" > "$fff.res"
566 process_result
$bff " $name" $pack
569 elif [ -f
"$ff.bin" ]; then
570 #Not executable (platform?)"
572 process_result
$bf "$bf" $pack
575 cat "$ff.cmp.err" > "$ff.res"
576 echo "Compilation error" > "$ff.res"
577 process_result
$bf "$bf" $pack
582 if [ "x$isnode" = "xfalse" ]; then
583 echo "engine: $engine ($enginebinname $OPT)"
584 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
586 if [ -n
"$nok" ]; then
588 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
590 if [ -n
"$nos" ]; then
593 if [ -n
"$todos" ]; then
594 echo "todo/fixme: $todos"
596 if [ -n
"$remains" ]; then
597 echo "sav that remains: $remains"
602 if [ "x$ERRLIST" != "x" ]; then
603 if [ -f
"$ERRLIST_TARGET" ]; then
604 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
606 uniq $ERRLIST > $ERRLIST_TARGET
610 echo >>$xml "</testsuite></testsuites>"
612 if [ -n
"$nok" ]; then