Skip to content

Commit 579eb79

Browse files
committed
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 <[email protected]> TryBot-Bypass: Michael Knyszek <[email protected]>
1 parent 808da68 commit 579eb79

File tree

22 files changed

+151
-26
lines changed

22 files changed

+151
-26
lines changed

src/bufio/bufio_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"bytes"
1010
"errors"
1111
"fmt"
12+
"internal/asan"
1213
"io"
1314
"math/rand"
1415
"strconv"
@@ -585,6 +586,9 @@ func TestWriteInvalidRune(t *testing.T) {
585586
}
586587

587588
func TestReadStringAllocs(t *testing.T) {
589+
if asan.Enabled {
590+
t.Skip("test allocates more with -asan; see #70079")
591+
}
588592
r := strings.NewReader(" foo foo 42 42 42 42 42 42 42 42 4.2 4.2 4.2 4.2\n")
589593
buf := NewReader(r)
590594
allocs := testing.AllocsPerRun(100, func() {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ import "C"
959959
import (
960960
"context"
961961
"fmt"
962+
"internal/asan"
962963
"math"
963964
"math/rand"
964965
"os"
@@ -1773,6 +1774,9 @@ func issue8331a() C.issue8331 {
17731774
// issue 10303
17741775

17751776
func test10303(t *testing.T, n int) {
1777+
if asan.Enabled {
1778+
t.Skip("variable z is heap-allocated due to extra allocations with -asan; see #70079")
1779+
}
17761780
if runtime.Compiler == "gccgo" {
17771781
t.Skip("gccgo permits C pointers on the stack")
17781782
}

src/cmd/compile/internal/test/issue53888_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !race
5+
//go:build !race && !asan && !msan
66

77
package test
88

src/cmd/dist/test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,8 @@ func (t *tester) registerTests() {
880880
}
881881
}
882882

883-
if t.raceDetectorSupported() {
883+
if t.raceDetectorSupported() && !t.msan && !t.asan {
884+
// N.B. -race is incompatible with -msan and -asan.
884885
t.registerRaceTests()
885886
}
886887

@@ -1090,10 +1091,18 @@ func (t *tester) internalLink() bool {
10901091
// linkmode=internal isn't supported.
10911092
return false
10921093
}
1094+
if t.msan || t.asan {
1095+
// linkmode=internal isn't supported by msan or asan.
1096+
return false
1097+
}
10931098
return true
10941099
}
10951100

10961101
func (t *tester) internalLinkPIE() bool {
1102+
if t.msan || t.asan {
1103+
// linkmode=internal isn't supported by msan or asan.
1104+
return false
1105+
}
10971106
switch goos + "-" + goarch {
10981107
case "darwin-amd64", "darwin-arm64",
10991108
"linux-amd64", "linux-arm64", "linux-ppc64le",
@@ -1232,18 +1241,22 @@ func (t *tester) registerCgoTests(heading string) {
12321241
}
12331242

12341243
// Static linking tests
1235-
if goos != "android" && p != "netbsd/arm" {
1244+
if goos != "android" && p != "netbsd/arm" && !t.msan && !t.asan {
12361245
// TODO(#56629): Why does this fail on netbsd-arm?
1246+
// TODO(#70080): Why does this fail with msan?
1247+
// asan doesn't support static linking (this is an explicit build error on the C side).
12371248
cgoTest("static", "testtls", "external", "static", staticCheck)
12381249
}
12391250
cgoTest("external", "testnocgo", "external", "", staticCheck)
1240-
if goos != "android" {
1251+
if goos != "android" && !t.msan && !t.asan {
1252+
// TODO(#70080): Why does this fail with msan?
1253+
// asan doesn't support static linking (this is an explicit build error on the C side).
12411254
cgoTest("static", "testnocgo", "external", "static", staticCheck)
12421255
cgoTest("static", "test", "external", "static", staticCheck)
12431256
// -static in CGO_LDFLAGS triggers a different code path
12441257
// than -static in -extldflags, so test both.
12451258
// See issue #16651.
1246-
if goarch != "loong64" {
1259+
if goarch != "loong64" && !t.msan && !t.asan {
12471260
// TODO(#56623): Why does this fail on loong64?
12481261
cgoTest("auto-static", "test", "auto", "static", staticCheck)
12491262
}

src/crypto/rand/rand_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"compress/flate"
1010
"crypto/internal/boring"
1111
"errors"
12+
"internal/asan"
13+
"internal/msan"
1214
"internal/race"
1315
"internal/testenv"
1416
"io"
@@ -155,8 +157,8 @@ func TestAllocations(t *testing.T) {
155157
// Might be fixable with https://go.dev/issue/56378.
156158
t.Skip("boringcrypto allocates")
157159
}
158-
if race.Enabled {
159-
t.Skip("urandomRead allocates under -race")
160+
if race.Enabled || msan.Enabled || asan.Enabled {
161+
t.Skip("urandomRead allocates under -race, -asan, and -msan")
160162
}
161163
testenv.SkipIfOptimizationOff(t)
162164

src/database/sql/convert_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package sql
77
import (
88
"database/sql/driver"
99
"fmt"
10+
"internal/asan"
1011
"reflect"
1112
"runtime"
1213
"strings"
@@ -353,6 +354,9 @@ func TestRawBytesAllocs(t *testing.T) {
353354
{"bool", false, "false"},
354355
{"time", time.Unix(2, 5).UTC(), "1970-01-01T00:00:02.000000005Z"},
355356
}
357+
if asan.Enabled {
358+
t.Skip("test allocates more with -asan; see #70079")
359+
}
356360

357361
var buf RawBytes
358362
rows := &Rows{}

src/encoding/binary/binary_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package binary
77
import (
88
"bytes"
99
"fmt"
10+
"internal/asan"
1011
"io"
1112
"math"
1213
"reflect"
@@ -710,6 +711,9 @@ func TestNoFixedSize(t *testing.T) {
710711
}
711712

712713
func TestAppendAllocs(t *testing.T) {
714+
if asan.Enabled {
715+
t.Skip("test allocates more with -asan; see #70079")
716+
}
713717
buf := make([]byte, 0, Size(&s))
714718
var err error
715719
allocs := testing.AllocsPerRun(1, func() {
@@ -745,6 +749,9 @@ var sizableTypes = []any{
745749
}
746750

747751
func TestSizeAllocs(t *testing.T) {
752+
if asan.Enabled {
753+
t.Skip("test allocates more with -asan; see #70079")
754+
}
748755
for _, data := range sizableTypes {
749756
t.Run(fmt.Sprintf("%T", data), func(t *testing.T) {
750757
// Size uses a sync.Map behind the scenes. The slow lookup path of

src/log/slog/attr_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
package slog
66

77
import (
8+
"internal/asan"
89
"internal/testenv"
910
"testing"
1011
"time"
1112
)
1213

1314
func TestAttrNoAlloc(t *testing.T) {
15+
if asan.Enabled {
16+
t.Skip("test allocates with -asan")
17+
}
1418
testenv.SkipIfOptimizationOff(t)
1519
// Assign values just to make sure the compiler doesn't optimize away the statements.
1620
var (

src/log/slog/logger_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package slog
77
import (
88
"bytes"
99
"context"
10+
"internal/asan"
11+
"internal/msan"
1012
"internal/race"
1113
"internal/testenv"
1214
"io"
@@ -644,8 +646,8 @@ func callerPC(depth int) uintptr {
644646
}
645647

646648
func wantAllocs(t *testing.T, want int, f func()) {
647-
if race.Enabled {
648-
t.Skip("skipping test in race mode")
649+
if race.Enabled || asan.Enabled || msan.Enabled {
650+
t.Skip("skipping test in race, asan, and msan modes")
649651
}
650652
testenv.SkipIfOptimizationOff(t)
651653
t.Helper()

src/log/slog/value_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package slog
66

77
import (
88
"fmt"
9+
"internal/asan"
910
"reflect"
1011
"strings"
1112
"testing"
@@ -86,6 +87,10 @@ func TestValueString(t *testing.T) {
8687
}
8788

8889
func TestValueNoAlloc(t *testing.T) {
90+
if asan.Enabled {
91+
t.Skip("test allocates more with -asan; see #70079")
92+
}
93+
8994
// Assign values just to make sure the compiler doesn't optimize away the statements.
9095
var (
9196
i int64

src/net/netip/netip_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"flag"
1111
"fmt"
12+
"internal/asan"
1213
"internal/testenv"
1314
"net"
1415
. "net/netip"
@@ -2132,6 +2133,10 @@ var (
21322133
)
21332134

21342135
func TestNoAllocs(t *testing.T) {
2136+
if asan.Enabled {
2137+
t.Skip("test allocates more with -asan; see #70079")
2138+
}
2139+
21352140
// Wrappers that panic on error, to prove that our alloc-free
21362141
// methods are returning successfully.
21372142
panicIP := func(ip Addr, err error) Addr {

src/net/udpsock_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package net
77
import (
88
"errors"
99
"fmt"
10+
"internal/asan"
1011
"internal/testenv"
1112
"net/netip"
1213
"os"
@@ -493,6 +494,9 @@ func TestAllocs(t *testing.T) {
493494
if !testableNetwork("udp4") {
494495
t.Skipf("skipping: udp4 not available")
495496
}
497+
if asan.Enabled {
498+
t.Skip("test allocates more with -asan; see #70079")
499+
}
496500

497501
// Optimizations are required to remove the allocs.
498502
testenv.SkipIfOptimizationOff(t)

src/reflect/all_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"flag"
1111
"fmt"
1212
"go/token"
13+
"internal/asan"
1314
"internal/goarch"
1415
"internal/goexperiment"
1516
"internal/testenv"
@@ -1278,6 +1279,9 @@ func TestDeepEqualAllocs(t *testing.T) {
12781279
if goexperiment.SwissMap {
12791280
t.Skipf("Maps on stack not yet implemented")
12801281
}
1282+
if asan.Enabled {
1283+
t.Skip("test allocates more with -asan; see #70079")
1284+
}
12811285

12821286
for _, tt := range deepEqualPerfTests {
12831287
t.Run(ValueOf(tt.x).Type().String(), func(t *testing.T) {
@@ -7353,6 +7357,9 @@ func TestPtrToMethods(t *testing.T) {
73537357
}
73547358

73557359
func TestMapAlloc(t *testing.T) {
7360+
if asan.Enabled {
7361+
t.Skip("test allocates more with -asan; see #70079")
7362+
}
73567363
m := ValueOf(make(map[int]int, 10))
73577364
k := ValueOf(5)
73587365
v := ValueOf(7)
@@ -7383,6 +7390,9 @@ func TestMapAlloc(t *testing.T) {
73837390
}
73847391

73857392
func TestChanAlloc(t *testing.T) {
7393+
if asan.Enabled {
7394+
t.Skip("test allocates more with -asan; see #70079")
7395+
}
73867396
// Note: for a chan int, the return Value must be allocated, so we
73877397
// use a chan *int instead.
73887398
c := ValueOf(make(chan *int, 1))
@@ -7745,11 +7755,14 @@ func TestMapIterReset(t *testing.T) {
77457755
}
77467756

77477757
// Reset should not allocate.
7758+
//
7759+
// Except with -asan, where there are additional allocations.
7760+
// See #70079.
77487761
n := int(testing.AllocsPerRun(10, func() {
77497762
iter.Reset(ValueOf(m2))
77507763
iter.Reset(Value{})
77517764
}))
7752-
if n > 0 {
7765+
if !asan.Enabled && n > 0 {
77537766
t.Errorf("MapIter.Reset allocated %d times", n)
77547767
}
77557768
}

src/runtime/arena.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,8 @@ func newUserArenaChunk() (unsafe.Pointer, *mspan) {
798798

799799
if asanenabled {
800800
// TODO(mknyszek): Track individual objects.
801-
rzSize := redZoneSize(span.elemsize)
802-
span.elemsize -= rzSize
803-
span.largeType.Size_ = span.elemsize
801+
// N.B. span.elemsize includes a redzone already.
804802
rzStart := span.base() + span.elemsize
805-
span.userArenaChunkFree = makeAddrRange(span.base(), rzStart)
806803
asanpoison(unsafe.Pointer(rzStart), span.limit-rzStart)
807804
asanunpoison(unsafe.Pointer(span.base()), span.elemsize)
808805
}
@@ -1067,6 +1064,11 @@ func (h *mheap) allocUserArenaChunk() *mspan {
10671064
s.freeindex = 1
10681065
s.allocCount = 1
10691066

1067+
// Adjust size to include redzone.
1068+
if asanenabled {
1069+
s.elemsize -= redZoneSize(s.elemsize)
1070+
}
1071+
10701072
// Account for this new arena chunk memory.
10711073
gcController.heapInUse.add(int64(userArenaChunkBytes))
10721074
gcController.heapReleased.add(-int64(userArenaChunkBytes))

src/runtime/debug_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ package runtime_test
1616
import (
1717
"fmt"
1818
"internal/abi"
19+
"internal/asan"
20+
"internal/msan"
1921
"math"
2022
"os"
2123
"regexp"
@@ -32,6 +34,14 @@ func startDebugCallWorker(t *testing.T) (g *runtime.G, after func()) {
3234
// a debugger.
3335
skipUnderDebugger(t)
3436

37+
// asan/msan instrumentation interferes with tests since we might
38+
// inject debugCallV2 while in the asan/msan runtime. This is a
39+
// problem for doing things like running the GC or taking stack
40+
// traces. Not sure why this is happening yet, but skip for now.
41+
if msan.Enabled || asan.Enabled {
42+
t.Skip("debugCallV2 is injected erroneously during asan/msan runtime calls; skipping")
43+
}
44+
3545
// This can deadlock if there aren't enough threads or if a GC
3646
// tries to interrupt an atomic loop (see issue #10958). Execute
3747
// an extra GC to ensure even the sweep phase is done (out of

src/runtime/gc_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package runtime_test
66

77
import (
88
"fmt"
9+
"internal/asan"
910
"math/bits"
1011
"math/rand"
1112
"os"
@@ -208,6 +209,9 @@ func TestGcZombieReporting(t *testing.T) {
208209
}
209210

210211
func TestGCTestMoveStackOnNextCall(t *testing.T) {
212+
if asan.Enabled {
213+
t.Skip("extra allocations with -asan causes this to fail; see #70079")
214+
}
211215
t.Parallel()
212216
var onStack int
213217
// GCTestMoveStackOnNextCall can fail in rare cases if there's
@@ -298,6 +302,9 @@ var pointerClassBSS *int
298302
var pointerClassData = 42
299303

300304
func TestGCTestPointerClass(t *testing.T) {
305+
if asan.Enabled {
306+
t.Skip("extra allocations cause this test to fail; see #70079")
307+
}
301308
t.Parallel()
302309
check := func(p unsafe.Pointer, want string) {
303310
t.Helper()

0 commit comments

Comments
 (0)