Patchwork libgo patch committed: Add timeout for tests

login
register
mail settings
Submitter Ian Taylor
Date March 31, 2011, 10:36 p.m.
Message ID <mcrei5mq5nk.fsf@google.com>
Download mbox | patch
Permalink /patch/89146/
State New
Headers show

Comments

Ian Taylor - March 31, 2011, 10:36 p.m.
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
Rainer Orth - April 1, 2011, 7:14 a.m.
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 Taylor - April 1, 2011, 2:20 p.m.
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.
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.
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.
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.
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.
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

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