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