summaryrefslogtreecommitdiffstats
path: root/libgo
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-31 22:36:10 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-31 22:36:10 +0000
commitaa686d7d15e611777da1bd513614aebfbfcdeb61 (patch)
tree7f9043433b2fefea2592a48ca03d456f776afc88 /libgo
parent7ca3c885ac59eed8b4d3ef56571c6260765e02c6 (diff)
downloadppe42-gcc-aa686d7d15e611777da1bd513614aebfbfcdeb61.tar.gz
ppe42-gcc-aa686d7d15e611777da1bd513614aebfbfcdeb61.zip
PR go/48242
libgo: Add timeout for tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@171803 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo')
-rw-r--r--libgo/go/testing/testing.go24
-rwxr-xr-xlibgo/testsuite/gotest12
2 files changed, 35 insertions, 1 deletions
diff --git a/libgo/go/testing/testing.go b/libgo/go/testing/testing.go
index d1893907a56..6d303cc6f2c 100644
--- a/libgo/go/testing/testing.go
+++ b/libgo/go/testing/testing.go
@@ -61,6 +61,7 @@ var (
memProfile = flag.String("test.memprofile", "", "write a memory profile to the named file after execution")
memProfileRate = flag.Int("test.memprofilerate", 0, "if >=0, sets runtime.MemProfileRate")
cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution")
+ timeout = flag.Int64("test.timeout", 0, "if > 0, sets time limit for tests in seconds")
)
// Short reports whether the -test.short flag is set.
@@ -158,7 +159,9 @@ func Main(matchString func(pat, str string) (bool, os.Error), tests []InternalTe
flag.Parse()
before()
+ startAlarm()
RunTests(matchString, tests)
+ stopAlarm()
RunBenchmarks(matchString, benchmarks)
after()
}
@@ -241,3 +244,24 @@ func after() {
f.Close()
}
}
+
+var timer *time.Timer
+
+// startAlarm starts an alarm if requested.
+func startAlarm() {
+ if *timeout > 0 {
+ timer = time.AfterFunc(*timeout*1e9, alarm)
+ }
+}
+
+// stopAlarm turns off the alarm.
+func stopAlarm() {
+ if *timeout > 0 {
+ timer.Stop()
+ }
+}
+
+// alarm is called if the timeout expires.
+func alarm() {
+ panic("test timed out")
+}
diff --git a/libgo/testsuite/gotest b/libgo/testsuite/gotest
index bcd725136b9..517c0e9f23e 100755
--- a/libgo/testsuite/gotest
+++ b/libgo/testsuite/gotest
@@ -32,6 +32,7 @@ loop=true
keep=false
prefix=
dejagnu=no
+timeout=60
while $loop; do
case "x$1" in
x--srcdir)
@@ -83,6 +84,15 @@ while $loop; do
dejagnu=`echo $1 | sed -e 's/^--dejagnu=//'`
shift
;;
+ x--timeout)
+ timeout=$2
+ shift
+ shift
+ ;;
+ x--timeout=*)
+ timeout=`echo $1 | sed -e 's/^--timeout=//'`
+ shift
+ ;;
x-*)
loop=false
;;
@@ -357,7 +367,7 @@ case "x$dejagnu" in
xno)
${GC} -g -c _testmain.go
${GL} *.o ${GOLIBS}
- ./a.out -test.short "$@"
+ ./a.out -test.short -test.timeout=$timeout "$@"
;;
xyes)
rm -rf ../testsuite/*.o
OpenPOWER on IntegriCloud