]> Cypherpunks repositories - gostls13.git/commitdiff
all: skip and fix various tests with -asan and -msan
authorMichael Anthony Knyszek <mknyszek@google.com>
Mon, 28 Oct 2024 17:23:40 +0000 (17:23 +0000)
committerMichael Knyszek <mknyszek@google.com>
Mon, 28 Oct 2024 21:04:51 +0000 (21:04 +0000)
First, skip all the allocation count tests.

In some cases this aligns with existing skips for -race, but in others
we've got new issues. These are debug modes, so some performance loss is
expected, and this is clearly no worse than today where the tests fail.

Next, skip internal linking and static linking tests for msan and asan.

With asan we get an explicit failure that neither are supported by the C
and/or Go compilers. With msan, we only get the Go compiler telling us
internal linking is unavailable. With static linking, we segfault
instead. Filed #70080 to track that.

Next, skip some malloc tests with asan that don't quite work because of
the redzone.

This is because of some sizeclass assumptions that get broken with the
redzone and the fact that the tiny allocator is effectively disabled
(again, due to the redzone).

Next, skip some runtime/pprof tests with asan, because of extra
allocations.

Next, skip some malloc tests with asan that also fail because of extra
allocations.

Next, fix up memstats accounting for arenas when asan is enabled. There
is a bug where more is added to the stats than subtracted. This also
simplifies the accounting a little.

Next, skip race tests with msan or asan enabled; they're mutually
incompatible.

Fixes #70054.
Fixes #64256.
Fixes #64257.
For #70079.
For #70080.

Change-Id: I99c02a0b9d621e44f1f918b307aa4a4944c3ec60
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-asan-clang15,gotip-linux-amd64-msan-clang15
Reviewed-on: https://go-review.googlesource.com/c/go/+/622855
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Bypass: Michael Knyszek <mknyszek@google.com>

22 files changed:
src/bufio/bufio_test.go
src/cmd/cgo/internal/test/test.go
src/cmd/compile/internal/test/issue53888_test.go
src/cmd/dist/test.go
src/crypto/rand/rand_test.go
src/database/sql/convert_test.go
src/encoding/binary/binary_test.go
src/log/slog/attr_test.go
src/log/slog/logger_test.go
src/log/slog/value_test.go
src/net/netip/netip_test.go
src/net/udpsock_test.go
src/reflect/all_test.go
src/runtime/arena.go
src/runtime/debug_test.go
src/runtime/gc_test.go
src/runtime/malloc_test.go
src/runtime/mfinal_test.go
src/runtime/pprof/mprof_test.go
src/runtime/pprof/protomem_test.go
src/slices/slices_test.go
src/strings/builder_test.go

