Fix file mode.
[llvm-testsuite.git] / RunSafelyAndStable.sh
blob33b0a2ac6314c90a51ea9a2a0c6480aa036b7f7c
1 #!/bin/sh
3 # Program: RunSafelyAndStable.sh
5 # Synopsis: This script runs another program three times by repeatedly
6 # invoking the RunSafely.sh script. It collects the timings of
7 # the program and reports the smallest one. The <outfile>.time
8 # file will reflect the time and result code of the fastest
9 # run.
11 # Syntax:
12 # ./RunSafelyAndStable.sh <ulimit> <exitok> <infile> <outfile> \
13 # <program> <args...>
15 # See the RunSafely.sh script for more details.
17 DIR=${0%%`basename $0`}
18 ULIMIT=$1
19 EXITOK=$2
20 INFILE=$3
21 OUTFILE=$4
22 PROGRAM=$5
23 shift 5
25 # Run it the first time
26 ${DIR}/RunSafely.sh $ULIMIT $EXITOK $INFILE $OUTFILE $PROGRAM $*
27 exitval=$?
28 mv $OUTFILE.time $OUTFILE.time1
29 TIME1=`grep program $OUTFILE.time1 | sed 's/^program//'`
30 echo "Program $PROGRAM run #1 time: $TIME1"
32 # Run it the second time
33 ${DIR}/RunSafely.sh $ULIMIT $EXITOK $INFILE $OUTFILE $PROGRAM $*
34 mv $OUTFILE.time $OUTFILE.time2
35 TIME2=`grep program $OUTFILE.time2 | sed 's/^program//'`
36 echo "Program $PROGRAM run #2 time: $TIME2"
38 # Run it the third time
39 ${DIR}/RunSafely.sh $ULIMIT $EXITOK $INFILE $OUTFILE $PROGRAM $*
40 mv $OUTFILE.time $OUTFILE.time3
41 TIME3=`grep program $OUTFILE.time3 | sed 's/^program//'`
42 echo "Program $PROGRAM run #3 time: $TIME3"
44 # Figure out which run had the smallest run time:
45 SHORTEST=`echo -e "$TIME1 time1\n$TIME2 time2\n$TIME3 time3" | sort |
46 head -1 | sed "s|.*time||"`
48 echo "Program $PROGRAM run #$SHORTEST was fastest"
49 cp $OUTFILE.time$SHORTEST $OUTFILE.time
51 exit $exitval