tests.sh: run junit2html to render xml files
[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 if test -n "GITLAB_CI" && echo "$1" | grep -f "gitlab_ci.skip" >/dev/null 2>&1; then
411 echo "=> $2: [skip gitlab ci]"
412 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
413 return 0
414 fi
415
416 # Skip by OS
417 local os_skip_file=$UNAME.skip
418 if test -e $os_skip_file && echo "$1" | grep -f "$os_skip_file" >/dev/null 2>&1; then
419 echo "=> $2: [skip os]"
420 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
421 return 0
422 fi
423
424 # Skip by hostname
425 local host_skip_file=`$HOSTNAME`.skip
426 if test -e $host_skip_file && echo "$1" | grep -f "$host_skip_file" >/dev/null 2>&1; then
427 echo "=> $2: [skip hostname]"
428 echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
429 return 0
430 fi
431 return 1
432 }
433
434 skip_exec()
435 {
436 test "$noskip" = true && return 1
437 for savdir in $savdirs .; do
438 local f="$savdir/exec.skip"
439 test -f "$f" || continue
440 if echo "$1" | grep -f "$f" >/dev/null 2>&1; then
441 echo -n "_ no exec by $f; "
442 return 0
443 fi
444 done
445 return 1
446 }
447
448 skip_cc()
449 {
450 test "$noskip" = true && return 1
451 for savdir in $savdirs .; do
452 local f="$savdir/cc.skip"
453 test -f "$f" || continue
454 if echo "$1" | grep -f "$f" >/dev/null 2>&1; then
455 return 0
456 fi
457 done
458 return 1
459 }
460
461 # Check that the resfile ($1) matches some magic strings in `todo` files.
462 istodo()
463 {
464 test "$no" = true && return 1
465 for savdir in $savdirs .; do
466 local f="$savdir/todo"
467 test -f "$f" || continue
468 if grep -f "$f" "$1" >/dev/null 2>&1; then
469 return 0
470 fi
471 done
472 return 1
473 }
474
475 find_nitc()
476 {
477 local name="$enginebinname"
478 local recent=`ls -t ../src/$name ../src/$name_[0-9] ../bin/$name ../contrib/nitin/bin/$name ../c_src/$name 2>/dev/null | head -1`
479 if [[ "x$recent" == "x" ]]; then
480 echo "Could not find binary for engine $engine, aborting"
481 exit 1
482 fi
483 if [ "x$isnode" = "xfalse" ]; then
484 echo "Found binary for engine $engine: $recent $OPT"
485 fi
486 NITC=$recent
487 }
488
489 verbose=false
490 isnode=false
491 autosav=false
492 stop=false
493 engine=nitc
494 noskip=
495 savdirs=
496 while [ $stop = false ]; do
497 case $1 in
498 -o) OPT="$OPT $2"; shift; shift;;
499 -v) verbose=true; shift;;
500 -h) usage; exit;;
501 --engine) engine="$2"; shift; shift;;
502 --noskip) noskip=true; shift;;
503 --outdir) outdir="$2"; shift; shift;;
504 --compdir) compdir="$2"; shift; shift;;
505 --node) isnode=true; shift;;
506 --autosav) autosav=true; shift;;
507 *) stop=true
508 esac
509 done
510 enginebinname=$engine
511 isinterpret=
512 isinteractive=
513 case $engine in
514 nitc|nitg)
515 engine=nitcs;
516 enginebinname=nitc;
517 OPT="--separate $OPT --compile-dir $compdir"
518 savdirs="sav/nitc-common/"
519 ;;
520 nitcs|nitg-s)
521 engine=nitcs;
522 enginebinname=nitc;
523 OPT="--separate $OPT --compile-dir $compdir"
524 savdirs="sav/nitc-common/"
525 ;;
526 nitce|nitg-e)
527 engine=nitce;
528 enginebinname=nitc;
529 OPT="--erasure $OPT --compile-dir $compdir"
530 savdirs="sav/nitc-common/"
531 ;;
532 nitcsg|nitg-sg)
533 engine=nitcsg;
534 enginebinname=nitc;
535 OPT="--semi-global $OPT --compile-dir $compdir"
536 savdirs="sav/nitc-common/"
537 ;;
538 nitcg|nitg-g)
539 engine=nitcg;
540 enginebinname=nitc;
541 OPT="--global $OPT --compile-dir $compdir"
542 savdirs="sav/nitc-common/"
543 ;;
544 nit)
545 engine=niti
546 isinterpret=true
547 ;;
548 niti)
549 enginebinname=nit
550 isinterpret=true
551 ;;
552 nitvm)
553 isinterpret=true
554 enginebinname=nit
555 OPT="--vm $OPT"
556 savdirs="sav/niti/"
557 ;;
558 nitin)
559 enginebinname=nitin
560 isinteractive=true
561 ;;
562 nitj)
563 engine=nitj;
564 OPT="--compile-dir $compdir --ant"
565 enginebinname=nitj;
566 savdirs="sav/nitc-common/"
567 ;;
568 emscripten)
569 enginebinname=nitc
570 OPT="-m emscripten_nodejs.nit --semi-global $OPT --compile-dir $compdir"
571 savdirs="sav/nitcsg/"
572 ;;
573 *)
574 echo "unknown engine $engine"
575 exit 1
576 ;;
577 esac
578
579 savdirs="sav/`$HOSTNAME` sav/$UNAME sav/$engine $savdirs sav/"
580 test -n "$GITLAB_CI" && savdirs="sav/gitlab_ci $savdirs"
581
582 # The default nitc compiler
583 [ -z "$NITC" ] && find_nitc
584
585 # Set NIT_DIR if needed
586 [ -z "$NIT_DIR" ] && export NIT_DIR=..
587
588 # Mark to distinguish files among tests
589 # MARK=
590
591 if [ $# = 0 ]; then
592 usage;
593 exit
594 fi
595
596 # CLEAN the out directory
597 rm -rf "$outdir/" 2>/dev/null
598 mkdir "$outdir" 2>/dev/null
599
600 # File where error tests are outputed
601 # Old ERRLIST is backuped
602 ERRLIST=${ERRLIST:-errlist}
603 ERRLIST_TARGET=$ERRLIST
604
605 # Initiate new ERRLIST
606 if [ "x$ERRLIST" = "x" ]; then
607 ERRLIST=/dev/null
608 else
609 ERRLIST=$ERRLIST.tmp
610 > "$ERRLIST"
611 fi
612
613 ok=""
614 nok=""
615 todos=""
616
617 if [ "x$XMLDIR" = "x" ]; then
618 xml="tests-$engine.xml"
619 else
620 sum=`echo $@ | md5sum | cut -f1 -d " "`
621 xml="$XMLDIR/tests-$engine-$sum.xml"
622 mkdir -p "$XMLDIR"
623 fi
624
625 echo >$xml "<testsuites><testsuite>"
626
627 for ii in "$@"; do
628 if [ ! -f "$ii" ]; then
629 echo "File '$ii' does not exist."
630 continue
631 fi
632 f=`basename -- "$ii" .nit`
633
634 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|'`
635
636 # Sould we skip the file for this engine?
637 need_skip "$f" "$f" "$pack" && continue
638
639 local_tmp=${ii/../AA}
640 if [ "x$local_tmp" = "x$ii" ]; then
641 includes="-I . -I ../lib/core -I ../lib/core/collection -I alt"
642 else
643 includes="-I alt"
644 fi
645
646 for i in "$ii" `./alterner.pl --start '#' --altsep '_' -- "$ii"`; do
647 bf=`basename -- "$i" .nit`
648 ff="$outdir/$bf"
649
650 # Sould we skip the alternative for this engine?
651 need_skip "$bf" "$bf" "$pack" && continue
652
653 echo -n "=> $bf: "
654
655 if [ -f "$f.inputs" ]; then
656 inputs="$f.inputs"
657 export MNIT_READ_INPUT="$f.inputs"
658 else
659 inputs=/dev/null
660 export MNIT_READ_INPUT=/dev/null
661 fi
662
663 ffout="$ff.bin"
664 if [ "$engine" = "emscripten" ]; then
665 ffout="$ff.bin.js"
666 fi
667
668 if [ -n "$isinterpret" ]; then
669 cat > "$ff.bin" <<END
670 exec $NITC --no-color $OPT $includes -- $(printf '%q' "$i") "\$@"
671 END
672 chmod +x "$ff.bin"
673 > "$ff.cmp.err"
674 > "$ff.compile.log"
675 ERR=0
676 echo 0.0 > "$ff.time.out"
677 elif [ -n "$isinteractive" ]; then
678 cat > "$ff.bin" <<END
679 exec $NITC --no-color --no-prompt --source-name $(printf '%q' "$i") $OPT $includes < $(printf '%q' "$i") "\$@"
680 END
681 chmod +x "$ff.bin"
682 > "$ff.cmp.err"
683 > "$ff.compile.log"
684 ERR=0
685 echo 0.0 > "$ff.time.out"
686 else
687 if skip_cc "$bf"; then
688 nocc="--no-cc"
689 else
690 nocc=
691 fi
692 # Compile
693 if [ "x$verbose" = "xtrue" ]; then
694 echo ""
695 echo $NITC --no-color $OPT -o "$ffout" "$includes" $nocc "$i"
696 fi
697 NIT_NO_STACK=1 JNI_LIB_PATH=$JNI_LIB_PATH JAVA_HOME=$JAVA_HOME \
698 saferun -o "$ff.time.out" $NITC --no-color $OPT -o "$ffout" $includes $nocc "$i" 2> "$ff.cmp.err" > "$ff.compile.log"
699 ERR=$?
700 if [ "x$verbose" = "xtrue" ]; then
701 cat -- "$ff.compile.log"
702 cat >&2 -- "$ff.cmp.err"
703 fi
704 # Clean
705 rm -r "$compdir" 2>/dev/null
706 fi
707 if [ "$engine" = "emscripten" ]; then
708 echo > "$ff.bin" "nodejs $ffout \"\$@\""
709 chmod +x "$ff.bin"
710 if grep "Fatal Error: more than one primitive class" "$ff.compile.log" > /dev/null; then
711 echo " [skip] do no not imports kernel"
712 echo >>$xml "<testcase classname='`xmlesc "$pack"`' name='`xmlesc "$bf"`' `timestamp`><skipped/></testcase>"
713 continue
714 fi
715 fi
716 if [ "$ERR" != 0 ]; then
717 echo -n "! "
718 cat -- "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
719 process_result "$bf" "$bf" "$pack"
720 elif [ -n "$nocc" ]; then
721 # not compiled
722 echo -n "nocc "
723 > "$ff.res"
724 process_result "$bf" "$bf" "$pack"
725 elif [ -x "$ff.bin" ]; then
726 if skip_exec "$bf"; then
727 # No exec
728 > "$ff.res"
729 process_result "$bf" "$bf" "$pack"
730 break
731 fi
732 echo -n ". "
733 # Execute
734 args=""
735 if [ "x$verbose" = "xtrue" ]; then
736 echo ""
737 echo "NIT_NO_STACK=1 $ff.bin" $args
738 fi
739 NIT_NO_STACK=1 LD_LIBRARY_PATH=$JNI_LIB_PATH WRITE="$ff.write" \
740 saferun -a -o "$ff.time.out" "$ff.bin" $args < "$inputs" > "$ff.res" 2>"$ff.err"
741 mv "$ff.time.out" "$ff.times.out"
742 awk '{ SUM += $1} END { print SUM }' "$ff.times.out" > "$ff.time.out"
743
744 if [ "x$verbose" = "xtrue" ]; then
745 cat -- "$ff.res"
746 cat >&2 -- "$ff.err"
747 fi
748 if [ -f "$ff.write" ]; then
749 cat -- "$ff.write" >> "$ff.res"
750 elif [ -d "$ff.write" ]; then
751 /bin/ls -F "$ff.write" >> "$ff.res"
752 fi
753 cp -- "$ff.res" "$ff.res2"
754 cat -- "$ff.cmp.err" "$ff.err" "$ff.res2" > "$ff.res"
755 process_result "$bf" "$bf" "$pack"
756
757 if [ -f "$f.args" ]; then
758 fargs=$f.args
759 cptr=0
760 while read line; do
761 ((cptr=cptr+1))
762 args="$line"
763 bff=$bf"_args"$cptr
764 fff=$ff"_args"$cptr
765 name="$bf args $cptr"
766
767 # Sould we skip the input for this engine?
768 need_skip "$bff" " $name" "$pack" && continue
769
770 # use a specific inputs file, if required
771 if [ -f "$bff.inputs" ]; then
772 ffinputs="$bff.inputs"
773 else
774 ffinputs="$inputs"
775 fi
776
777 rm -rf "$fff.res" "$fff.err" "$fff.write" 2> /dev/null
778 if [ "x$verbose" = "xtrue" ]; then
779 echo ""
780 echo "NIT_NO_STACK=1 $ff.bin" $args
781 fi
782 echo -n "==> $name "
783 echo "$ff.bin $args" > "$fff.bin"
784 chmod +x "$fff.bin"
785 WRITE="$fff.write" saferun -o "$fff.time.out" sh -c "NIT_NO_STACK=1 $fff.bin < $ffinputs > $fff.res 2>$fff.err"
786 if [ "x$verbose" = "xtrue" ]; then
787 cat -- "$fff.res"
788 cat >&2 -- "$fff.err"
789 fi
790 if [ -f "$fff.write" ]; then
791 cat -- "$fff.write" >> "$fff.res"
792 elif [ -d "$fff.write" ]; then
793 /bin/ls -F -- "$fff.write" >> "$fff.res"
794 fi
795 if [ -s "$fff.err" ]; then
796 cp -- "$fff.res" "$fff.res2"
797 cat -- "$fff.err" "$fff.res2" > "$fff.res"
798 fi
799 process_result "$bff" " $name" "$pack"
800 done < "$fargs"
801 fi
802 elif [ -f "$ff.bin" ]; then
803 #Not executable (platform?)"
804 > "$ff.res"
805 process_result "$bf" "$bf" "$pack"
806 else
807 echo -n "! "
808 cat -- "$ff.cmp.err" > "$ff.res"
809 echo "Compilation error" > "$ff.res"
810 process_result "$bf" "$bf" "$pack"
811 fi
812 done
813 done
814
815 if [ "x$isnode" = "xfalse" ]; then
816 echo "engine: $engine ($enginebinname $OPT)"
817 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos $todos | wc -w`
818
819 if [ -n "$nok" ]; then
820 echo "fail: $nok"
821 echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
822 fi
823 if [ -n "$nos" ]; then
824 echo "no sav: $nos"
825 fi
826 if [ -n "$todos" ]; then
827 echo "todo/fixme: $todos"
828 fi
829 if [ -n "$remains" ]; then
830 echo "sav that remains: $remains"
831 fi
832 fi
833
834 # write $ERRLIST
835 if [ "x$ERRLIST" != "x" ]; then
836 if [ -f "$ERRLIST_TARGET" ]; then
837 mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
838 fi
839 uniq $ERRLIST > $ERRLIST_TARGET
840 rm $ERRLIST
841 fi
842
843 echo >>$xml "</testsuite></testsuites>"
844
845 if type junit2html >/dev/null; then
846 junit2html "$xml"
847 fi
848
849 if [ -n "$nok" ]; then
850 exit 1
851 else
852 exit 0
853 fi