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
)
57 # $1 is the pattern of the test
58 # $2 is the file to compare to
60 # 0: if the file to compare to do not exists
61 # 1: if the file match
62 # 2: if the file match with soso
63 # 3: if the file do not match
64 function compare_to_result
()
68 if [ ! -r
"$sav" ]; then return 0; fi
69 test "`cat "$sav"`" = "UNDEFINED" && return 1
70 diff -u
"$sav" "$outdir/$pattern.res" > "$outdir/$pattern.diff.sav.log"
71 if [ "$?" == 0 ]; then
74 sed '/[Ww]arning/d;/[Ee]rror/d' "$outdir/$pattern.res" > "$outdir/$pattern.res2"
75 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "$outdir/$pattern.sav2"
76 grep '[Ee]rror' "$outdir/$pattern.res" >/dev
/null
&& echo "Error" >> "$outdir/$pattern.res2"
77 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "$outdir/$pattern.sav2"
78 diff -u
"$outdir/$pattern.sav2" "$outdir/$pattern.res2" > "$outdir/$pattern.diff.sav.log2"
79 if [ "$?" == 0 ]; then
86 # As argument: the pattern used for the file
87 function process_result
()
104 echo >>$xml "<testcase classname='$pack' name='$description' time='`cat $outdir/$pattern.time.out`' timestamp='`date -Iseconds`'>"
105 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
106 for savdir
in $savdirs; do
107 sav
=$savdir/fixme
/$pattern.res
108 compare_to_result
"$pattern" "$sav"
118 if [ -z
"$FIRST" ]; then
125 if [ -z
"$FIRST" ]; then
133 sav
=$savdir/$pattern.res
134 compare_to_result
"$pattern" "$sav"
144 if [ -z
"$FIRST" ]; then
151 if [ -z
"$FIRST" ]; then
159 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
160 grep 'NOT YET IMPLEMENTED' "$outdir/$pattern.res" >/dev
/null
162 if [ -n
"$SAV" ]; then
163 if [ -n
"$OLD" ]; then
164 echo "[*ok*] $outdir/$pattern.res $SAV - but $OLD remains!"
165 echo >>$xml "<error message='ok $outdir/$pattern.res - but $OLD remains'/>"
166 remains
="$remains $OLD"
168 echo "[ok] $outdir/$pattern.res $SAV"
171 elif [ -n
"$FIXME" ]; then
172 if [ -n
"$OLD" ]; then
173 echo "[*fixme*] $outdir/$pattern.res $FIXME - but $OLD remains!"
174 echo >>$xml "<error message='ok $outdir/$pattern.res - but $OLD remains'/>"
175 remains
="$remains $OLD"
177 echo "[fixme] $outdir/$pattern.res $FIXME"
178 echo >>$xml "<skipped/>"
180 todos
="$todos $pattern"
181 elif [ "x$NYI" = "x0" ]; then
182 echo "[todo] $outdir/$pattern.res -> not yet implemented"
183 echo >>$xml "<skipped/>"
184 todos
="$todos $pattern"
185 elif [ -n
"$SOSO" ]; then
186 echo "[======= soso $outdir/$pattern.res $SOSO =======]"
187 echo >>$xml "<error message='soso $outdir/$pattern.res $SOSO'/>"
188 echo >>$xml "<system-out><![CDATA["
189 cat -v
$outdir/$pattern.
diff.sav.log |
head >>$xml -n
50
190 echo >>$xml "]]></system-out>"
192 echo "$ii" >> "$ERRLIST"
193 elif [ -n
"$SOSOF" ]; then
194 echo "[======= fixme soso $outdir/$pattern.res $SOSOF =======]"
195 echo >>$xml "<error message='soso $outdir/$pattern.res $SOSO'/>"
196 echo >>$xml "<system-out><![CDATA["
197 cat -v
$outdir/$pattern.
diff.sav.log |
head >>$xml -n
50
198 echo >>$xml "]]></system-out>"
200 echo "$ii" >> "$ERRLIST"
201 elif [ -n
"$NSAV" ]; then
202 echo "[======= fail $outdir/$pattern.res $NSAV =======]"
203 echo >>$xml "<error message='fail $outdir/$pattern.res $NSAV'/>"
204 echo >>$xml "<system-out><![CDATA["
205 cat -v
$outdir/$pattern.
diff.sav.log |
head >>$xml -n
50
206 echo >>$xml "]]></system-out>"
208 echo "$ii" >> "$ERRLIST"
209 elif [ -n
"$NFIXME" ]; then
210 echo "[======= changed $outdir/$pattern.res $NFIXME ======]"
211 echo >>$xml "<error message='changed $outdir/$pattern.res $NFIXME'/>"
212 echo >>$xml "<system-out><![CDATA["
213 cat -v
$outdir/$pattern.
diff.sav.log |
head >>$xml -n
50
214 echo >>$xml "]]></system-out>"
216 echo "$ii" >> "$ERRLIST"
217 elif [ -s
$outdir/$pattern.res
]; then
218 echo "[=== no sav ===] $outdir/$pattern.res is not empty"
219 echo >>$xml "<error message='no sav and not empty'/>"
220 echo >>$xml "<system-out><![CDATA["
221 cat -v
>>$xml $outdir/$pattern.res
222 echo >>$xml "]]></system-out>"
224 echo "$ii" >> "$ERRLIST"
226 # no sav but empty res
227 echo "[0k] $outdir/$pattern.res is empty"
230 if test -s
$outdir/$pattern.
cmp.err
; then
231 echo >>$xml "<system-err><![CDATA["
232 cat -v
>>$xml $outdir/$pattern.
cmp.err
233 echo >>$xml "]]></system-err>"
235 echo >>$xml "</testcase>"
240 test "$noskip" = true
&& return 1
241 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
243 echo >>$xml "<testcase classname='$3' name='$2' timestamp='`date -Iseconds`'><skipped/></testcase>"
246 if test -n
"$isinterpret" && echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
247 echo "=> $2: [skip exec]"
248 echo >>$xml "<testcase classname='$3' name='$2' timestamp='`date -Iseconds`'><skipped/></testcase>"
256 test "$noskip" = true
&& return 1
257 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
266 test "$noskip" = true
&& return 1
267 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
275 name
="$enginebinname"
276 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
277 if [[ "x$recent" == "x" ]]; then
278 echo "Could not find binary for engine $engine, aborting"
281 echo "Find binary for engine $engine: $recent $OPT"
290 while [ $stop = false
]; do
292 -o
) OPT
="$OPT $2"; shift; shift;;
293 -v
) verbose
=true
; shift;;
295 --engine
) engine
="$2"; shift; shift;;
296 --noskip
) noskip
=true
; shift;;
297 --outdir
) outdir
="$2"; shift; shift;;
298 --compdir
) compdir
="$2"; shift; shift;;
302 enginebinname
=$engine
308 OPT
="--separate $OPT --compile-dir $compdir"
312 OPT
="--separate $OPT --compile-dir $compdir"
316 OPT
="--erasure $OPT --compile-dir $compdir"
320 OPT
="--semi-global $OPT --compile-dir $compdir"
324 OPT
="--global $OPT --compile-dir $compdir"
340 OPT
="-m emscripten_nodejs.nit --semi-global $OPT --compile-dir $compdir"
341 savdirs
="sav/nitg-sg/"
344 echo "disabled engine $engine"
348 echo "unknown engine $engine"
353 savdirs
="sav/$engine $savdirs sav/"
355 # The default nitc compiler
356 [ -z
"$NITC" ] && find_nitc
358 # Set NIT_DIR if needed
359 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
361 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
362 TIMEOUT
="timelimit -t 600"
363 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
364 TIMEOUT
="timeout 600s"
366 echo "No timelimit or timeout command detected. Tests may hang :("
369 # Mark to distinguish files among tests
372 # File where error tests are outputed
373 # Old ERRLIST is backuped
374 ERRLIST
=${ERRLIST:-errlist}
375 ERRLIST_TARGET
=$ERRLIST
382 # Initiate new ERRLIST
383 if [ "x$ERRLIST" = "x" ]; then
393 xml
="tests-$engine.xml"
394 echo >$xml "<testsuites><testsuite>"
396 # CLEAN the out directory
397 rm -rf
"$outdir/" 2>/dev
/null
398 mkdir
"$outdir" 2>/dev
/null
401 if [ ! -f
$ii ]; then
402 echo "File '$ii' does not exist."
405 f
=`basename "$ii" .nit`
407 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|'`
409 # Sould we skip the file for this engine?
410 need_skip
$f $f $pack && continue
413 if [ "x$tmp" = "x$ii" ]; then
414 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
419 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
420 bf
=`basename $i .nit`
423 # Sould we skip the alternative for this engine?
424 need_skip
$bf $bf $pack && continue
428 if [ -f
"$f.inputs" ]; then
430 export MNIT_READ_INPUT
="$f.inputs"
433 export MNIT_READ_INPUT
=/dev
/null
437 if [ "$engine" = "emscripten" ]; then
441 if [ -n
"$isinterpret" ]; then
442 cat > "$ff.bin" <<END
443 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
449 echo 0.0 > "$ff.time.out"
451 if skip_cc
"$bf"; then
457 if [ "x$verbose" = "xtrue" ]; then
459 echo $NITC --no
-color
$OPT -o
"$ffout" "$i" "$includes" $nocc
461 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
462 /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"
464 if [ "x$verbose" = "xtrue" ]; then
465 cat "$ff.compile.log"
466 cat >&2 "$ff.cmp.err"
469 if [ "$engine" = "emscripten" ]; then
470 echo > "$ff.bin" "nodejs $ffout \"\$@\""
472 if grep "Fatal Error: more than one primitive class" "$ff.compile.log" > /dev
/null
; then
473 echo " [skip] do no not imports kernel"
474 echo >>$xml "<testcase classname='$pack' name='$bf' timestamp='`date -Iseconds`'><skipped/></testcase>"
478 if [ "$ERR" != 0 ]; then
480 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
481 process_result
$bf $bf $pack
482 elif [ -n
"$nocc" ]; then
486 process_result
$bf $bf $pack
487 elif [ -x
"$ff.bin" ]; then
488 if skip_exec
"$bf"; then
491 process_result
$bf $bf $pack
497 if [ "x$verbose" = "xtrue" ]; then
499 echo "NIT_NO_STACK=1 $ff.bin" $args
501 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
502 /usr
/bin
/time -f
%U
-a
-o
"$ff.time.out" $TIMEOUT "$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
503 mv $ff.
time.out
$ff.
times.out
504 awk '{ SUM += $1} END { print SUM }' $ff.
times.out
> $ff.
time.out
506 if [ "x$verbose" = "xtrue" ]; then
510 if [ -f
"$ff.write" ]; then
511 cat "$ff.write" >> "$ff.res"
512 elif [ -d
"$ff.write" ]; then
513 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
515 cp "$ff.res" "$ff.res2"
516 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
517 process_result
$bf $bf $pack
519 if [ -f
"$f.args" ]; then
527 name
="$bf args $cptr"
529 # Sould we skip the input for this engine?
530 need_skip
$bff " $name" $pack && continue
532 # use a specific inputs file, if required
533 if [ -f
"$bff.inputs" ]; then
534 ffinputs
="$bff.inputs"
539 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
540 if [ "x$verbose" = "xtrue" ]; then
542 echo "NIT_NO_STACK=1 $ff.bin" $args
545 echo "$ff.bin $args" > "$fff.bin"
547 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"
548 if [ "x$verbose" = "xtrue" ]; then
552 if [ -f
"$fff.write" ]; then
553 cat "$fff.write" >> "$fff.res"
554 elif [ -d
"$fff.write" ]; then
555 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
557 if [ -s
"$fff.err" ]; then
558 cp "$fff.res" "$fff.res2"
559 cat "$fff.err" "$fff.res2" > "$fff.res"
561 process_result
$bff " $name" $pack
564 elif [ -f
"$ff.bin" ]; then
565 #Not executable (platform?)"
567 process_result
$bf "$bf" $pack
570 cat "$ff.cmp.err" > "$ff.res"
571 echo "Compilation error" > "$ff.res"
572 process_result
$bf "$bf" $pack
577 echo "engine: $engine ($enginebinname $OPT)"
578 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
580 if [ -n
"$nok" ]; then
582 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
584 if [ -n
"$nos" ]; then
587 if [ -n
"$todos" ]; then
588 echo "todo/fixme: $todos"
590 if [ -n
"$remains" ]; then
591 echo "sav that remains: $remains"
595 if [ "x$ERRLIST" != "x" ]; then
596 if [ -f
"$ERRLIST_TARGET" ]; then
597 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
599 uniq $ERRLIST > $ERRLIST_TARGET
603 echo >>$xml "</testsuite></testsuites>"
605 if [ -n
"$nok" ]; then