diff options
| author | Russ Cox <rsc@golang.org> | 2015-06-03 22:21:07 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-06-05 04:31:10 +0000 |
| commit | fddc3ca11c38b063cb24e14d99cc023e746d0e20 (patch) | |
| tree | e8508747e2dce5064d131b72eece371e3dde4569 /src/testing/testing.go | |
| parent | de305a197f5c9ca3bb09da024e06ba7be0c7435d (diff) | |
| download | go-fddc3ca11c38b063cb24e14d99cc023e746d0e20.tar.xz | |
testing: add -test.count flag to run tests and benchmarks multiple times
The flag is available from the go test command as -count:
% go test -run XXX -bench . -count 3
PASS
BenchmarkSprintfEmpty 30000000 54.0 ns/op
BenchmarkSprintfEmpty 30000000 51.9 ns/op
BenchmarkSprintfEmpty 30000000 53.8 ns/op
BenchmarkSprintfString 10000000 238 ns/op
BenchmarkSprintfString 10000000 239 ns/op
BenchmarkSprintfString 10000000 234 ns/op
BenchmarkSprintfInt 10000000 232 ns/op
BenchmarkSprintfInt 10000000 226 ns/op
BenchmarkSprintfInt 10000000 225 ns/op
...
If -cpu is set, each test is run n times for each cpu value.
Original by r (CL 10663).
Change-Id: If3dfbdf21698952daac9249b5dbca66f5301e91b
Reviewed-on: https://go-review.googlesource.com/10669
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Diffstat (limited to 'src/testing/testing.go')
| -rw-r--r-- | src/testing/testing.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go index 2a1c45f768..f64629fe53 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -172,6 +172,7 @@ var ( // Report as tests are run; default is silent for success. chatty = flag.Bool("test.v", false, "verbose: print additional output") + count = flag.Uint("test.count", 1, "run tests and benchmarks `n` times") coverProfile = flag.String("test.coverprofile", "", "write a coverage profile to the named file after execution") match = flag.String("test.run", "", "regular expression to select tests and examples to run") memProfile = flag.String("test.memprofile", "", "write a memory profile to the named file after execution") @@ -724,9 +725,13 @@ func parseCpuList() { fmt.Fprintf(os.Stderr, "testing: invalid value %q for -test.cpu\n", val) os.Exit(1) } - cpuList = append(cpuList, cpu) + for i := uint(0); i < *count; i++ { + cpuList = append(cpuList, cpu) + } } if cpuList == nil { - cpuList = append(cpuList, runtime.GOMAXPROCS(-1)) + for i := uint(0); i < *count; i++ { + cpuList = append(cpuList, runtime.GOMAXPROCS(-1)) + } } } |
