46cb74f52997620f19eefba01f2919ba68355520
[nit.git] / tests / tests.sh
1 #!/bin/bash
2 # This file is part of NIT ( http://www.nitlanguage.org ).
3 #
4 # Copyright 2004-2008 Jean Privat <jean@pryen.org>
5 #
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
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
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.
17
18 # This shell script compile, run and verify Nit program files
19
20 # Set lang do default to avoid failed tests because of locale
21 export LANG=C.UTF-8
22 export LC_ALL=C.UTF-8
23 if uname | grep Darwin 1>/dev/null 2>&1; then
24 export LANG=en_US.UTF-8
25 export LC_ALL=en_US.UTF-8
26 fi
27
28 export NIT_TESTING=true
29 # Use the pid as a collision prevention
30 export NIT_TESTING_ID=$$
31 export NIT_SRAND=0
32
33 # Identify this as a tests.sh test to differentiate from a nitunit test
34 export NIT_TESTING_TESTS_SH=true
35
36 unset NIT_DIR
37
38 # Get the first Java lib available
39 if which_java=$(which javac 2>/dev/null); then
40
41 if sh -c "readlink -f ." 1>/dev/null 2>&1; then
42 READLINK="readlink -f"
43 else
44 # Darwin?
45 READLINK="readlink"
46 fi
47 JAVA_HOME=$(dirname $(dirname $($READLINK "$which_java")))
48
49 shopt -s nullglob
50 paths=`echo $JAVA_HOME/jre/lib/*/{client,server}/libjvm.so`
51 if [ -n "$paths" ]; then
52 paths=($paths)
53 JNI_LIB_PATH=`dirname ${paths[0]}`
54 fi
55 shopt -u nullglob
56 fi
57
58 outdir="out"
59 compdir="nit_compile"
60
61 # User CPU time limit (in seconds)
62 # Is used to avoid to CPU intensive test (infinite loops). See ulimit -t
63 usertimelimit=600 # 1 CPU minute
64
65 # Real-time limit (in seconds)
66 # Is used to avoid waiting or sleeping tests.
67 # Require timeout or timelimit, or else is not used.
68 realtimelimit=300 # 5 min
69
70 # User limit for write files (in kilo-bytes)
71 # Is used to avoid execution that loop and fill the hard drive. See ulimit -f
72 # Note that a test might require a lot of temporary disk space (eg. nitc+gcc)
73 filelimit=100000 # ~100MB
74
75 # Limit (in bytes) for generated .res file.
76 # Larger ones are truncated and will fail tests
77 # Is used to avoid processing huge crappy res file (diff, xml, etc)
78 reslimit=100000 # ~100KB
79
80 usage()
81 {
82 e=`basename "$0"`
83 cat<<END
84 Usage: $e [options] modulenames
85 -o option Pass option to the engine
86 -v Verbose (show tests steps)
87 -h This help
88 --engine Use a specific engine (default=nitc)
89 --noskip Do not skip a test even if the .skip file matches
90 --outdir Use a specific output folder (default=out/)
91 --compdir Use a specific temporary compilation folder (default=$compdir)
92 --node Run as a node in parallel, will not output context information
93 --autosav Copy the .res files directly in the sav folder overriding existing .res files
94 END
95 }
96
97 # Run a command with a timeout and a time count.
98 # Options:
99 # -o file write the user time into file (REQUIRED). see `-o` in `man time`
100 # -a append the time to the file (instead of overwriting it). see `-a` in `man time`
101 saferun()
102 {
103 local stop=false
104 local o=
105 local a=
106 while [ $stop = false ]; do
107 case "$1" in
108 -o) o="$2"; shift; shift;;
109 -a) a="-a"; shift;;
110 *) stop=true
111 esac
112 done
113 (
114 ulimit -f "$filelimit" 2> /dev/null
115 ulimit -t "$usertimelimit" 2> /dev/null
116 if test -d "$1"; then
117 find $1 | sort
118 elif test -n "$TIME"; then
119 $TIME -o "$o" $a $TIMEOUT "$@"
120 else
121 if test -n "$a"; then echo 0 >> "$o"; else echo 0 > "$o"; fi
122 $TIMEOUT "$@"
123 fi
124 )
125 }
126
127 # Output a timestamp attribute for XML, or an empty line
128 timestamp()
129 {
130 if test -n "$TIMESTAMP"; then
131 echo "timestamp='`$TIMESTAMP`'"
132 else
133 echo ""
134 fi
135
136 }
137
138 # Get platform specific commands ##########################
139
140 # Detect a working timeout
141 if sh -c "timelimit echo" 1>/dev/null 2>&1; then
142 TIMEOUT="timelimit -t $realtimelimit"
143 elif sh -c "timeout 1 echo" 1>/dev/null 2>&1; then
144 TIMEOUT="timeout ${realtimelimit}s"
145 else
146 echo "No timelimit or timeout command detected. Tests may hang :("
147 fi
148
149 # Detect a working time command
150 if command time --quiet -f%e true 2>/dev/null; then
151 TIME="command time --quiet -f%e"
152 elif command time -f%e true 2>/dev/null; then
153 TIME="command time -f%e"
154 elif command gtime -f%e true 2>/dev/null; then
155 TIME="command gtime -f%e"
156 else
157 TIME=
158 fi
159
160 # Detect a working date command
161 if date -Iseconds >/dev/null 2>&1; then
162 TIMESTAMP="date -Iseconds"
163 else
164 TIMESTAMP=
165 fi
166
167 # Detect a working hostname command
168 if hostname --version 2>&1 | grep coreutils >/dev/null 2>&1; then
169 HOSTNAME="hostname"
170 else
171 HOSTNAME="hostname -s"
172 fi
173
174 UNAME=`uname | sed s/-.*//`
175
176 # $1 is the pattern of the test
177 # $2 is the file to compare to
178 # the result is:
179 # 0: if the file to compare to do not exists
180 # 1: if the file match
181 # 2: if the file match with soso
182 # 3: if the file do not match
183 function compare_to_result()
184 {
185 local pattern="$1"
186 local sav="$2"
187 if [ ! -r "$sav" ]; then return 0; fi
188 test "`cat -- "$sav"`" = "UNDEFINED" && return 1
189 diff -u --strip-trailing-cr -- "$sav" "$outdir/$pattern.res" > "$outdir/$pattern.diff.sav.log"
190 if [ "$?" == 0 ]; then
191 return 1
192 fi
193 sed '/[Ww]arning/d;/[Ee]rror/d' "$outdir/$pattern.res" > "$outdir/$pattern.res2"
194 sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "$outdir/$pattern.sav2"
195 grep '[Ee]rror' "$outdir/$pattern.res" >/dev/null && echo "Error" >> "$outdir/$pattern.res2"
196 grep '[Ee]rror' "$sav" >/dev/null && echo "Error" >> "$outdir/$pattern.sav2"
197 diff -u --strip-trailing-cr "$outdir/$pattern.sav2" "$outdir/$pattern.res2" > "$outdir/$pattern.diff.sav.log2"
198 if [ "$?" == 0 ]; then
199 return 2
200 else
201 return 3
202 fi
203 }
204
205 function xmlesc()
206 {
207 sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'<<EOF
208 $*
209 EOF
210 }
211
212 # As argument: the pattern used for the file
213 function process_result()
214 {
215 # Result
216 local pattern=$1
217 local description=$2
218 local pack=$3
219 local SAV=""
220 local NSAV=""
221 local FIXME=""
222 local NFIXME=""
223 local SOSO=""
224 local NSOSO=""
225 local SOSOF=""
226 local NSOSOF=""
227 local OLD=""
228 local LIST=""
229 local FIRST=""
230
231 # Truncate too big res file
232 local size=$(wc -c < "$outdir/$pattern.res")
233 if test -n "$reslimit" -a "$size" -gt "$reslimit"; then
234 # The most portable way to truncate a file is with Perl
235 perl -e "truncate \"$outdir/$pattern.res\", $reslimit;"
236 echo "***TRUNCATED***" >> "$outdir/$pattern.res"
237 fi
238
239 echo >>$xml "<testcase classname='`xmlesc "$pack"`' name='`xmlesc "$description"`' time='`cat -- "$outdir/$pattern.time.out"`' `timestamp`>"
240 #for sav in "sav/$engine/fixme/$pattern.res" "sav/$engine/$pattern.res" "sav/fixme/$pattern.res" "sav/$pattern.res" "sav/$pattern.sav"; do
241 for savdir in $savdirs; do
242 local sav=$savdir/fixme/$pattern.res
243 compare_to_result "$pattern" "$sav"
244 case "$?" in
245 0)
246 ;; # no file
247 1)
248 OLD="$LIST"
249 FIXME="$sav"
250 LIST="$LIST $sav"
251 ;;
252 2)
253 if [ -z "$FIRST" ]; then
254 SOSOF="$sav"
255 FIRST="$sav"
256 fi
257 LIST="$LIST $sav"
258 ;;
259 3)
260 if [ -z "$FIRST" ]; then
261 NFIXME="$sav"
262 FIRST="$sav"
263 fi
264 LIST="$LIST $sav"
265 ;;
266 esac
267
268 sav=$savdir/$pattern.res
269 compare_to_result "$pattern" "$sav"
270 case "$?" in
271 0)
272 ;; # no file
273 1)
274 OLD="$LIST"
275 SAV="$sav"
276 LIST="$LIST $sav"
277 ;;
278 2)
279 if [ -z "$FIRST" ]; then
280 SOSO="$sav"
281 FIRST="$sav"
282 fi
283 LIST="$LIST $sav"
284 ;;
285 3)
286 if [ -z "$FIRST" ]; then
287 NSAV="$sav"
288 FIRST="$sav"
289 fi
290 LIST="$LIST $sav"
291 ;;
292 esac
293 done
294 OLD=`echo "$OLD" | sed -e 's/ */ /g' -e 's/^ //' -e 's/ $//'`
295 istodo "$outdir/$pattern.res"
296 NYI="$?"
297 if [ -n "$SAV" ]; then
298 if [ -n "$OLD" ]; then
299 echo "[*ok*] $outdir/$pattern.res $SAV - but $OLD remains!"
300 echo >>$xml "<error message='`xmlesc "ok $outdir/$pattern.res - but $OLD remains"`'/>"
301 remains="$remains $OLD"
302 test "$autosav" = "true" && rm "$OLD"
303 else
304 echo "[ok] $outdir/$pattern.res $SAV"
305 fi
306 ok="$ok $pattern"
307 elif [ -n "$FIXME" ]; then
308 if [ -n "$OLD" ]; then
309 echo "[*fixme*] $outdir/$pattern.res $FIXME - but $OLD remains!"
310 echo >>$xml "<error message='`xmlesc "ok $outdir/$pattern.res - but $OLD remains"`'/>"
311 remains="$remains $OLD"
312 test "$autosav" = "true" && rm "$OLD"
313 else
314 echo "[fixme] $outdir/$pattern.res $FIXME"
315 echo >>$xml "<skipped/>"
316 fi
317 todos="$todos $pattern"
318 elif [ "x$NYI" = "x0" ]; then
319 echo "[todo] $outdir/$pattern.res -> not yet implemented"
320 echo >>$xml "<skipped/>"
321 todos="$todos $pattern"
322 elif [ -n "$SOSO" ]; then
323 echo "[======= soso $outdir/$pattern.res $SOSO =======]"
324 echo >>$xml "<error message='`xmlesc "soso $outdir/$pattern.res $SOSO"`'/>"
325 echo >>$xml "<system-out><![CDATA["
326 cat -v -- "$outdir/$pattern.diff.sav.log" | head >>$xml -n 50
327 echo >>$xml "]]></system-out>"
328 nok="$nok $pattern"
329 echo "$ii" >> "$ERRLIST"
330 test "$autosav" = "true" && cp "$outdir/$pattern.res" "$SOSO"
331 elif [ -n "$SOSOF" ]; then
332 echo "[======= fixme soso $outdir/$pattern.res $SOSOF =======]"
333 echo >>$xml "<error message='`xmlesc "soso $outdir/$pattern.res $SOSO"`'/>"
334 echo >>$xml "<system-out><![CDATA["
335 cat -v -- "$outdir/$pattern.diff.sav.log" | head >>$xml -n 50
336 echo >>$xml "]]></system-out>"
337 nok="$nok $pattern"
338 echo "$ii" >> "$ERRLIST"
339 test "$autosav" = "true" && cp "$outdir/$pattern.res" && "$SOSO"
340 elif [ -n "$NSAV" ]; then
341 echo "[======= fail $outdir/$pattern.res $NSAV =======]"
342 echo >>$xml "<error message='`xmlesc "fail $outdir/$pattern.res $NSAV"`'/>"
343 echo >>$xml "<system-out><![CDATA["
344 cat -v -- "$outdir/$pattern.diff.sav.log" | head >>$xml -n 50
345 echo >>$xml "]]></system-out>"
346 nok="$nok $pattern"
347 echo "$ii" >> "$ERRLIST"
348 test "$autosav" = "true" && cp "$outdir/$pattern.res" "$NSAV"
349 elif [ -n "$NFIXME" ]; then
350 echo "[======= changed $outdir/$pattern.res $NFIXME ======]"
351 echo >>$xml "<error message='`xmlesc "changed $outdir/$pattern.res $NFIXME"`'/>"
352 echo >>$xml "<system-out><![CDATA["
353 cat -v -- "$outdir/$pattern.diff.sav.log" | head >>$xml -n 50
354 echo >>$xml "]]></system-out>"
355 nok="$nok $pattern"
356 echo "$ii" >> "$ERRLIST"
357 test "$autosav" = "true" && cp "$outdir/$pattern.res" "$NFIXME"
358 elif [ -s "$outdir/$pattern.res" ]; then
359 echo "[=== no sav ===] $outdir/$pattern.res is not empty"
360 echo >>$xml "<error message='no sav and not empty'/>"
361 echo >>$xml "<system-out><![CDATA["
362 cat -v >>$xml -- "$outdir/$pattern.res"
363 echo >>$xml "]]></system-out>"
364 nos="$nos $pattern"
365 echo "$ii" >> "$ERRLIST"
366 test "$autosav" = "true" && cp "$outdir/$pattern.res" "sav/"
367 else
368 # no sav but empty res
369 echo "[0k] $outdir/$pattern.res is empty"
370 ok="$ok $pattern"
371 fi
372 if test -s "$outdir/$pattern.cmp.err"; then
373 echo >>$xml "<system-err><![CDATA["
374 cat -v >>$xml -- "$outdir/$pattern.cmp.err"
375 echo >>$xml "]]></system-err>"
376 fi
377 echo >>$xml "</testcase>"
378 }
379
380 need_skip()
381 {
382 test "$noskip" = true && return 1
383 if echo "$1" | grep -f "$engine.skip" >/dev/null 2>&1; then
384 echo "=> $2: [skip]"
385 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
386 return 0
387 fi
388 if test -n "$isinterpret" && echo "$1" | grep -f "exec.skip" >/dev/null 2>&1; then
389 echo "=> $2: [skip exec]"
390 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
391 return 0
392 fi
393
394 # Skip by OS
395 local os_skip_file=$UNAME.skip
396 if test -e $os_skip_file && echo "$1" | grep -f "$os_skip_file" >/dev/null 2>&1; then
397 echo "=> $2: [skip os]"
398 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
399 return 0
400 fi
401
402 # Skip by hostname
403 local host_skip_file=`$HOSTNAME`.skip
404 if test -e $host_skip_file && echo "$1" | grep -f "$host_skip_file" >/dev/null 2>&1; then
405 echo "=> $2: [skip hostname]"
406 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
407 return 0
408 fi
409 return 1
410 }
411
412 skip_exec()
413 {
414 test "$noskip" = true && return 1
415 for savdir in $savdirs .; do
416 local f="$savdir/exec.skip"
417 test -f "$f" || continue
418 if echo "$1" | grep -f "$f" >/dev/null 2>&1; then
419 echo -n "_ no exec by $f; "
420 return 0
421 fi
422 done
423 return 1
424 }
425
426 skip_cc()
427 {
428 test "$noskip" = true && return 1
429 for savdir in $savdirs .; do
430 local f="$savdir/cc.skip"
431 test -f "$f" || continue
432 if echo "$1" | grep -f "$f" >/dev/null 2>&1; then
433 return 0
434 fi
435 done
436 return 1
437 }
438
439 # Check that the resfile ($1) matches some magic strings in `todo` files.
440 istodo()
441 {
442 test "$no" = true && return 1
443 for savdir in $savdirs .; do
444 local f="$savdir/todo"
445 test -f "$f" || continue
446 if grep -f "$f" "$1" >/dev/null 2>&1; then
447 return 0
448 fi
449 done
450 return 1
451 }
452
453 find_nitc()
454 {
455 local name="$enginebinname"
456 local recent=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../contrib/nitin/bin/$name ../c_src/$name 2>/dev/null | head -1`
457 if [[ "x$recent" == "x" ]]; then
458 echo "Could not find binary for engine $engine, aborting"
459 exit 1
460 fi
461 if [ "x$isnode" = "xfalse" ]; then
462 echo "Found binary for engine $engine: $recent $OPT"
463 fi
464 NITC=$recent
465 }
466
467 verbose=false
468 isnode=false
469 autosav=false
470 stop=false
471 engine=nitc
472 noskip=
473 savdirs=
474 while [ $stop = false ]; do
475 case $1 in
476 -o) OPT="$OPT $2"; shift; shift;;
477 -v) verbose=true; shift;;
478 -h) usage; exit;;
479 --engine) engine="$2"; shift; shift;;
480 --noskip) noskip=true; shift;;
481 --outdir) outdir="$2"; shift; shift;;
482 --compdir) compdir="$2"; shift; shift;;
483 --node) isnode=true; shift;;
484 --autosav) autosav=true; shift;;
485 *) stop=true
486 esac
487 done
488 enginebinname=$engine
489 isinterpret=
490 isinteractive=
491 case $engine in
492 nitc|nitg)
493 engine=nitcs;
494 enginebinname=nitc;
495 OPT="--separate $OPT --compile-dir $compdir"
496 savdirs="sav/nitc-common/"
497 ;;
498 nitcs|nitg-s)
499 engine=nitcs;
500 enginebinname=nitc;
501 OPT="--separate $OPT --compile-dir $compdir"
502 savdirs="sav/nitc-common/"
503 ;;
504 nitce|nitg-e)
505 engine=nitce;
506 enginebinname=nitc;
507 OPT="--erasure $OPT --compile-dir $compdir"
508 savdirs="sav/nitc-common/"
509 ;;
510 nitcsg|nitg-sg)
511 engine=nitcsg;
512 enginebinname=nitc;
513 OPT="--semi-global $OPT --compile-dir $compdir"
514 savdirs="sav/nitc-common/"
515 ;;
516 nitcg|nitg-g)
517 engine=nitcg;
518 enginebinname=nitc;
519 OPT="--global $OPT --compile-dir $compdir"
520 savdirs="sav/nitc-common/"
521 ;;
522 nit)
523 engine=niti
524 isinterpret=true
525 ;;
526 niti)
527 enginebinname=nit
528 isinterpret=true
529 ;;
530 nitvm)
531 isinterpret=true
532 enginebinname=nit
533 OPT="--vm $OPT"
534 savdirs="sav/niti/"
535 ;;
536 nitin)
537 enginebinname=nitin
538 isinteractive=true
539 ;;
540 nitj)
541 engine=nitj;
542 OPT="--compile-dir $compdir --ant"
543 enginebinname=nitj;
544 savdirs="sav/nitc-common/"
545 ;;
546 emscripten)
547 enginebinname=nitc
548 OPT="-m emscripten_nodejs.nit --semi-global $OPT --compile-dir $compdir"
549 savdirs="sav/nitcsg/"
550 ;;
551 *)
552 echo "unknown engine $engine"
553 exit 1
554 ;;
555 esac
556
557 savdirs="sav/`$HOSTNAME` sav/$UNAME sav/$engine $savdirs sav/"
558
559 # The default nitc compiler
560 [ -z "$NITC" ] && find_nitc
561
562 # Set NIT_DIR if needed
563 [ -z "$NIT_DIR" ] && export NIT_DIR=..
564
565 # Mark to distinguish files among tests
566 # MARK=
567
568 if [ $# = 0 ]; then
569 usage;
570 exit
571 fi
572
573 # CLEAN the out directory
574 rm -rf "$outdir/" 2>/dev/null
575 mkdir "$outdir" 2>/dev/null
576
577 # File where error tests are outputed
578 # Old ERRLIST is backuped
579 ERRLIST=${ERRLIST:-errlist}
580 ERRLIST_TARGET=$ERRLIST
581
582 # Initiate new ERRLIST
583 if [ "x$ERRLIST" = "x" ]; then
584 ERRLIST=/dev/null
585 else
586 ERRLIST=$ERRLIST.tmp
587 > "$ERRLIST"
588 fi
589
590 ok=""
591 nok=""
592 todos=""
593
594 if [ "x$XMLDIR" = "x" ]; then
595 xml="tests-$engine.xml"
596 else
597 sum=`echo $@ | md5sum | cut -f1 -d " "`
598 xml="$XMLDIR/tests-$engine-$sum.xml"
599 mkdir -p "$XMLDIR"
600 fi
601
602 echo >$xml "<testsuites><testsuite>"
603
604 for ii in "$@"; do
605 if [ ! -f "$ii" ]; then
606 echo "File '$ii' does not exist."
607 continue
608 fi
609 f=`basename -- "$ii" .nit`
610
611 pack="tests.${engine}".`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|'`
612
613 # Sould we skip the file for this engine?
614 need_skip "$f" "$f" "$pack" && continue
615
616 local_tmp=${ii/../AA}
617 if [ "x$local_tmp" = "x$ii" ]; then
618 includes="-I . -I ../lib/core -I ../lib/core/collection -I alt"
619 else
620 includes="-I alt"
621 fi
622
623 for i in "$ii" `./alterner.pl --start '#' --altsep '_' -- "$ii"`; do
624 bf=`basename -- "$i" .nit`
625 ff="$outdir/$bf"
626
627 # Sould we skip the alternative for this engine?
628 need_skip "$bf" "$bf" "$pack" && continue
629
630 echo -n "=> $bf: "
631
632 if [ -f "$f.inputs" ]; then
633 inputs="$f.inputs"
634 export MNIT_READ_INPUT="$f.inputs"
635 else
636 inputs=/dev/null
637 export MNIT_READ_INPUT=/dev/null
638 fi
639
640 ffout="$ff.bin"
641 if [ "$engine" = "emscripten" ]; then
642 ffout="$ff.bin.js"
643 fi
644
645 if [ -n "$isinterpret" ]; then
646 cat > "$ff.bin" <<END
647 exec $NITC --no-color $OPT $includes -- $(printf '%q' "$i") "\$@"
648 END
649 chmod +x "$ff.bin"
650 > "$ff.cmp.err"
651 > "$ff.compile.log"
652 ERR=0
653 echo 0.0 > "$ff.time.out"
654 elif [ -n "$isinteractive" ]; then
655 cat > "$ff.bin" <<END
656 exec $NITC --no-color --no-prompt --source-name $(printf '%q' "$i") $OPT $includes < $(printf '%q' "$i") "\$@"
657 END
658 chmod +x "$ff.bin"
659 > "$ff.cmp.err"
660 > "$ff.compile.log"
661 ERR=0
662 echo 0.0 > "$ff.time.out"
663 else
664 if skip_cc "$bf"; then
665 nocc="--no-cc"
666 else
667 nocc=
668 fi
669 # Compile
670 if [ "x$verbose" = "xtrue" ]; then
671 echo ""
672 echo $NITC --no-color $OPT -o "$ffout" "$includes" $nocc "$i"
673 fi
674 NIT_NO_STACK=1 JNI_LIB_PATH=$JNI_LIB_PATH JAVA_HOME=$JAVA_HOME \
675 saferun -o "$ff.time.out" $NITC --no-color $OPT -o "$ffout" $includes $nocc "$i" 2> "$ff.cmp.err" > "$ff.compile.log"
676 ERR=$?
677 if [ "x$verbose" = "xtrue" ]; then
678 cat -- "$ff.compile.log"
679 cat >&2 -- "$ff.cmp.err"
680 fi
681 # Clean
682 rm -r "$compdir" 2>/dev/null
683 fi
684 if [ "$engine" = "emscripten" ]; then
685 echo > "$ff.bin" "nodejs $ffout \"\$@\""
686 chmod +x "$ff.bin"
687 if grep "Fatal Error: more than one primitive class" "$ff.compile.log" > /dev/null; then
688 echo " [skip] do no not imports kernel"
689 echo >>$xml "<testcase classname='`xmlesc "$pack"`' name='`xmlesc "$bf"`' `timestamp`><skipped/></testcase>"
690 continue
691 fi
692 fi
693 if [ "$ERR" != 0 ]; then
694 echo -n "! "
695 cat -- "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
696 process_result "$bf" "$bf" "$pack"
697 elif [ -n "$nocc" ]; then
698 # not compiled
699 echo -n "nocc "
700 > "$ff.res"
701 process_result "$bf" "$bf" "$pack"
702 elif [ -x "$ff.bin" ]; then
703 if skip_exec "$bf"; then
704 # No exec
705 > "$ff.res"
706 process_result "$bf" "$bf" "$pack"
707 break
708 fi
709 echo -n ". "
710 # Execute
711 args=""
712 if [ "x$verbose" = "xtrue" ]; then
713 echo ""
714 echo "NIT_NO_STACK=1 $ff.bin" $args
715 fi
716 NIT_NO_STACK=1 LD_LIBRARY_PATH=$JNI_LIB_PATH WRITE="$ff.write" \
717 saferun -a -o "$ff.time.out" "$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
718 mv "$ff.time.out" "$ff.times.out"
719 awk '{ SUM += $1} END { print SUM }' "$ff.times.out" > "$ff.time.out"
720
721 if [ "x$verbose" = "xtrue" ]; then
722 cat -- "$ff.res"
723 cat >&2 -- "$ff.err"
724 fi
725 if [ -f "$ff.write" ]; then
726 cat -- "$ff.write" >> "$ff.res"
727 elif [ -d "$ff.write" ]; then
728 /bin/ls -F "$ff.write" >> "$ff.res"
729 fi
730 cp -- "$ff.res" "$ff.res2"
731 cat -- "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
732 process_result "$bf" "$bf" "$pack"
733
734 if [ -f "$f.args" ]; then
735 fargs=$f.args
736 cptr=0
737 while read line; do
738 ((cptr=cptr+1))
739 args="$line"
740 bff=$bf"_args"$cptr
741 fff=$ff"_args"$cptr
742 name="$bf args $cptr"
743
744 # Sould we skip the input for this engine?
745 need_skip "$bff" " $name" "$pack" && continue
746
747 # use a specific inputs file, if required
748 if [ -f "$bff.inputs" ]; then
749 ffinputs="$bff.inputs"
750 else
751 ffinputs="$inputs"
752 fi
753
754 rm -rf "$fff.res" "$fff.err" "$fff.write" 2> /dev/null
755 if [ "x$verbose" = "xtrue" ]; then
756 echo ""
757 echo "NIT_NO_STACK=1 $ff.bin" $args
758 fi
759 echo -n "==> $name "
760 echo "$ff.bin $args" > "$fff.bin"
761 chmod +x "$fff.bin"
762 WRITE="$fff.write" saferun -o "$fff.time.out" sh -c "NIT_NO_STACK=1 $fff.bin < $ffinputs > $fff.res 2>$fff.err"
763 if [ "x$verbose" = "xtrue" ]; then
764 cat -- "$fff.res"
765 cat >&2 -- "$fff.err"
766 fi
767 if [ -f "$fff.write" ]; then
768 cat -- "$fff.write" >> "$fff.res"
769 elif [ -d "$fff.write" ]; then
770 /bin/ls -F -- "$fff.write" >> "$fff.res"
771 fi
772 if [ -s "$fff.err" ]; then
773 cp -- "$fff.res" "$fff.res2"
774 cat -- "$fff.err" "$fff.res2" > "$fff.res"
775 fi
776 process_result "$bff" " $name" "$pack"
777 done < "$fargs"
778 fi
779 elif [ -f "$ff.bin" ]; then
780 #Not executable (platform?)"
781 > "$ff.res"
782 process_result "$bf" "$bf" "$pack"
783 else
784 echo -n "! "
785 cat -- "$ff.cmp.err" > "$ff.res"
786 echo "Compilation error" > "$ff.res"
787 process_result "$bf" "$bf" "$pack"
788 fi
789 done
790 done
791
792 if [ "x$isnode" = "xfalse" ]; then
793 echo "engine: $engine ($enginebinname $OPT)"
794 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
795
796 if [ -n "$nok" ]; then
797 echo "fail: $nok"
798 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
799 fi
800 if [ -n "$nos" ]; then
801 echo "no sav: $nos"
802 fi
803 if [ -n "$todos" ]; then
804 echo "todo/fixme: $todos"
805 fi
806 if [ -n "$remains" ]; then
807 echo "sav that remains: $remains"
808 fi
809 fi
810
811 # write $ERRLIST
812 if [ "x$ERRLIST" != "x" ]; then
813 if [ -f "$ERRLIST_TARGET" ]; then
814 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
815 fi
816 uniq $ERRLIST > $ERRLIST_TARGET
817 rm $ERRLIST
818 fi
819
820 echo >>$xml "</testsuite></testsuites>"
821
822 if [ -n "$nok" ]; then
823 exit 1
824 else
825 exit 0
826 fi