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
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 --engine Use a specific engine
(default
=nitg
)
47 --noskip Do not skip a
test even
if the .skip
file matches
51 # $1 is the pattern of the test
52 # $2 is the file to compare to
54 # 0: if the file to compare to do not exists
55 # 1: if the file match
56 # 2: if the file match with soso
57 # 3: if the file do not match
58 function compare_to_result
()
62 if [ ! -r
"$sav" ]; then return 0; fi
63 test "`cat "$sav"`" = "UNDEFINED" && return 1
64 diff -u
"$sav" "out/$pattern.res" > "out/$pattern.diff.sav.log"
65 if [ "$?" == 0 ]; then
68 sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
69 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.sav2"
70 grep '[Ee]rror' "out/$pattern.res" >/dev
/null
&& echo "Error" >> "out/$pattern.res2"
71 grep '[Ee]rror' "$sav" >/dev
/null
&& echo "Error" >> "out/$pattern.sav2"
72 diff -u
"out/$pattern.sav2" "out/$pattern.res2" > "out/$pattern.diff.sav.log2"
73 if [ "$?" == 0 ]; then
80 # As argument: the pattern used for the file
81 function process_result
()
98 echo >>$xml "<testcase classname='$pack' name='$description'>"
99 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
100 for savdir
in $savdirs; do
101 sav
=$savdir/fixme
/$pattern.res
102 compare_to_result
"$pattern" "$sav"
112 if [ -z
"$FIRST" ]; then
119 if [ -z
"$FIRST" ]; then
127 sav
=$savdir/$pattern.res
128 compare_to_result
"$pattern" "$sav"
138 if [ -z
"$FIRST" ]; then
145 if [ -z
"$FIRST" ]; then
153 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
154 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
156 if [ -n
"$SAV" ]; then
157 if [ -n
"$OLD" ]; then
158 echo "[*ok*] out/$pattern.res $SAV - but $OLD remains!"
159 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
160 remains
="$remains $OLD"
162 echo "[ok] out/$pattern.res $SAV"
165 elif [ -n
"$FIXME" ]; then
166 if [ -n
"$OLD" ]; then
167 echo "[*fixme*] out/$pattern.res $FIXME - but $OLD remains!"
168 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
169 remains
="$remains $OLD"
171 echo "[fixme] out/$pattern.res $FIXME"
172 echo >>$xml "<skipped/>"
174 todos
="$todos $pattern"
175 elif [ "x$NYI" = "x0" ]; then
176 echo "[todo] out/$pattern.res -> not yet implemented"
177 echo >>$xml "<skipped/>"
178 todos
="$todos $pattern"
179 elif [ -n
"$SOSO" ]; then
180 echo "[======= soso out/$pattern.res $SOSO =======]"
181 echo >>$xml "<error message='soso out/$pattern.res $SOSO'/>"
182 echo >>$xml "<system-out><![CDATA["
183 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
184 echo >>$xml "]]></system-out>"
186 echo "$ii" >> "$ERRLIST"
187 elif [ -n
"$SOSOF" ]; then
188 echo "[======= fixme soso out/$pattern.res $SOSOF =======]"
189 echo >>$xml "<error message='soso out/$pattern.res $SOSO'/>"
190 echo >>$xml "<system-out><![CDATA["
191 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
192 echo >>$xml "]]></system-out>"
194 echo "$ii" >> "$ERRLIST"
195 elif [ -n
"$NSAV" ]; then
196 echo "[======= fail out/$pattern.res $NSAV =======]"
197 echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
198 echo >>$xml "<system-out><![CDATA["
199 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
200 echo >>$xml "]]></system-out>"
202 echo "$ii" >> "$ERRLIST"
203 elif [ -n
"$NFIXME" ]; then
204 echo "[======= changed out/$pattern.res $NFIXME ======]"
205 echo >>$xml "<error message='changed out/$pattern.res $NFIXME'/>"
206 echo >>$xml "<system-out><![CDATA["
207 cat -v out
/$pattern.
diff.sav.log |
head >>$xml -n
50
208 echo >>$xml "]]></system-out>"
210 echo "$ii" >> "$ERRLIST"
211 elif [ -s out
/$pattern.res
]; then
212 echo "[=== no sav ===] out/$pattern.res is not empty"
213 echo >>$xml "<error message='no sav and not empty'/>"
214 echo >>$xml "<system-out><![CDATA["
215 cat -v
>>$xml out
/$pattern.res
216 echo >>$xml "]]></system-out>"
219 # no sav but empty res
220 echo "[0k] out/$pattern.res is empty"
223 if test -s out
/$pattern.
cmp.err
; then
224 echo >>$xml "<system-err><![CDATA["
225 cat -v
>>$xml out
/$pattern.
cmp.err
226 echo >>$xml "]]></system-err>"
228 echo >>$xml "</testcase>"
233 test "$noskip" = true
&& return 1
234 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
236 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
239 if test $engine = niti
&& echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
240 echo "=> $2: [skip exec]"
241 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
249 test "$noskip" = true
&& return 1
250 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
259 test "$noskip" = true
&& return 1
260 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
268 name
="$enginebinname"
269 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
270 if [[ "x$recent" == "x" ]]; then
271 echo "Could not find binary for engine $engine, aborting"
274 echo "Find binary for engine $engine: $recent $OPT"
283 while [ $stop = false
]; do
285 -o
) OPT
="$OPT $2"; shift; shift;;
286 -v
) verbose
=true
; shift;;
288 --engine
) engine
="$2"; shift; shift;;
289 --noskip
) noskip
=true
; shift;;
293 enginebinname
=$engine
298 OPT
="--separate $OPT"
302 OPT
="--separate $OPT"
310 OPT
="--semi-global $OPT"
323 echo "disabled engine $engine"
327 echo "unknown engine $engine"
332 savdirs
="sav/$engine $savdirs sav/"
334 # The default nitc compiler
335 [ -z
"$NITC" ] && find_nitc
337 # Set NIT_DIR if needed
338 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
340 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
341 TIMEOUT
="timelimit -t 600"
342 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
343 TIMEOUT
="timeout 600s"
345 echo "No timelimit or timeout command detected. Tests may hang :("
348 # Mark to distinguish files among tests
351 # File where error tests are outputed
352 # Old ERRLIST is backuped
353 ERRLIST
=${ERRLIST:-errlist}
354 ERRLIST_TARGET
=$ERRLIST
361 # Initiate new ERRLIST
362 if [ "x$ERRLIST" = "x" ]; then
372 xml
="tests-$engine.xml"
373 echo >$xml "<testsuites><testsuite>"
375 # CLEAN the out directory
376 rm -rf out
/ 2>/dev
/null
377 mkdir out
2>/dev
/null
380 if [ ! -f
$ii ]; then
381 echo "File '$ii' does not exist."
384 f
=`basename "$ii" .nit`
386 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|'`
388 # Sould we skip the file for this engine?
389 need_skip
$f $f $pack && continue
392 if [ "x$tmp" = "x$ii" ]; then
393 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
398 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
399 bf
=`basename $i .nit`
402 # Sould we skip the alternative for this engine?
403 need_skip
$bf $bf $pack && continue
407 if [ -f
"$f.inputs" ]; then
413 if [ "$engine" = "niti" ]; then
414 cat > "./$ff.bin" <<END
415 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
422 if skip_cc
"$bf"; then
428 if [ "x$verbose" = "xtrue" ]; then
430 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes" $nocc
432 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
433 $TIMEOUT $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes $nocc 2> "$ff.cmp.err" > "$ff.compile.log"
435 if [ "x$verbose" = "xtrue" ]; then
436 cat "$ff.compile.log"
437 cat >&2 "$ff.cmp.err"
440 if [ "$ERR" != 0 ]; then
442 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
443 process_result
$bf $bf $pack
444 elif skip_exec
"$bf"; then
447 process_result
$bf $bf $pack
448 elif [ -n
"$nocc" ]; then
452 process_result
$bf $bf $pack
453 elif [ -x
"./$ff.bin" ]; then
457 if [ "x$verbose" = "xtrue" ]; then
459 echo "NIT_NO_STACK=1 ./$ff.bin" $args
461 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
462 $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
463 if [ "x$verbose" = "xtrue" ]; then
467 if [ -f
"$ff.write" ]; then
468 cat "$ff.write" >> "$ff.res"
469 elif [ -d
"$ff.write" ]; then
470 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
472 cp "$ff.res" "$ff.res2"
473 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
474 process_result
$bf $bf $pack
476 if [ -f
"$f.args" ]; then
484 name
="$bf args $cptr"
486 # Sould we skip the input for this engine?
487 need_skip
$bff " $name" $pack && continue
489 # use a specific inputs file, if required
490 if [ -f
"$bff.inputs" ]; then
491 ffinputs
="$bff.inputs"
496 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
497 if [ "x$verbose" = "xtrue" ]; then
499 echo "NIT_NO_STACK=1 ./$ff.bin" $args
502 echo "./$ff.bin $args" > "./$fff.bin"
503 chmod +x
"./$fff.bin"
504 WRITE
="$fff.write" sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $ffinputs > $fff.res 2>$fff.err"
505 if [ "x$verbose" = "xtrue" ]; then
509 if [ -f
"$fff.write" ]; then
510 cat "$fff.write" >> "$fff.res"
511 elif [ -d
"$fff.write" ]; then
512 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
514 if [ -s
"$fff.err" ]; then
515 cp "$fff.res" "$fff.res2"
516 cat "$fff.err" "$fff.res2" > "$fff.res"
518 process_result
$bff " $name" $pack
521 elif [ -f
"./$ff.bin" ]; then
522 echo "Not executable (platform?)" > "$ff.res"
523 process_result
$bf "$bf" $pack
526 cat "$ff.cmp.err" > "$ff.res"
527 echo "Compilation error" > "$ff.res"
528 process_result
$bf "$bf" $pack
533 echo "engine: $engine ($enginebinname $OPT)"
534 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
536 if [ -n
"$nok" ]; then
538 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
540 if [ -n
"$nos" ]; then
543 if [ -n
"$todos" ]; then
544 echo "todo/fixme: $todos"
546 if [ -n
"$remains" ]; then
547 echo "sav that remains: $remains"
551 if [ "x$ERRLIST" != "x" ]; then
552 if [ -x
"$ERRLIST_TARGET" ]; then
553 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
555 mv $ERRLIST $ERRLIST_TARGET
558 echo >>$xml "</testsuite></testsuites>"
560 if [ -n
"$nok" ]; then