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
26 # Get the first Java lib available
28 paths
=`echo /usr/lib/jvm/*/`
32 paths
=`echo $JAVA_HOME/jre/lib/*/{client,server}/`
34 JNI_LIB_PATH
=${paths[0]}
41 Usage
: $e [options
] modulenames
42 -o option Pass option to the engine
43 -v Verbose
(show tests steps
)
45 --engine Use a specific engine
(default
=nitg
)
46 --noskip Do not skip a
test even
if the .skip
file matches
50 # $1 is the pattern of the test
51 # $2 is the file to compare to
53 # 0: if the file to compare to do not exists
54 # 1: if the file match
55 # 2: if the file match with soso
56 # 3: if the file do not match
57 function compare_to_result
()
61 if [ ! -r
"$sav" ]; then return 0; fi
62 diff -u
"$sav" "out/$pattern.res" > "out/$pattern.diff.sav.log"
63 if [ "$?" == 0 ]; then
66 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
67 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.sav2"
68 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
69 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
70 diff -u
"out/$pattern.sav2" "out/$pattern.res2" > "out/$pattern.diff.sav.log2"
71 if [ "$?" == 0 ]; then
78 # As argument: the pattern used for the file
79 function process_result
()
96 echo >>$xml "<testcase classname='$pack' name='$description'>"
97 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
98 for savdir
in $savdirs; do
99 sav
=$savdir/fixme
/$pattern.res
100 compare_to_result
"$pattern" "$sav"
110 if [ -z
"$FIRST" ]; then
117 if [ -z
"$FIRST" ]; then
125 sav
=$savdir/$pattern.res
126 compare_to_result
"$pattern" "$sav"
136 if [ -z
"$FIRST" ]; then
143 if [ -z
"$FIRST" ]; then
151 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
152 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
154 if [ -n
"$SAV" ]; then
155 if [ -n
"$OLD" ]; then
156 echo "[*ok*] out/$pattern.res $SAV - but $OLD remains!"
157 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
158 remains
="$remains $OLD"
160 echo "[ok] out/$pattern.res $SAV"
163 elif [ -n
"$FIXME" ]; then
164 if [ -n
"$OLD" ]; then
165 echo "[*fixme*] out/$pattern.res $FIXME - but $OLD remains!"
166 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
167 remains
="$remains $OLD"
169 echo "[fixme] out/$pattern.res $FIXME"
170 echo >>$xml "<skipped/>"
172 todos
="$todos $pattern"
173 elif [ "x$NYI" = "x0" ]; then
174 echo "[todo] out/$pattern.res -> not yet implemented"
175 echo >>$xml "<skipped/>"
176 todos
="$todos $pattern"
177 elif [ -n
"$SOSO" ]; then
178 echo "[======= soso out/$pattern.res $SOSO =======]"
179 echo >>$xml "<error message='soso out/$pattern.res $SOSO'/>"
180 echo >>$xml "<system-out><![CDATA["
181 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
182 echo >>$xml "]]></system-out>"
184 echo "$ii" >> "$ERRLIST"
185 elif [ -n
"$SOSOF" ]; then
186 echo "[======= fixme soso out/$pattern.res $SOSOF =======]"
187 echo >>$xml "<error message='soso out/$pattern.res $SOSO'/>"
188 echo >>$xml "<system-out><![CDATA["
189 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
190 echo >>$xml "]]></system-out>"
192 echo "$ii" >> "$ERRLIST"
193 elif [ -n
"$NSAV" ]; then
194 echo "[======= fail out/$pattern.res $NSAV =======]"
195 echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
196 echo >>$xml "<system-out><![CDATA["
197 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
198 echo >>$xml "]]></system-out>"
200 echo "$ii" >> "$ERRLIST"
201 elif [ -n
"$NFIXME" ]; then
202 echo "[======= changed out/$pattern.res $NFIXME ======]"
203 echo >>$xml "<error message='changed out/$pattern.res $NFIXME'/>"
204 echo >>$xml "<system-out><![CDATA["
205 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
206 echo >>$xml "]]></system-out>"
208 echo "$ii" >> "$ERRLIST"
209 elif [ -s out
/$pattern.res
]; then
210 echo "[=== no sav ===] out/$pattern.res is not empty"
211 echo >>$xml "<error message='no sav and not empty'/>"
212 echo >>$xml "<system-out><![CDATA["
213 cat -v
>>$xml out
/$pattern.res
214 echo >>$xml "]]></system-out>"
217 # no sav but empty res
218 echo "[0k] out/$pattern.res is empty"
221 if test -s out
/$pattern.
cmp.err
; then
222 echo >>$xml "<system-err><![CDATA["
223 cat -v
>>$xml out
/$pattern.
cmp.err
224 echo >>$xml "]]></system-err>"
226 echo >>$xml "</testcase>"
231 test "$noskip" = true
&& return 1
232 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
234 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
237 if test $engine = niti
&& echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
238 echo "=> $2: [skip exec]"
239 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
247 test "$noskip" = true
&& return 1
248 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
257 test "$noskip" = true
&& return 1
258 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
266 name
="$enginebinname"
267 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
268 if [[ "x$recent" == "x" ]]; then
269 echo "Could not find binary for engine $engine, aborting"
272 echo "Find binary for engine $engine: $recent $OPT"
281 while [ $stop = false
]; do
283 -o
) OPT
="$OPT $2"; shift; shift;;
284 -v
) verbose
=true
; shift;;
286 --engine
) engine
="$2"; shift; shift;;
287 --noskip
) noskip
=true
; shift;;
291 enginebinname
=$engine
296 OPT
="--separate $OPT"
300 OPT
="--separate $OPT"
317 echo "disabled engine $engine"
321 echo "unknown engine $engine"
326 savdirs
="sav/$engine $savdirs sav/"
328 # The default nitc compiler
329 [ -z
"$NITC" ] && find_nitc
331 # Set NIT_DIR if needed
332 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
334 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
335 TIMEOUT
="timelimit -t 600"
336 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
337 TIMEOUT
="timeout 600s"
339 echo "No timelimit or timeout command detected. Tests may hang :("
342 # Mark to distinguish files among tests
345 # File where error tests are outputed
346 # Old ERRLIST is backuped
347 ERRLIST
=${ERRLIST:-errlist}
348 ERRLIST_TARGET
=$ERRLIST
355 # Initiate new ERRLIST
356 if [ "x$ERRLIST" = "x" ]; then
366 xml
="tests-$engine.xml"
367 echo >$xml "<testsuites><testsuite>"
369 # CLEAN the out directory
370 rm -rf out
/ 2>/dev
/null
371 mkdir out
2>/dev
/null
374 if [ ! -f
$ii ]; then
375 echo "File '$ii' does not exist."
378 f
=`basename "$ii" .nit`
380 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|'`
382 # Sould we skip the file for this engine?
383 need_skip
$f $f $pack && continue
386 if [ "x$tmp" = "x$ii" ]; then
387 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
392 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
393 bf
=`basename $i .nit`
396 # Sould we skip the alternative for this engine?
397 need_skip
$bf $bf $pack && continue
401 if [ -f
"$f.inputs" ]; then
407 if [ "$engine" = "niti" ]; then
408 cat > "./$ff.bin" <<END
409 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
416 if skip_cc
"$bf"; then
422 if [ "x$verbose" = "xtrue" ]; then
424 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes" $nocc
426 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
427 $TIMEOUT $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes $nocc 2> "$ff.cmp.err" > "$ff.compile.log"
429 if [ "x$verbose" = "xtrue" ]; then
430 cat "$ff.compile.log"
431 cat >&2 "$ff.cmp.err"
434 if [ "$ERR" != 0 ]; then
436 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
437 process_result
$bf $bf $pack
438 elif skip_exec
"$bf"; then
441 process_result
$bf $bf $pack
442 elif [ -n
"$nocc" ]; then
446 process_result
$bf $bf $pack
447 elif [ -x
"./$ff.bin" ]; then
451 if [ "x$verbose" = "xtrue" ]; then
453 echo "NIT_NO_STACK=1 ./$ff.bin" $args
455 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
456 $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
457 if [ "x$verbose" = "xtrue" ]; then
461 if [ -f
"$ff.write" ]; then
462 cat "$ff.write" >> "$ff.res"
463 elif [ -d
"$ff.write" ]; then
464 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
466 cp "$ff.res" "$ff.res2"
467 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
468 process_result
$bf $bf $pack
470 if [ -f
"$f.args" ]; then
478 name
="$bf args $cptr"
480 # Sould we skip the input for this engine?
481 need_skip
$bff " $name" $pack && continue
483 # use a specific inputs file, if required
484 if [ -f
"$bff.inputs" ]; then
485 ffinputs
="$bff.inputs"
490 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
491 if [ "x$verbose" = "xtrue" ]; then
493 echo "NIT_NO_STACK=1 ./$ff.bin" $args
496 echo "./$ff.bin $args" > "./$fff.bin"
497 chmod +x
"./$fff.bin"
498 WRITE
="$fff.write" sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $ffinputs > $fff.res 2>$fff.err"
499 if [ "x$verbose" = "xtrue" ]; then
503 if [ -f
"$fff.write" ]; then
504 cat "$fff.write" >> "$fff.res"
505 elif [ -d
"$fff.write" ]; then
506 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
508 if [ -s
"$fff.err" ]; then
509 cp "$fff.res" "$fff.res2"
510 cat "$fff.err" "$fff.res2" > "$fff.res"
512 process_result
$bff " $name" $pack
515 elif [ -f
"./$ff.bin" ]; then
516 echo "Not executable (platform?)" > "$ff.res"
517 process_result
$bf "$bf" $pack
520 cat "$ff.cmp.err" > "$ff.res"
521 echo "Compilation error" > "$ff.res"
522 process_result
$bf "$bf" $pack
527 echo "engine: $engine ($enginebinname $OPT)"
528 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
530 if [ -n
"$nok" ]; then
532 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
534 if [ -n
"$nos" ]; then
537 if [ -n
"$todos" ]; then
538 echo "todo/fixme: $todos"
540 if [ -n
"$remains" ]; then
541 echo "sav that remains: $remains"
545 if [ "x$ERRLIST" != "x" ]; then
546 if [ -x
"$ERRLIST_TARGET" ]; then
547 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
549 mv $ERRLIST $ERRLIST_TARGET
552 echo >>$xml "</testsuite></testsuites>"
554 if [ -n
"$nok" ]; then