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.
16 # Common functions for all the bench scripts
18 # Run a single command multiple time and store the execution times
19 # in the current $res file.
21 # $1: title of the command
22 # $2: long desription of the command
23 # rest: the command to execute
24 function bench_command
()
26 if [ "$dry_run" = "true" ]; then return; fi
31 if test "$verbose" = true
; then outputopts
="/dev/stdout"; else outputopts
="/dev/null"; fi
33 echo "$title" > "$timeout"
34 echo "# $desc" >> "$timeout"
35 echo "\$ $@" >> "$timeout"
37 echo "** [$title] $desc **"
42 # Execute the commands $count times
43 for i
in `seq 1 "$count"`; do
44 /usr
/bin
/time -f
"%U" -o
"$timeout" -a
"$@" > $outputopts 2>&1 ||
{ failed
=true
; die
"$1: failed"; }
49 line
=`compute_stats "$timeout"`
53 test -z
"$xml" && return
54 echo >>"$xml" "<testcase classname='bench.`basename $res .dat`' name='$title' time='`echo $line | cut -f 1 -d " "`' timestamp='`date -Iseconds`'>"
55 if test -n
"$failed"; then
56 echo >>"$xml" "<error message='Command failed'/>"
58 echo >>"$xml" "</testcase>"
61 # Run a simble command witout storing the execution time
62 # Used to display command on verbose and skip long executions when dry_run is given
63 # $@ command to execute
64 function run_command
()
66 if [ "$dry_run" = "true" ]; then return; fi
68 "$@" || die
"$@: failed"
71 # Check if the test should be skiped according to its name
72 # $1: name of the test
73 # $2: description of the test
74 # $NOTSKIPED: arguments
77 if test -z
"$NOTSKIPED"; then
81 if test "$NOTSKIPED" = "all"; then
83 elif echo "$1" |
egrep "$NOTSKIPED" >/dev
/null
2>&1; then
84 : # Found one to execute
88 if test -n
"$html"; then
89 echo >>"$html" "<h2>$1</h2>"
97 # Helper function. Print the error message and set $died to 1