Add polly tests to configure file.
[llvm-testsuite.git] / TimedExec.sh
blobe61fc0e0c58366085c7a08aee17792b445ebbf36
1 #!/bin/sh
3 # Program: TimedExec.sh
5 # Synopsis: This script is a watchdog wrapper. It runs the specified program
6 # but times out if it does not complete in the allocated time frame.
7 # Syntax: ./TimedExec.sh <timeout> <dir> <program> <args...>
10 if [ $# -lt 3 ]; then
11 echo "./TimedExec.sh <timeout> <dir> <program> <args...>"
12 exit 1
15 PARENT=""
16 if [ "$1" = "-p" ]; then
17 PARENT=$2; shift; shift;
20 TIMEOUT=$1
21 DIR=$2
22 shift 2
24 if [ -z "$PARENT" ]; then
25 # Start a watchdog process
26 $0 -p $$ $TIMEOUT $* &
27 cd $DIR
28 exec "$@"
29 else
30 # Sleep for a specified time then wake up to kill the parent process.
31 exec > /dev/null 2>&1
32 SEC=0
33 while [ $SEC -lt $TIMEOUT ]; do
34 sleep 1
35 # Check if parent has completed.
36 kill -0 $PARENT 2>/dev/null
37 if [ $? -eq 1 ]; then
38 exit 0
40 SEC=$(($SEC + 1))
41 done
42 kill $PARENT && (sleep 2; kill -1 $PARENT) && (sleep 2; kill -9 $PARENT)
43 fi
45 exit 0