aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/testing
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-03-31 22:36:10 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-03-31 22:36:10 +0000
commit4bce572db2a654c9f17bb798b8469df11d3147e3 (patch)
tree7f9043433b2fefea2592a48ca03d456f776afc88 /libgo/go/testing
parentc9103dde9636989de0f34dd1656bd2cd477f6fdf (diff)
downloadgcc-4bce572db2a654c9f17bb798b8469df11d3147e3.zip
gcc-4bce572db2a654c9f17bb798b8469df11d3147e3.tar.gz
gcc-4bce572db2a654c9f17bb798b8469df11d3147e3.tar.bz2
re PR go/48242 (gotest needs timeout mechanism)
PR go/48242 libgo: Add timeout for tests. From-SVN: r171803
Diffstat (limited to 'libgo/go/testing')
-rw-r--r--libgo/go/testing/testing.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/libgo/go/testing/testing.go b/libgo/go/testing/testing.go
index d189390..6d303cc 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")
+}