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]}`
40 # User CPU time limit (in seconds)
41 # Is used to avoid to CPU intensive test (infinite loops). See ulimit -t
42 usertimelimit
=600 # 1 CPU minute
44 # Real-time limit (in seconds)
45 # Is used to avoid waiting or sleeping tests.
46 # Require timeout or timelimit, or else is not used.
47 realtimelimit
=300 # 5 min
49 # User limit for write files (in kilo-bytes)
50 # Is used to avoid execution that loop and fill the hard drive. See ulimit -f
51 # Note that a test might require a lot of temporary disk space (eg. nitc+gcc)
52 filelimit
=100000 # ~100MB
54 # Limit (in bytes) for generated .res file.
55 # Larger ones are truncated and will fail tests
56 # Is used to avoid processing huge crappy res file (diff, xml, etc)
57 reslimit
=100000 # ~100KB
63 Usage
: $e [options
] modulenames
64 -o option Pass option to the engine
65 -v Verbose
(show tests steps
)
67 --engine Use a specific engine
(default
=nitc
)
68 --noskip Do not skip a
test even
if the .skip
file matches
69 --outdir Use a specific output folder
(default
=out
/)
70 --compdir Use a specific temporary compilation folder
(default
=$compdir)
71 --node Run as a node
in parallel
, will not output context information
72 --autosav Copy the .res files directly
in the sav folder overriding existing .res files
76 # Run a command with a timeout and a time count.
78 # -o file write the user time into file (REQUIRED). see `-o` in `man time`
79 # -a append the time to the file (instead of overwriting it). see `-a` in `man time`
85 while [ $stop = false
]; do
87 -o
) o
="$2"; shift; shift;;
93 ulimit -f
"$filelimit"
94 ulimit -t
"$usertimelimit"
97 elif test -n
"$TIME"; then
98 $TIME -o
"$o" $a $TIMEOUT "$@"
100 if test -n
"$a"; then echo 0 >> "$o"; else echo 0 > "$o"; fi
106 # Output a timestamp attribute for XML, or an empty line
109 if test -n
"$TIMESTAMP"; then
110 echo "timestamp='`$TIMESTAMP`'"
117 # Get platform specific commands ##########################
119 # Detect a working timeout
120 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
121 TIMEOUT
="timelimit -t $realtimelimit"
122 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
123 TIMEOUT
="timeout ${realtimelimit}s"
125 echo "No timelimit or timeout command detected. Tests may hang :("
128 # Detect a working time command
129 if env
time --quiet
-f
%U true
2>/dev
/null
; then
130 TIME
="env time --quiet -f%U"
131 elif env
time -f
%U true
2>/dev
/null
; then
137 # Detect a working date command
138 if date -Iseconds
>/dev
/null
2>&1; then
139 TIMESTAMP
="date -Iseconds"
144 # $1 is the pattern of the test
145 # $2 is the file to compare to
147 # 0: if the file to compare to do not exists
148 # 1: if the file match
149 # 2: if the file match with soso
150 # 3: if the file do not match
151 function compare_to_result
()
155 if [ ! -r
"$sav" ]; then return 0; fi
156 test "`cat -- "$sav"`" = "UNDEFINED" && return 1
157 diff -u
-- "$sav" "$outdir/$pattern.res" > "$outdir/$pattern.diff.sav.log"
158 if [ "$?" == 0 ]; then
161 sed '/[Ww]arning/d;/[Ee]rror/d' "$outdir/$pattern.res" > "$outdir/$pattern.res2"
162 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "$outdir/$pattern.sav2"
163 grep '[Ee]rror' "$outdir/$pattern.res" >/dev
/null
&& echo "Error" >> "$outdir/$pattern.res2"
164 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "$outdir/$pattern.sav2"
165 diff -u
"$outdir/$pattern.sav2" "$outdir/$pattern.res2" > "$outdir/$pattern.diff.sav.log2"
166 if [ "$?" == 0 ]; then
175 sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g'<<EOF
180 # As argument: the pattern used for the file
181 function process_result
()
199 # Truncate too big res file
200 local size
=$
(wc -c
< "$outdir/$pattern.res")
201 if test -n
"$reslimit" -a
"$size" -gt
"$reslimit"; then
202 # The most portable way to truncate a file is with Perl
203 perl
-e
"truncate \"$outdir/$pattern.res\", $reslimit;"
204 echo "***TRUNCATED***" >> "$outdir/$pattern.res"
207 echo >>$xml "<testcase classname='`xmlesc "$pack"`' name='`xmlesc "$description"`' time='`cat -- "$outdir/$pattern.
time.out
"`' `timestamp`>"
208 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
209 for savdir
in $savdirs; do
210 local sav
=$savdir/fixme
/$pattern.res
211 compare_to_result
"$pattern" "$sav"
221 if [ -z
"$FIRST" ]; then
228 if [ -z
"$FIRST" ]; then
236 sav
=$savdir/$pattern.res
237 compare_to_result
"$pattern" "$sav"
247 if [ -z
"$FIRST" ]; then
254 if [ -z
"$FIRST" ]; then
262 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
263 istodo
"$outdir/$pattern.res"
265 if [ -n
"$SAV" ]; then
266 if [ -n
"$OLD" ]; then
267 echo "[*ok*] $outdir/$pattern.res $SAV - but $OLD remains!"
268 echo >>$xml "<error message='`xmlesc "ok
$outdir/$pattern.res
- but
$OLD remains
"`'/>"
269 remains
="$remains $OLD"
270 test "$autosav" = "true" && rm "$OLD"
272 echo "[ok] $outdir/$pattern.res $SAV"
275 elif [ -n
"$FIXME" ]; then
276 if [ -n
"$OLD" ]; then
277 echo "[*fixme*] $outdir/$pattern.res $FIXME - but $OLD remains!"
278 echo >>$xml "<error message='`xmlesc "ok
$outdir/$pattern.res
- but
$OLD remains
"`'/>"
279 remains
="$remains $OLD"
280 test "$autosav" = "true" && rm "$OLD"
282 echo "[fixme] $outdir/$pattern.res $FIXME"
283 echo >>$xml "<skipped/>"
285 todos
="$todos $pattern"
286 elif [ "x$NYI" = "x0" ]; then
287 echo "[todo] $outdir/$pattern.res -> not yet implemented"
288 echo >>$xml "<skipped/>"
289 todos
="$todos $pattern"
290 elif [ -n
"$SOSO" ]; then
291 echo "[======= soso $outdir/$pattern.res $SOSO =======]"
292 echo >>$xml "<error message='`xmlesc "soso
$outdir/$pattern.res
$SOSO"`'/>"
293 echo >>$xml "<system-out><![CDATA["
294 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
295 echo >>$xml "]]></system-out>"
297 echo "$ii" >> "$ERRLIST"
298 test "$autosav" = "true" && cp "$outdir/$pattern.res" "$SOSO"
299 elif [ -n
"$SOSOF" ]; then
300 echo "[======= fixme soso $outdir/$pattern.res $SOSOF =======]"
301 echo >>$xml "<error message='`xmlesc "soso
$outdir/$pattern.res
$SOSO"`'/>"
302 echo >>$xml "<system-out><![CDATA["
303 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
304 echo >>$xml "]]></system-out>"
306 echo "$ii" >> "$ERRLIST"
307 test "$autosav" = "true" && cp "$outdir/$pattern.res" && "$SOSO"
308 elif [ -n
"$NSAV" ]; then
309 echo "[======= fail $outdir/$pattern.res $NSAV =======]"
310 echo >>$xml "<error message='`xmlesc "fail
$outdir/$pattern.res
$NSAV"`'/>"
311 echo >>$xml "<system-out><![CDATA["
312 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
313 echo >>$xml "]]></system-out>"
315 echo "$ii" >> "$ERRLIST"
316 test "$autosav" = "true" && cp "$outdir/$pattern.res" "$NSAV"
317 elif [ -n
"$NFIXME" ]; then
318 echo "[======= changed $outdir/$pattern.res $NFIXME ======]"
319 echo >>$xml "<error message='`xmlesc "changed
$outdir/$pattern.res
$NFIXME"`'/>"
320 echo >>$xml "<system-out><![CDATA["
321 cat -v
-- "$outdir/$pattern.diff.sav.log" |
head >>$xml -n
50
322 echo >>$xml "]]></system-out>"
324 echo "$ii" >> "$ERRLIST"
325 test "$autosav" = "true" && cp "$outdir/$pattern.res" "$NFIXME"
326 elif [ -s
"$outdir/$pattern.res" ]; then
327 echo "[=== no sav ===] $outdir/$pattern.res is not empty"
328 echo >>$xml "<error message='no sav and not empty'/>"
329 echo >>$xml "<system-out><![CDATA["
330 cat -v
>>$xml -- "$outdir/$pattern.res"
331 echo >>$xml "]]></system-out>"
333 echo "$ii" >> "$ERRLIST"
334 test "$autosav" = "true" && cp "$outdir/$pattern.res" "sav/"
336 # no sav but empty res
337 echo "[0k] $outdir/$pattern.res is empty"
340 if test -s
"$outdir/$pattern.cmp.err"; then
341 echo >>$xml "<system-err><![CDATA["
342 cat -v
>>$xml -- "$outdir/$pattern.cmp.err"
343 echo >>$xml "]]></system-err>"
345 echo >>$xml "</testcase>"
350 test "$noskip" = true
&& return 1
351 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
353 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
356 if test -n
"$isinterpret" && echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
357 echo "=> $2: [skip exec]"
358 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
363 local os_skip_file
=`uname`.skip
364 if test -e
$os_skip_file && echo "$1" |
grep -f
"$os_skip_file" >/dev
/null
2>&1; then
365 echo "=> $2: [skip os]"
366 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
371 local host_skip_file
=`hostname -s`.skip
372 if test -e
$host_skip_file && echo "$1" |
grep -f
"$host_skip_file" >/dev
/null
2>&1; then
373 echo "=> $2: [skip hostname]"
374 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
382 test "$noskip" = true
&& return 1
383 for savdir
in $savdirs .
; do
384 local f
="$savdir/exec.skip"
385 test -f
"$f" ||
continue
386 if echo "$1" |
grep -f
"$f" >/dev
/null
2>&1; then
387 echo -n
"_ no exec by $f; "
396 test "$noskip" = true
&& return 1
397 for savdir
in $savdirs .
; do
398 local f
="$savdir/cc.skip"
399 test -f
"$f" ||
continue
400 if echo "$1" |
grep -f
"$f" >/dev
/null
2>&1; then
407 # Check that the resfile ($1) matches some magic strings in `todo` files.
410 test "$no" = true
&& return 1
411 for savdir
in $savdirs .
; do
412 local f
="$savdir/todo"
413 test -f
"$f" ||
continue
414 if grep -f
"$f" "$1" >/dev
/null
2>&1; then
423 local name
="$enginebinname"
424 local recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
425 if [[ "x$recent" == "x" ]]; then
426 echo "Could not find binary for engine $engine, aborting"
429 if [ "x$isnode" = "xfalse" ]; then
430 echo "Found binary for engine $engine: $recent $OPT"
442 while [ $stop = false
]; do
444 -o
) OPT
="$OPT $2"; shift; shift;;
445 -v
) verbose
=true
; shift;;
447 --engine
) engine
="$2"; shift; shift;;
448 --noskip
) noskip
=true
; shift;;
449 --outdir
) outdir
="$2"; shift; shift;;
450 --compdir
) compdir
="$2"; shift; shift;;
451 --node
) isnode
=true
; shift;;
452 --autosav
) autosav
=true
; shift;;
456 enginebinname
=$engine
462 OPT
="--separate $OPT --compile-dir $compdir"
463 savdirs
="sav/nitc-common/"
468 OPT
="--separate $OPT --compile-dir $compdir"
469 savdirs
="sav/nitc-common/"
474 OPT
="--erasure $OPT --compile-dir $compdir"
475 savdirs
="sav/nitc-common/"
480 OPT
="--semi-global $OPT --compile-dir $compdir"
481 savdirs
="sav/nitc-common/"
486 OPT
="--global $OPT --compile-dir $compdir"
487 savdirs
="sav/nitc-common/"
505 OPT
="--compile-dir $compdir --ant"
507 savdirs
="sav/nitc-common/"
511 OPT
="-m emscripten_nodejs.nit --semi-global $OPT --compile-dir $compdir"
512 savdirs
="sav/nitcsg/"
515 echo "unknown engine $engine"
520 savdirs
="sav/`hostname -s` sav/`uname` sav/$engine $savdirs sav/"
522 # The default nitc compiler
523 [ -z
"$NITC" ] && find_nitc
525 # Set NIT_DIR if needed
526 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
528 # Mark to distinguish files among tests
536 # CLEAN the out directory
537 rm -rf
"$outdir/" 2>/dev
/null
538 mkdir
"$outdir" 2>/dev
/null
540 # File where error tests are outputed
541 # Old ERRLIST is backuped
542 ERRLIST
=${ERRLIST:-errlist}
543 ERRLIST_TARGET
=$ERRLIST
545 # Initiate new ERRLIST
546 if [ "x$ERRLIST" = "x" ]; then
557 if [ "x$XMLDIR" = "x" ]; then
558 xml
="tests-$engine.xml"
560 sum=`echo $@ | md5sum | cut -f1 -d " "`
561 xml
="$XMLDIR/tests-$engine-$sum.xml"
565 echo >$xml "<testsuites><testsuite>"
568 if [ ! -f
"$ii" ]; then
569 echo "File '$ii' does not exist."
572 f
=`basename -- "$ii" .nit`
574 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|'`
576 # Sould we skip the file for this engine?
577 need_skip
"$f" "$f" "$pack" && continue
580 if [ "x$tmp" = "x$ii" ]; then
581 includes
="-I . -I ../lib/core -I ../lib/core/collection -I alt"
586 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' -- "$ii"`; do
587 bf
=`basename -- "$i" .nit`
590 # Sould we skip the alternative for this engine?
591 need_skip
"$bf" "$bf" "$pack" && continue
595 if [ -f
"$f.inputs" ]; then
597 export MNIT_READ_INPUT
="$f.inputs"
600 export MNIT_READ_INPUT
=/dev
/null
604 if [ "$engine" = "emscripten" ]; then
608 if [ -n
"$isinterpret" ]; then
609 cat > "$ff.bin" <<END
610 exec $NITC --no
-color
$OPT $includes -- $
(printf '%q' "$i") "\$@"
616 echo 0.0 > "$ff.time.out"
618 if skip_cc
"$bf"; then
624 if [ "x$verbose" = "xtrue" ]; then
626 echo $NITC --no
-color
$OPT -o
"$ffout" "$includes" $nocc "$i"
628 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
629 saferun
-o
"$ff.time.out" $NITC --no
-color
$OPT -o
"$ffout" $includes $nocc "$i" 2> "$ff.cmp.err" > "$ff.compile.log"
631 if [ "x$verbose" = "xtrue" ]; then
632 cat -- "$ff.compile.log"
633 cat >&2 -- "$ff.cmp.err"
636 rm -r
"$compdir" 2>/dev
/null
638 if [ "$engine" = "emscripten" ]; then
639 echo > "$ff.bin" "nodejs $ffout \"\$@\""
641 if grep "Fatal Error: more than one primitive class" "$ff.compile.log" > /dev
/null
; then
642 echo " [skip] do no not imports kernel"
643 echo >>$xml "<testcase classname='`xmlesc "$pack"`' name='`xmlesc "$bf"`' `timestamp`><skipped/></testcase>"
647 if [ "$ERR" != 0 ]; then
649 cat -- "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
650 process_result
"$bf" "$bf" "$pack"
651 elif [ -n
"$nocc" ]; then
655 process_result
"$bf" "$bf" "$pack"
656 elif [ -x
"$ff.bin" ]; then
657 if skip_exec
"$bf"; then
660 process_result
"$bf" "$bf" "$pack"
666 if [ "x$verbose" = "xtrue" ]; then
668 echo "NIT_NO_STACK=1 $ff.bin" $args
670 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
671 saferun
-a
-o
"$ff.time.out" "$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
672 mv "$ff.time.out" "$ff.times.out"
673 awk '{ SUM += $1} END { print SUM }' "$ff.times.out" > "$ff.time.out"
675 if [ "x$verbose" = "xtrue" ]; then
679 if [ -f
"$ff.write" ]; then
680 cat -- "$ff.write" >> "$ff.res"
681 elif [ -d
"$ff.write" ]; then
682 LANG
=C
/bin
/ls -F
"$ff.write" >> "$ff.res"
684 cp -- "$ff.res" "$ff.res2"
685 cat -- "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
686 process_result
"$bf" "$bf" "$pack"
688 if [ -f
"$f.args" ]; then
696 name
="$bf args $cptr"
698 # Sould we skip the input for this engine?
699 need_skip
"$bff" " $name" "$pack" && continue
701 # use a specific inputs file, if required
702 if [ -f
"$bff.inputs" ]; then
703 ffinputs
="$bff.inputs"
708 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
709 if [ "x$verbose" = "xtrue" ]; then
711 echo "NIT_NO_STACK=1 $ff.bin" $args
714 echo "$ff.bin $args" > "$fff.bin"
716 WRITE
="$fff.write" saferun
-o
"$fff.time.out" sh
-c
"NIT_NO_STACK=1 $fff.bin < $ffinputs > $fff.res 2>$fff.err"
717 if [ "x$verbose" = "xtrue" ]; then
719 cat >&2 -- "$fff.err"
721 if [ -f
"$fff.write" ]; then
722 cat -- "$fff.write" >> "$fff.res"
723 elif [ -d
"$fff.write" ]; then
724 LANG
=C
/bin
/ls -F
-- "$fff.write" >> "$fff.res"
726 if [ -s
"$fff.err" ]; then
727 cp -- "$fff.res" "$fff.res2"
728 cat -- "$fff.err" "$fff.res2" > "$fff.res"
730 process_result
"$bff" " $name" "$pack"
733 elif [ -f
"$ff.bin" ]; then
734 #Not executable (platform?)"
736 process_result
"$bf" "$bf" "$pack"
739 cat -- "$ff.cmp.err" > "$ff.res"
740 echo "Compilation error" > "$ff.res"
741 process_result
"$bf" "$bf" "$pack"
746 if [ "x$isnode" = "xfalse" ]; then
747 echo "engine: $engine ($enginebinname $OPT)"
748 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
750 if [ -n
"$nok" ]; then
752 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
754 if [ -n
"$nos" ]; then
757 if [ -n
"$todos" ]; then
758 echo "todo/fixme: $todos"
760 if [ -n
"$remains" ]; then
761 echo "sav that remains: $remains"
766 if [ "x$ERRLIST" != "x" ]; then
767 if [ -f
"$ERRLIST_TARGET" ]; then
768 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
770 uniq $ERRLIST > $ERRLIST_TARGET
774 echo >>$xml "</testsuite></testsuites>"
776 if [ -n
"$nok" ]; then