diff mbox

libgo patch committed: Add timeout for tests

Message ID mcrei5mq5nk.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor March 31, 2011, 10:36 p.m. UTC
This patch to libgo adds a timeout for the libgo tests.  The default is
60 seconds.  It can be changed by an argument to gotest, which would
normally be used as, e.g.,
  make GOTESTFLAGS="--timeout=120" check-target-libgo

Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.  This is PR go/48242.

Ian

Comments

Rainer Orth April 1, 2011, 7:14 a.m. UTC | #1
Ian Lance Taylor <iant@google.com> writes:

> This patch to libgo adds a timeout for the libgo tests.  The default is
> 60 seconds.  It can be changed by an argument to gotest, which would
> normally be used as, e.g.,
>   make GOTESTFLAGS="--timeout=120" check-target-libgo

Great, thanks.

Shouldn't the default match the DejaGnu default of 300, though?

	Rainer
Ian Lance Taylor April 1, 2011, 2:20 p.m. UTC | #2
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:

> Ian Lance Taylor <iant@google.com> writes:
>
>> This patch to libgo adds a timeout for the libgo tests.  The default is
>> 60 seconds.  It can be changed by an argument to gotest, which would
>> normally be used as, e.g.,
>>   make GOTESTFLAGS="--timeout=120" check-target-libgo
>
> Great, thanks.
>
> Shouldn't the default match the DejaGnu default of 300, though?

Sure, it could, but why?  If any of these tests fail to complete in a
minute, something is badly wrong.

Ian
Rainer Orth April 1, 2011, 2:21 p.m. UTC | #3
Ian Lance Taylor <iant@google.com> writes:

>> Shouldn't the default match the DejaGnu default of 300, though?
>
> Sure, it could, but why?  If any of these tests fail to complete in a
> minute, something is badly wrong.

Ok, I'll see how long they take on my 250 MHz R10k MIPS :-)

	Rainer
Mike Stump April 1, 2011, 9:36 p.m. UTC | #4
On Apr 1, 2011, at 12:14 AM, Rainer Orth wrote:
> Ian Lance Taylor <iant@google.com> writes:
> 
>> This patch to libgo adds a timeout for the libgo tests.  The default is
>> 60 seconds.  It can be changed by an argument to gotest, which would
>> normally be used as, e.g.,
>>  make GOTESTFLAGS="--timeout=120" check-target-libgo
> 
> Great, thanks.
> 
> Shouldn't the default match the DejaGnu default of 300, though?

No...  I like the idea that people trim it down to something sane.  If nothing else, as a way to discourage them from big stupid test cases.
Mike Stump April 1, 2011, 9:37 p.m. UTC | #5
On Apr 1, 2011, at 7:21 AM, Rainer Orth wrote:
> Ian Lance Taylor <iant@google.com> writes:
> 
>>> Shouldn't the default match the DejaGnu default of 300, though?
>> 
>> Sure, it could, but why?  If any of these tests fail to complete in a
>> minute, something is badly wrong.
> 
> Ok, I'll see how long they take on my 250 MHz R10k MIPS :-)

I'd rather slow environments and slow machines setup a scaling factor with which they can expand the time as needed.  So, using a rs232 port at 110 to download testcases, scaling_factor=1000 or so.
Rainer Orth April 4, 2011, 5:49 p.m. UTC | #6
Mike Stump <mikestump@comcast.net> writes:

>> Shouldn't the default match the DejaGnu default of 300, though?
>
> No...  I like the idea that people trim it down to something sane.  If nothing else, as a way to discourage them from big stupid test cases.

No argument from me, since I've often been bitten by slower testcases.
I just argue that we should be consistent throughout the tree.  If that
means going for a 60 second default, fine :-)

	Rainer
Rainer Orth April 4, 2011, 5:49 p.m. UTC | #7
Mike Stump <mikestump@comcast.net> writes:

>> Ok, I'll see how long they take on my 250 MHz R10k MIPS :-)
>
> I'd rather slow environments and slow machines setup a scaling factor with which they can expand the time as needed.  So, using a rs232 port at 110 to download testcases, scaling_factor=1000 or so.

That's what I already did for this box.  Probably time to get rid of it ;-)

	Rainer
diff mbox

Patch

diff -r 86dce29de0ad libgo/go/testing/testing.go
--- a/libgo/go/testing/testing.go	Thu Mar 31 15:18:20 2011 -0700
+++ b/libgo/go/testing/testing.go	Thu Mar 31 15:33:09 2011 -0700
@@ -61,6 +61,7 @@ 
 	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 @@ 
 	flag.Parse()
 
 	before()
+	startAlarm()
 	RunTests(matchString, tests)
+	stopAlarm()
 	RunBenchmarks(matchString, benchmarks)
 	after()
 }
@@ -241,3 +244,24 @@ 
 		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 -r 86dce29de0ad libgo/testsuite/gotest
--- a/libgo/testsuite/gotest	Thu Mar 31 15:18:20 2011 -0700
+++ b/libgo/testsuite/gotest	Thu Mar 31 15:33:09 2011 -0700
@@ -32,6 +32,7 @@ 
 keep=false
 prefix=
 dejagnu=no
+timeout=60
 while $loop; do
 	case "x$1" in
         x--srcdir)
@@ -83,6 +84,15 @@ 
 		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 @@ 
 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