]> Cypherpunks repositories - gostls13.git/commitdiff
testing: add -test.count flag to run tests and benchmarks multiple times
authorRuss Cox <rsc@golang.org>
Thu, 4 Jun 2015 02:21:07 +0000 (22:21 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 5 Jun 2015 04:31:10 +0000 (04:31 +0000)
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>
src/cmd/go/alldocs.go
src/cmd/go/test.go
src/cmd/go/testflag.go
src/testing/testing.go

index 2b1cbf98ec9586bd9266adf913936544aed9e1c0..2c4451a0a7dc404db3e3abfc1ab9efa0624c6d70 100644 (file)
@@ -1135,6 +1135,11 @@ control the execution of any test:
            if -test.blockprofile is set without this flag, all blocking events
            are recorded, equivalent to -test.blockprofilerate=1.
 
+       -count n
+           Run each test and benchmark n times (default 1).
+           If -cpu is set, run n times for each GOMAXPROCS value.
+           Examples are always run once.
+
        -cover
            Enable coverage analysis.
 
index 22018f9372b53ed4a759644908177920b974b09c..ae9a9fa537cfcf41cb4bb81ec8c5a0a6e4946055 100644 (file)
@@ -141,6 +141,11 @@ control the execution of any test:
            if -test.blockprofile is set without this flag, all blocking events
            are recorded, equivalent to -test.blockprofilerate=1.
 
+       -count n
+           Run each test and benchmark n times (default 1).
+           If -cpu is set, run n times for each GOMAXPROCS value.
+           Examples are always run once.
+
        -cover
            Enable coverage analysis.
 
index db1266ea94a02aa72d955121cea093a185b933e9..03416d582e4562549a0edf1233872f9ea7216d5d 100644 (file)
@@ -55,6 +55,7 @@ var testFlagDefn = []*testFlagSpec{
        {name: "bench", passToTest: true},
        {name: "benchmem", boolVar: new(bool), passToTest: true},
        {name: "benchtime", passToTest: true},
+       {name: "count", passToTest: true},
        {name: "coverprofile", passToTest: true},
        {name: "cpu", passToTest: true},
        {name: "cpuprofile", passToTest: true},
index 2a1c45f7683c2fec5a253990a21dc31faae32bf0..f64629fe53335ff3eb67cf1b7c73059fb78737b9 100644 (file)
@@ -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))
+               }
        }
 }