summaryrefslogtreecommitdiffstats
path: root/libgo/go/testing
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-24 23:46:17 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-24 23:46:17 +0000
commitf97228863f84f4d7d87959ea40df40130f2ec912 (patch)
tree9319bca77115a32f6a0b5e8bcd651465b14c76da /libgo/go/testing
parentd304b9e1af728d54ec16155c3d2116dc398c33c6 (diff)
downloadppe42-gcc-f97228863f84f4d7d87959ea40df40130f2ec912.tar.gz
ppe42-gcc-f97228863f84f4d7d87959ea40df40130f2ec912.zip
Update to current version of Go library.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@171427 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/testing')
-rw-r--r--libgo/go/testing/script/script.go4
-rw-r--r--libgo/go/testing/testing.go61
2 files changed, 59 insertions, 6 deletions
diff --git a/libgo/go/testing/script/script.go b/libgo/go/testing/script/script.go
index 11f5a74251a..b341b1f896b 100644
--- a/libgo/go/testing/script/script.go
+++ b/libgo/go/testing/script/script.go
@@ -306,8 +306,8 @@ func recvValues(multiplex chan<- interface{}, channel interface{}) {
c := reflect.NewValue(channel).(*reflect.ChanValue)
for {
- v := c.Recv()
- if c.Closed() {
+ v, ok := c.Recv()
+ if !ok {
multiplex <- channelClosed{channel}
return
}
diff --git a/libgo/go/testing/testing.go b/libgo/go/testing/testing.go
index 324b5a70e1f..ab8cf999a25 100644
--- a/libgo/go/testing/testing.go
+++ b/libgo/go/testing/testing.go
@@ -43,12 +43,18 @@ import (
"fmt"
"os"
"runtime"
+ "runtime/pprof"
"time"
)
-// Report as tests are run; default is silent for success.
-var chatty = flag.Bool("test.v", false, "verbose: print additional output")
-var match = flag.String("test.run", "", "regular expression to select tests to run")
+var (
+ // Report as tests are run; default is silent for success.
+ chatty = flag.Bool("test.v", false, "verbose: print additional output")
+ match = flag.String("test.run", "", "regular expression to select tests to run")
+ 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")
+)
// Insert final newline if needed and tabs after internal newlines.
@@ -136,8 +142,16 @@ func tRunner(t *T, test *InternalTest) {
// An internal function but exported because it is cross-package; part of the implementation
// of gotest.
-func Main(matchString func(pat, str string) (bool, os.Error), tests []InternalTest) {
+func Main(matchString func(pat, str string) (bool, os.Error), tests []InternalTest, benchmarks []InternalBenchmark) {
flag.Parse()
+
+ before()
+ RunTests(matchString, tests)
+ RunBenchmarks(matchString, benchmarks)
+ after()
+}
+
+func RunTests(matchString func(pat, str string) (bool, os.Error), tests []InternalTest) {
ok := true
if len(tests) == 0 {
println("testing: warning: no tests to run")
@@ -176,3 +190,42 @@ func Main(matchString func(pat, str string) (bool, os.Error), tests []InternalTe
}
println("PASS")
}
+
+// before runs before all testing.
+func before() {
+ if *memProfileRate > 0 {
+ runtime.MemProfileRate = *memProfileRate
+ }
+ if *cpuProfile != "" {
+ f, err := os.Open(*cpuProfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0666)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "testing: %s", err)
+ return
+ }
+ if err := pprof.StartCPUProfile(f); err != nil {
+ fmt.Fprintf(os.Stderr, "testing: can't start cpu profile: %s", err)
+ f.Close()
+ return
+ }
+ // Could save f so after can call f.Close; not worth the effort.
+ }
+
+}
+
+// after runs after all testing.
+func after() {
+ if *cpuProfile != "" {
+ pprof.StopCPUProfile() // flushes profile to disk
+ }
+ if *memProfile != "" {
+ f, err := os.Open(*memProfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0666)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "testing: %s", err)
+ return
+ }
+ if err = pprof.WriteHeapProfile(f); err != nil {
+ fmt.Fprintf(os.Stderr, "testing: can't write %s: %s", *memProfile, err)
+ }
+ f.Close()
+ }
+}
OpenPOWER on IntegriCloud