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