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 test "`cat "$sav"`" = "UNDEFINED" && return 1
63 diff -u
"$sav" "out/$pattern.res" > "out/$pattern.diff.sav.log"
64 if [ "$?" == 0 ]; then
67 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
68 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.sav2"
69 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
70 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
71 diff -u
"out/$pattern.sav2" "out/$pattern.res2" > "out/$pattern.diff.sav.log2"
72 if [ "$?" == 0 ]; then
79 # As argument: the pattern used for the file
80 function process_result
()
97 echo >>$xml "<testcase classname='$pack' name='$description'>"
98 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
99 for savdir
in $savdirs; do
100 sav
=$savdir/fixme
/$pattern.res
101 compare_to_result
"$pattern" "$sav"
111 if [ -z
"$FIRST" ]; then
118 if [ -z
"$FIRST" ]; then
126 sav
=$savdir/$pattern.res
127 compare_to_result
"$pattern" "$sav"
137 if [ -z
"$FIRST" ]; then
144 if [ -z
"$FIRST" ]; then
152 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
153 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
155 if [ -n
"$SAV" ]; then
156 if [ -n
"$OLD" ]; then
157 echo "[*ok*] out/$pattern.res $SAV - but $OLD remains!"
158 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
159 remains
="$remains $OLD"
161 echo "[ok] out/$pattern.res $SAV"
164 elif [ -n
"$FIXME" ]; then
165 if [ -n
"$OLD" ]; then
166 echo "[*fixme*] out/$pattern.res $FIXME - but $OLD remains!"
167 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
168 remains
="$remains $OLD"
170 echo "[fixme] out/$pattern.res $FIXME"
171 echo >>$xml "<skipped/>"
173 todos
="$todos $pattern"
174 elif [ "x$NYI" = "x0" ]; then
175 echo "[todo] out/$pattern.res -> not yet implemented"
176 echo >>$xml "<skipped/>"
177 todos
="$todos $pattern"
178 elif [ -n
"$SOSO" ]; then
179 echo "[======= soso out/$pattern.res $SOSO =======]"
180 echo >>$xml "<error message='soso out/$pattern.res $SOSO'/>"
181 echo >>$xml "<system-out><![CDATA["
182 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
183 echo >>$xml "]]></system-out>"
185 echo "$ii" >> "$ERRLIST"
186 elif [ -n
"$SOSOF" ]; then
187 echo "[======= fixme soso out/$pattern.res $SOSOF =======]"
188 echo >>$xml "<error message='soso out/$pattern.res $SOSO'/>"
189 echo >>$xml "<system-out><![CDATA["
190 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
191 echo >>$xml "]]></system-out>"
193 echo "$ii" >> "$ERRLIST"
194 elif [ -n
"$NSAV" ]; then
195 echo "[======= fail out/$pattern.res $NSAV =======]"
196 echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
197 echo >>$xml "<system-out><![CDATA["
198 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
199 echo >>$xml "]]></system-out>"
201 echo "$ii" >> "$ERRLIST"
202 elif [ -n
"$NFIXME" ]; then
203 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 echo "[=== no sav ===] out/$pattern.res is not empty"
212 echo >>$xml "<error message='no sav and not empty'/>"
213 echo >>$xml "<system-out><![CDATA["
214 cat -v
>>$xml out
/$pattern.res
215 echo >>$xml "]]></system-out>"
218 # no sav but empty res
219 echo "[0k] out/$pattern.res is empty"
222 if test -s out
/$pattern.
cmp.err
; then
223 echo >>$xml "<system-err><![CDATA["
224 cat -v
>>$xml out
/$pattern.
cmp.err
225 echo >>$xml "]]></system-err>"
227 echo >>$xml "</testcase>"
232 test "$noskip" = true
&& return 1
233 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
235 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
238 if test $engine = niti
&& echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
239 echo "=> $2: [skip exec]"
240 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
248 test "$noskip" = true
&& return 1
249 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
258 test "$noskip" = true
&& return 1
259 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
267 name
="$enginebinname"
268 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
269 if [[ "x$recent" == "x" ]]; then
270 echo "Could not find binary for engine $engine, aborting"
273 echo "Find binary for engine $engine: $recent $OPT"
282 while [ $stop = false
]; do
284 -o
) OPT
="$OPT $2"; shift; shift;;
285 -v
) verbose
=true
; shift;;
287 --engine
) engine
="$2"; shift; shift;;
288 --noskip
) noskip
=true
; shift;;
292 enginebinname
=$engine
297 OPT
="--separate $OPT"
301 OPT
="--separate $OPT"
309 OPT
="--semi-global $OPT"
323 OPT
="-m emscripten_nodejs.nit --semi-global $OPT"
324 savdirs
="sav/nitg-sg/"
327 echo "disabled engine $engine"
331 echo "unknown engine $engine"
336 savdirs
="sav/$engine $savdirs sav/"
338 # The default nitc compiler
339 [ -z
"$NITC" ] && find_nitc
341 # Set NIT_DIR if needed
342 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
344 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
345 TIMEOUT
="timelimit -t 600"
346 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
347 TIMEOUT
="timeout 600s"
349 echo "No timelimit or timeout command detected. Tests may hang :("
352 # Mark to distinguish files among tests
355 # File where error tests are outputed
356 # Old ERRLIST is backuped
357 ERRLIST
=${ERRLIST:-errlist}
358 ERRLIST_TARGET
=$ERRLIST
365 # Initiate new ERRLIST
366 if [ "x$ERRLIST" = "x" ]; then
376 xml
="tests-$engine.xml"
377 echo >$xml "<testsuites><testsuite>"
379 # CLEAN the out directory
380 rm -rf out
/ 2>/dev
/null
381 mkdir out
2>/dev
/null
384 if [ ! -f
$ii ]; then
385 echo "File '$ii' does not exist."
388 f
=`basename "$ii" .nit`
390 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|'`
392 # Sould we skip the file for this engine?
393 need_skip
$f $f $pack && continue
396 if [ "x$tmp" = "x$ii" ]; then
397 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
402 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
403 bf
=`basename $i .nit`
406 # Sould we skip the alternative for this engine?
407 need_skip
$bf $bf $pack && continue
411 if [ -f
"$f.inputs" ]; then
418 if [ "$engine" = "emscripten" ]; then
422 if [ "$engine" = "niti" ]; then
423 cat > "./$ff.bin" <<END
424 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
431 if skip_cc
"$bf"; then
437 if [ "x$verbose" = "xtrue" ]; then
439 echo $NITC --no
-color
$OPT -o
"$ffout" "$i" "$includes" $nocc
441 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
442 $TIMEOUT $NITC --no
-color
$OPT -o
"$ffout" "$i" $includes $nocc 2> "$ff.cmp.err" > "$ff.compile.log"
444 if [ "x$verbose" = "xtrue" ]; then
445 cat "$ff.compile.log"
446 cat >&2 "$ff.cmp.err"
449 if [ "$engine" = "emscripten" ]; then
450 echo > "./$ff.bin" "nodejs $ffout \"\$@\""
452 if grep "Fatal Error: more than one primitive class" "$ff.compile.log" > /dev
/null
; then
453 echo " [skip] do no not imports kernel"
454 echo >>$xml "<testcase classname='$pack' name='$bf'><skipped/></testcase>"
458 if [ "$ERR" != 0 ]; then
460 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
461 process_result
$bf $bf $pack
462 elif skip_exec
"$bf"; then
465 process_result
$bf $bf $pack
466 elif [ -n
"$nocc" ]; then
470 process_result
$bf $bf $pack
471 elif [ -x
"./$ff.bin" ]; then
475 if [ "x$verbose" = "xtrue" ]; then
477 echo "NIT_NO_STACK=1 ./$ff.bin" $args
479 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
480 $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
481 if [ "x$verbose" = "xtrue" ]; then
485 if [ -f
"$ff.write" ]; then
486 cat "$ff.write" >> "$ff.res"
487 elif [ -d
"$ff.write" ]; then
488 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
490 cp "$ff.res" "$ff.res2"
491 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
492 process_result
$bf $bf $pack
494 if [ -f
"$f.args" ]; then
502 name
="$bf args $cptr"
504 # Sould we skip the input for this engine?
505 need_skip
$bff " $name" $pack && continue
507 # use a specific inputs file, if required
508 if [ -f
"$bff.inputs" ]; then
509 ffinputs
="$bff.inputs"
514 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
515 if [ "x$verbose" = "xtrue" ]; then
517 echo "NIT_NO_STACK=1 ./$ff.bin" $args
520 echo "./$ff.bin $args" > "./$fff.bin"
521 chmod +x
"./$fff.bin"
522 WRITE
="$fff.write" sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $ffinputs > $fff.res 2>$fff.err"
523 if [ "x$verbose" = "xtrue" ]; then
527 if [ -f
"$fff.write" ]; then
528 cat "$fff.write" >> "$fff.res"
529 elif [ -d
"$fff.write" ]; then
530 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
532 if [ -s
"$fff.err" ]; then
533 cp "$fff.res" "$fff.res2"
534 cat "$fff.err" "$fff.res2" > "$fff.res"
536 process_result
$bff " $name" $pack
539 elif [ -f
"./$ff.bin" ]; then
540 echo "Not executable (platform?)" > "$ff.res"
541 process_result
$bf "$bf" $pack
544 cat "$ff.cmp.err" > "$ff.res"
545 echo "Compilation error" > "$ff.res"
546 process_result
$bf "$bf" $pack
551 echo "engine: $engine ($enginebinname $OPT)"
552 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
554 if [ -n
"$nok" ]; then
556 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
558 if [ -n
"$nos" ]; then
561 if [ -n
"$todos" ]; then
562 echo "todo/fixme: $todos"
564 if [ -n
"$remains" ]; then
565 echo "sav that remains: $remains"
569 if [ "x$ERRLIST" != "x" ]; then
570 if [ -x
"$ERRLIST_TARGET" ]; then
571 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
573 mv $ERRLIST $ERRLIST_TARGET
576 echo >>$xml "</testsuite></testsuites>"
578 if [ -n
"$nok" ]; then