2 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 # Number of times a command must be run with bench_command
21 # User time limit (in second) before a command is aborted
24 # Common functions for all the bench scripts
26 # Run a single command multiple time and store the execution times
27 # in the current $res file.
29 # $1: title of the command
30 # $2: long desription of the command
31 # rest: the command to execute
32 function bench_command
()
34 if [ "$dry_run" = "true" ]; then return; fi
39 if test "$verbose" = true
; then outputopts
="/dev/stdout"; else outputopts
="/dev/null"; fi
41 echo "$title" > "$timeout"
42 echo "# $desc" >> "$timeout"
43 echo "\$ $@" >> "$timeout"
45 echo "** [$title] $desc **"
50 # Execute the commands $count times
51 for i
in `seq 1 "$count"`; do
53 ulimit -t
"$usertimelimit" 2> /dev
/null
54 /usr
/bin
/time -f
"%U" -o
"$timeout" -a
"$@" > $outputopts 2>&1
55 ) ||
{ err
=$?
; failed
=true
; die
"$1: failed with $err"; }
58 test -n
"$failed" && break
61 line
=`compute_stats "$timeout"`
65 if test -n
"$xml"; then
66 echo >>"$xml" "<testcase classname='bench.`basename $res .dat`' name='$title' time='`echo $line | cut -f 1 -d " "`' timestamp='`date -Iseconds`'>"
67 if test -n
"$failed"; then
68 echo >>"$xml" "<error message='Command failed'/>"
70 echo >>"$xml" "</testcase>"
75 # Run a simble command witout storing the execution time
76 # Used to display command on verbose and skip long executions when dry_run is given
77 # $@ command to execute
78 function run_command
()
80 if [ "$dry_run" = "true" ]; then return; fi
82 "$@" || die
"$@: failed"
85 # Check if the test should be skiped according to its name
86 # $1: name of the test
87 # $2: description of the test
88 # $NOTSKIPED: arguments
91 if test -z
"$NOTSKIPED"; then
95 if test "$NOTSKIPED" = "all"; then
97 elif echo "$1" |
egrep "$NOTSKIPED" >/dev
/null
2>&1; then
98 : # Found one to execute
102 if test -n
"$html"; then
103 echo >>"$html" "<h2 id="$1">$1</h2>"
111 # Helper function. Print the error message and set $died to 1