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
22 export NIT_TESTING
=true
27 # Get the first Java lib available
29 paths
=`echo /usr/lib/jvm/*/`
33 paths
=`echo $JAVA_HOME/jre/lib/*/{client,server}/`
35 JNI_LIB_PATH
=${paths[0]}
42 Usage
: $e [options
] modulenames
43 -o option Pass option to the engine
44 -v Verbose
(show tests steps
)
46 --tap Produce TAP output
47 --engine Use a specific engine
(default
=nitg
)
48 --noskip Do not skip a
test even
if the .skip
file matches
49 --[no
]soso Force
enable (or disable
) SOSO
53 # $1 is the pattern of the test
54 # $2 is the file to compare to
56 # 0: if the file to compare to do not exists
57 # 1: if the file match
58 # 2: if the file match with soso
59 # 3: if the file do not match
60 function compare_to_result
()
64 if [ ! -r
"$sav" ]; then return 0; fi
65 diff -u
"$sav" "out/$pattern.res" > "out/$pattern.diff.sav.log"
66 if [ "$?" == 0 ]; then
69 [ -z
"$soso" ] && return 3
70 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
71 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.sav2"
72 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
73 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
74 diff -u
"out/$pattern.sav2" "out/$pattern.res2" > "out/$pattern.diff.sav.log"
75 if [ "$?" == 0 ]; then
82 # As argument: the pattern used for the file
83 function process_result
()
85 ((tapcount
=tapcount
+1))
101 echo >>$xml "<testcase classname='$pack' name='$description'>"
102 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
103 for savdir
in $savdirs; do
104 sav
=$savdir/$pattern.res
105 compare_to_result
"$pattern" "$sav"
123 if [ -z
"$FIRST" ]; then
129 if [ -z
"$FIRST" ]; then
137 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
138 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
140 if [ -n
"$SAV" ]; then
141 if [ -n
"$tap" ]; then
142 echo "ok - $description"
143 elif [ -n
"$OLD" ]; then
144 echo "[*ok*] out/$pattern.res $SAV - but $OLD remains!"
145 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
146 remains
="$remains $OLD"
148 echo "[ok] out/$pattern.res $SAV"
151 elif [ -n
"$FIXME" ]; then
152 if [ -n
"$tap" ]; then
153 echo "not ok - $description # TODO expected failure"
154 elif [ -n
"$OLD" ]; then
155 echo "[*fixme*] out/$pattern.res $FIXME - but $OLD remains!"
156 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
157 remains
="$remains $OLD"
159 echo "[fixme] out/$pattern.res $FIXME"
160 echo >>$xml "<skipped/>"
162 todos
="$todos $pattern"
163 elif [ -n
"$SOSO" ]; then
164 if [ -n
"$tap" ]; then
165 echo "ok - $description # SOSO"
167 echo "[soso] out/$pattern.res $SOSO"
170 elif [ "x$NYI" = "x0" ]; then
171 if [ -n
"$tap" ]; then
172 echo "not ok - $description # TODO not yet implemented"
174 echo "[todo] out/$pattern.res -> not yet implemented"
175 echo >>$xml "<skipped/>"
177 todos
="$todos $pattern"
178 elif [ -n
"$SOSOF" ]; then
179 if [ -n
"$tap" ]; then
180 echo "not ok - $description # TODO SOSO expected failure"
182 echo "[fixme soso] out/$pattern.res $SOSOF"
183 echo >>$xml "<skipped/>"
185 todos
="$todos $pattern"
186 elif [ -n
"$NSAV" ]; then
187 if [ -n
"$tap" ]; then
188 echo "not ok - $description"
190 echo "[======= fail out/$pattern.res $NSAV =======]"
192 echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
193 echo >>$xml "<system-out><![CDATA["
194 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
195 echo >>$xml "]]></system-out>"
197 echo "$ii" >> "$ERRLIST"
198 elif [ -n
"$NFIXME" ]; then
199 if [ -n
"$tap" ]; then
200 echo "not ok - $description"
202 echo "[======= changed out/$pattern.res $NFIXME ======]"
204 echo >>$xml "<error message='changed out/$pattern.res $NFIXME'/>"
205 echo >>$xml "<system-out><![CDATA["
206 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
207 echo >>$xml "]]></system-out>"
209 echo "$ii" >> "$ERRLIST"
210 elif [ -s out
/$pattern.res
]; then
211 if [ -n
"$tap" ]; then
212 echo "no ok - $description"
214 echo "[=== no sav ===] out/$pattern.res is not empty"
216 echo >>$xml "<error message='no sav and not empty'/>"
217 echo >>$xml "<system-out><![CDATA["
218 cat -v
>>$xml out
/$pattern.res
219 echo >>$xml "]]></system-out>"
222 # no sav but empty res
223 if [ -n
"$tap" ]; then
224 echo "ok - $description"
226 echo "[0k] out/$pattern.res is empty"
230 if test -s out
/$pattern.
cmp.err
; then
231 echo >>$xml "<system-err><![CDATA["
232 cat -v
>>$xml out
/$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
242 ((tapcount
=tapcount
+1))
243 if [ -n
"$tap" ]; then
244 echo "ok - $2 # skip"
248 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
251 if test $engine = niti
&& echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
252 ((tapcount
=tapcount
+1))
253 if [ -n
"$tap" ]; then
254 echo "ok - $2 # skip"
256 echo "=> $2: [skip exec]"
258 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
266 test "$noskip" = true
&& return 1
267 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
276 test "$noskip" = true
&& return 1
277 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
285 ((tapcount
=tapcount
+1))
286 name
="$enginebinname"
287 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
288 if [[ "x$recent" == "x" ]]; then
289 if [ -n
"$tap" ]; then
290 echo "not ok - find binary for $engine"
291 echo "Bail out! Could not find binary for engine $engine, aborting"
293 echo "Could not find binary for engine $engine, aborting"
297 if [ -n
"$tap" ]; then
298 echo "ok - find binary for $engine: $recent $OPT"
300 echo "Find binary for engine $engine: $recent $OPT"
310 while [ $stop = false
]; do
312 -o
) OPT
="$OPT $2"; shift; shift;;
313 -v
) verbose
=true
; shift;;
315 --tap
) tap
=true
; shift;;
316 --engine
) engine
="$2"; shift; shift;;
317 --noskip
) noskip
=true
; shift;;
318 --soso
) soso
=true
; shift;;
319 --nososo
) nososo
=true
; shift;;
323 enginebinname
=$engine
328 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
329 OPT
="--separate $OPT"
333 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
334 OPT
="--separate $OPT"
338 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
343 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
348 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
352 savdirs
="sav/$engine/fixme/ sav/$engine/ sav/fixme/ sav/"
355 echo "disabled engine $engine"
359 echo "unknown engine $engine"
364 # The default nitc compiler
365 [ -z
"$NITC" ] && find_nitc
367 # Set NIT_DIR if needed
368 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
370 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
371 TIMEOUT
="timelimit -t 600"
372 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
373 TIMEOUT
="timeout 600s"
375 echo "No timelimit or timeout command detected. Tests may hang :("
378 # Mark to distinguish files among tests
381 # File where error tests are outputed
382 # Old ERRLIST is backuped
383 ERRLIST
=${ERRLIST:-errlist}
384 ERRLIST_TARGET
=$ERRLIST
391 # Initiate new ERRLIST
392 if [ "x$ERRLIST" = "x" ]; then
402 xml
="tests-$engine.xml"
403 echo >$xml "<testsuites><testsuite>"
405 # CLEAN the out directory
406 rm -rf out
/ 2>/dev
/null
407 mkdir out
2>/dev
/null
410 if [ ! -f
$ii ]; then
411 echo "File '$ii' does not exist."
414 f
=`basename "$ii" .nit`
416 pack
=`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|'`
418 # Sould we skip the file for this engine?
419 need_skip
$f $f $pack && continue
422 if [ "x$tmp" = "x$ii" ]; then
423 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
428 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
429 bf
=`basename $i .nit`
432 # Sould we skip the alternative for this engine?
433 need_skip
$bf $bf $pack && continue
435 test -z
"$tap" && echo -n
"=> $bf: "
437 if [ -f
"$f.inputs" ]; then
439 export MNIT_READ_INPUT
="$f.inputs"
442 export MNIT_READ_INPUT
=/dev
/null
445 if [ "$engine" = "niti" ]; then
446 cat > "./$ff.bin" <<END
447 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
454 if skip_cc
"$bf"; then
460 if [ "x$verbose" = "xtrue" ]; then
462 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes" $nocc
464 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
465 $TIMEOUT $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes $nocc 2> "$ff.cmp.err" > "$ff.compile.log"
467 if [ "x$verbose" = "xtrue" ]; then
468 cat "$ff.compile.log"
469 cat >&2 "$ff.cmp.err"
472 if [ "$ERR" != 0 ]; then
473 test -z
"$tap" && echo -n
"! "
474 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
475 process_result
$bf $bf $pack
476 elif skip_exec
"$bf"; then
479 process_result
$bf $bf $pack
480 elif [ -n
"$nocc" ]; then
482 test -z
"$tap" && echo -n
"nocc "
484 process_result
$bf $bf $pack
485 elif [ -x
"./$ff.bin" ]; then
486 test -z
"$tap" && echo -n
". "
489 if [ "x$verbose" = "xtrue" ]; then
491 echo "NIT_NO_STACK=1 ./$ff.bin" $args
493 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
494 $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
495 if [ "x$verbose" = "xtrue" ]; then
499 if [ -f
"$ff.write" ]; then
500 cat "$ff.write" >> "$ff.res"
501 elif [ -d
"$ff.write" ]; then
502 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
504 cp "$ff.res" "$ff.res2"
505 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
506 process_result
$bf $bf $pack
508 if [ -f
"$f.args" ]; then
516 name
="$bf args $cptr"
518 # Sould we skip the input for this engine?
519 need_skip
$bff " $name" $pack && continue
521 # use a specific inputs file, if required
522 if [ -f
"$bff.inputs" ]; then
523 ffinputs
="$bff.inputs"
528 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
529 if [ "x$verbose" = "xtrue" ]; then
531 echo "NIT_NO_STACK=1 ./$ff.bin" $args
533 test -z
"$tap" && echo -n
"==> $name "
534 echo "./$ff.bin $args" > "./$fff.bin"
535 chmod +x
"./$fff.bin"
536 WRITE
="$fff.write" sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $ffinputs > $fff.res 2>$fff.err"
537 if [ "x$verbose" = "xtrue" ]; then
541 if [ -f
"$fff.write" ]; then
542 cat "$fff.write" >> "$fff.res"
543 elif [ -d
"$fff.write" ]; then
544 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
546 if [ -s
"$fff.err" ]; then
547 cp "$fff.res" "$fff.res2"
548 cat "$fff.err" "$fff.res2" > "$fff.res"
550 process_result
$bff " $name" $pack
553 elif [ -f
"./$ff.bin" ]; then
554 echo "Not executable (platform?)" > "$ff.res"
555 process_result
$bf "$bf" $pack
557 test -z
"$tap" && echo -n
"! "
558 cat "$ff.cmp.err" > "$ff.res"
559 echo "Compilation error" > "$ff.res"
560 process_result
$bf "$bf" $pack
565 if [ -n
"$tap" ]; then
567 echo "# ok:" `echo $ok | wc -w`
568 echo "# not ok:" `echo $nok | wc -w`
569 echo "# no sav:" `echo $nos | wc -w`
570 echo "# todo/fixme:" `echo $todos | wc -w`
571 echo "# of sav that remains:" `echo $remains | wc -w`
575 echo "engine: $engine ($enginebinname $OPT)"
576 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
578 if [ -n
"$nok" ]; then
580 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
582 if [ -n
"$nos" ]; then
585 if [ -n
"$todos" ]; then
586 echo "todo/fixme: $todos"
588 if [ -n
"$remains" ]; then
589 echo "sav that remains: $remains"
593 if [ "x$ERRLIST" != "x" ]; then
594 if [ -x
"$ERRLIST_TARGET" ]; then
595 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
597 mv $ERRLIST $ERRLIST_TARGET
600 echo >>$xml "</testsuite></testsuites>"
602 if [ -n
"$nok" ]; then