diff options
Diffstat (limited to 'libgo/go/testing')
-rw-r--r-- | libgo/go/testing/benchmark.go | 8 | ||||
-rw-r--r-- | libgo/go/testing/testing.go | 18 |
2 files changed, 17 insertions, 9 deletions
diff --git a/libgo/go/testing/benchmark.go b/libgo/go/testing/benchmark.go index ad93802..cf73e2b 100644 --- a/libgo/go/testing/benchmark.go +++ b/libgo/go/testing/benchmark.go @@ -8,10 +8,11 @@ import ( "flag" "fmt" "os" + "runtime" "time" ) -var matchBenchmarks = flag.String("benchmarks", "", "regular expression to select benchmarks to run") +var matchBenchmarks = flag.String("test.bench", "", "regular expression to select benchmarks to run") // An internal type but exported because it is cross-package; part of the implementation // of gotest. @@ -64,6 +65,9 @@ func (b *B) nsPerOp() int64 { // runN runs a single benchmark for the specified number of iterations. func (b *B) runN(n int) { + // Try to get a comparable environment for each run + // by clearing garbage from previous runs. + runtime.GC() b.N = n b.ResetTimer() b.StartTimer() @@ -175,7 +179,7 @@ func RunBenchmarks(matchString func(pat, str string) (bool, os.Error), benchmark for _, Benchmark := range benchmarks { matched, err := matchString(*matchBenchmarks, Benchmark.Name) if err != nil { - println("invalid regexp for -benchmarks:", err.String()) + println("invalid regexp for -test.bench:", err.String()) os.Exit(1) } if !matched { diff --git a/libgo/go/testing/testing.go b/libgo/go/testing/testing.go index 0e04935..324b5a7 100644 --- a/libgo/go/testing/testing.go +++ b/libgo/go/testing/testing.go @@ -12,7 +12,7 @@ // // Functions of the form // func BenchmarkXxx(*testing.B) -// are considered benchmarks, and are executed by gotest when the -benchmarks +// are considered benchmarks, and are executed by gotest when the -test.bench // flag is provided. // // A sample benchmark function looks like this: @@ -43,11 +43,12 @@ import ( "fmt" "os" "runtime" + "time" ) // Report as tests are run; default is silent for success. -var chatty = flag.Bool("v", false, "verbose: print additional output") -var match = flag.String("match", "", "regular expression to select tests to run") +var chatty = flag.Bool("test.v", false, "verbose: print additional output") +var match = flag.String("test.run", "", "regular expression to select tests to run") // Insert final newline if needed and tabs after internal newlines. @@ -91,7 +92,7 @@ func (t *T) FailNow() { // and records the text in the error log. func (t *T) Log(args ...interface{}) { t.errors += "\t" + tabify(fmt.Sprintln(args...)) } -// Log formats its arguments according to the format, analogous to Printf(), +// Logf formats its arguments according to the format, analogous to Printf(), // and records the text in the error log. func (t *T) Logf(format string, args ...interface{}) { t.errors += "\t" + tabify(fmt.Sprintf(format, args...)) @@ -144,7 +145,7 @@ func Main(matchString func(pat, str string) (bool, os.Error), tests []InternalTe for i := 0; i < len(tests); i++ { matched, err := matchString(*match, tests[i].Name) if err != nil { - println("invalid regexp for -match:", err.String()) + println("invalid regexp for -test.run:", err.String()) os.Exit(1) } if !matched { @@ -153,16 +154,19 @@ func Main(matchString func(pat, str string) (bool, os.Error), tests []InternalTe if *chatty { println("=== RUN ", tests[i].Name) } + ns := -time.Nanoseconds() t := new(T) t.ch = make(chan *T) go tRunner(t, &tests[i]) <-t.ch + ns += time.Nanoseconds() + tstr := fmt.Sprintf("(%.1f seconds)", float64(ns)/1e9) if t.failed { - println("--- FAIL:", tests[i].Name) + println("--- FAIL:", tests[i].Name, tstr) print(t.errors) ok = false } else if *chatty { - println("--- PASS:", tests[i].Name) + println("--- PASS:", tests[i].Name, tstr) print(t.errors) } } |