Skip to content

Commit 5e7d9a8

Browse files
authored
fix: TestGenericsHashKeyInPprofBuilder, TestGenericsShape on gotip (#150)
1 parent e584e4d commit 5e7d9a8

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
GO_VERSION_PRE20 := $(shell go version | awk '{print $$3}' | awk -F '.' '{print ($$1 == "go1" && int($$2) < 20)}')
21
TEST_PACKAGES := ./... ./godeltaprof/compat/... ./godeltaprof/...
2+
GO ?= go
3+
GOTIP ?= gotip
34

45
.PHONY: test
56
test:
6-
go test -race $(shell go list $(TEST_PACKAGES) | grep -v /example)
7+
$(GO) test -race $(shell $(GO) list $(TEST_PACKAGES) | grep -v /example)
78

89
.PHONY: go/mod
910
go/mod:
@@ -18,6 +19,6 @@ go/mod:
1819
# https://github.com/grafana/pyroscope-go/issues/129
1920
.PHONY: gotip/fix
2021
gotip/fix:
21-
cd godeltaprof/compat/ && gotip get -d -v golang.org/x/tools@v0.25.0
22+
cd godeltaprof/compat/ && $(GOTIP) get -v golang.org/x/tools@v0.34.0
2223
git --no-pager diff
2324
! git diff | grep toolchain

godeltaprof/compat/generics_go21_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package compat
66
import (
77
"bytes"
88
"fmt"
9-
"github.com/google/pprof/profile"
109
"io"
1110
"runtime"
1211
"runtime/pprof"
@@ -16,6 +15,7 @@ import (
1615
"testing"
1716
"time"
1817

18+
"github.com/google/pprof/profile"
1919
"github.com/grafana/pyroscope-go/godeltaprof"
2020
"github.com/stretchr/testify/require"
2121
)
@@ -60,7 +60,8 @@ func TestGenericsShape(t *testing.T) {
6060
runtime.MemProfileRate = prev
6161
}()
6262

63-
_ = genericAllocFunc[int](239)
63+
it := genericAllocFunc[int](239)
64+
escape(it)
6465

6566
runtime.GC()
6667

@@ -233,10 +234,11 @@ func TestGenericsHashKeyInPprofBuilder(t *testing.T) {
233234
runtime.MemProfileRate = previousRate
234235
}()
235236
for _, sz := range []int{128, 256} {
236-
genericAllocFunc[uint32](sz / 4)
237+
_ = genericAllocFunc[uint32](sz / 4)
237238
}
238239
for _, sz := range []int{32, 64} {
239-
genericAllocFunc[uint64](sz / 8)
240+
it := genericAllocFunc[uint64](sz / 8)
241+
escape(it)
240242
}
241243

242244
runtime.GC()
@@ -349,3 +351,10 @@ func WriteHeapProfile(w io.Writer) error {
349351
})
350352
return dh.Profile(w)
351353
}
354+
355+
// make sure a is on the heap
356+
// https://go-review.googlesource.com/c/go/+/649035
357+
// https://go-review.googlesource.com/c/go/+/653856
358+
func escape(a any) {
359+
fmt.Println(a)
360+
}

0 commit comments

Comments
 (0)