index c68184269288dc9d0a7b34d9f03bfdfa8ac732a2..60752d38f65c31c84d141947a3cb2004d998daee 100644 (file)
@@ -9,6 +9,7 @@ import (
        "bytes"
        "errors"
        "fmt"
+       "internal/asan"
        "io"
        "math/rand"
        "strconv"
@@ -585,6 +586,9 @@ func TestWriteInvalidRune(t *testing.T) {
 }
 
 func TestReadStringAllocs(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
        r := strings.NewReader("       foo       foo        42        42        42        42        42        42        42        42       4.2       4.2       4.2       4.2\n")
        buf := NewReader(r)
        allocs := testing.AllocsPerRun(100, func() {
index c1375c2691a13115e5c2472d8551c5a39dd6da7c..fcac076225324735c6c75d22175aa590610655cb 100644 (file)
@@ -959,6 +959,7 @@ import "C"
 import (
        "context"
        "fmt"
+       "internal/asan"
        "math"
        "math/rand"
        "os"
@@ -1773,6 +1774,9 @@ func issue8331a() C.issue8331 {
 // issue 10303
 
 func test10303(t *testing.T, n int) {
+       if asan.Enabled {
+               t.Skip("variable z is heap-allocated due to extra allocations with -asan; see #70079")
+       }
        if runtime.Compiler == "gccgo" {
                t.Skip("gccgo permits C pointers on the stack")
        }
index 0d5b13b5c877b25097c6d02079a14d91744c5c16..c25c545e0817298d51a57eb4df796aecc065a65f 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build !race
+//go:build !race && !asan && !msan
 
 package test
 
index 0facfb579cb196ceace19a07279e8d3202a31483..eb1ea1c6abc215d80316bedc1ed6e8595ddca43e 100644 (file)
@@ -880,7 +880,8 @@ func (t *tester) registerTests() {
                }
        }
 
-       if t.raceDetectorSupported() {
+       if t.raceDetectorSupported() && !t.msan && !t.asan {
+               // N.B. -race is incompatible with -msan and -asan.
                t.registerRaceTests()
        }
 
@@ -1090,10 +1091,18 @@ func (t *tester) internalLink() bool {
                // linkmode=internal isn't supported.
                return false
        }
+       if t.msan || t.asan {
+               // linkmode=internal isn't supported by msan or asan.
+               return false
+       }
        return true
 }
 
 func (t *tester) internalLinkPIE() bool {
+       if t.msan || t.asan {
+               // linkmode=internal isn't supported by msan or asan.
+               return false
+       }
        switch goos + "-" + goarch {
        case "darwin-amd64", "darwin-arm64",
                "linux-amd64", "linux-arm64", "linux-ppc64le",
@@ -1232,18 +1241,22 @@ func (t *tester) registerCgoTests(heading string) {
                        }
 
                        // Static linking tests
-                       if goos != "android" && p != "netbsd/arm" {
+                       if goos != "android" && p != "netbsd/arm" && !t.msan && !t.asan {
                                // TODO(#56629): Why does this fail on netbsd-arm?
+                               // TODO(#70080): Why does this fail with msan?
+                               // asan doesn't support static linking (this is an explicit build error on the C side).
                                cgoTest("static", "testtls", "external", "static", staticCheck)
                        }
                        cgoTest("external", "testnocgo", "external", "", staticCheck)
-                       if goos != "android" {
+                       if goos != "android" && !t.msan && !t.asan {
+                               // TODO(#70080): Why does this fail with msan?
+                               // asan doesn't support static linking (this is an explicit build error on the C side).
                                cgoTest("static", "testnocgo", "external", "static", staticCheck)
                                cgoTest("static", "test", "external", "static", staticCheck)
                                // -static in CGO_LDFLAGS triggers a different code path
                                // than -static in -extldflags, so test both.
                                // See issue #16651.
-                               if goarch != "loong64" {
+                               if goarch != "loong64" && !t.msan && !t.asan {
                                        // TODO(#56623): Why does this fail on loong64?
                                        cgoTest("auto-static", "test", "auto", "static", staticCheck)
                                }
index 63581b75fdbc7fa047b60726b291fb1392c0b4f1..2d84fdc90015a42b5dad1f251f0e914613c71ada 100644 (file)
@@ -9,6 +9,8 @@ import (
        "compress/flate"
        "crypto/internal/boring"
        "errors"
+       "internal/asan"
+       "internal/msan"
        "internal/race"
        "internal/testenv"
        "io"
@@ -155,8 +157,8 @@ func TestAllocations(t *testing.T) {
                // Might be fixable with https://go.dev/issue/56378.
                t.Skip("boringcrypto allocates")
        }
-       if race.Enabled {
-               t.Skip("urandomRead allocates under -race")
+       if race.Enabled || msan.Enabled || asan.Enabled {
+               t.Skip("urandomRead allocates under -race, -asan, and -msan")
        }
        testenv.SkipIfOptimizationOff(t)
 
index f94db8e5f85edb73544ee0e549089923e15c5711..1b2e61c143ae136e01685b1eb1f6a382c28bcc90 100644 (file)
@@ -7,6 +7,7 @@ package sql
 import (
        "database/sql/driver"
        "fmt"
+       "internal/asan"
        "reflect"
        "runtime"
        "strings"
@@ -353,6 +354,9 @@ func TestRawBytesAllocs(t *testing.T) {
                {"bool", false, "false"},
                {"time", time.Unix(2, 5).UTC(), "1970-01-01T00:00:02.000000005Z"},
        }
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
 
        var buf RawBytes
        rows := &Rows{}
index 9e5fed53b72d5255159b496af1fdfed39952cd68..e0c5c0d9e0d7ee3f9894fcf9d29dcc95ff0ddeea 100644 (file)
@@ -7,6 +7,7 @@ package binary
 import (
        "bytes"
        "fmt"
+       "internal/asan"
        "io"
        "math"
        "reflect"
@@ -710,6 +711,9 @@ func TestNoFixedSize(t *testing.T) {
 }
 
 func TestAppendAllocs(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
        buf := make([]byte, 0, Size(&s))
        var err error
        allocs := testing.AllocsPerRun(1, func() {
@@ -745,6 +749,9 @@ var sizableTypes = []any{
 }
 
 func TestSizeAllocs(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
        for _, data := range sizableTypes {
                t.Run(fmt.Sprintf("%T", data), func(t *testing.T) {
                        // Size uses a sync.Map behind the scenes. The slow lookup path of
index e01447cfedd19e5652e878796ab4fe244e838e8c..1f2ce2621b5b587fb18418295ed1b0b742c23b25 100644 (file)
@@ -5,12 +5,16 @@
 package slog
 
 import (
+       "internal/asan"
        "internal/testenv"
        "testing"
        "time"
 )
 
 func TestAttrNoAlloc(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("test allocates with -asan")
+       }
        testenv.SkipIfOptimizationOff(t)
        // Assign values just to make sure the compiler doesn't optimize away the statements.
        var (
index bb1c8a16ea46ac4b988c9a0ab27645f7e8c93440..9efd4ed0e91f1cc329eeebcfd0b015b49bc809a2 100644 (file)
@@ -7,6 +7,8 @@ package slog
 import (
        "bytes"
        "context"
+       "internal/asan"
+       "internal/msan"
        "internal/race"
        "internal/testenv"
        "io"
@@ -644,8 +646,8 @@ func callerPC(depth int) uintptr {
 }
 
 func wantAllocs(t *testing.T, want int, f func()) {
-       if race.Enabled {
-               t.Skip("skipping test in race mode")
+       if race.Enabled || asan.Enabled || msan.Enabled {
+               t.Skip("skipping test in race, asan, and msan modes")
        }
        testenv.SkipIfOptimizationOff(t)
        t.Helper()
index 3e191589c5f6ae81fc640b308e60e2310ccfe032..4f405938ced42af83a17ebc04503551d6bd99760 100644 (file)
@@ -6,6 +6,7 @@ package slog
 
 import (
        "fmt"
+       "internal/asan"
        "reflect"
        "strings"
        "testing"
@@ -86,6 +87,10 @@ func TestValueString(t *testing.T) {
 }
 
 func TestValueNoAlloc(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
+
        // Assign values just to make sure the compiler doesn't optimize away the statements.
        var (
                i  int64
index 68975ad234f0a138416201c1300332d0c7c41422..ea03f9a9e72473f4b7dadfd2d1989fc3cef4fac2 100644 (file)
@@ -9,6 +9,7 @@ import (
        "encoding/json"
        "flag"
        "fmt"
+       "internal/asan"
        "internal/testenv"
        "net"
        . "net/netip"
@@ -2132,6 +2133,10 @@ var (
 )
 
 func TestNoAllocs(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
+
        // Wrappers that panic on error, to prove that our alloc-free
        // methods are returning successfully.
        panicIP := func(ip Addr, err error) Addr {
index 43065d06dab7719b53718a0ef6f067242b59c9f1..6dacc81df6e059f85e564d642ab6f830c90759bc 100644 (file)
@@ -7,6 +7,7 @@ package net
 import (
        "errors"
        "fmt"
+       "internal/asan"
        "internal/testenv"
        "net/netip"
        "os"
@@ -493,6 +494,9 @@ func TestAllocs(t *testing.T) {
        if !testableNetwork("udp4") {
                t.Skipf("skipping: udp4 not available")
        }
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
 
        // Optimizations are required to remove the allocs.
        testenv.SkipIfOptimizationOff(t)
index b3f4545531533580fa2dc0077b728c2de9bb5c14..db273899b0f3808771246cc9a203dc81ceb19665 100644 (file)
@@ -10,6 +10,7 @@ import (
        "flag"
        "fmt"
        "go/token"
+       "internal/asan"
        "internal/goarch"
        "internal/goexperiment"
        "internal/testenv"
@@ -1278,6 +1279,9 @@ func TestDeepEqualAllocs(t *testing.T) {
        if goexperiment.SwissMap {
                t.Skipf("Maps on stack not yet implemented")
        }
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
 
        for _, tt := range deepEqualPerfTests {
                t.Run(ValueOf(tt.x).Type().String(), func(t *testing.T) {
@@ -7353,6 +7357,9 @@ func TestPtrToMethods(t *testing.T) {
 }
 
 func TestMapAlloc(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
        m := ValueOf(make(map[int]int, 10))
        k := ValueOf(5)
        v := ValueOf(7)
@@ -7383,6 +7390,9 @@ func TestMapAlloc(t *testing.T) {
 }
 
 func TestChanAlloc(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
        // Note: for a chan int, the return Value must be allocated, so we
        // use a chan *int instead.
        c := ValueOf(make(chan *int, 1))
@@ -7745,11 +7755,14 @@ func TestMapIterReset(t *testing.T) {
        }
 
        // Reset should not allocate.
+       //
+       // Except with -asan, where there are additional allocations.
+       // See #70079.
        n := int(testing.AllocsPerRun(10, func() {
                iter.Reset(ValueOf(m2))
                iter.Reset(Value{})
        }))
-       if n > 0 {
+       if !asan.Enabled && n > 0 {
                t.Errorf("MapIter.Reset allocated %d times", n)
        }
 }
index ff59014a8a29435df9bf8af71fc72b8800e918a8..ab876dd21fa6b7b2f1806452ef365299ecf0bea6 100644 (file)
@@ -798,11 +798,8 @@ func newUserArenaChunk() (unsafe.Pointer, *mspan) {
 
        if asanenabled {
                // TODO(mknyszek): Track individual objects.
-               rzSize := redZoneSize(span.elemsize)
-               span.elemsize -= rzSize
-               span.largeType.Size_ = span.elemsize
+               // N.B. span.elemsize includes a redzone already.
                rzStart := span.base() + span.elemsize
-               span.userArenaChunkFree = makeAddrRange(span.base(), rzStart)
                asanpoison(unsafe.Pointer(rzStart), span.limit-rzStart)
                asanunpoison(unsafe.Pointer(span.base()), span.elemsize)
        }
@@ -1067,6 +1064,11 @@ func (h *mheap) allocUserArenaChunk() *mspan {
        s.freeindex = 1
        s.allocCount = 1
 
+       // Adjust size to include redzone.
+       if asanenabled {
+               s.elemsize -= redZoneSize(s.elemsize)
+       }
+
        // Account for this new arena chunk memory.
        gcController.heapInUse.add(int64(userArenaChunkBytes))
        gcController.heapReleased.add(-int64(userArenaChunkBytes))
index 0ee873d43f52e152b62e940c5523cf431d4ee831..37093cd87e6c900e18f65884e1868876e2cdcc2d 100644 (file)
@@ -16,6 +16,8 @@ package runtime_test
 import (
        "fmt"
        "internal/abi"
+       "internal/asan"
+       "internal/msan"
        "math"
        "os"
        "regexp"
@@ -32,6 +34,14 @@ func startDebugCallWorker(t *testing.T) (g *runtime.G, after func()) {
        // a debugger.
        skipUnderDebugger(t)
 
+       // asan/msan instrumentation interferes with tests since we might
+       // inject debugCallV2 while in the asan/msan runtime. This is a
+       // problem for doing things like running the GC or taking stack
+       // traces. Not sure why this is happening yet, but skip for now.
+       if msan.Enabled || asan.Enabled {
+               t.Skip("debugCallV2 is injected erroneously during asan/msan runtime calls; skipping")
+       }
+
        // This can deadlock if there aren't enough threads or if a GC
        // tries to interrupt an atomic loop (see issue #10958). Execute
        // an extra GC to ensure even the sweep phase is done (out of
index 63ccbeb32841e2a48898cdcb5fe88f04942bf85b..4faade50e81ae4d02448fa0d9fee4a540078de84 100644 (file)
@@ -6,6 +6,7 @@ package runtime_test
 
 import (
        "fmt"
+       "internal/asan"
        "math/bits"
        "math/rand"
        "os"
@@ -208,6 +209,9 @@ func TestGcZombieReporting(t *testing.T) {
 }
 
 func TestGCTestMoveStackOnNextCall(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("extra allocations with -asan causes this to fail; see #70079")
+       }
        t.Parallel()
        var onStack int
        // GCTestMoveStackOnNextCall can fail in rare cases if there's
@@ -298,6 +302,9 @@ var pointerClassBSS *int
 var pointerClassData = 42
 
 func TestGCTestPointerClass(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("extra allocations cause this test to fail; see #70079")
+       }
        t.Parallel()
        check := func(p unsafe.Pointer, want string) {
                t.Helper()
index 8c162fbea4b158a2f3f69cc6b59b74f0a5d2a1b3..67bceef2e30db89e8d02ac9c63db6548c4f26651 100644 (file)
@@ -7,6 +7,7 @@ package runtime_test
 import (
        "flag"
        "fmt"
+       "internal/asan"
        "internal/race"
        "internal/testenv"
        "os"
@@ -157,6 +158,9 @@ func TestTinyAlloc(t *testing.T) {
        if runtime.Raceenabled {
                t.Skip("tinyalloc suppressed when running in race mode")
        }
+       if asan.Enabled {
+               t.Skip("tinyalloc suppressed when running in asan mode due to redzone")
+       }
        const N = 16
        var v [N]unsafe.Pointer
        for i := range v {
@@ -182,6 +186,9 @@ func TestTinyAllocIssue37262(t *testing.T) {
        if runtime.Raceenabled {
                t.Skip("tinyalloc suppressed when running in race mode")
        }
+       if asan.Enabled {
+               t.Skip("tinyalloc suppressed when running in asan mode due to redzone")
+       }
        // Try to cause an alignment access fault
        // by atomically accessing the first 64-bit
        // value of a tiny-allocated object.
index 87d31c472c1b01110348d990009b3b68f5584b3a..5c93c74cfb2f08c5b778b83d07a6c14e4c2ce21a 100644 (file)
@@ -5,6 +5,7 @@
 package runtime_test
 
 import (
+       "internal/asan"
        "runtime"
        "testing"
        "time"
@@ -165,6 +166,9 @@ func adjChunks() (*objtype, *objtype) {
 
 // Make sure an empty slice on the stack doesn't pin the next object in memory.
 func TestEmptySlice(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("skipping with -asan: test assumes exact size class alignment, but asan redzone breaks that assumption")
+       }
        x, y := adjChunks()
 
        // the pointer inside xs points to y.
@@ -194,6 +198,9 @@ func adjStringChunk() (string, *objtype) {
 
 // Make sure an empty string on the stack doesn't pin the next object in memory.
 func TestEmptyString(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("skipping with -asan: test assumes exact size class alignment, but asan redzone breaks that assumption")
+       }
        x, y := adjStringChunk()
 
        ss := x[objsize:] // change objsize to objsize-1 and the test passes
index ef373b36848437ff02230f211691d686eb4d921f..7c4a37e3c996fb721ab8500e5ba36d91f92338cc 100644 (file)
@@ -9,6 +9,7 @@ package pprof
 import (
        "bytes"
        "fmt"
+       "internal/asan"
        "internal/profile"
        "reflect"
        "regexp"
@@ -63,6 +64,10 @@ func allocateReflect() {
 var memoryProfilerRun = 0
 
 func TestMemoryProfiler(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("extra allocations with -asan throw off the test; see #70079")
+       }
+
        // Disable sampling, otherwise it's difficult to assert anything.
        oldRate := runtime.MemProfileRate
        runtime.MemProfileRate = 1
@@ -93,31 +98,31 @@ func TestMemoryProfiler(t *testing.T) {
        }{{
                stk: []string{"runtime/pprof.allocatePersistent1K", "runtime/pprof.TestMemoryProfiler"},
                legacy: fmt.Sprintf(`%v: %v \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
-#      0x[0-9,a-f]+    runtime/pprof\.allocatePersistent1K\+0x[0-9,a-f]+       .*runtime/pprof/mprof_test\.go:47
-#      0x[0-9,a-f]+    runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test\.go:82
+#      0x[0-9,a-f]+    runtime/pprof\.allocatePersistent1K\+0x[0-9,a-f]+       .*runtime/pprof/mprof_test\.go:48
+#      0x[0-9,a-f]+    runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test\.go:87
 `, 32*memoryProfilerRun, 1024*memoryProfilerRun, 32*memoryProfilerRun, 1024*memoryProfilerRun),
        }, {
                stk: []string{"runtime/pprof.allocateTransient1M", "runtime/pprof.TestMemoryProfiler"},
                legacy: fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
-#      0x[0-9,a-f]+    runtime/pprof\.allocateTransient1M\+0x[0-9,a-f]+        .*runtime/pprof/mprof_test.go:24
-#      0x[0-9,a-f]+    runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:79
+#      0x[0-9,a-f]+    runtime/pprof\.allocateTransient1M\+0x[0-9,a-f]+        .*runtime/pprof/mprof_test.go:25
+#      0x[0-9,a-f]+    runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:84
 `, (1<<10)*memoryProfilerRun, (1<<20)*memoryProfilerRun),
        }, {
                stk: []string{"runtime/pprof.allocateTransient2M", "runtime/pprof.TestMemoryProfiler"},
                legacy: fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
-#      0x[0-9,a-f]+    runtime/pprof\.allocateTransient2M\+0x[0-9,a-f]+        .*runtime/pprof/mprof_test.go:30
-#      0x[0-9,a-f]+    runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:80
+#      0x[0-9,a-f]+    runtime/pprof\.allocateTransient2M\+0x[0-9,a-f]+        .*runtime/pprof/mprof_test.go:31
+#      0x[0-9,a-f]+    runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:85
 `, memoryProfilerRun, (2<<20)*memoryProfilerRun),
        }, {
                stk: []string{"runtime/pprof.allocateTransient2MInline", "runtime/pprof.TestMemoryProfiler"},
                legacy: fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
-#      0x[0-9,a-f]+    runtime/pprof\.allocateTransient2MInline\+0x[0-9,a-f]+  .*runtime/pprof/mprof_test.go:34
-#      0x[0-9,a-f]+    runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:81
+#      0x[0-9,a-f]+    runtime/pprof\.allocateTransient2MInline\+0x[0-9,a-f]+  .*runtime/pprof/mprof_test.go:35
+#      0x[0-9,a-f]+    runtime/pprof\.TestMemoryProfiler\+0x[0-9,a-f]+ .*runtime/pprof/mprof_test.go:86
 `, memoryProfilerRun, (2<<20)*memoryProfilerRun),
        }, {
                stk: []string{"runtime/pprof.allocateReflectTransient"},
                legacy: fmt.Sprintf(`0: 0 \[%v: %v\] @( 0x[0-9,a-f]+)+
-#      0x[0-9,a-f]+    runtime/pprof\.allocateReflectTransient\+0x[0-9,a-f]+   .*runtime/pprof/mprof_test.go:55
+#      0x[0-9,a-f]+    runtime/pprof\.allocateReflectTransient\+0x[0-9,a-f]+   .*runtime/pprof/mprof_test.go:56
 `, memoryProfilerRun, (2<<20)*memoryProfilerRun),
        }}
 
index 8e9732a33156e1a4798328d1d04615d86c4902a0..885f4dca5b87624814bb9577782fda766f66d43c 100644 (file)
@@ -7,6 +7,7 @@ package pprof
 import (
        "bytes"
        "fmt"
+       "internal/asan"
        "internal/profile"
        "internal/profilerecord"
        "internal/testenv"
@@ -119,6 +120,9 @@ func locationToStrings(loc *profile.Location, funcs []string) []string {
 
 // This is a regression test for https://go.dev/issue/64528 .
 func TestGenericsHashKeyInPprofBuilder(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("extra allocations with -asan throw off the test; see #70079")
+       }
        previousRate := runtime.MemProfileRate
        runtime.MemProfileRate = 1
        defer func() {
@@ -178,6 +182,9 @@ func nonRecursiveGenericAllocFunction[CurrentOp any, OtherOp any](alloc bool) {
 }
 
 func TestGenericsInlineLocations(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("extra allocations with -asan throw off the test; see #70079")
+       }
        if testenv.OptimizationOff() {
                t.Skip("skipping test with optimizations disabled")
        }
index 26cbb87fcd6c04e40ab2c44431e263b2427fadf7..f830bb7fb54661b8676942f4f6d20d4aefc4e2d5 100644 (file)
@@ -6,6 +6,8 @@ package slices_test
 
 import (
        "cmp"
+       "internal/asan"
+       "internal/msan"
        "internal/race"
        "internal/testenv"
        "math"
@@ -497,7 +499,7 @@ func TestInsert(t *testing.T) {
                }
        }
 
-       if !testenv.OptimizationOff() && !race.Enabled {
+       if !testenv.OptimizationOff() && !race.Enabled && !asan.Enabled && !msan.Enabled {
                // Allocations should be amortized.
                const count = 50
                n := testing.AllocsPerRun(10, func() {
@@ -953,7 +955,7 @@ func TestGrow(t *testing.T) {
        }
        if n := testing.AllocsPerRun(100, func() { _ = Grow(s2, cap(s2)-len(s2)+1) }); n != 1 {
                errorf := t.Errorf
-               if race.Enabled || testenv.OptimizationOff() {
+               if race.Enabled || msan.Enabled || asan.Enabled || testenv.OptimizationOff() {
                        errorf = t.Logf // this allocates multiple times in race detector mode
                }
                errorf("Grow should allocate once when given insufficient capacity; allocated %v times", n)
@@ -1314,7 +1316,7 @@ func TestConcat(t *testing.T) {
                _ = sink
                if allocs > 1 {
                        errorf := t.Errorf
-                       if testenv.OptimizationOff() || race.Enabled {
+                       if testenv.OptimizationOff() || race.Enabled || asan.Enabled || msan.Enabled {
                                errorf = t.Logf
                        }
                        errorf("Concat(%v) allocated %v times; want 1", tc.s, allocs)
index 36fd7a77e3abaa23283adeaf44aac5a098bba5e6..06cd3e3b7ab77f04a4915070356ce7825ca21219 100644 (file)
@@ -6,6 +6,7 @@ package strings_test
 
 import (
        "bytes"
+       "internal/asan"
        . "strings"
        "testing"
        "unicode/utf8"
@@ -89,6 +90,10 @@ func TestBuilderReset(t *testing.T) {
 
 func TestBuilderGrow(t *testing.T) {
        for _, growLen := range []int{0, 100, 1000, 10000, 100000} {
+               if asan.Enabled {
+                       t.Logf("skipping allocs check for growLen %d: extra allocs with -asan; see #70079", growLen)
+                       continue
+               }
                p := bytes.Repeat([]byte{'a'}, growLen)
                allocs := testing.AllocsPerRun(100, func() {
                        var b Builder
@@ -188,6 +193,9 @@ func TestBuilderWriteByte(t *testing.T) {
 }
 
 func TestBuilderAllocs(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
        // Issue 23382; verify that copyCheck doesn't force the
        // Builder to escape and be heap allocated.
        n := testing.AllocsPerRun(10000, func() {
@@ -387,6 +395,9 @@ func BenchmarkBuildString_ByteBuffer(b *testing.B) {
 }
 
 func TestBuilderGrowSizeclasses(t *testing.T) {
+       if asan.Enabled {
+               t.Skip("test allocates more with -asan; see #70079")
+       }
        s := Repeat("a", 19)
        allocs := testing.AllocsPerRun(100, func() {
                var b Builder