Skip to content

Commit 74fe516

Browse files
jupjBryan C. Mills
authored and
Bryan C. Mills
committed
cmd/go: add -benchtime to cacheable test flags
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 <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Trust: Jay Conrod <[email protected]> Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 82a1e0f commit 74fe516

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/cmd/go/alldocs.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/test/test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ elapsed time in the summary line.
118118
119119
The rule for a match in the cache is that the run involves the same
120120
test binary and the flags on the command line come entirely from a
121-
restricted set of 'cacheable' test flags, defined as -cpu, -list,
122-
-parallel, -run, -short, and -v. If a run of go test has any test
121+
restricted set of 'cacheable' test flags, defined as -benchtime, -cpu,
122+
-list, -parallel, -run, -short, and -v. If a run of go test has any test
123123
or non-test flags outside this set, the result is not cached. To
124124
disable test caching, use any test flag or argument other than the
125125
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
13331333
return false
13341334
}
13351335
switch arg[:i] {
1336-
case "-test.cpu",
1336+
case "-test.benchtime",
1337+
"-test.cpu",
13371338
"-test.list",
13381339
"-test.parallel",
13391340
"-test.run",

src/cmd/go/testdata/script/test_cache_inputs.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ rm $WORK/external.txt
9999
go test testcache -run=ExternalFile
100100
stdout '\(cached\)'
101101

102+
# The -benchtime flag without -bench should not affect caching.
103+
go test testcache -run=Benchtime -benchtime=1x
104+
go test testcache -run=Benchtime -benchtime=1x
105+
stdout '\(cached\)'
106+
107+
go test testcache -run=Benchtime -bench=Benchtime -benchtime=1x
108+
go test testcache -run=Benchtime -bench=Benchtime -benchtime=1x
109+
! stdout '\(cached\)'
110+
102111
# Executables within GOROOT and GOPATH should affect caching,
103112
# even if the test does not stat them explicitly.
104113

@@ -228,6 +237,10 @@ func TestExternalFile(t *testing.T) {
228237
func TestOSArgs(t *testing.T) {
229238
t.Log(os.Args)
230239
}
240+
241+
func TestBenchtime(t *testing.T) {
242+
}
243+
231244
-- mkold.go --
232245
package main
233246

0 commit comments

Comments
 (0)