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