]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add -benchtime to cacheable test flags
authorJohan Jansson <johan.jansson@iki.fi>
Wed, 24 Mar 2021 15:14:29 +0000 (17:14 +0200)
committerBryan C. Mills <bcmills@google.com>
Thu, 25 Mar 2021 18:05:10 +0000 (18:05 +0000)
Add -benchtime to the list of flags that allow caching test results.

If -benchtime is set without -bench, no benchmarks are run. The cache
does not need to be invalidated in this case.

If -benchtime is set with -bench, benchmarks are run. The cache is
invalidated due to the -bench flag in this case.

Fixes #44555

Change-Id: I2eb5c9f389a587d150fb984590d145251d0fa2dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/304689
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/go/alldocs.go
src/cmd/go/internal/test/test.go
src/cmd/go/testdata/script/test_cache_inputs.txt

index 9aac344a3f57d3351b9c25611fb921797e761f49..b15b77fac8403a788e09e3701c93cd754ce29923 100644 (file)
 //
 // The rule for a match in the cache is that the run involves the same
 // test binary and the flags on the command line come entirely from a
-// restricted set of 'cacheable' test flags, defined as -cpu, -list,
-// -parallel, -run, -short, and -v. If a run of go test has any test
+// restricted set of 'cacheable' test flags, defined as -benchtime, -cpu,
+// -list, -parallel, -run, -short, and -v. If a run of go test has any test
 // or non-test flags outside this set, the result is not cached. To
 // disable test caching, use any test flag or argument other than the
 // cacheable flags. The idiomatic way to disable test caching explicitly
index 230ea2d3189d15f7b14a157661f116030a53a3c7..ebe13205f75dc3a45dd10ecbf0636e31a847a0f7 100644 (file)
@@ -118,8 +118,8 @@ elapsed time in the summary line.
 
 The rule for a match in the cache is that the run involves the same
 test binary and the flags on the command line come entirely from a
-restricted set of 'cacheable' test flags, defined as -cpu, -list,
--parallel, -run, -short, and -v. If a run of go test has any test
+restricted set of 'cacheable' test flags, defined as -benchtime, -cpu,
+-list, -parallel, -run, -short, and -v. If a run of go test has any test
 or non-test flags outside this set, the result is not cached. To
 disable test caching, use any test flag or argument other than the
 cacheable flags. The idiomatic way to disable test caching explicitly
@@ -1333,7 +1333,8 @@ func (c *runCache) tryCacheWithID(b *work.Builder, a *work.Action, id string) bo
                        return false
                }
                switch arg[:i] {
-               case "-test.cpu",
+               case "-test.benchtime",
+                       "-test.cpu",
                        "-test.list",
                        "-test.parallel",
                        "-test.run",
index 50486e19090dd304c0fe22a9241e5c8ca1b8a5ff..d694a30994710e70145469998b3fd086b5f2964f 100644 (file)
@@ -99,6 +99,15 @@ rm $WORK/external.txt
 go test testcache -run=ExternalFile
 stdout '\(cached\)'
 
+# The -benchtime flag without -bench should not affect caching.
+go test testcache -run=Benchtime -benchtime=1x
+go test testcache -run=Benchtime -benchtime=1x
+stdout '\(cached\)'
+
+go test testcache -run=Benchtime -bench=Benchtime -benchtime=1x
+go test testcache -run=Benchtime -bench=Benchtime -benchtime=1x
+! stdout '\(cached\)'
+
 # Executables within GOROOT and GOPATH should affect caching,
 # even if the test does not stat them explicitly.
 
@@ -228,6 +237,10 @@ func TestExternalFile(t *testing.T) {
 func TestOSArgs(t *testing.T) {
        t.Log(os.Args)
 }
+
+func TestBenchtime(t *testing.T) {
+}
+
 -- mkold.go --
 package main