mirror of
https://github.com/golang/go
synced 2025-04-20 01:10:30 +00:00
Currently, if the user stops the timer in a B.Loop benchmark loop, the benchmark will run until it hits the timeout and fails. Fix this by detecting that the timer is stopped and failing the benchmark right away. We avoid making the fast path more expensive for this check by "poisoning" the B.Loop iteration counter when the timer is stopped so that it falls back to the slow path, which can check the timer. This causes b to escape from B.Loop, which is totally harmless because it was already definitely heap-allocated. But it causes the test/inline_testingbloop.go errorcheck test to fail. I don't think the escape messages actually mattered to that test, they just had to be matched. To fix this, we drop the debug level to -m=1, since -m=2 prints a lot of extra information for escaping parameters that we don't want to deal with, and change one error check to allow b to escape. Fixes #72974. Change-Id: I7d4abbb1ec1e096685514536f91ba0d581cca6b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/659657 Auto-Submit: Austin Clements <austin@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/660558 Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
// errorcheck -0 -m
|
|
|
|
// Copyright 2024 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Test no inlining of function calls in testing.B.Loop.
|
|
// See issue #61515.
|
|
|
|
package foo
|
|
|
|
import "testing"
|
|
|
|
func caninline(x int) int { // ERROR "can inline caninline"
|
|
return x
|
|
}
|
|
|
|
func test(b *testing.B) { // ERROR "leaking param: b"
|
|
for i := 0; i < b.N; i++ {
|
|
caninline(1) // ERROR "inlining call to caninline"
|
|
}
|
|
for b.Loop() { // ERROR "skip inlining within testing.B.loop" "inlining call to testing\.\(\*B\)\.Loop"
|
|
caninline(1)
|
|
}
|
|
for i := 0; i < b.N; i++ {
|
|
caninline(1) // ERROR "inlining call to caninline"
|
|
}
|
|
for b.Loop() { // ERROR "skip inlining within testing.B.loop" "inlining call to testing\.\(\*B\)\.Loop"
|
|
caninline(1)
|
|
}
|
|
for i := 0; i < b.N; i++ {
|
|
caninline(1) // ERROR "inlining call to caninline"
|
|
}
|
|
for b.Loop() { // ERROR "skip inlining within testing.B.loop" "inlining call to testing\.\(\*B\)\.Loop"
|
|
caninline(1)
|
|
}
|
|
}
|