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