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]}
43 Usage
: $e [options
] modulenames
44 -o option Pass option to the engine
45 -v Verbose
(show tests steps
)
47 --engine Use a specific engine
(default
=nitg
)
48 --noskip Do not skip a
test even
if the .skip
file matches
52 # $1 is the pattern of the test
53 # $2 is the file to compare to
55 # 0: if the file to compare to do not exists
56 # 1: if the file match
57 # 2: if the file match with soso
58 # 3: if the file do not match
59 function compare_to_result
()
63 if [ ! -r
"$sav" ]; then return 0; fi
64 test "`cat "$sav"`" = "UNDEFINED" && return 1
65 diff -u
"$sav" "out/$pattern.res" > "out/$pattern.diff.sav.log"
66 if [ "$?" == 0 ]; then
69 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
70 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.sav2"
71 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
72 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
73 diff -u
"out/$pattern.sav2" "out/$pattern.res2" > "out/$pattern.diff.sav.log2"
74 if [ "$?" == 0 ]; then
81 # As argument: the pattern used for the file
82 function process_result
()
99 echo >>$xml "<testcase classname='$pack' name='$description' time='`cat out/$pattern.time.out`' timestamp='`date -Iseconds`'>"
100 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
101 for savdir
in $savdirs; do
102 sav
=$savdir/fixme
/$pattern.res
103 compare_to_result
"$pattern" "$sav"
113 if [ -z
"$FIRST" ]; then
120 if [ -z
"$FIRST" ]; then
128 sav
=$savdir/$pattern.res
129 compare_to_result
"$pattern" "$sav"
139 if [ -z
"$FIRST" ]; then
146 if [ -z
"$FIRST" ]; then
154 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
155 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
157 if [ -n
"$SAV" ]; then
158 if [ -n
"$OLD" ]; then
159 echo "[*ok*] out/$pattern.res $SAV - but $OLD remains!"
160 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
161 remains
="$remains $OLD"
163 echo "[ok] out/$pattern.res $SAV"
166 elif [ -n
"$FIXME" ]; then
167 if [ -n
"$OLD" ]; then
168 echo "[*fixme*] out/$pattern.res $FIXME - but $OLD remains!"
169 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
170 remains
="$remains $OLD"
172 echo "[fixme] out/$pattern.res $FIXME"
173 echo >>$xml "<skipped/>"
175 todos
="$todos $pattern"
176 elif [ "x$NYI" = "x0" ]; then
177 echo "[todo] out/$pattern.res -> not yet implemented"
178 echo >>$xml "<skipped/>"
179 todos
="$todos $pattern"
180 elif [ -n
"$SOSO" ]; then
181 echo "[======= soso out/$pattern.res $SOSO =======]"
182 echo >>$xml "<error message='soso out/$pattern.res $SOSO'/>"
183 echo >>$xml "<system-out><![CDATA["
184 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
185 echo >>$xml "]]></system-out>"
187 echo "$ii" >> "$ERRLIST"
188 elif [ -n
"$SOSOF" ]; then
189 echo "[======= fixme soso out/$pattern.res $SOSOF =======]"
190 echo >>$xml "<error message='soso out/$pattern.res $SOSO'/>"
191 echo >>$xml "<system-out><![CDATA["
192 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
193 echo >>$xml "]]></system-out>"
195 echo "$ii" >> "$ERRLIST"
196 elif [ -n
"$NSAV" ]; then
197 echo "[======= fail out/$pattern.res $NSAV =======]"
198 echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
199 echo >>$xml "<system-out><![CDATA["
200 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
201 echo >>$xml "]]></system-out>"
203 echo "$ii" >> "$ERRLIST"
204 elif [ -n
"$NFIXME" ]; then
205 echo "[======= changed out/$pattern.res $NFIXME ======]"
206 echo >>$xml "<error message='changed out/$pattern.res $NFIXME'/>"
207 echo >>$xml "<system-out><![CDATA["
208 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
209 echo >>$xml "]]></system-out>"
211 echo "$ii" >> "$ERRLIST"
212 elif [ -s out
/$pattern.res
]; then
213 echo "[=== no sav ===] out/$pattern.res is not empty"
214 echo >>$xml "<error message='no sav and not empty'/>"
215 echo >>$xml "<system-out><![CDATA["
216 cat -v
>>$xml out
/$pattern.res
217 echo >>$xml "]]></system-out>"
219 echo "$ii" >> "$ERRLIST"
221 # no sav but empty res
222 echo "[0k] out/$pattern.res is empty"
225 if test -s out
/$pattern.
cmp.err
; then
226 echo >>$xml "<system-err><![CDATA["
227 cat -v
>>$xml out
/$pattern.
cmp.err
228 echo >>$xml "]]></system-err>"
230 echo >>$xml "</testcase>"
235 test "$noskip" = true
&& return 1
236 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
238 echo >>$xml "<testcase classname='$3' name='$2' timestamp='`date -Iseconds`'><skipped/></testcase>"
241 if test -n
"$isinterpret" && echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
242 echo "=> $2: [skip exec]"
243 echo >>$xml "<testcase classname='$3' name='$2' timestamp='`date -Iseconds`'><skipped/></testcase>"
251 test "$noskip" = true
&& return 1
252 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
261 test "$noskip" = true
&& return 1
262 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
270 name
="$enginebinname"
271 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
272 if [[ "x$recent" == "x" ]]; then
273 echo "Could not find binary for engine $engine, aborting"
276 echo "Find binary for engine $engine: $recent $OPT"
285 while [ $stop = false
]; do
287 -o
) OPT
="$OPT $2"; shift; shift;;
288 -v
) verbose
=true
; shift;;
290 --engine
) engine
="$2"; shift; shift;;
291 --noskip
) noskip
=true
; shift;;
295 enginebinname
=$engine
301 OPT
="--separate $OPT"
305 OPT
="--separate $OPT"
313 OPT
="--semi-global $OPT"
333 OPT
="-m emscripten_nodejs.nit --semi-global $OPT"
334 savdirs
="sav/nitg-sg/"
337 echo "disabled engine $engine"
341 echo "unknown engine $engine"
346 savdirs
="sav/$engine $savdirs sav/"
348 # The default nitc compiler
349 [ -z
"$NITC" ] && find_nitc
351 # Set NIT_DIR if needed
352 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
354 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
355 TIMEOUT
="timelimit -t 600"
356 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
357 TIMEOUT
="timeout 600s"
359 echo "No timelimit or timeout command detected. Tests may hang :("
362 # Mark to distinguish files among tests
365 # File where error tests are outputed
366 # Old ERRLIST is backuped
367 ERRLIST
=${ERRLIST:-errlist}
368 ERRLIST_TARGET
=$ERRLIST
375 # Initiate new ERRLIST
376 if [ "x$ERRLIST" = "x" ]; then
386 xml
="tests-$engine.xml"
387 echo >$xml "<testsuites><testsuite>"
389 # CLEAN the out directory
390 rm -rf out
/ 2>/dev
/null
391 mkdir out
2>/dev
/null
394 if [ ! -f
$ii ]; then
395 echo "File '$ii' does not exist."
398 f
=`basename "$ii" .nit`
400 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|'`
402 # Sould we skip the file for this engine?
403 need_skip
$f $f $pack && continue
406 if [ "x$tmp" = "x$ii" ]; then
407 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
412 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
413 bf
=`basename $i .nit`
416 # Sould we skip the alternative for this engine?
417 need_skip
$bf $bf $pack && continue
421 if [ -f
"$f.inputs" ]; then
423 export MNIT_READ_INPUT
="$f.inputs"
426 export MNIT_READ_INPUT
=/dev
/null
430 if [ "$engine" = "emscripten" ]; then
434 if [ -n
"$isinterpret" ]; then
435 cat > "./$ff.bin" <<END
436 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
442 echo 0.0 > "$ff.time.out"
444 if skip_cc
"$bf"; then
450 if [ "x$verbose" = "xtrue" ]; then
452 echo $NITC --no
-color
$OPT -o
"$ffout" "$i" "$includes" $nocc
454 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
455 /usr
/bin
/time --quiet
-f
%U
-o
"$ff.time.out" $TIMEOUT $NITC --no
-color
$OPT -o
"$ffout" "$i" $includes $nocc 2> "$ff.cmp.err" > "$ff.compile.log"
457 if [ "x$verbose" = "xtrue" ]; then
458 cat "$ff.compile.log"
459 cat >&2 "$ff.cmp.err"
462 if [ "$engine" = "emscripten" ]; then
463 echo > "./$ff.bin" "nodejs $ffout \"\$@\""
465 if grep "Fatal Error: more than one primitive class" "$ff.compile.log" > /dev
/null
; then
466 echo " [skip] do no not imports kernel"
467 echo >>$xml "<testcase classname='$pack' name='$bf' timestamp='`date -Iseconds`'><skipped/></testcase>"
471 if [ "$ERR" != 0 ]; then
473 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
474 process_result
$bf $bf $pack
475 elif [ -n
"$nocc" ]; then
479 process_result
$bf $bf $pack
480 elif [ -x
"./$ff.bin" ]; then
481 if skip_exec
"$bf"; then
484 process_result
$bf $bf $pack
490 if [ "x$verbose" = "xtrue" ]; then
492 echo "NIT_NO_STACK=1 ./$ff.bin" $args
494 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
495 /usr
/bin
/time --quiet
-f
%U
-a
-o
"$ff.time.out" $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
496 mv $ff.
time.out
$ff.
times.out
497 awk '{ SUM += $1} END { print SUM }' $ff.
times.out
> $ff.
time.out
499 if [ "x$verbose" = "xtrue" ]; then
503 if [ -f
"$ff.write" ]; then
504 cat "$ff.write" >> "$ff.res"
505 elif [ -d
"$ff.write" ]; then
506 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
508 cp "$ff.res" "$ff.res2"
509 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
510 process_result
$bf $bf $pack
512 if [ -f
"$f.args" ]; then
520 name
="$bf args $cptr"
522 # Sould we skip the input for this engine?
523 need_skip
$bff " $name" $pack && continue
525 # use a specific inputs file, if required
526 if [ -f
"$bff.inputs" ]; then
527 ffinputs
="$bff.inputs"
532 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
533 if [ "x$verbose" = "xtrue" ]; then
535 echo "NIT_NO_STACK=1 ./$ff.bin" $args
538 echo "./$ff.bin $args" > "./$fff.bin"
539 chmod +x
"./$fff.bin"
540 WRITE
="$fff.write" /usr
/bin
/time --quiet
-f
%U
-o
"$fff.time.out" sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $ffinputs > $fff.res 2>$fff.err"
541 if [ "x$verbose" = "xtrue" ]; then
545 if [ -f
"$fff.write" ]; then
546 cat "$fff.write" >> "$fff.res"
547 elif [ -d
"$fff.write" ]; then
548 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
550 if [ -s
"$fff.err" ]; then
551 cp "$fff.res" "$fff.res2"
552 cat "$fff.err" "$fff.res2" > "$fff.res"
554 process_result
$bff " $name" $pack
557 elif [ -f
"./$ff.bin" ]; then
558 #Not executable (platform?)"
560 process_result
$bf "$bf" $pack
563 cat "$ff.cmp.err" > "$ff.res"
564 echo "Compilation error" > "$ff.res"
565 process_result
$bf "$bf" $pack
570 echo "engine: $engine ($enginebinname $OPT)"
571 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
573 if [ -n
"$nok" ]; then
575 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
577 if [ -n
"$nos" ]; then
580 if [ -n
"$todos" ]; then
581 echo "todo/fixme: $todos"
583 if [ -n
"$remains" ]; then
584 echo "sav that remains: $remains"
588 if [ "x$ERRLIST" != "x" ]; then
589 if [ -f
"$ERRLIST_TARGET" ]; then
590 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
592 uniq $ERRLIST > $ERRLIST_TARGET
596 echo >>$xml "</testsuite></testsuites>"
598 if [ -n
"$nok" ]; then