aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2024-10-28 17:23:40 +0000
committerMichael Knyszek <mknyszek@google.com>2024-10-28 21:04:51 +0000
commit579eb79f62d92db872d730f5fe954ca2b7dce8ae (patch)
treeed7e1a415490d4e0d8a44c8e35f7c5728b812479 /src/runtime
parent808da68c1c66e05a04a7d4bc046f27811711d7ff (diff)
downloadgo-579eb79f62d92db872d730f5fe954ca2b7dce8ae.tar.xz
all: skip and fix various tests with -asan and -msan
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>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/arena.go10
-rw-r--r--src/runtime/debug_test.go10
-rw-r--r--src/runtime/gc_test.go7
-rw-r--r--src/runtime/malloc_test.go7
-rw-r--r--src/runtime/mfinal_test.go7
-rw-r--r--src/runtime/pprof/mprof_test.go23
-rw-r--r--src/runtime/pprof/protomem_test.go7
7 files changed, 58 insertions, 13 deletions
diff --git a/src/runtime/arena.go b/src/runtime/arena.go
index ff59014a8a..ab876dd21f 100644
--- a/src/runtime/arena.go
+++ b/src/runtime/arena.go
@@ -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))
diff --git a/src/runtime/debug_test.go b/src/runtime/debug_test.go
index 0ee873d43f..37093cd87e 100644
--- a/src/runtime/debug_test.go
+++ b/src/runtime/debug_test.go
@@ -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
diff --git a/src/runtime/gc_test.go b/src/runtime/gc_test.go
index 63ccbeb328..4faade50e8 100644
--- a/src/runtime/gc_test.go
+++ b/src/runtime/gc_test.go
@@ -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()
diff --git a/src/runtime/malloc_test.go b/src/runtime/malloc_test.go
index 8c162fbea4..67bceef2e3 100644
--- a/src/runtime/malloc_test.go
+++ b/src/runtime/malloc_test.go
@@ -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.
diff --git a/src/runtime/mfinal_test.go b/src/runtime/mfinal_test.go
index 87d31c472c..5c93c74cfb 100644
--- a/src/runtime/mfinal_test.go
+++ b/src/runtime/mfinal_test.go
@@ -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
diff --git a/src/runtime/pprof/mprof_test.go b/src/runtime/pprof/mprof_test.go
index ef373b3684..7c4a37e3c9 100644
--- a/src/runtime/pprof/mprof_test.go
+++ b/src/runtime/pprof/mprof_test.go
@@ -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),
}}
diff --git a/src/runtime/pprof/protomem_test.go b/src/runtime/pprof/protomem_test.go
index 8e9732a331..885f4dca5b 100644
--- a/src/runtime/pprof/protomem_test.go
+++ b/src/runtime/pprof/protomem_test.go
@@ -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")
}