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
47 --[no
]soso Force
enable (or disable
) SOSO
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 diff -u
"$sav" "out/$pattern.res" > "out/$pattern.diff.sav.log"
64 if [ "$?" == 0 ]; then
67 [ -z
"$soso" ] && return 3
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.log"
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"
116 if [ -z
"$FIRST" ]; then
124 sav
=$savdir/$pattern.res
125 compare_to_result
"$pattern" "$sav"
139 if [ -z
"$FIRST" ]; then
147 OLD
=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
148 grep 'NOT YET IMPLEMENTED' "out/$pattern.res" >/dev
/null
150 if [ -n
"$SAV" ]; then
151 if [ -n
"$OLD" ]; then
152 echo "[*ok*] out/$pattern.res $SAV - but $OLD remains!"
153 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
154 remains
="$remains $OLD"
156 echo "[ok] out/$pattern.res $SAV"
159 elif [ -n
"$FIXME" ]; then
160 if [ -n
"$OLD" ]; then
161 echo "[*fixme*] out/$pattern.res $FIXME - but $OLD remains!"
162 echo >>$xml "<error message='ok out/$pattern.res - but $OLD remains'/>"
163 remains
="$remains $OLD"
165 echo "[fixme] out/$pattern.res $FIXME"
166 echo >>$xml "<skipped/>"
168 todos
="$todos $pattern"
169 elif [ -n
"$SOSO" ]; then
170 echo "[soso] out/$pattern.res $SOSO"
172 elif [ "x$NYI" = "x0" ]; then
173 echo "[todo] out/$pattern.res -> not yet implemented"
174 echo >>$xml "<skipped/>"
175 todos
="$todos $pattern"
176 elif [ -n
"$SOSOF" ]; then
177 echo "[fixme soso] out/$pattern.res $SOSOF"
178 echo >>$xml "<skipped/>"
179 todos
="$todos $pattern"
180 elif [ -n
"$NSAV" ]; then
181 echo "[======= fail out/$pattern.res $NSAV =======]"
182 echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
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
"$NFIXME" ]; then
189 echo "[======= changed out/$pattern.res $NFIXME ======]"
190 echo >>$xml "<error message='changed out/$pattern.res $NFIXME'/>"
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 [ -s out
/$pattern.res
]; then
197 echo "[=== no sav ===] out/$pattern.res is not empty"
198 echo >>$xml "<error message='no sav and not empty'/>"
199 echo >>$xml "<system-out><![CDATA["
200 cat -v
>>$xml out
/$pattern.res
201 echo >>$xml "]]></system-out>"
204 # no sav but empty res
205 echo "[0k] out/$pattern.res is empty"
208 if test -s out
/$pattern.
cmp.err
; then
209 echo >>$xml "<system-err><![CDATA["
210 cat -v
>>$xml out
/$pattern.
cmp.err
211 echo >>$xml "]]></system-err>"
213 echo >>$xml "</testcase>"
218 test "$noskip" = true
&& return 1
219 if echo "$1" |
grep -f
"$engine.skip" >/dev
/null
2>&1; then
221 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
224 if test $engine = niti
&& echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
225 echo "=> $2: [skip exec]"
226 echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
234 test "$noskip" = true
&& return 1
235 if echo "$1" |
grep -f
"exec.skip" >/dev
/null
2>&1; then
244 test "$noskip" = true
&& return 1
245 if echo "$1" |
grep -f
"cc.skip" >/dev
/null
2>&1; then
253 name
="$enginebinname"
254 recent
=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../c_src/$name 2>/dev/null | head -1`
255 if [[ "x$recent" == "x" ]]; then
256 echo "Could not find binary for engine $engine, aborting"
259 echo "Find binary for engine $engine: $recent $OPT"
268 while [ $stop = false
]; do
270 -o
) OPT
="$OPT $2"; shift; shift;;
271 -v
) verbose
=true
; shift;;
273 --engine
) engine
="$2"; shift; shift;;
274 --noskip
) noskip
=true
; shift;;
275 --soso
) soso
=true
; shift;;
276 --nososo
) nososo
=true
; shift;;
280 enginebinname
=$engine
285 OPT
="--separate $OPT"
289 OPT
="--separate $OPT"
306 echo "disabled engine $engine"
310 echo "unknown engine $engine"
315 savdirs
="sav/$engine $savdirs sav/"
317 # The default nitc compiler
318 [ -z
"$NITC" ] && find_nitc
320 # Set NIT_DIR if needed
321 [ -z
"$NIT_DIR" ] && export NIT_DIR
=..
323 if sh
-c
"timelimit echo" 1>/dev
/null
2>&1; then
324 TIMEOUT
="timelimit -t 600"
325 elif sh
-c
"timeout 1 echo" 1>/dev
/null
2>&1; then
326 TIMEOUT
="timeout 600s"
328 echo "No timelimit or timeout command detected. Tests may hang :("
331 # Mark to distinguish files among tests
334 # File where error tests are outputed
335 # Old ERRLIST is backuped
336 ERRLIST
=${ERRLIST:-errlist}
337 ERRLIST_TARGET
=$ERRLIST
344 # Initiate new ERRLIST
345 if [ "x$ERRLIST" = "x" ]; then
355 xml
="tests-$engine.xml"
356 echo >$xml "<testsuites><testsuite>"
358 # CLEAN the out directory
359 rm -rf out
/ 2>/dev
/null
360 mkdir out
2>/dev
/null
363 if [ ! -f
$ii ]; then
364 echo "File '$ii' does not exist."
367 f
=`basename "$ii" .nit`
369 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|'`
371 # Sould we skip the file for this engine?
372 need_skip
$f $f $pack && continue
375 if [ "x$tmp" = "x$ii" ]; then
376 includes
="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
381 for i
in "$ii" `./alterner.pl --start '#' --altsep '_' $ii`; do
382 bf
=`basename $i .nit`
385 # Sould we skip the alternative for this engine?
386 need_skip
$bf $bf $pack && continue
390 if [ -f
"$f.inputs" ]; then
396 if [ "$engine" = "niti" ]; then
397 cat > "./$ff.bin" <<END
398 exec $NITC --no
-color
$OPT "$i" $includes -- "\$@"
405 if skip_cc
"$bf"; then
411 if [ "x$verbose" = "xtrue" ]; then
413 echo $NITC --no
-color
$OPT -o
"$ff.bin" "$i" "$includes" $nocc
415 NIT_NO_STACK
=1 JNI_LIB_PATH
=$JNI_LIB_PATH JAVA_HOME
=$JAVA_HOME \
416 $TIMEOUT $NITC --no
-color
$OPT -o
"$ff.bin" "$i" $includes $nocc 2> "$ff.cmp.err" > "$ff.compile.log"
418 if [ "x$verbose" = "xtrue" ]; then
419 cat "$ff.compile.log"
420 cat >&2 "$ff.cmp.err"
423 if [ "$ERR" != 0 ]; then
425 cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
426 process_result
$bf $bf $pack
427 elif skip_exec
"$bf"; then
430 process_result
$bf $bf $pack
431 elif [ -n
"$nocc" ]; then
435 process_result
$bf $bf $pack
436 elif [ -x
"./$ff.bin" ]; then
440 if [ "x$verbose" = "xtrue" ]; then
442 echo "NIT_NO_STACK=1 ./$ff.bin" $args
444 NIT_NO_STACK
=1 LD_LIBRARY_PATH
=$JNI_LIB_PATH \
445 $TIMEOUT "./$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
446 if [ "x$verbose" = "xtrue" ]; then
450 if [ -f
"$ff.write" ]; then
451 cat "$ff.write" >> "$ff.res"
452 elif [ -d
"$ff.write" ]; then
453 LANG
=C
/bin
/ls -F
$ff.
write >> "$ff.res"
455 cp "$ff.res" "$ff.res2"
456 cat "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
457 process_result
$bf $bf $pack
459 if [ -f
"$f.args" ]; then
467 name
="$bf args $cptr"
469 # Sould we skip the input for this engine?
470 need_skip
$bff " $name" $pack && continue
472 # use a specific inputs file, if required
473 if [ -f
"$bff.inputs" ]; then
474 ffinputs
="$bff.inputs"
479 rm -rf
"$fff.res" "$fff.err" "$fff.write" 2> /dev
/null
480 if [ "x$verbose" = "xtrue" ]; then
482 echo "NIT_NO_STACK=1 ./$ff.bin" $args
485 echo "./$ff.bin $args" > "./$fff.bin"
486 chmod +x
"./$fff.bin"
487 WRITE
="$fff.write" sh
-c
"NIT_NO_STACK=1 $TIMEOUT ./$fff.bin < $ffinputs > $fff.res 2>$fff.err"
488 if [ "x$verbose" = "xtrue" ]; then
492 if [ -f
"$fff.write" ]; then
493 cat "$fff.write" >> "$fff.res"
494 elif [ -d
"$fff.write" ]; then
495 LANG
=C
/bin
/ls -F
$fff.
write >> "$fff.res"
497 if [ -s
"$fff.err" ]; then
498 cp "$fff.res" "$fff.res2"
499 cat "$fff.err" "$fff.res2" > "$fff.res"
501 process_result
$bff " $name" $pack
504 elif [ -f
"./$ff.bin" ]; then
505 echo "Not executable (platform?)" > "$ff.res"
506 process_result
$bf "$bf" $pack
509 cat "$ff.cmp.err" > "$ff.res"
510 echo "Compilation error" > "$ff.res"
511 process_result
$bf "$bf" $pack
516 echo "engine: $engine ($enginebinname $OPT)"
517 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
519 if [ -n
"$nok" ]; then
521 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
523 if [ -n
"$nos" ]; then
526 if [ -n
"$todos" ]; then
527 echo "todo/fixme: $todos"
529 if [ -n
"$remains" ]; then
530 echo "sav that remains: $remains"
534 if [ "x$ERRLIST" != "x" ]; then
535 if [ -x
"$ERRLIST_TARGET" ]; then
536 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
538 mv $ERRLIST $ERRLIST_TARGET
541 echo >>$xml "</testsuite></testsuites>"
543 if [ -n
"$nok" ]; then